Example #1
0
 static void Main()
 {
     JsonRpcClient client = new JsonRpcClient();
     client.Url = "http://www.raboof.com/projects/jayrock/demo.ashx";
     Console.WriteLine(client.Invoke("system.about"));
     Console.WriteLine(client.Invoke("system.version"));
     Console.WriteLine(string.Join(Environment.NewLine, (string[]) (new ArrayList((ICollection) client.Invoke("system.listMethods"))).ToArray(typeof(string))));
     Console.WriteLine(client.Invoke("now"));
     Console.WriteLine(client.Invoke("sum", 123, 456));
     Console.WriteLine(client.Invoke("total", new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }));
     client.CookieContainer = new CookieContainer();
     Console.WriteLine(client.Invoke("counter"));
     Console.WriteLine(client.Invoke("counter"));
 }
Example #2
0
        static void Main()
        {
            //
            // Demonstration of client calls to a JSON-RPC service.
            //

            JsonRpcClient client = new JsonRpcClient();
            client.Url = "http://www.raboof.com/projects/jayrock/demo.ashx";
            Console.WriteLine(client.Invoke("system.about"));
            Console.WriteLine(client.Invoke("system.version"));
            Console.WriteLine(string.Join(Environment.NewLine, (string[]) (new ArrayList((ICollection) client.Invoke("system.listMethods"))).ToArray(typeof(string))));
            Console.WriteLine(client.Invoke("now"));
            Console.WriteLine(client.Invoke("sum", 123, 456));
            Console.WriteLine(client.Invoke("total", new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }));
            client.CookieContainer = new CookieContainer();
            Console.WriteLine(client.Invoke("counter"));
            Console.WriteLine(client.Invoke("counter"));

            //
            // Demonstration of a JsonWriter implementation (JsonCodeWriter)
            // that writes code in terms of itself. So we take some JSON
            // text and covert it into the JsonWriter API.
            //

            CodeEntryPointMethod codeMainMethod = new CodeEntryPointMethod();
            codeMainMethod.Statements.Add(new CodeVariableDeclarationStatement(typeof(JsonWriter), "writer", new CodeObjectCreateExpression(typeof(EmptyJsonWriter))));

            JsonCodeWriter writer = new JsonCodeWriter(new CodeVariableReferenceExpression("writer"), codeMainMethod.Statements);
            writer.WriteFromReader(new JsonTextReader(new StringReader(@"
                {
                    firstName : 'John',
                    lastName : 'Doe'
                }")));

            CodeTypeDeclaration codeType = new CodeTypeDeclaration("Program");
            codeType.Members.Add(codeMainMethod);

            CodeGeneratorOptions options = new CodeGeneratorOptions();
            GetLanguageProvider("c#").CreateGenerator().GenerateCodeFromType(codeType, Console.Out, options);
            GetLanguageProvider("vb").CreateGenerator().GenerateCodeFromType(codeType, Console.Out, options);
        }