Microsoft Developer Network > Domovská stránka fór > Live Framework > Trying to get around lack of looping in scripts
Odeslat dotazOdeslat dotaz
 

OdpovědětTrying to get around lack of looping in scripts

  • 6. listopadu 2008 16:05Jamie ThomsonMVPUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     Obsahuje kód
    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

Odpovědi

  • 6. listopadu 2008 18:01Shelly Guo - MSFTMSFTUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     OdpovědětObsahuje kód
    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);

    }

Všechny reakce