Is there a way to either create a new Environment Variable from within a WF 4.0 workflow or update an existing one if it already exists?
You can set a enviroment variable inside an code activity.
You can use the System.Activities.Statements.InvokeMethod activity to call the System.Environment.SetEnvironmentVariable static method.
In the Parameters setting, you'll need to pass 2 'In' parameters. The first will be the name of your environment variable, the 2nd will be the value.
Related
I have a single Rails application that is currently being accessed via lets say https://www.domain1.com and I would like to enable the application to be accessed by a second domain, lets say https://www.domain2.com which would then set a global instance variable.
I would then like to use this instance variable to control certain things on the page such as content, styles and images.
Any ideas how I could achieve this?
E.g.
def my_action
#domain_instance_variable = request.domain
$domain_global_variable = request.domain
end
A global variable and an instance variable are different things. An instance variable is scoped to an instance of a class, and a global variable has a global scope. It's a good rule of thumb to minimize scope.
In the case of Rails code in controllers, views or helpers, you can just call request.domain directly instead of assigning that to a variable.
I know how we can declare global variable in config file and then access through
Service Locator
Currently I am getting this Global variable in controller with the help of service locator and then pass it to models while creating object.
Question: Is it possible that I can get the Global variable in model directly rather than passing in all the models through controller?
Yes it is possible to get the variable declared in global file into model directly. Instead of declaring it as variable, just define it as constant in the global file so that you can access that variable easily in any models.
define('VAR_NAME',Value);
and access the variable using.
constant('VAR_NAME');
Hope it helps
Thanks
What is the difference between using a local variable, an instance variable, and one created with the 'let' method inside RSpec tests?
Using a let is the best choice if you need to reuse the variable, otherwise a local variable may make more sense. But you can decide for yourself given the differences:
Local variable
Only accessible from within one test, i.e. it cannot be reused.
Instance variable
Accessible from all tests within the example group. Assigned and evaluated on every test run in example group.
Let
Accessible from all tests within the example group. Lazily evaluated so it is only created (and the code to create it) when it is actually used in a test.
A let may still make sense instead of a local variable if the variable logically belongs to a context or describe block rather than an individual test—but that's preference based on test structure.
can i change the value of parameter in called target and then retrieve it in the calling target in ant.Probably By refid if there is any other way that is appreciated.
Normally you cannot modify an ant property in ant once it's set, but as oers pointed out in a comment, you can use the Variable task in ant-contrib. You can even override an existing property with a Variable. According to the documentation, you should still use properties in most cases, and only use variables in the cases where you really need to be able to modify a value.
Another workaround is to set additional properties and call the other targets using those properties.
I need a global variable that I can call from the templates.
I edited app_globals.py in lib directory to declare PATH_TO_IMAGES like this
class Globals(object):
"""Container for objects available throughout the life of the application.
One instance of Globals is created during application initialization and
is available during requests via the 'app_globals' variable.
"""
PATH_TO_IMAGES = ""
def __init__(self):
"""Do nothing, by default."""
pass
Now I can call from any template the image path like this
<img src="${g.PATH_TO_IMAGES}/${p.image}" />
The image path is stored inside a settings table on the app's database, but I can't initialize it from Globals declaration, i get this error:
sqlalchemy.exc.UnboundExecutionError:
Could not locate a bind configured on
mapper
Mapper|Settings|settings,
SQL expression or this Session
My guess is that database binding happens after Globals is initialized. So my questions is, which is the best place to initialize a global variable in TurboGears 2 and which is the best practice to that.
Just use a cached property:
class Globals(object):
"""Container for objects available throughout the life of the application.
One instance of Globals is created during application initialization and
is available during requests via the 'app_globals' variable.
"""
#property
def PATH_TO_IMAGES(self):
try:
return self._path_to_images
except AttributeError:
self._path_to_images = db_session.query(XXX) # Fill in your query here
return self._path_to_images
PS : your question is a generic Python question really. I suggest you read the official Python docs before posting other similar questions.
You probably need to create your own database connection to get this data from the database.
In SQLAlchemy terms, you'll want to create your own engine, session, etc. Just make sure to clean up after you're done.
I would probably do this in app_cfg.py using on_startup to get it into the config, and then stick it in the Globals object later on if you still need to.
You may set PATH_TO_IMAGES to it's definite value once the models are initialized. The sooner being at the end of the 'init_model' function declared in model/init.py.