How can I create a foreach loop with "Foreach From Variable Enumerator" in SSIS programmatically - ssis

I'm trying to create an SSIS package dynamically using DTS Runtime classes.
I'm trying to create a foreach loop using "Foreach From Variable Enumerator", where my variable contains an ArrayList with the necessary collection.
I'm unable to find a way through which i can set the variable (under enumerator configuration, as seen in VS) which will hold the collection for looping.
I'm not finding any options in forEachLoop.ForEachEnumerator. Nor am I able to cast forEachEnumeratorHost.InnerObject to an enumerator I want. I found on MSDN a class Microsoft.SqlServer.Dts.Runtime.Enumerators.FromVar.ForEachFromVarEnumerator. But I'm not able to find the FromVar class in Enumerators. Am i missing something grave?
Has anyone else done this? I find it difficult to believe that something which can be done so easily through Visual Studio UI, cannot be done programmatically.
Below is the code I have now...
ForEachLoop forEachLoop = p.Executables.Add("STOCK:FOREACHLOOP") as
ForEachLoop;
// Create a VariableMappings and VariableMapping objects.
ForEachVariableMapping forEachVariableMapping =
forEachLoop.VariableMappings.Add();
// Create a mapping between the variable and its value.
forEachVariableMapping.VariableName = #"User::CurrentTableName";
forEachVariableMapping.ValueIndex = 0;
ForEachEnumeratorInfo forEachEnumeratorInfo =
runtimeApp.ForEachEnumeratorInfos["Foreach From Variable Enumerator"];
ForEachEnumeratorHost forEachEnumeratorHost =
forEachEnumeratorInfo.CreateNew();

You are almost there...I think you are forgetting to set the ForEachEnumerator property of the forEachLoop object.
ForEachLoop forEachLoop = p.Executables.Add("STOCK:FOREACHLOOP") as ForEachLoop;
ForEachEnumeratorInfo forEachEnumeratorInfo = runtimeApp.ForEachEnumeratorInfos["Foreach From Variable Enumerator"];
ForEachEnumeratorHost forEachEnumeratorHost = forEachEnumeratorInfo.CreateNew();
//forEachEnumeratorHost.CollectionEnumerator = false; // true or false; set accordingly.
// cast the inner object to ForEachFromVarEnumerator
ForEachFromVarEnumerator = forEachEnumeratorHost.InnerObject as ForEachFromVarEnumerator;
// Now that you have the ForEachFromVarEnumerator, set its properties.
// For variable name, do not forget the variable's name space and the variable name (separated by ::)
ForEachFromVarEnumerator.VariableName = "var_namespace" + "::" + "var_name";
// finally.....
forEachLoop.ForEachEnumerator = forEachEnumeratorHost; // DO NOT FORGET THIS. Here you are setting what the actual enumerator would be

You can do like this:
Script task
Make sure MyList variable is Writeable
ArrayList NewList = new ArrayList();
NewList.Add("Ost");
NewList.Add("Hest");
Dts.Variables["User::MyList"].Value = NewList;
Dts.TaskResult = (int)ScriptResults.Success;

The first step is
Add an assembly reference to Microsoft.SqlServer.ForEachFromVarEnumerator.dll and then one can get access to the Microsoft.SqlServer.Dts.Runtime.Enumerators.FromVar.ForEachFromVarEnumerator class.
And then the rest of the answer is exactly what #Sam has mentioned above.

Related

Set data in UNB segment EDIFACT

Do you know how I can set UNB in EDIFACT?
I have a CSV input file:
VRD1;100;200;0;0;L
And the output should be:
UNA:+.? '
UNB+UNOA:2+100:14+200:14+200305:0704+00000000000000++AAA'
UNH+1+INVRPT:D:96A:UN:EAN005'
BGM+10::9+20200305070403+9
I have to map the second and third fields to UNB.
I appreciate any help in this regard. Thank you in advance.
You should be able to do this using the EdiOverride message context properties. You can find them in the Microsoft.BizTalk.Edi.BaseArtifacts assembly found in the BizTalk Server installation folder.
For instance, in an orchestration, you can do this:
EdifactMessage(EdiOverride.OverrideEDIHeader) = true;
EdifactMessage(EdiOverride.UNB2_1) = xpath(CsvMessage, ...); // 100
EdifactMessage(EdiOverride.UNB3_1) = xpath(CsvMessage, ...); // 200
Add a correlation set with the same properties to your send shape.
If you want to set them in a pipeline, use the property namespace http://schemas.microsoft.com/BizTalk/2006/edi-properties.

AS3: Getting values of objects by referencing their name

I'm reading XML and attaching values to objects in two seperate movieclips. Like this
Map01:
Marker01.name = hello there
Marker01.short = hel
Marker01.value = 12
Map02:
Marker02.name = hello there
Marker02.short = hel
Marker02.value = 99
Now I'm clicking on Marker01 in Map01 and get its name and value. I want to compare its value to that of Marker01 in Map02, using the name, or better yet .short because the names are long and use special characters/spaces. How do I do this? I've pretty much tried everything that seemed logical!
EDIT: sample code for clarification
var marker01:mc_marker = new mc_marker();
marker01.name="hello there";
marker01.short="abc";
marker01.val="99";
marker01.x=10;
marker01.y=10;
this.mc_map01.addChild(marker01);
var marker02:mc_marker = new mc_marker();
marker02.name="hello there";
marker02.short="abc";
marker02.val="20";
marker02.x=10;
marker02.y=10;
this.mc_map02.addChild(marker02);
marker01.addEventListener(MouseEvent.MOUSE_UP, showMarkerInfo);
marker02.addEventListener(MouseEvent.MOUSE_UP, showMarkerInfo);
function showMarkerInfo(event:MouseEvent):void {
txt_ms.text=event.target.short;
txt_mv.text=event.target.val;
if (event.target.short==mc_map02.marker02.short){
txt_mvi.text="here should be the marker02 value";
}
}
You have a typo there. Map02 use Marker1 things.
If its a typo in Stackoverflow,
this.getChildByName( "Marker01" ) will return you the movieclip, buy its name. take care though, as "name" is what it searches for. You used "hello there" when you should put Marker01 as the name. I would suggest you put a property called "data" and put the xml info in it so it doesn't conflict.
In the end you have:
if( this.getChildByName( "Marker01" ).data.value == this.getChildByName( "Marker02" ).data.value ).
I assume this is because you generate Marker0X at runtime and you can't declare some variables and use them directly.
Browny points if you make "data" a instance of a custom class where you can compare two "data". If you need more help, add a comment ^_^

Splice then re-index array in ActionScript 3

I want to remove the first four indexes from the array using splice(), then rebuild the array starting at index 0. How do I do this?
Array.index[0] = 'one';
Array.index[1] = 'two';
Array.index[2] = 'three';
Array.index[3] = 'four';
Array.index[4] = 'five';
Array.index[5] = 'six';
Array.index[6] = 'seven';
Array.index[7] = 'eight';
Array.splice(0, 4);
Array.index[0] = 'five';
Array.index[1] = 'six';
Array.index[2] = 'seven';
Array.index[3] = 'eight';
I am accessing the array via a timer, on each iteration I want to remove the first four indexes of the array. I assumed splice() would remove the indexes then rebuild the array starting at 0 index. it doesn't, so instead what I have done is created a 'deleteIndex' variable, on each iteration a +4 is added to deleteIndex.
var deleteIndex:int = 4;
function updateTimer(event:TimerEvent):void
{
Array.splice(0,deleteIndex);
deleteIndex = deleteIndex + 4;
}
What type of object is "Array" in the code you have shown? The Flash Array object does not have a property named "index". The Array class is dynamic, which means that it let's you add random properties to it at run time (which seems to be what you are doing).
In any case, if you are using the standard Flash Array class, it's splice() method updates the array indexes automatically. Here is a code example that proves it:
var a:Array = [1,2,3,4,5];
trace("third element: ", a[2]); // output: 3
a.splice(2,1); // delete 3rd element
trace(a); // output: 1,2,4,5
trace(a.length); // ouput: 4
trace("third element: ", a[2]); // output: 4
If I am understanding what you want correctly, you need to use the unshift method of Array.
example :
var someArray:Array = new Array(0,1,2,3,4,5,6,7,8);
someArray.splice(0,4);
somearray.unshift(5,6,7,8);
Also, you are using the Array Class improperly, you need to create an instance of an array to work with first.
The question is confusing because you used Array class name instead of an instance of an array. But as the commenter on this post said, if you splice elements, it automatically re-indexes.
im not sure what you want to do, but Array=Array.splice(0,4) should fix somethin..

Add a new property to an object stored with scriptDB

I created a database (scriptDB) and have stored information (more than 40 properties of about 600 people-students-).
var obj = {
alumne_id: email,
alumne_ordre: nomsencer_ordre,
alumne_timestamp: {created: new Date (). getTime (), changed:'', editor: 'unedited'},
alumne_nom: {nom: nomREAD, cognom1: cognom1READ, cognom2: cognom2READ, cognoms: cognomsREAD, nomsencer: nomsencerREAD},
(...)
}
 
I stored this object in my database:
var stored = db.save(ob);
I defined thus, properties of objects and have my stored. This works perfectly and update data, for example, change "alumne_nom.nom" to a new value: 'Joana'
Now I want to add new properties to all or some of these objects (students).
The problem is that I can add a property as
newproperty1
with:
stored.newproperty1 = '50 '
But I can not do:
stored.newproperty1.sub1
stored.newproperty1.sub2
stored.newproperty1.sub3
Does anyone know how I can add these subproperties?
To add "subproperties" you need to first define the property. You can do it by setting an empty object to it, e.g.
stored.newproperty1 = {};
//then all subs should work
stored.newproperty1.sub1 = 10;
You could already pass the subs definitions on the braces as you do with the object as well:
stored.newproperty1 = {sub1:10, sub2:20, etc:'value'};

Dynamic variables in ActionScript 3.0

so.... eval() out of the question, any idea to do this? I also don't know how to use "this" expression or set() in actionscript 3 ( i seem couldn't find any complete reference on it ), just say through php file a multiple variable (test1, test2, test3,...) sent by "echo", how the flash aplication recieved it? I'm trying not to use xml on mysql to php to flash aplication. Simply how to change a string to a variable ?
example
(in as3-actions frame panel)
function datagridfill(event:MouseEvent):void{
var varfill:URLVariables = new URLVariables();
varfill.tell = "do it";
var filler:URLRequest = new URLRequest();
filler.url = "http://127.0.0.1/flashdbas3/sendin.php";
filler.data = varfill;
var filling:URLLoader = new URLLoader();
filling.dataFormat = URLLoaderDataFormat.VARIABLES;
filling.load(filler);
filling.addEventListener(Event.COMPLETE, datain);
function datain(evt:Event){
var arraygrid:Array = new Array();
testing.text = evt.target.Name2 // worked
// just say i = 1
i=1;
arraygrid.push({Name:this["evt.target.Name"+i],
Test:this.["evt.target.Test"+i]}); // error
//or
arraygrid.push({Name:this["Name"+i],
Test:this.["Test"+i]}); // error too
// eval() noexistent, set() didn't worked on actions frame panel
//?????
}
};
I hope it's very clear.
You could use this[varName] if I understand your question right.
So if varName is a variable containing a string which should be a variables name, you could set and read that variable like this:
this[varName] = "someValue";
trace(this[varName]);
Update:
In your example, you could try: evt.target["Test"+i] instead of Test:this.["evt.target.Test"+i]
If you have a set of strings that you'd like to associate with values, the standard AS3 approach is to use an object as a hash table:
var o = {}
o["test1"] = 7
o["test2"] = "fish"
print(o["test1"])