Example #1
0
        private List <T> eval_array <T>(string code, params Parameter <T>[] param)
        {
            var    dict   = param.ToDictionary(k => k.Key, v => v);
            object result = _testserver.call("run", "eval_array", code, dict);

            return(((List <object>)result).Select(s => (T)Convert.ChangeType(s, typeof(T))).ToList());
        }
Example #2
0
        public static void Test()
        {
            Console.WriteLine("Testing Pyro echo server (make sure it's running, with nameserver enabled)...");
            Console.WriteLine("Pyrolite version: " + Config.PYROLITE_VERSION);

            setConfig();
            Console.WriteLine("serializer used: {0}", Config.SERIALIZER);
            if (Config.SERIALIZER == Config.SerializerType.serpent)
            {
                Console.WriteLine("note that for the serpent serializer, you need to have the Razorvine.Serpent assembly available.");
            }

            NameServerProxy ns = NameServerProxy.locateNS(null);
            PyroProxy       p  = new PyroProxy(ns.lookup("test.echoserver"));

            // PyroProxy p=new PyroProxy("localhost",9999,"test.echoserver");

            Object x = 42;

            Console.WriteLine("echo param:");
            PrettyPrint.print(x);
            Object result = p.call("echo", x);

            Console.WriteLine("return value:");
            PrettyPrint.print(result);

            String s = "This string is way too long. This string is way too long. This string is way too long. This string is way too long. ";

            s = s + s + s + s + s;
            Console.WriteLine("echo param:");
            PrettyPrint.print(s);
            result = p.call("echo", s);
            Console.WriteLine("return value:");
            PrettyPrint.print(result);

            Console.WriteLine("dict test.");
            IDictionary <string, object> map = new Dictionary <string, object>()
            {
                { "value", 42 },
                { "message", "hello" },
                { "timestamp", DateTime.Now }
            };

            result = p.call("echo", map);
            Console.WriteLine("return value:");
            PrettyPrint.print(result);


            Console.WriteLine("error test.");
            try {
                result = p.call("error");
            } catch (PyroException e) {
                Console.WriteLine("Pyro Exception (expected)! {0}", e.Message);
                Console.WriteLine("Pyro Exception cause: {0}", e.InnerException);
                Console.WriteLine("Pyro Exception remote traceback:\n>>>\n{0}<<<", e._pyroTraceback);
            }

            Console.WriteLine("shutting down the test echo server.");
            p.call("shutdown");
        }
Example #3
0
        public static void Test()
        {
            Console.WriteLine("Testing Pyro flame server (make sure it's running on localhost 9999)...");
            Console.WriteLine("Pyrolite version: " + Config.PYROLITE_VERSION);

            setConfig();

            PyroProxy flame = new PyroProxy("localhost", 9999, "Pyro.Flame");

            Console.WriteLine("builtin:");
            using (FlameBuiltin r_max = (FlameBuiltin)flame.call("builtin", "max"))
            {
                int maximum = (int)r_max.call(new int[] { 22, 99, 1 });
                Console.WriteLine("maximum=" + maximum);
            }

            using (FlameModule r_module = (FlameModule)flame.call("module", "socket"))
            {
                String hostname = (String)r_module.call("gethostname");
                Console.WriteLine("hostname=" + hostname);
            }

            int sum = (int)flame.call("evaluate", "9+9");

            Console.WriteLine("sum=" + sum);

            flame.call("execute", "import sys; sys.stdout.write('HELLO FROM C#\\n')");

            using (FlameRemoteConsole console = (FlameRemoteConsole)flame.call("console"))
            {
                console.interact();
            }
        }
Example #4
0
        private String connect()
        {
            playfield = new_playfield();
            Object result  = playfield.call("test", "connected");
            string message = (string)result;  // cast to the type that 'pythonmethod' returns

            playfield_panel.Width  = (int)playfield.call("get_width");
            playfield_panel.Height = (int)playfield.call("get_height");
            block     = (PyroProxy)playfield.call("create_block");
            connected = true; // Pyro Proxies are not thread safe
            return(message);
        }
Example #5
0
        private void update_blocks()
        {
            // http://www.dotnetperls.com/arraylist
            List <Object> proxies        = (List <Object>)playfield.call("get_blocks");
            ArrayList     current_blocks = new ArrayList();

            foreach (PyroProxy block in proxies)
            {
                current_blocks.Add(Block.FromPyroProxy(block));
                block.close();
            }
            this.blocks = current_blocks;
        }
    public static void Main(string[] args)
    {
        Console.WriteLine("Pyrolite version: " + Config.PYROLITE_VERSION);
        string hostname = (string)args[0];
        int    port     = int.Parse(args[1]);

        using (var flame = new PyroProxy(hostname, port, "Pyro.Flame"))
        {
            dynamic r_module = flame.call("module", "socket");
            Console.WriteLine("hostname=" + r_module.call("gethostname"));

            var console = (FlameRemoteConsole)flame.call("console");
            console.interact();
            console.close();
        }
    }
Example #7
0
        public static Ball FromPyroProxy(PyroProxy proxy)
        {
            IDictionary values = (IDictionary)proxy.call("asDict");
            int         x      = (int)values["x"];
            int         y      = (int)values["y"];
            int         radius = (int)values["radius"];

            return(new Ball(x, y, radius));
        }
Example #8
0
        public static Block FromPyroProxy(PyroProxy proxy)
        {
            IDictionary values = (IDictionary)proxy.call("asDict");
            int         x      = (int)values["x"];
            int         y      = (int)values["y"];
            int         width  = (int)values["width"];
            int         height = (int)values["height"];

            return(new Block(x, y, width, height));
        }
Example #9
0
 public static void Main(string[] args)
 {
     using (NameServerProxy ns = NameServerProxy.locateNS(null))
     {
         using (PyroProxy remoteobject = new PyroProxy(ns.lookup("Your.Pyro.Object")))
         {
             object result  = remoteobject.call("pythonmethod", 42, "hello", new int[] { 1, 2, 3 });
             string message = (string)result;   // cast to the type that 'pythonmethod' returns
             Console.WriteLine("result message=" + message);
         }
     }
 }
Example #10
0
        public static void Test()
        {
            Console.WriteLine("Testing Pyro echo server (make sure it's running on localhost 9999)...");
            Console.WriteLine("Pyrolite version: " + Config.PYROLITE_VERSION);

            setConfig();

            PyroProxy p = new PyroProxy("localhost", 9999, "test.echoserver");

            Object x = 42;

            Console.WriteLine("echo param:");
            PrettyPrint.print(x);
            Object result = p.call("echo", x);

            Console.WriteLine("return value:");
            PrettyPrint.print(result);

            String s = "This string is way too long. This string is way too long. This string is way too long. This string is way too long. ";

            s = s + s + s + s + s;
            Console.WriteLine("echo param:");
            PrettyPrint.print(s);
            result = p.call("echo", s);
            Console.WriteLine("return value:");
            PrettyPrint.print(result);

            Console.WriteLine("error test.");
            try {
                result = p.call("error");
            } catch (PyroException e) {
                Console.WriteLine("Pyro Exception (expected)! {0}", e.Message);
                Console.WriteLine("Pyro Exception cause: {0}", e.InnerException);
                Console.WriteLine("Pyro Exception remote traceback:\n>>>\n{0}<<<", e._pyroTraceback);
            }

            Console.WriteLine("shutting down the test echo server.");
            p.call("shutdown");
        }
        private void HandleListAllEvents()
        {
            List <object> eventsObjects = (List <object>)proxy.call("events_list");

            List <CalendarEventDto> events = eventsObjects.ConvertAll(new Converter <object, CalendarEventDto>(CalendarEventDto.CalendarEventDtoFromDict));

            HandleDisplayEventList(events);
        }
Example #12
0
        public static void Test()
        {
            Console.WriteLine("Testing Pyro nameserver connection (make sure it's running with a broadcast server)...");
            Console.WriteLine("Pyrolite version: " + Config.PYROLITE_VERSION);

            setConfig();
            Console.WriteLine("serializer used: {0}", Config.SERIALIZER);
            if (Config.SERIALIZER == Config.SerializerType.serpent)
            {
                Console.WriteLine("note that for the serpent serializer, you need to have the Razorvine.Serpent assembly available.");
            }

            NameServerProxy ns = NameServerProxy.locateNS(null);

            Console.WriteLine("discovered ns at " + ns.hostname + ":" + ns.port);
            ns.ping();

            Console.WriteLine("objects registered in the name server:");
            IDictionary <string, string> objects = ns.list(null, null);

            foreach (string key in objects.Keys)
            {
                Console.WriteLine(key + " --> " + objects[key]);
            }

            ns.register("java.test", new PyroURI("PYRO:JavaTest@localhost:9999"), false);
            Console.WriteLine("uri=" + ns.lookup("java.test"));
            Console.WriteLine("using a new proxy to call the nameserver.");
            PyroProxy p = new PyroProxy(ns.lookup("Pyro.NameServer"));

            p.call("ping");

            int num_removed = ns.remove(null, "java.", null);

            Console.WriteLine("number of removed entries: {0}", num_removed);

            try {
                Console.WriteLine("uri=" + ns.lookup("java.test"));              // should fail....
            } catch (PyroException x) {
                // ok
                Console.WriteLine("got a PyroException (expected): {0}", x.Message);
            }
        }
Example #13
0
        private static void Test()
        {
            Console.WriteLine("Testing Pyro nameserver connection (make sure it's running with a broadcast server)...");
            Console.WriteLine("Pyrolite version: " + Config.PYROLITE_VERSION);

            SetConfig();
            // Config.SERIALIZER = Config.SerializerType.pickle;

            Console.WriteLine("serializer used: {0}", Config.SERIALIZER);
            if (Config.SERIALIZER == Config.SerializerType.serpent)
            {
                Console.WriteLine("note that for the serpent serializer, you need to have the Razorvine.Serpent assembly available.");
            }

            using (NameServerProxy ns = NameServerProxy.locateNS(null, hmacKey: HmacKey))
            {
                Console.WriteLine("discovered ns at " + ns.hostname + ":" + ns.port);
                ns.ping();

                Console.WriteLine("lookup of name server object:");
                PyroURI uri = ns.lookup("Pyro.NameServer");
                Console.WriteLine("   " + uri);
                Console.WriteLine("lookup of name server object, with metadata:");
                var tmeta = ns.lookup("Pyro.NameServer", true);
                Console.WriteLine("   uri:  " + tmeta.Item1);
                Console.WriteLine("   meta: " + string.Join(", ", tmeta.Item2));
                var metadata = tmeta.Item2;
                metadata.Add("updated-by-dotnet-pyrolite");
                ns.set_metadata("Pyro.NameServer", metadata);


                Console.WriteLine("\nobjects registered in the name server:");
                var objects = ns.list(null, null);
                foreach (string key in objects.Keys)
                {
                    Console.WriteLine(key + " --> " + objects[key]);
                }

                Console.WriteLine("\nobjects registered in the name server, with metadata:");
                var objectsm = ns.list_with_meta(null, null);
                foreach (string key in objectsm.Keys)
                {
                    var registration = objectsm[key];
                    Console.WriteLine(key + " --> " + registration.Item1);
                    Console.WriteLine("      metadata: " + string.Join(", ", registration.Item2));
                }

                Console.WriteLine("\nobjects registered having all metadata:");
                objects = ns.list(null, null, new [] { "blahblah", "class:Pyro4.naming.NameServer" }, null);
                foreach (string name in objects.Keys)
                {
                    Console.WriteLine(name + " --> " + objects[name]);
                }
                Console.WriteLine("\nobjects registered having any metadata:");
                objects = ns.list(null, null, null, new [] { "blahblah", "class:Pyro4.naming.NameServer" });
                foreach (string name in objects.Keys)
                {
                    Console.WriteLine(name + " --> " + objects[name]);
                }
                Console.WriteLine("\nobjects registered having any metadata (showing it too):");
                objectsm = ns.list_with_meta(null, null, null, new [] { "blahblah", "class:Pyro4.naming.NameServer" });
                foreach (string name in objectsm.Keys)
                {
                    var entry = objectsm[name];
                    Console.WriteLine(name + " --> " + entry.Item1);
                    Console.WriteLine("      metadata: " + string.Join(", ", entry.Item2));
                }

                Console.WriteLine("");
                ns.register("dotnet.test", new PyroURI("PYRO:DotnetTest@localhost:9999"), false);
                ns.register("dotnet.testmeta", new PyroURI("PYRO:DotnetTest@localhost:9999"), false, new [] { "example", "from-dotnet-pyrolite" });

                Console.WriteLine("uri=" + ns.lookup("dotnet.test"));
                Console.WriteLine("using a new proxy to call the nameserver.");

                using (PyroProxy p = new PyroProxy(ns.lookup("Pyro.NameServer")))
                {
                    p.pyroHmacKey = HmacKey;
                    p.call("ping");
                }

                int numRemoved = ns.remove(null, "dotnet.", null);
                Console.WriteLine("number of removed entries: {0}", numRemoved);

                try {
                    Console.WriteLine("uri=" + ns.lookup("dotnet.test"));                // should fail....
                } catch (PyroException x) {
                    // ok
                    Console.WriteLine("got a PyroException (expected): {0}", x.Message);
                }
            }
        }
 public static object test_method(this PyroProxy proxy, params object[] arguments)
 {
     return(proxy.call("test_method", arguments));    // you get the point
 }