Trying to get around lack of looping in scripts
- Hi,
As discussed in this thread: http://social.msdn.microsoft.com/Forums/en-US/liveframework/thread/10e19310-9eba-43e2-b70e-8ac44132cb79 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.
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):
ResourceScript<SequenceStatement> script2 = Statement.Sequence( Statement.CreateMediaResource<DataEntryResource>( tweetTitle, null, tweet, Statement.Bind( "CollectionUrl", "feedHandle", "Response.MediaResourcesLink") ) ).Compile();
"feedHandle" 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:
System.InvalidOperationException was unhandled
Message="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"
Source="Microsoft.LiveFX.ResourceModel"
StackTrace:
at Microsoft.LiveFX.ResourceModel.Scripting.Statement.Compile(Statement statement)
at Microsoft.LiveFX.ResourceModel.Scripting.SequenceStatement.Compile()
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
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
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
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.
Any suggestions would be welcomed.
Thanks
Jamie
http://jamiethomson.spaces.live.com/ | http://blogs.conchango.com/jamiethomson
回答
- 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:
public
static void MultipleResources(){
Uri meshObjsUri = new Uri(serverUrl + "/V0.1/Mesh/MeshObjects"); //Uri[] externalResources = GetExternalResourceLinks(); // TODO: Implement this to get the list of external link. . MeshObjectResource folder = new MeshObjectResource("My Photo Album");folder.Type =
"LiveMeshFolder"; DataFeedResource df = new DataFeedResource("Flickr Pictures");df.Type =
"LiveMeshFiles"; List<Statement> childStatements = new List<Statement>();childStatements.Add(
Statement.CreateResource<MeshObjectResource>("folder", meshObjsUri, folder));childStatements.Add(
Statement.CreateResource<DataFeedResource>("datafeed", null, df, Statement.Bind("CollectionUrl", "folder", "Response.DataFeedsLink"))); for (int i = 0; i < externalResources.Length; i++){
Uri externalLink = externalResources[i];childStatements.Add(
Statement.CreateMediaResource<DataEntryResource>("file" + i.ToString(), null, externalLink, Statement.Bind("CollectionUrl", "datafeed", "Response.MediaResourcesLink")));}
// Create the Statement DOM SequenceStatement sequence = Statement.Sequence(childStatements.ToArray()); // Compile the Statement DOM into Resource Script ResourceScript<SequenceStatement> script = sequence.Compile(); // Execute the Resource Script NetworkCredential scriptCreds = new NetworkCredential(username, password, serverUrl + "/V0.1/Script");script.RunAtServer(scriptCreds);
}
- 回答の候補に設定Shelly Guo - MSFTMSFT2008年11月6日 18:02
- 回答としてマークJamie ThomsonMVP2008年11月6日 18:07
- 編集済みVikas-AhujaMSFT, モデレータ2008年11月6日 18:19added attribute has code
すべての返信
- 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:
public
static void MultipleResources(){
Uri meshObjsUri = new Uri(serverUrl + "/V0.1/Mesh/MeshObjects"); //Uri[] externalResources = GetExternalResourceLinks(); // TODO: Implement this to get the list of external link. . MeshObjectResource folder = new MeshObjectResource("My Photo Album");folder.Type =
"LiveMeshFolder"; DataFeedResource df = new DataFeedResource("Flickr Pictures");df.Type =
"LiveMeshFiles"; List<Statement> childStatements = new List<Statement>();childStatements.Add(
Statement.CreateResource<MeshObjectResource>("folder", meshObjsUri, folder));childStatements.Add(
Statement.CreateResource<DataFeedResource>("datafeed", null, df, Statement.Bind("CollectionUrl", "folder", "Response.DataFeedsLink"))); for (int i = 0; i < externalResources.Length; i++){
Uri externalLink = externalResources[i];childStatements.Add(
Statement.CreateMediaResource<DataEntryResource>("file" + i.ToString(), null, externalLink, Statement.Bind("CollectionUrl", "datafeed", "Response.MediaResourcesLink")));}
// Create the Statement DOM SequenceStatement sequence = Statement.Sequence(childStatements.ToArray()); // Compile the Statement DOM into Resource Script ResourceScript<SequenceStatement> script = sequence.Compile(); // Execute the Resource Script NetworkCredential scriptCreds = new NetworkCredential(username, password, serverUrl + "/V0.1/Script");script.RunAtServer(scriptCreds);
}
- 回答の候補に設定Shelly Guo - MSFTMSFT2008年11月6日 18:02
- 回答としてマークJamie ThomsonMVP2008年11月6日 18:07
- 編集済みVikas-AhujaMSFT, モデレータ2008年11月6日 18:19added attribute has code
- Interesting, thanks Shelly. I'm heading out the door right now but will try and look at this tomorrow. Thank you very very much.
-Jamie
http://jamiethomson.spaces.live.com/ | http://blogs.conchango.com/jamiethomson- 編集済みJamie ThomsonMVP2008年11月6日 18:06error
- Hi Shelly,
FYI, I took this code and put a blog post together around it: http://blogs.conchango.com/jamiethomson/archive/2008/11/10/livefx-introduction-to-resource-scripts.aspx
-Jamie
http://jamiethomson.spaces.live.com/ | http://blogs.conchango.com/jamiethomson Hi Jamie and all -
Ben has did a blog post on Looping in Resource Script and is availabe for read here:
http://blogs.msdn.com/benwilli/archive/2009/03/30/feeling-a-bit-loopy.aspx
This posting is provided "AS IS" with no warranties, and confers no rights.

