Trying to get around lack of looping in scripts Hi,<br>As discussed in this thread: <a href="http://social.msdn.microsoft.com/Forums/en-US/liveframework/thread/10e19310-9eba-43e2-b70e-8ac44132cb79">http://social.msdn.microsoft.com/Forums/en-US/liveframework/thread/10e19310-9eba-43e2-b70e-8ac44132cb79</a> there is no looping construct in the scripting language and its preventing me from doing what I want to do. Namely I'm trying to copy a collection of resources from the web into a meshObject - the difficulty comes in that the number of resources is arbitrary.<br><br>The furthest I've got is to create the MeshObject and its feed and the I'm using the following code to attempt to upload each resource (seperate script for each resource):<br><br> <div style="border-right:#7f9db9 1px solid;border-top:#7f9db9 1px solid;font-size:11px;overflow:auto;border-left:#7f9db9 1px solid;line-height:100%! important;border-bottom:#7f9db9 1px solid;font-family:Courier New;background-color:white"> <table style="border-top-width:0px;border-left-width:0px;margin:2px 0px;width:99%;border-bottom:#eee 0px solid;border-collapse:collapse;background-color:#fff;border-right-width:0px" cellspacing=0 cellpadding=0> <colgroup> <col style="padding-left:10px;font-size:11px;border-bottom:#f7f7f7 1px solid;font-family:Courier New;white-space:nowrap"> <tbody> <tr> <td><font style="font-size:11px">ResourceScript&lt;SequenceStatement&gt; script2 = Statement.Sequence(  </font></td></tr> <tr> <td style="background-color:#f7f7f7">                    Statement.CreateMediaResource&lt;DataEntryResource&gt;(  </td></tr> <tr> <td>                        tweetTitle, </font><font style="color:blue">null</font><font style="font-size:11px">, tweet, Statement.Bind(  </font></td></tr> <tr> <td style="background-color:#f7f7f7">                            </font><font style="color:blue">&quot;CollectionUrl&quot;</font><font style="font-size:11px">, </font><font style="color:blue">&quot;feedHandle&quot;</font><font style="font-size:11px">, </font><font style="color:blue">&quot;Response.MediaResourcesLink&quot;</font><font style="font-size:11px">)  </font></td></tr> <tr> <td>                        )  </td></tr> <tr> <td style="background-color:#f7f7f7">                    ).Compile(); </td></tr></tbody></table></div><br><br>&quot;feedHandle&quot; is how I referred to the feed when I created it but of course it means nothing in this because its a different script. Naturally it fails with error:<br><br>System.InvalidOperationException was unhandled<br>  Message=&quot;Validation Errors were found:\nerror 0: Microsoft.LiveFX.ResourceModel.Scripting.PropertyBinding. -- Statement 'feedHandle' specified as source of binding for statement '-1969758866' cound not be found.\n&quot;<br>  Source=&quot;Microsoft.LiveFX.ResourceModel&quot;<br>  StackTrace:<br>       at Microsoft.LiveFX.ResourceModel.Scripting.Statement.Compile(Statement statement)<br>       at Microsoft.LiveFX.ResourceModel.Scripting.SequenceStatement.Compile()<br>       at Exploring_scripts.Program.CreateMeshFolderUsingScript(String user, String pwd, String uriRoot, String[] tweetsIDs) in C:\Documents and Settings\jamie\My Documents\Visual Studio 2008\Projects\Mesh Investigation\Exploring scripts\Program.cs:line 89<br>       at Exploring_scripts.Program.Main(String[] args) in C:\Documents and Settings\jamie\My Documents\Visual Studio 2008\Projects\Mesh Investigation\Exploring scripts\Program.cs:line 22<br>       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)<br>       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)<br>       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()<br>       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)<br>       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)<br>       at System.Threading.ThreadHelper.ThreadStart()<br>  InnerException: <br><br><br>So, I'm completely stumped. The thread I linked to earlier suggested building the script source dynamically but I haven't a clue how to create a script object out of that.<br><br>Any suggestions would be welcomed.<br><br>Thanks<br>Jamie<br><hr size="1" align="left" width="25%"><a href="http://jamiethomson.spaces.live.com/">http://jamiethomson.spaces.live.com/</a> | <a href="http://blogs.conchango.com/jamiethomson">http://blogs.conchango.com/jamiethomson</a>© 2009 Microsoft Corporation. All rights reserved.Mon, 30 Mar 2009 18:51:13 Z9f43d49a-547e-44aa-b0f8-91c581a87111http://social.msdn.microsoft.com/Forums/en-US/liveframework/thread/9f43d49a-547e-44aa-b0f8-91c581a87111#9f43d49a-547e-44aa-b0f8-91c581a87111http://social.msdn.microsoft.com/Forums/en-US/liveframework/thread/9f43d49a-547e-44aa-b0f8-91c581a87111#9f43d49a-547e-44aa-b0f8-91c581a87111Jamie Thomsonhttp://social.msdn.microsoft.com/Profile/en-US/?user=Jamie%20ThomsonTrying to get around lack of looping in scripts Hi,<br>As discussed in this thread: <a href="http://social.msdn.microsoft.com/Forums/en-US/liveframework/thread/10e19310-9eba-43e2-b70e-8ac44132cb79">http://social.msdn.microsoft.com/Forums/en-US/liveframework/thread/10e19310-9eba-43e2-b70e-8ac44132cb79</a> there is no looping construct in the scripting language and its preventing me from doing what I want to do. Namely I'm trying to copy a collection of resources from the web into a meshObject - the difficulty comes in that the number of resources is arbitrary.<br><br>The furthest I've got is to create the MeshObject and its feed and the I'm using the following code to attempt to upload each resource (seperate script for each resource):<br><br> <div style="border-right:#7f9db9 1px solid;border-top:#7f9db9 1px solid;font-size:11px;overflow:auto;border-left:#7f9db9 1px solid;line-height:100%! important;border-bottom:#7f9db9 1px solid;font-family:Courier New;background-color:white"> <table style="border-top-width:0px;border-left-width:0px;margin:2px 0px;width:99%;border-bottom:#eee 0px solid;border-collapse:collapse;background-color:#fff;border-right-width:0px" cellspacing=0 cellpadding=0> <colgroup> <col style="padding-left:10px;font-size:11px;border-bottom:#f7f7f7 1px solid;font-family:Courier New;white-space:nowrap"> <tbody> <tr> <td><font style="font-size:11px">ResourceScript&lt;SequenceStatement&gt; script2 = Statement.Sequence(  </font></td></tr> <tr> <td style="background-color:#f7f7f7">                    Statement.CreateMediaResource&lt;DataEntryResource&gt;(  </td></tr> <tr> <td>                        tweetTitle, </font><font style="color:blue">null</font><font style="font-size:11px">, tweet, Statement.Bind(  </font></td></tr> <tr> <td style="background-color:#f7f7f7">                            </font><font style="color:blue">&quot;CollectionUrl&quot;</font><font style="font-size:11px">, </font><font style="color:blue">&quot;feedHandle&quot;</font><font style="font-size:11px">, </font><font style="color:blue">&quot;Response.MediaResourcesLink&quot;</font><font style="font-size:11px">)  </font></td></tr> <tr> <td>                        )  </td></tr> <tr> <td style="background-color:#f7f7f7">                    ).Compile(); </td></tr></tbody></table></div><br><br>&quot;feedHandle&quot; is how I referred to the feed when I created it but of course it means nothing in this because its a different script. Naturally it fails with error:<br><br>System.InvalidOperationException was unhandled<br>  Message=&quot;Validation Errors were found:\nerror 0: Microsoft.LiveFX.ResourceModel.Scripting.PropertyBinding. -- Statement 'feedHandle' specified as source of binding for statement '-1969758866' cound not be found.\n&quot;<br>  Source=&quot;Microsoft.LiveFX.ResourceModel&quot;<br>  StackTrace:<br>       at Microsoft.LiveFX.ResourceModel.Scripting.Statement.Compile(Statement statement)<br>       at Microsoft.LiveFX.ResourceModel.Scripting.SequenceStatement.Compile()<br>       at Exploring_scripts.Program.CreateMeshFolderUsingScript(String user, String pwd, String uriRoot, String[] tweetsIDs) in C:\Documents and Settings\jamie\My Documents\Visual Studio 2008\Projects\Mesh Investigation\Exploring scripts\Program.cs:line 89<br>       at Exploring_scripts.Program.Main(String[] args) in C:\Documents and Settings\jamie\My Documents\Visual Studio 2008\Projects\Mesh Investigation\Exploring scripts\Program.cs:line 22<br>       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)<br>       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)<br>       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()<br>       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)<br>       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)<br>       at System.Threading.ThreadHelper.ThreadStart()<br>  InnerException: <br><br><br>So, I'm completely stumped. The thread I linked to earlier suggested building the script source dynamically but I haven't a clue how to create a script object out of that.<br><br>Any suggestions would be welcomed.<br><br>Thanks<br>Jamie<br><hr size="1" align="left" width="25%"><a href="http://jamiethomson.spaces.live.com/">http://jamiethomson.spaces.live.com/</a> | <a href="http://blogs.conchango.com/jamiethomson">http://blogs.conchango.com/jamiethomson</a>Thu, 06 Nov 2008 16:05:05 Z2008-11-06T16:05:05Zhttp://social.msdn.microsoft.com/Forums/en-US/liveframework/thread/9f43d49a-547e-44aa-b0f8-91c581a87111#99ad29ba-c056-48b3-a790-9503ab0fa17ehttp://social.msdn.microsoft.com/Forums/en-US/liveframework/thread/9f43d49a-547e-44aa-b0f8-91c581a87111#99ad29ba-c056-48b3-a790-9503ab0fa17eShelly Guo - MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Shelly%20Guo%20-%20MSFTTrying to get around lack of looping in scripts Hi Jamie, bindings can only refer to statements within the same script.  When I suggested building the script dynamically, I meant to construct one script by adding statements based on the number of resources you want to create.  Try the following example:<br><br><font color="#0000ff" size=3><font color="#0000ff" size=3> <p><font style="font-size:10px">public</font></font></font><font style="font-size:10px"> <font style="font-size:10px" color="#0000ff"><font style="font-size:10px" color="#0000ff">static</font></font> <font style="font-size:10px" color="#0000ff"><font style="font-size:10px" color="#0000ff">void</font></font></font><font size=3><font style="font-size:10px"> MultipleResources()</font></p> <p><font style="font-size:10px">{</font></p> <p></font><font style="font-size:10px"><font style="font-size:10px" color="#2b91af"><font style="font-size:10px" color="#2b91af">Uri</font></font><font style="font-size:10px"> meshObjsUri = </font><font style="font-size:10px" color="#0000ff"><font style="font-size:10px" color="#0000ff">new</font></font> <font style="font-size:10px" color="#2b91af"><font style="font-size:10px" color="#2b91af">Uri</font></font><font style="font-size:10px">(serverUrl + </font><font style="font-size:10px" color="#a31515"><font style="font-size:10px" color="#a31515">&quot;/V0.1/Mesh/MeshObjects&quot;</font></font></font><font size=3><font style="font-size:10px">);</font></p> <p></font><font color="#008000" size=3><font color="#008000" size=3><font style="font-size:10px">//Uri[] externalResources = GetExternalResourceLinks(); // TODO: Implement this to get the list of external link.  .</font></p></font></font><font size=3> <p></font><font style="font-size:10px"><font style="font-size:10px" color="#2b91af"><font style="font-size:10px" color="#2b91af">MeshObjectResource</font></font><font style="font-size:10px"> folder = </font><font style="font-size:10px" color="#0000ff"><font style="font-size:10px" color="#0000ff">new</font></font> <font style="font-size:10px" color="#2b91af"><font style="font-size:10px" color="#2b91af">MeshObjectResource</font></font><font style="font-size:10px">(</font><font style="font-size:10px" color="#a31515"><font style="font-size:10px" color="#a31515">&quot;My Photo Album&quot;</font></font></font><font size=3><font style="font-size:10px">);</font></p> <p><font style="font-size:10px">folder.Type = </font></font><font color="#a31515" size=3><font style="font-size:10px" color="#a31515">&quot;LiveMeshFolder&quot;</font></font><font size=3><font style="font-size:10px">;</font></p> <p></font><font style="font-size:10px"><font style="font-size:10px" color="#2b91af"><font style="font-size:10px" color="#2b91af">DataFeedResource</font></font><font style="font-size:10px"> df = </font><font style="font-size:10px" color="#0000ff"><font style="font-size:10px" color="#0000ff">new</font></font> <font style="font-size:10px" color="#2b91af"><font style="font-size:10px" color="#2b91af">DataFeedResource</font></font><font style="font-size:10px">(</font><font style="font-size:10px" color="#a31515"><font style="font-size:10px" color="#a31515">&quot;Flickr Pictures&quot;</font></font></font><font size=3><font style="font-size:10px">);</font></p> <p><font style="font-size:10px">df.Type = </font></font><font color="#a31515" size=3><font style="font-size:10px" color="#a31515">&quot;LiveMeshFiles&quot;</font></font><font size=3><font style="font-size:10px">;</font></p> <p></font><font style="font-size:10px"><font style="font-size:10px" color="#2b91af"><font style="font-size:10px" color="#2b91af">List</font></font><font style="font-size:10px">&lt;</font><font style="font-size:10px" color="#2b91af"><font style="font-size:10px" color="#2b91af">Statement</font></font><font style="font-size:10px">&gt; childStatements = </font><font style="font-size:10px" color="#0000ff"><font style="font-size:10px" color="#0000ff">new</font></font> <font style="font-size:10px" color="#2b91af"><font style="font-size:10px" color="#2b91af">List</font></font><font style="font-size:10px">&lt;</font><font style="font-size:10px" color="#2b91af"><font style="font-size:10px" color="#2b91af">Statement</font></font></font><font size=3><font style="font-size:10px">&gt;();</font></p> <p><font style="font-size:10px">childStatements.Add(</font></font><font style="font-size:10px"><font style="font-size:10px" color="#2b91af"><font style="font-size:10px" color="#2b91af">Statement</font></font><font style="font-size:10px">.CreateResource&lt;</font><font style="font-size:10px" color="#2b91af"><font style="font-size:10px" color="#2b91af">MeshObjectResource</font></font><font style="font-size:10px">&gt;(</font><font style="font-size:10px" color="#a31515"><font style="font-size:10px" color="#a31515">&quot;folder&quot;</font></font></font><font size=3><font style="font-size:10px">, meshObjsUri, folder));</font></p> <p><font style="font-size:10px">childStatements.Add(</font></font><font style="font-size:10px"><font style="font-size:10px" color="#2b91af"><font style="font-size:10px" color="#2b91af">Statement</font></font><font style="font-size:10px">.CreateResource&lt;</font><font style="font-size:10px" color="#2b91af"><font style="font-size:10px" color="#2b91af">DataFeedResource</font></font><font style="font-size:10px">&gt;(</font><font style="font-size:10px" color="#a31515"><font style="font-size:10px" color="#a31515">&quot;datafeed&quot;</font></font><font style="font-size:10px">, </font><font style="font-size:10px" color="#0000ff"><font style="font-size:10px" color="#0000ff">null</font></font><font style="font-size:10px">, df, </font><font style="font-size:10px" color="#2b91af"><font style="font-size:10px" color="#2b91af">Statement</font></font><font style="font-size:10px">.Bind(</font><font style="font-size:10px" color="#a31515"><font style="font-size:10px" color="#a31515">&quot;CollectionUrl&quot;</font></font><font style="font-size:10px">, </font><font style="font-size:10px" color="#a31515"><font style="font-size:10px" color="#a31515">&quot;folder&quot;</font></font><font style="font-size:10px">, </font><font style="font-size:10px" color="#a31515"><font style="font-size:10px" color="#a31515">&quot;Response.DataFeedsLink&quot;</font></font></font><font size=3><font style="font-size:10px">)));</font></p> <p><font style="font-size:10px"></font></p> <p></font><font style="font-size:10px"><font style="font-size:10px" color="#0000ff"><font style="font-size:10px" color="#0000ff">for</font></font><font style="font-size:10px"> (</font><font style="font-size:10px" color="#0000ff"><font style="font-size:10px" color="#0000ff">int</font></font></font><font size=3><font style="font-size:10px"> i = 0; i &lt; externalResources.Length; i++)</font></p> <p><font style="font-size:10px">{</font></p> <p></font><font color="#2b91af" size=3><font style="font-size:10px" color="#2b91af">Uri</font></font><font size=3><font style="font-size:10px"> externalLink = externalResources[i];</font></p> <p><font style="font-size:10px">childStatements.Add(</font></font><font style="font-size:10px"><font style="font-size:10px" color="#2b91af"><font style="font-size:10px" color="#2b91af">Statement</font></font><font style="font-size:10px">.CreateMediaResource&lt;</font><font style="font-size:10px" color="#2b91af"><font style="font-size:10px" color="#2b91af">DataEntryResource</font></font><font style="font-size:10px">&gt;(</font><font style="font-size:10px" color="#a31515"><font style="font-size:10px" color="#a31515">&quot;file&quot;</font></font><font style="font-size:10px"> + i.ToString(), </font><font style="font-size:10px" color="#0000ff"><font style="font-size:10px" color="#0000ff">null</font></font><font style="font-size:10px">, externalLink, </font><font style="font-size:10px" color="#2b91af"><font style="font-size:10px" color="#2b91af">Statement</font></font><font style="font-size:10px">.Bind(</font><font style="font-size:10px" color="#a31515"><font style="font-size:10px" color="#a31515">&quot;CollectionUrl&quot;</font></font><font style="font-size:10px">, </font><font style="font-size:10px" color="#a31515"><font style="font-size:10px" color="#a31515">&quot;datafeed&quot;</font></font><font style="font-size:10px">, </font><font style="font-size:10px" color="#a31515"><font style="font-size:10px" color="#a31515">&quot;Response.MediaResourcesLink&quot;</font></font></font><font size=3><font style="font-size:10px">)));</font></p> <p><font style="font-size:10px">}</font></p> <p></font><font color="#008000" size=3><font color="#008000" size=3><font style="font-size:10px">// Create the Statement DOM</font></p></font></font><font size=3> <p></font><font style="font-size:10px"><font style="font-size:10px" color="#2b91af"><font style="font-size:10px" color="#2b91af">SequenceStatement</font></font><font style="font-size:10px"> sequence = </font><font style="font-size:10px" color="#2b91af"><font style="font-size:10px" color="#2b91af">Statement</font></font></font><font size=3><font style="font-size:10px">.Sequence(childStatements.ToArray());</font></p> <p><font style="font-size:10px"></font></p> <p></font><font color="#008000" size=3><font color="#008000" size=3><font style="font-size:10px">// Compile the Statement DOM into Resource Script</font></p></font></font><font size=3> <p></font><font style="font-size:10px"><font style="font-size:10px" color="#2b91af"><font style="font-size:10px" color="#2b91af">ResourceScript</font></font><font style="font-size:10px">&lt;</font><font style="font-size:10px" color="#2b91af"><font style="font-size:10px" color="#2b91af">SequenceStatement</font></font></font><font size=3><font style="font-size:10px">&gt; script = sequence.Compile();</font></p> <p></font><font color="#008000" size=3><font color="#008000" size=3><font style="font-size:10px">// Execute the Resource Script</font></p></font></font><font size=3> <p></font><font style="font-size:10px"><font style="font-size:10px" color="#2b91af"><font style="font-size:10px" color="#2b91af">NetworkCredential</font></font><font style="font-size:10px"> scriptCreds = </font><font style="font-size:10px" color="#0000ff"><font style="font-size:10px" color="#0000ff">new</font></font> <font style="font-size:10px" color="#2b91af"><font style="font-size:10px" color="#2b91af">NetworkCredential</font></font><font style="font-size:10px">(username, password, serverUrl + </font><font style="font-size:10px" color="#a31515"><font style="font-size:10px" color="#a31515">&quot;/V0.1/Script&quot;</font></font></font><font size=3><font style="font-size:10px">);</font></p> <p><font style="font-size:10px">script.RunAtServer(scriptCreds);</font></p> <p><font style="font-size:10px">}</font></p></font>Thu, 06 Nov 2008 18:01:51 Z2008-11-06T18:19:32Zhttp://social.msdn.microsoft.com/Forums/en-US/liveframework/thread/9f43d49a-547e-44aa-b0f8-91c581a87111#2624e5f3-38b5-4202-b10f-465ff9ade146http://social.msdn.microsoft.com/Forums/en-US/liveframework/thread/9f43d49a-547e-44aa-b0f8-91c581a87111#2624e5f3-38b5-4202-b10f-465ff9ade146Jamie Thomsonhttp://social.msdn.microsoft.com/Profile/en-US/?user=Jamie%20ThomsonTrying to get around lack of looping in scripts Interesting, thanks Shelly. I'm heading out the door right now but will try and look at this tomorrow. Thank you very very much.<br><br>-Jamie <hr align=left width="25%" size=1> <a href="http://jamiethomson.spaces.live.com/">http://jamiethomson.spaces.live.com/</a> | <a href="http://blogs.conchango.com/jamiethomson">http://blogs.conchango.com/jamiethomson</a>Thu, 06 Nov 2008 18:03:22 Z2008-11-06T18:06:23Zhttp://social.msdn.microsoft.com/Forums/en-US/liveframework/thread/9f43d49a-547e-44aa-b0f8-91c581a87111#6c3952ad-1710-46dc-a0d3-b9b2ab12d46fhttp://social.msdn.microsoft.com/Forums/en-US/liveframework/thread/9f43d49a-547e-44aa-b0f8-91c581a87111#6c3952ad-1710-46dc-a0d3-b9b2ab12d46fJamie Thomsonhttp://social.msdn.microsoft.com/Profile/en-US/?user=Jamie%20ThomsonTrying to get around lack of looping in scripts Hi Shelly,<br>FYI, I took this code and put a blog post together around it: <a>http://blogs.conchango.com/jamiethomson/archive/2008/11/10/livefx-introduction-to-resource-scripts.aspx</a><br><br>-Jamie<hr size="1" align="left" width="25%"><a href="http://jamiethomson.spaces.live.com/">http://jamiethomson.spaces.live.com/</a> | <a href="http://blogs.conchango.com/jamiethomson">http://blogs.conchango.com/jamiethomson</a>Mon, 10 Nov 2008 18:55:51 Z2008-11-10T18:55:51Zhttp://social.msdn.microsoft.com/Forums/en-US/liveframework/thread/9f43d49a-547e-44aa-b0f8-91c581a87111#ada2ef2e-ed33-4173-8a56-260277823f28http://social.msdn.microsoft.com/Forums/en-US/liveframework/thread/9f43d49a-547e-44aa-b0f8-91c581a87111#ada2ef2e-ed33-4173-8a56-260277823f28Vikas-Ahujahttp://social.msdn.microsoft.com/Profile/en-US/?user=Vikas-AhujaTrying to get around lack of looping in scripts<p>Hi Jamie and all - <br/><br/>Ben has did a blog post on Looping in Resource Script and is availabe for read here:<br/><a href="http://blogs.msdn.com/benwilli/archive/2009/03/30/feeling-a-bit-loopy.aspx">http://blogs.msdn.com/benwilli/archive/2009/03/30/feeling-a-bit-loopy.aspx</a> </p><hr class="sig">This posting is provided &quot;AS IS&quot; with no warranties, and confers no rights.Mon, 30 Mar 2009 18:51:10 Z2009-03-30T18:51:10Z