Beispiel #1
0
        private void HandleWhisperMessage(NetMQMessage msg)
        {
            string whispertype = msg[3].ConvertToString();

            if (whispertype == Endpoint.Commands.REQ_FULL_GRAPH.ToString())
            {
                SendFullGraph();
            }
            else if (whispertype == Endpoint.Commands.SEND_GRAPH.ToString())
            {
                ReceivedGraph(_remoteEndpoints[new Guid(msg[1].Buffer)], msg[4].ConvertToString());
            }
            else if (whispertype == Endpoint.Commands.PLUG_MSG.ToString())
            {
                Log("Received remote message for local plug: " + msg.ToString());
                Message    remotemsg = Message.FromZyreWhisper(msg);
                OutputPlug outplug   = RemoteEndpoints[new Guid(msg[1].Buffer)].LocateOutputPlugAtAddress(remotemsg.address);
                outplug.Update(remotemsg);
            }
            else if (whispertype == Endpoint.Commands.PLUG_CONNECT.ToString())
            {
                Address inputaddress  = Address.FromFullPath(msg[4].ConvertToString());
                Address outputaddress = Address.FromFullPath(msg[5].ConvertToString());

                Log(string.Format("Remote request to connect O->:{0} to ->I:{1}", inputaddress.ToString(), outputaddress.ToString()));
                OutputPlug outplug = RemoteEndpoints[new Guid(msg[1].Buffer)].LocateOutputPlugAtAddress(outputaddress);
                InputPlug  inplug  = LocateInputPlugAtAddress(inputaddress);
                inplug.Connect(outplug);
            }
            else
            {
                Log("Unknown whisper type received for message " + msg.ToString());
            }
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            string guid       = Guid.NewGuid().ToString();
            string endpointid = guid.Substring(Math.Max(0, guid.Length - 4));

            using (ZyreEndpoint local = new ZyreEndpoint(endpointid, (s) => { Console.WriteLine("LOCAL: " + s); }))
            {
                Console.WriteLine("Starting Showtime test");
                System.Threading.Thread.Sleep(1000);

                Console.Clear();

                Console.WriteLine("How many nodes to create?");
                CreateNodes(local, 2);
                LinkNodesInChain(local);

                Console.WriteLine("Connect to local or remote? (l/r)");
                Endpoint targetEndpoint = null;
                while (targetEndpoint == null)
                {
                    char key = Console.ReadKey().KeyChar;
                    Console.WriteLine("");
                    if (key == 'l')
                    {
                        targetEndpoint = local;

                        Console.WriteLine("Test node chain?");
                        if ((Console.ReadKey().KeyChar == 'y') ? true : false)
                        {
                            LinkNodesInChain(targetEndpoint);
                            TestNodeLink(targetEndpoint);
                        }
                    }
                    else if (key == 'r')
                    {
                        local.StartZyre();
                        local.ListNodes();
                        Console.WriteLine("Waiting for remote nodes...");

                        while (local.RemoteEndpoints.Values.Count == 0)
                        {
                            System.Threading.Thread.Sleep(100);
                        }

                        foreach (Endpoint remoteEndpoint in local.RemoteEndpoints.Values)
                        {
                            targetEndpoint = remoteEndpoint;
                            break;
                        }
                    }
                    else
                    {
                        Console.WriteLine(string.Format("Didn't understand input \'{0}\'. Please enter l or r", key));
                    }
                }

                //Setup message test
                local.ListNodes();
                Console.WriteLine("\nEnter index of source node");
                Node outnode = local.Nodes[int.Parse(Console.ReadLine())];

                outnode.ListOutputs();
                Console.WriteLine("\nEnter index of source plug");
                OutputPlug output = outnode.Outputs[int.Parse(Console.ReadLine())];

                targetEndpoint.ListNodes();
                Console.WriteLine("\nEnter index of destination node");
                Node innode = targetEndpoint.Nodes[int.Parse(Console.ReadLine())];

                innode.ListInputs();
                Console.WriteLine("\nEnter index of destination plug");
                InputPlug input = innode.Inputs[int.Parse(Console.ReadLine())];


                Console.WriteLine(string.Format("About to connect {0} -> {1}", output.Path, input.Path));
                input.Connect(output);

                System.Threading.Thread.Sleep(1000);

                do
                {
                    Console.WriteLine("\nEnter message:");
                    output.Update(Console.ReadLine());
                } while (Console.ReadKey(true).Key != ConsoleKey.Escape);


                Console.WriteLine("Testing local output removal");
                output.Dispose();

                Console.WriteLine("\nRemaining outputs:");
                outnode.ListOutputs();

                System.Threading.Thread.Sleep(1000);


                Console.WriteLine("Testing local node removal");
                outnode.Dispose();

                Console.WriteLine("\nRemaining nodes:");
                local.ListNodes();

                System.Threading.Thread.Sleep(1000);

                //local.Dispose();
            }
        }