Пример #1
0
 public void Cleanup()
 {
     _testserver.Dispose();
     _testserver = null;
     _ns.Dispose();
     _ns = null;
 }
Пример #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");
        }
Пример #3
0
        public void Init()
        {
            _ns         = NameServerProxy.locateNS(null);
            _testserver = new PyroProxy(_ns.lookup("mxnet.csharp.testserver"));

            Serializer.RegisterClass(typeof(Parameter <float>), Parameter <float> .Convert);
        }
Пример #4
0
 private PyroProxy new_playfield()
 {
     using (NameServerProxy ns = NameServerProxy.locateNS(null))
     {
         using (PyroProxy playfield = new PyroProxy(ns.lookup("ping.playfield")))
         {
             return(playfield);
         }
     }
 }
Пример #5
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);
         }
     }
 }
Пример #6
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);
            }
        }
Пример #7
0
        static protected byte[] hmacKey = null;  // Encoding.UTF8.GetBytes("foo");


        public void Run()
        {
            Console.WriteLine("Testing Pyro echo server (make sure it's running, with nameserver enabled)...");
            Console.WriteLine("Pyrolite version: " + Config.PYROLITE_VERSION);

            //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.");
            }

            NameServerProxy ns = NameServerProxy.locateNS(null, hmacKey: hmacKey);

            using (dynamic p = new PyroProxy(ns.lookup("test.echoserver")))
            {
                p.pyroHmacKey   = hmacKey;
                p.pyroHandshake = "banana";

                // non-dynamic way of constructing a proxy is:
                // PyroProxy p=new PyroProxy("localhost",9999,"test.echoserver");

                Console.WriteLine("echo(), param=42:");
                Object result = p.echo(42);
                Console.WriteLine("return value:");
                PrettyPrint.print(result);

                Console.WriteLine("oneway_echo(), param=999:");
                result = p.oneway_echo(999);
                Console.WriteLine("return value:");
                PrettyPrint.print(result);

                // attribute access
                result = p.verbose;
                bool verbosity = (bool)result;
                Console.WriteLine("value of verbose attr: {0}", verbosity);
                p.verbose = !verbosity;
                result    = p.getattr("verbose");
                verbosity = (bool)result;
                Console.WriteLine("value of verbose attr after toggle: {0}", verbosity);


                // some more examples

                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.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.echo(map);
                Console.WriteLine("return value:");
                PrettyPrint.print(result);

                // echo a pyro proxy and validate that all relevant attributes are also present on the proxy we got back.
                Console.WriteLine("proxy test.");
                result = p.echo(p);
                PyroProxy p2 = (PyroProxy)result;
                Console.WriteLine("response proxy: " + p2);
                Debug.Assert(p2.objectid == "test.echoserver");
                Debug.Assert((string)p2.pyroHandshake == "banana");
                Debug.Assert(p2.pyroMethods.Contains("echo"));
                if (p2.pyroHmacKey != null)
                {
                    string hmac2 = Encoding.UTF8.GetString(p2.pyroHmacKey);
                    Debug.Assert(hmac2 == Encoding.UTF8.GetString(hmacKey));
                }

                Console.WriteLine("remote iterator test.");
                var iter = p.generator();
                foreach (var item in iter)
                {
                    Console.WriteLine("  got item: " + item);
                }

                Console.WriteLine("error test.");
                try {
                    result = p.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);
                }
                try {
                    result = p.error_with_text();
                } 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.shutdown();
            }
        }
Пример #8
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);
                }
            }
        }
Пример #9
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);
            dynamic         p  = new PyroProxy(ns.lookup("test.echoserver"));

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

            Console.WriteLine("echo(), param=42:");
            Object result = p.echo(42);

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

            Console.WriteLine("oneway_echo(), param=999:");
            result = p.oneway_echo(999);
            Console.WriteLine("return value:");
            PrettyPrint.print(result);

            // attribute access
            result = p.verbose;
            bool verbosity = (bool)result;

            Console.WriteLine("value of verbose attr: {0}", verbosity);
            p.verbose = !verbosity;
            result    = p.getattr("verbose");
            verbosity = (bool)result;
            Console.WriteLine("value of verbose attr after toggle: {0}", verbosity);


            // some more examples

            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.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.echo(map);
            Console.WriteLine("return value:");
            PrettyPrint.print(result);


            Console.WriteLine("error test.");
            try {
                result = p.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.shutdown();
        }