I am trying to read a package variable during design-time. I am able to do it during run-time fairly easily:
IDTSVariables variables = null;
pipelineComponent.VariableDispenser.LockForRead("MyVariable");
pipelineComponent.VariableDispenser.GetVariables(out variables);
But during design-time, I don't have a PipelineComponent and I can't find any object that will give me a VariableDispenser.
I've looked at the IDtsVariableService class, but it appears to only provide a helper UI to facilitate the creation of new variables -- I want to read an existing variable.
Turns out I was close, it was the IDtsPipelineEnvironmentService class:
Variables vars = null;
IDtsPipelineEnvironmentService pipelineService = (IDtsPipelineEnvironmentService)serviceProvider_.GetService(typeof(IDtsPipelineEnvironmentService));
pipelineService.PipelineTaskHost.VariableDispenser.LockForRead("VARIABLE_NAME");
pipelineService.PipelineTaskHost.VariableDispenser.GetVariables(ref vars);
VARIABLE = vars[0].Value.ToString();
vars.Unlock();
Probably, the following link might help you.
Accessing Variables in SSIS code
Related
I implementing basic library to deal with Windows Firewall API.
I faced with strange result with INetFwPolicy2::ExcludedInterfaces property.
I set excluded interface via Firewall.cpl and when read property I got array of some guids. I am not sure from where this GUID come. It is not Interface GUID. I select all interfaces from Win32_NetworkAdapter and there no such GUID.
Also when I try assign this value back I got invalid argument or not found errors.
This code based on msdn example written on on VBS, but it really does not matter I have same error on C. Original example did not works either.
Const NET_FW_PROFILE2_PRIVATE = 2
Set fwPolicy2 = CreateObject("HNetCfg.FwPolicy2")
CurrentProfiles = fwPolicy2.CurrentProfileTypes
if ( CurrentProfiles AND NET_FW_PROFILE2_PRIVATE ) then
InterfaceArray = fwPolicy2.ExcludedInterfaces(NET_FW_PROFILE2_PRIVATE)
if (IsEmpty(InterfaceArray)) then
WScript.Echo( "InterfaceArray is Empty" )
else
WScript.Echo( Join(InterfaceArray) )
end if
fwPolicy2.ExcludedInterfaces(NET_FW_PROFILE2_PRIVATE) = InterfaceArray
end if
Check your csproj file xml in your executing assembly (not necessarily the assembly that uses windows-firewall-api if it is referenced). For each configuration there is a <PropertyGroup> tag, and each should have a child tag <Prefer32Bit>false</Prefer32Bit> (or at least the one that you compile with).
Background
I'm trying to create a function componentFromJson that can reconstitute a component graph from JSON. I took a simple approach where I'm using getMetaData in order to lookup the component properties to instantiate the right types.
The function would be used like: comp = componentFromJson(json, 'RootComponentType')
Problem
The problem is that the type of the properties are not necessarily fully qualified because namespaces may have been imported, as we can see below.
<cfimport path="some.namespace.Test">
<cfcomponent>
<cfproperty name="test" type="Test">
</cfcomponent>
When I'm trying to do createObject('Test') from the componentFromJson function context it's obviously failing because the calling context doesn't have the imports.
I have tried many different ways to resolve the problem, including temporarily defining the component factory function on the parent component dynamically and using invoke to call the factory function in the context of the parent CFC, but it doesn't work.
E.g.
<cfscript>
parentCmp = createObject('SomeCmp');
parentCmp.createComponent = function (type) {
return createObject(type);
};
childCmp = invoke(parentCmp, 'createComponent', { type = 'Test' });
</cfscript>
Horrible solution
The only way I can think of solving this issue right now is to parse the ColdFusion code of the CFC and extract the import statements, but I'm expecting this to be way too slow for the purpose. Not only that but this wouldn't cover all edge cases.
Ideas?
I'd like to know if someone has a better idea for solving this issue? Is there an entirely different approach I could take? There is probably a way to do this using the ColdFusion runtime classes, but I haven't figured it out yet.
Well, it turns out that it wasn't so hard when you knew the underlying mechanics of the ColdFusion runtime (which I had trouble to find initially).
I finally discovered that a ColdFusion component, which is represented as a coldfusion.runtime.TemplateProxy was encapsulating a coldfusion.runtime.CFPage instance which in turns has a createObject method.
Therefore, here's the solution I came up with using Java reflection:
<cfset host = new SomeComponent()>
<cfset pageField = createObject('java', 'coldfusion.runtime.TemplateProxy').getClass().getDeclaredField('page')>
<cfset pageField.setAccessible(true)>
<cfset page = pageField.get(host)>
<cfset test = page.createObject('Test')>
Do you know how to use dynamic/chained variables inside a controller variable definition?
I have created this plnkr to further outline what I am trying to achieve: http://plnkr.co/edit/xOjhf8b7ZIxVhc1Id3xo
In the NodeCtrl, I am trying to dynamically access a node from a json object and I can't find the correct syntax to write out the chain.
I have tried a number of combinations but haven't found the correct way yet:
//var jsonChunk = "data." + $scope.transcendType;
$scope.tabinventory = data.$scope.transcendType;
//data;
//jsonChunk;
//function() { return "data." + $scope.transcendType; };
alert($tabinventory[0].title)
//alert($scope.tabinventory.project[0].title);
Any help you could provide would be greatly appreciated.
All the best,
Ben
Have you tried logging $scope.transcendType to make sure it's properly defined in that context?
Assuming it's properly defined, try data[$scope.transcendType].
I created variable with datatype object and created property for this object and asignt value to it.
var tileModel : Object = new Object();
tileModel.property = 10;
But I got warning in FDT Ide. Could not resolve variable (may be a dynamic member)
I have found that possibly solution might be use /*FDT_IGNORE*/ but I would rather solve it some clasic way.
Thank you for every answer
Use array notation as follows:
tileModel["property"] = 10;
To not have FDT flag this as an error, you'll need to adjust the parser to ignore it.
See screenshot:
I'm going back to the basics here but in Lua, you can define a table like so:
myTable = {}
myTable [1] = 12
Printing the table reference itself brings back a pointer to it. To access its elements you need to specify an index (i.e. exactly like you would an array)
print(myTable ) --prints pointer
print(myTable[1]) --prints 12
Now functions are a different story. You can define and print a function like so:
myFunc = function() local x = 14 end --Defined function
print(myFunc) --Printed pointer to function
Is there a way to access the body of a defined function. I am trying to put together a small code visualizer and would like to 'seed' a given function with special functions/variables to allow a visualizer to 'hook' itself into the code, I would need to be able to redefine the function either from a variable or a string.
There is no way to get access to body source code of given function in plain Lua. Source code is thrown away after compilation to byte-code.
Note BTW that function may be defined in run-time with loadstring-like facility.
Partial solutions are possible — depending on what you actually want to achieve.
You may get source code position from the debug library — if debug library is enabled and debug symbols are not stripped from the bytecode. After that you may load actual source file and extract code from there.
You may decorate functions you're interested in manually with required metadata. Note that functions in Lua are valid table keys, so you may create a function-to-metadata table. You would want to make this table weak-keyed, so it would not prevent functions from being collected by GC.
If you would need a solution for analyzing Lua code, take a look at Metalua.
Check out Lua Introspective Facilities in the debugging library.
The main introspective function in the
debug library is the debug.getinfo
function. Its first parameter may be a
function or a stack level. When you
call debug.getinfo(foo) for some
function foo, you get a table with
some data about that function. The
table may have the following fields:
The field you would want is func I think.
Using the debug library is your only bet. Using that, you can get either the string (if the function is defined in a chunk that was loaded with 'loadstring') or the name of the file in which the function was defined; together with the line-numbers at which the function definition starts and ends. See the documentation.
Here at my current job we have patched Lua so that it even gives you the column numbers for the start and end of the function, so you can get the function source using that. The patch is not very difficult to reproduce, but I don't think I'll be allowed to post it here :-(
You could accomplish this by creating an environment for each function (see setfenv) and using global (versus local) variables. Variables created in the function would then appear in the environment table after the function is executed.
env = {}
myFunc = function() x = 14 end
setfenv(myFunc, env)
myFunc()
print(myFunc) -- prints pointer
print(env.x) -- prints 14
Alternatively, you could make use of the Debug Library:
> myFunc = function() local x = 14 ; debug.debug() end
> myFunc()
> lua_debug> _, x = debug.getlocal(3, 1)
> lua_debug> print(x) -- prints 14
It would probably be more useful to you to retrieve the local variables with a hook function instead of explicitly entering debug mode (i.e. adding the debug.debug() call)
There is also a Debug Interface in the Lua C API.