示例#1
0
            public IEnumerator GetEnumerator()
            {
                if (this.proxy == null)
                {
                    yield break;
                }

                while (true)
                {
                    if (this.proxy.sock == null)
                    {
                        throw new PyroException("the proxy for this stream result has been closed");
                    }
                    object value;
                    try {
                        value = this.proxy.internal_call("get_next_stream_item", Config.DAEMON_NAME, 0, false, this.streamId);
                    } catch (PyroException x) {
                        if (stopIterationExceptions.Contains(x.PythonExceptionType))
                        {
                            // iterator ended normally. no need to call close_stream, server will have closed the stream on its side already.
                            this.proxy = null;
                            yield break;
                        }
                        Dispose();
                        throw;
                    }
                    yield return(value);
                }
            }
示例#2
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();

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

		Console.WriteLine("builtin:");
		using(dynamic r_max=(FlameBuiltin)flame.builtin("max"))
		{
			int maximum=(int)r_max(new int[]{22,99,1});		// invoke remote max() builtin function
			Console.WriteLine("maximum="+maximum);
		}
		
		using(dynamic r_module=(FlameModule)flame.module("socket"))
		{
			String hostname=(String)r_module.gethostname();		// get remote hostname
			Console.WriteLine("hostname="+hostname);
		}
		
		int sum=(int)flame.evaluate("9+9");
		Console.WriteLine("sum="+sum);
		
		flame.execute("import sys; sys.stdout.write('HELLO FROM C#\\n')");
		
		using(FlameRemoteConsole console=(FlameRemoteConsole)flame.console())
		{
			console.interact();
		}
	}
示例#3
0
        public void pickle(object o, Stream outs, Pickler currentPickler)
        {
            PyroProxy proxy = (PyroProxy)o;

            outs.WriteByte(Opcodes.GLOBAL);
            var output = Encoding.Default.GetBytes("Pyro4.core\nProxy\n");

            outs.Write(output, 0, output.Length);
            outs.WriteByte(Opcodes.EMPTY_TUPLE);
            outs.WriteByte(Opcodes.NEWOBJ);

            // args(8): pyroUri, pyroOneway(hashset), pyroMethods(set), pyroAttrs(set), pyroTimeout, pyroHmacKey, pyroHandshake, pyroMaxRetries
            object[] args =
            {
                new PyroURI(proxy.objectid, proxy.hostname, proxy.port),
                proxy.pyroOneway,
                proxy.pyroMethods,
                proxy.pyroAttrs,
                0.0,
                proxy.pyroHmacKey,
                proxy.pyroHandshake,
                0          // maxretries is not yet supported/used by pyrolite
            };
            currentPickler.save(args);
            outs.WriteByte(Opcodes.BUILD);
        }
        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();
            }
        }
示例#5
0
		public void PyroClasses()
		{
			var uri = new PyroURI("PYRO:something@localhost:4444");
			byte[] s = this.ser.serializeData(uri);
			object x = this.ser.deserializeData(s);
			Assert.AreEqual(uri, x);

			var proxy = new PyroProxy(uri);
			s = this.ser.serializeData(proxy);
			x = this.ser.deserializeData(s);
			PyroProxy proxy2 = (PyroProxy) x;
			Assert.AreEqual(uri.host, proxy2.hostname);
			Assert.AreEqual(uri.objectid, proxy2.objectid);
			Assert.AreEqual(uri.port, proxy2.port);

			PyroException ex = new PyroException("error");
			s = this.ser.serializeData(ex);
			x = this.ser.deserializeData(s);
			PyroException ex2 = (PyroException) x;
			Assert.AreEqual(ex.Message, ex2.Message);
			Assert.IsNull(ex._pyroTraceback);
			
			// try another kind of pyro exception
			s = Encoding.UTF8.GetBytes("{'attributes':{'tb': 'traceback', '_pyroTraceback': ['line1', 'line2']},'__exception__':True,'args':('hello',42),'__class__':'CommunicationError'}");
			x = this.ser.deserializeData(s);
			ex2 = (PyroException) x;
			Assert.AreEqual("hello", ex2.Message);
			Assert.AreEqual("traceback", ex2.Data["tb"]);
			Assert.AreEqual("line1line2", ex2._pyroTraceback);
		}
        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();

            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);
            }
        }
        public void PyroClassesPickle()
        {
            var pickler = new PickleSerializer();
            var uri = new PyroURI("PYRO:something@localhost:4444");
            byte[] s = pickler.serializeData(uri);
            object x = pickler.deserializeData(s);
            Assert.AreEqual(uri, x);

            var proxy = new PyroProxy(uri);
            proxy.correlation_id = Guid.NewGuid();
            proxy.pyroHandshake = "apples";
            proxy.pyroHmacKey = Encoding.UTF8.GetBytes("secret");
            proxy.pyroAttrs = new HashSet<string>();
            proxy.pyroAttrs.Add("attr1");
            proxy.pyroAttrs.Add("attr2");
            s = pickler.serializeData(proxy);
            x = pickler.deserializeData(s);
            PyroProxy proxy2 = (PyroProxy) x;
            Assert.AreEqual(uri.host, proxy2.hostname);
            Assert.AreEqual(uri.objectid, proxy2.objectid);
            Assert.AreEqual(uri.port, proxy2.port);
            Assert.IsNull(proxy2.correlation_id, "correlation_id is not serialized on the proxy object");
            Assert.AreEqual(proxy.pyroHandshake, proxy2.pyroHandshake);
            Assert.AreEqual(proxy.pyroHmacKey, proxy2.pyroHmacKey);
            Assert.AreEqual(2, proxy2.pyroAttrs.Count);
            Assert.AreEqual(proxy.pyroAttrs, proxy2.pyroAttrs);

            PyroException ex = new PyroException("error");
            s = pickler.serializeData(ex);
            x = pickler.deserializeData(s);
            PyroException ex2 = (PyroException) x;
            Assert.AreEqual(ex.Message, ex2.Message);
            Assert.IsNull(ex._pyroTraceback);
        }
 public void testPickleUnpickleProxy()
 {
     PyroProxy proxy=new PyroProxy("hostname",9999,"objectid");
     Pickler p=new Pickler();
     byte[] pickled_proxy=p.dumps(proxy);
     object result=U(pickled_proxy);
     Assert.IsInstanceOfType(typeof(System.Collections.Hashtable), result); // proxy objects cannot be properly pickled and are pickled as bean, hence HashMap
 }
示例#9
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);
 }
示例#10
0
 public void Dispose()
 {
     if (this.proxy != null && this.proxy.sock != null)
     {
         this.proxy.internal_call("close_stream", Config.DAEMON_NAME, Message.FLAGS_ONEWAY, false, this.streamId);
     }
     this.proxy = null;
 }
示例#11
0
 public void close()
 {
     if(remoteconsole!=null) {
     remoteconsole.call("terminate");
     remoteconsole.close();
     remoteconsole = null;
     }
 }
示例#12
0
 public void Dispose()
 {
     if (proxy?.sock != null)
     {
         proxy.internal_call("close_stream", Config.DAEMON_NAME, Message.FLAGS_ONEWAY, false, streamId);
     }
     proxy = null;
 }
示例#13
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);
 }
示例#14
0
	public void testPickleUnpickleProxy() {
		PyroProxy proxy=new PyroProxy("hostname",9999,"objectid");
		PyroSerializer ser = new PickleSerializer();
		byte[] pickled_proxy=ser.serializeData(proxy);
		PyroProxy result = (PyroProxy) ser.deserializeData(pickled_proxy);
		Assert.AreEqual(proxy.hostname, result.hostname);
		Assert.AreEqual(proxy.objectid, result.objectid);
		Assert.AreEqual(proxy.port, result.port);
	}
示例#15
0
 public void close()
 {
     if (remoteconsole != null)
     {
         remoteconsole.call("terminate");
         remoteconsole.close();
         remoteconsole = null;
     }
 }
示例#16
0
        public static IDictionary ToSerpentDict(object obj)
        {
            PyroProxy proxy = (PyroProxy)obj;
            var       dict  = new Hashtable();
            string    uri   = string.Format("PYRO:{0}@{1}:{2}", proxy.objectid, proxy.hostname, proxy.port);

            dict["state"]     = new object[] { uri, new HashSet <object>(), 0.0 };
            dict["__class__"] = "Pyro4.core.Proxy";
            return(dict);
        }
示例#17
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");
        }
 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);
         }
     }
 }
 public void testPickleUnpickleProxy()
 {
     PyroProxy proxy=new PyroProxy("hostname",9999,"objectid");
     proxy.pyroHmacKey = Encoding.UTF8.GetBytes("secret");
     proxy.pyroHandshake = "apples";
     PyroSerializer ser = new PickleSerializer();
     byte[] pickled_proxy=ser.serializeData(proxy);
     PyroProxy result = (PyroProxy) ser.deserializeData(pickled_proxy);
     Assert.AreEqual(proxy.hostname, result.hostname);
     Assert.AreEqual(proxy.objectid, result.objectid);
     Assert.AreEqual(proxy.port, result.port);
     Assert.AreEqual(Encoding.UTF8.GetBytes("secret"), result.pyroHmacKey);
     Assert.AreEqual("apples", result.pyroHandshake);
 }
    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();
        }
    }
示例#21
0
        public static object FromSerpentDict(IDictionary dict)
        {
            // note: the state array received in the dict conforms to the list produced by Pyro4's Proxy.__getstate_for_dict__
            // that means, we must get an array of length 8:  (the same as with ToSerpentDict above!)
            // uri, oneway set, methods set, attrs set, timeout, hmac_key, handshake, maxretries  (in this order)
            object[] state = (object[])dict["state"];
            PyroURI uri = new PyroURI((string)state[0]);
            var proxy = new PyroProxy(uri);

            // the following nasty piece of code is similar to _processMetaData from the PyroProxy
            // this is because the three collections can either be an array or a set
            object[] oneway_array = state[1] as object[];
            object[] methods_array = state[2] as object[];
            object[] attrs_array = state[3] as object[];
            if(oneway_array!=null)
            proxy.pyroOneway = new HashSet<string>(oneway_array.Select(o=>o as string));
            else if((state[1] as HashSet<string>) != null)
            proxy.pyroOneway = state[1] as HashSet<string>;
            else
            proxy.pyroOneway = new HashSet<string> ((state[1] as HashSet<object>).Select(o=>o.ToString()));

            if(methods_array!=null)
            proxy.pyroMethods = new HashSet<string>(methods_array.Select(o=>o as string));
            else if((state[2] as HashSet<string>) != null)
            proxy.pyroMethods = state[2] as HashSet<string>;
            else
            proxy.pyroMethods = new HashSet<string>((state[2] as HashSet<object>).Select(o=>o.ToString()));

            if(attrs_array!=null)
            proxy.pyroAttrs = new HashSet<string>(attrs_array.Select(o=>o as string));
            else if((state[3] as HashSet<string>) != null)
            proxy.pyroAttrs = state[3] as HashSet<string>;
            else
            proxy.pyroAttrs = new HashSet<string>((state[3] as HashSet<object>).Select(o=>o.ToString()));

            if(state[5]!=null) {
            string encodedHmac = (string)state[5];
            if(encodedHmac.StartsWith("b64:", StringComparison.InvariantCulture)) {
                proxy.pyroHmacKey = Convert.FromBase64String(encodedHmac.Substring(4));
            } else {
                throw new PyroException("hmac encoding error");
            }
            }
            proxy.pyroHandshake = state[6];
            // maxretries is not used/supported in pyrolite, so simply ignore it

            return proxy;
        }
示例#22
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.");

            using(NameServerProxy ns=NameServerProxy.locateNS(null, hmacKey: hmacKey))
            {
            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.");

            using(PyroProxy p=new PyroProxy(ns.lookup("Pyro.NameServer")))
            {
                p.pyroHmacKey = hmacKey;
                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);
            }

            Console.WriteLine("\r\nEnter to exit:"); Console.ReadLine();
            }
        }
示例#23
0
        public void pickle(object o, Stream outs, Pickler currentPickler)
        {
            PyroProxy proxy = (PyroProxy)o;

            outs.WriteByte(Opcodes.GLOBAL);
            byte[] output = Encoding.Default.GetBytes("Pyro4.core\nProxy\n");
            outs.Write(output, 0, output.Length);
            outs.WriteByte(Opcodes.EMPTY_TUPLE);
            outs.WriteByte(Opcodes.NEWOBJ);

            // parameters are: pyroUri, pyroOneway(hashset), pyroTimeout
            object[] args = new object[] {
                new PyroURI(proxy.objectid, proxy.hostname, proxy.port),
                new HashSet <object>(),
                0.0
            };
            currentPickler.save(args);
            outs.WriteByte(Opcodes.BUILD);
        }
示例#24
0
        public void PyroClassesSerpent()
        {
            var ser = new SerpentSerializer();
            var uri = new PyroURI("PYRO:something@localhost:4444");
            byte[] s = ser.serializeData(uri);
            object x = ser.deserializeData(s);
            Assert.AreEqual(uri, x);

            var proxy = new PyroProxy(uri);
            proxy.correlation_id = Guid.NewGuid();
            proxy.pyroHandshake = "apples";
            proxy.pyroHmacKey = Encoding.UTF8.GetBytes("secret");
            proxy.pyroAttrs = new HashSet<string>();
            proxy.pyroAttrs.Add("attr1");
            proxy.pyroAttrs.Add("attr2");
            s = ser.serializeData(proxy);
            x = ser.deserializeData(s);
            PyroProxy proxy2 = (PyroProxy) x;
            Assert.AreEqual(uri.host, proxy2.hostname);
            Assert.AreEqual(uri.objectid, proxy2.objectid);
            Assert.AreEqual(uri.port, proxy2.port);
            Assert.IsNull(proxy2.correlation_id, "correlation_id is not serialized on the proxy object");
            Assert.AreEqual(proxy.pyroHandshake, proxy2.pyroHandshake);
            Assert.AreEqual(proxy.pyroHmacKey, proxy2.pyroHmacKey);
            Assert.AreEqual(2, proxy2.pyroAttrs.Count);
            Assert.AreEqual(proxy.pyroAttrs, proxy2.pyroAttrs);

            PyroException ex = new PyroException("error");
            s = ser.serializeData(ex);
            x = ser.deserializeData(s);
            PyroException ex2 = (PyroException) x;
            Assert.AreEqual(ex.Message, ex2.Message);
            Assert.IsNull(ex._pyroTraceback);

            // try another kind of pyro exception
            s = Encoding.UTF8.GetBytes("{'attributes':{'tb': 'traceback', '_pyroTraceback': ['line1', 'line2']},'__exception__':True,'args':('hello',42),'__class__':'CommunicationError'}");
            x = ser.deserializeData(s);
            ex2 = (PyroException) x;
            Assert.AreEqual("hello", ex2.Message);
            Assert.AreEqual("traceback", ex2.Data["tb"]);
            Assert.AreEqual("line1line2", ex2._pyroTraceback);
        }
示例#25
0
		public void PyroClasses()
		{
			var uri = new PyroURI("PYRO:object@host:4444");
			byte[] s = this.ser.serializeData(uri);
			object x = this.ser.deserializeData(s);
			Assert.AreEqual(uri, x);

			var proxy = new PyroProxy(uri);
			s = this.ser.serializeData(proxy);
			x = this.ser.deserializeData(s);
			PyroProxy proxy2 = (PyroProxy) x;
			Assert.AreEqual(uri.host, proxy2.hostname);
			Assert.AreEqual(uri.objectid, proxy2.objectid);
			Assert.AreEqual(uri.port, proxy2.port);

			var ex = new PyroException("error");
			ex._pyroTraceback = "traceback";
			s = this.ser.serializeData(ex);
			x = this.ser.deserializeData(s);
			PyroException ex2 = (PyroException) x;
			Assert.AreEqual(ex.Message, ex2.Message);
			Assert.AreEqual("traceback", ex2._pyroTraceback);
		}
示例#26
0
        public static IDictionary ToSerpentDict(object obj)
        {
            // note: the state array returned here must conform to the list consumed by Pyro4's Proxy.__setstate_from_dict__
            // that means, we make an array of length 8:
            // uri, oneway set, methods set, attrs set, timeout, hmac_key, handshake, maxretries  (in this order)
            PyroProxy proxy       = (PyroProxy)obj;
            var       dict        = new Hashtable();
            string    uri         = string.Format("PYRO:{0}@{1}:{2}", proxy.objectid, proxy.hostname, proxy.port);
            string    encodedHmac = proxy.pyroHmacKey != null? "b64:" + Convert.ToBase64String(proxy.pyroHmacKey) : null;

            dict["state"] = new [] {
                uri,
                proxy.pyroOneway,
                proxy.pyroMethods,
                proxy.pyroAttrs,
                0.0,
                encodedHmac,
                proxy.pyroHandshake,
                0          // maxretries is not yet supported/used by pyrolite
            };
            dict["__class__"] = "Pyro4.core.Proxy";
            return(dict);
        }
示例#27
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");
        }
示例#28
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;
 }
示例#29
0
 /// <summary>
 /// for the unpickler to restore state
 /// </summary>
 public void __setstate__(Hashtable values)
 {
     remoteconsole = (PyroProxy)values["remoteconsole"];
 }
示例#30
0
 private PyroProxy new_playfield()
 {
     using (NameServerProxy ns = NameServerProxy.locateNS(null))
     {
         using (PyroProxy playfield = new PyroProxy(ns.lookup("ping.playfield")))
         {
             return playfield;
         }
     }
 }
示例#31
0
        public static object FromSerpentDict(IDictionary dict)
        {
            // note: the state array received in the dict conforms to the list produced by Pyro4's Proxy.__getstate_for_dict__
            // that means, we must get an array of length 8:  (the same as with ToSerpentDict above!)
            // uri, oneway set, methods set, attrs set, timeout, hmac_key, handshake, maxretries  (in this order)
            object[] state = (object[])dict["state"];
            PyroURI  uri   = new PyroURI((string)state[0]);
            var      proxy = new PyroProxy(uri);

            // the following nasty piece of code is similar to _processMetaData from the PyroProxy
            // this is because the three collections can either be an array or a set
            object[] oneway_array  = state[1] as object[];
            object[] methods_array = state[2] as object[];
            object[] attrs_array   = state[3] as object[];
            if (oneway_array != null)
            {
                proxy.pyroOneway = new HashSet <string>(oneway_array.Select(o => o as string));
            }
            else if ((state[1] as HashSet <string>) != null)
            {
                proxy.pyroOneway = state[1] as HashSet <string>;
            }
            else
            {
                proxy.pyroOneway = new HashSet <string> ((state[1] as HashSet <object>).Select(o => o.ToString()));
            }

            if (methods_array != null)
            {
                proxy.pyroMethods = new HashSet <string>(methods_array.Select(o => o as string));
            }
            else if ((state[2] as HashSet <string>) != null)
            {
                proxy.pyroMethods = state[2] as HashSet <string>;
            }
            else
            {
                proxy.pyroMethods = new HashSet <string>((state[2] as HashSet <object>).Select(o => o.ToString()));
            }

            if (attrs_array != null)
            {
                proxy.pyroAttrs = new HashSet <string>(attrs_array.Select(o => o as string));
            }
            else if ((state[3] as HashSet <string>) != null)
            {
                proxy.pyroAttrs = state[3] as HashSet <string>;
            }
            else
            {
                proxy.pyroAttrs = new HashSet <string>((state[3] as HashSet <object>).Select(o => o.ToString()));
            }

            if (state[5] != null)
            {
                string encodedHmac = (string)state[5];
                if (encodedHmac.StartsWith("b64:", StringComparison.InvariantCulture))
                {
                    proxy.pyroHmacKey = Convert.FromBase64String(encodedHmac.Substring(4));
                }
                else
                {
                    throw new PyroException("hmac encoding error");
                }
            }
            proxy.pyroHandshake = state[6];
            // maxretries is not used/supported in pyrolite, so simply ignore it

            return(proxy);
        }
示例#32
0
 /// <summary>
 /// for the unpickler to restore state
 /// </summary>
 public void __setstate__(Hashtable values)
 {
     flameserver = (PyroProxy)values["flameserver"];
     module      = (string)values["module"];
 }
示例#33
0
	/// <summary>
	/// for the unpickler to restore state
	/// </summary>
	public void __setstate__(Hashtable values) {
		flameserver=(PyroProxy) values["flameserver"];
		module=(string) values["module"];
	}
示例#34
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.");

            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:");
            IDictionary<string,string> 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:");
            IDictionary<string, Tuple<string, ISet<string>>> 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 num_removed=ns.remove(null, "dotnet.", null);
            Console.WriteLine("number of removed entries: {0}",num_removed);

            try {
                Console.WriteLine("uri=" + ns.lookup("dotnet.test"));	 // should fail....
            } catch (PyroException x) {
                // ok
                Console.WriteLine("got a PyroException (expected): {0}", x.Message);
            }

            Console.WriteLine("\r\nEnter to exit:"); Console.ReadLine();
            }
        }
示例#35
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();
	}
示例#36
0
 /// <summary>
 /// for the unpickler to restore state
 /// </summary>
 public void __setstate__(Hashtable values)
 {
     flameserver=(PyroProxy) values["flameserver"];
     builtin=(string) values["builtin"];
 }
示例#37
0
        public void PyroProxySerpent()
        {
            PyroURI uri = new PyroURI("PYRO:something@localhost:4444");
            PyroProxy proxy = new PyroProxy(uri);
            proxy.correlation_id = Guid.NewGuid();
            proxy.pyroHandshake = "apples";
            proxy.pyroHmacKey = Encoding.UTF8.GetBytes("secret");
            proxy.pyroAttrs = new HashSet<string>();
            proxy.pyroAttrs.Add("attr1");
            proxy.pyroAttrs.Add("attr2");
            var data = PyroProxyPickler.ToSerpentDict(proxy);
            Assert.AreEqual(2, data.Count);
            Assert.AreEqual("Pyro4.core.Proxy", data["__class__"]);
            Assert.AreEqual(8, ((object[])data["state"]).Length);

            PyroProxy proxy2 = (PyroProxy) PyroProxyPickler.FromSerpentDict(data);
            Assert.AreEqual(proxy.objectid, proxy2.objectid);
            Assert.AreEqual("apples", proxy2.pyroHandshake);
        }
示例#38
0
 /// <summary>
 /// for the unpickler to restore state
 /// </summary>
 public void __setstate__(Hashtable values)
 {
     remoteconsole=(PyroProxy)values["remoteconsole"];
 }
示例#39
0
        protected static byte[] hmacKey = null; // Encoding.UTF8.GetBytes("foo");

        #endregion Fields

        #region Methods

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

            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.Count == 7);
            if(p2.pyroHmacKey!=null) {
                string hmac2 = Encoding.UTF8.GetString(p2.pyroHmacKey);
                Debug.Assert(hmac2==Encoding.UTF8.GetString(hmacKey));
            }

            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();
            }
        }
示例#40
0
 public StreamResultIterator(string streamId, PyroProxy proxy)
 {
     this.streamId = streamId;
     this.proxy    = proxy;
 }
示例#41
0
 /// <summary>
 /// for the unpickler to restore state
 /// </summary>
 public void __setstate__(Hashtable values)
 {
     _flameserver = (PyroProxy)values["flameserver"];
     _builtin     = (string)values["builtin"];
 }
示例#42
0
        public void testProxyCorrelationId()
        {
            PyroProxy p = new PyroProxy(new PyroURI("PYRO:foo@localhost:55555"));
            p.correlation_id = null;
            var ann = p.annotations();
            Assert.AreEqual(0, ann.Count);
            p.correlation_id = Guid.NewGuid();
            ann = p.annotations();
            Assert.AreEqual(1, ann.Count);
            Assert.IsTrue(ann.ContainsKey("CORR"));

            Guid uuid = new Guid(ann["CORR"]);
            Assert.AreEqual(p.correlation_id, uuid);
        }