Click to Rate and Give Feedback
MSDN
MSDN Library
Live Services SDK
Live Framework SDK
Resource Scripts
 Serializing Resource Scripts

  Switch on low bandwidth view
Serializing Resource Scripts
[This is preliminary documentation and is subject to change.]

Live Framework statements can be represented by using JSON and XML formats. The JSON and the XML representations are created by serializing the statement Data Object Model (DOM) by calling the SaveAsJson and SaveAsPlainOldXml methods, respectively. The serialized representations are most commonly used for running scripts on the server by using HTTP POST requests. Because they use declarative markup to expose the structure of Live Framework statements, they are useful for many other things, including the creation of visually based programming tools that leverage Live Framework. This topic demonstrates how to serialize Resource Script statements from C# into the supported target markup.

Prior to serializing Live Framework script statements, you must instantiate a ResourceScript instance. The following C# example shows the code for instantiating a sequence statement. This code will be used to demonstrate serializing to JSON and XML in the following sections.

SequenceStatement myScriptDom = Statement.Sequence(

   Statement.CreateResource<MeshObjectResource>(new Uri("https://user-ctp.windows.net/V0.1/Mesh/MeshObjects"), new MeshObjectResource("hello, scripts1")),

   Statement.CreateResource<MeshObjectResource>(new Uri("https://user-ctp.windows.net/V0.1/Mesh/MeshObjects"), new MeshObjectResource("hello, scripts2")),

);

The following example shows the syntax to use for serializing a script to JSON, outputting a file named source.json.txt:

myScriptDom.Source.SaveAsJson(@"c:\source.json.txt");

The code looks like this example when represented in JSON:

{

   "Children" : [

     { "__type" : "CreateResourceStatement:http://mesh.com",

     "Request" : {

       "__type" : "MeshObject:http://mesh.com",

       "Title" : "hello, scripts1"

     },

     "CollectionUrl" : https://user-ctp.windows.net/V0.1/Mesh/MeshObjects

   }, {

   "__type" : "CreateResourceStatement:http://mesh.com",

     "Request" : {

       "__type" : "MeshObject:http://mesh.com",

       "Title" : "hello, scripts2"

     },

     "CollectionUrl" : https://user-ctp.windows.net/V0.1/Mesh/MeshObjects

   } ]

}

The following example shows the syntax to use for serializing to XML, outputting a file named source.xml:

myScriptDom.Source.SaveAsPlainOldXml(@"c:\source.xml");

The code looks like this example when represented in XML:

<Sequence xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://mesh.com">

   <Children>

      <Statement i:type="CreateResourceStatementOfMeshObjectrWq1H2Lp">

         <Request i:type="MeshObject">

            <Title>hello, scripts1</Title>

         </Request>

         <CollectionUrl>https://user-ctp.windows.net/V0.1/Mesh/MeshObjects</CollectionUrl>

      </Statement>

      <Statement i:type="CreateResourceStatementOfMeshObjectrWq1H2Lp">

         <Request i:type="MeshObject">

            <Title>hello, scripts2</Title>

            101

         </Request>

         <CollectionUrl>https://user-ctp.windows.net/V0.1/Mesh/MeshObjects</CollectionUrl>

      </Statement>

   </Children>

</Sequence>

Dd217479.note(en-us,MSDN.10).gifNote:
SaveAsJson and SaveAsPlainOldXml can also save to a Stream object.
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker