Esempio n. 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());
            }
        }
Esempio n. 2
0
        public InputPlug LocateInputPlugAtAddress(Address address)
        {
            Node      n = Nodes.Find(node => node.Name == address.node);
            InputPlug p = n.Inputs.Find(outplug => outplug.Name == address.originPlug);

            return(Nodes.Find(node => node.Name == address.node)?.Inputs.Find(outplug => outplug.Name == address.originPlug));
        }
Esempio n. 3
0
        public InputPlug AddInput(string name)
        {
            InputPlug iplug = new InputPlug(this, 0, PlugCount() * 15 + 20, name);

            m_inplugs.Add(iplug);
            m_rect.height = PlugCount() * 15 + 20;
            return(iplug);
        }
Esempio n. 4
0
        private void ReceivedGraph(Endpoint remoteEndpoint, string graphjson)
        {
            Console.WriteLine("Got graph update from " + remoteEndpoint.Name);

            JsonSerializerSettings settings = new JsonSerializerSettings
            {
                ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
                ContractResolver    = new PrivateResolver()
            };

            List <GraphUpdate> remoteupdates = JsonConvert.DeserializeObject <List <GraphUpdate> >(graphjson, settings);

            foreach (GraphUpdate nodeupdate in remoteupdates)
            {
                //Create or retrieve current node
                Node activenode = remoteEndpoint.CreateNode(nodeupdate.node);

                var missingremoteinputs  = nodeupdate.node.Inputs.Where(i => i.destroyed);
                var missingremoteoutputs = nodeupdate.node.Outputs.Where(o => o.destroyed);

                var newremoteinputs  = nodeupdate.node.Inputs.Where(p => !activenode.Inputs.Any(l => p.Path == l.Path) && !p.destroyed);
                var newremoteoutputs = nodeupdate.node.Outputs.Where(p => !activenode.Outputs.Any(l => p.Path == l.Path) && !p.destroyed);

                //Remove old plugs from the local node
                foreach (InputPlug input in missingremoteinputs)
                {
                    InputPlug localinput = activenode.Inputs.Find(i => input.Name == i.Name);
                    localinput.Dispose();
                }

                foreach (OutputPlug output in missingremoteoutputs)
                {
                    OutputPlug localoutput = activenode.Outputs.Find(o => output.Name == o.Name);
                    localoutput.Dispose();
                }

                //Add new plugs to nodes.
                foreach (InputPlug newinput in newremoteinputs)
                {
                    activenode.CreateInputPlug(newinput);
                }

                foreach (OutputPlug newoutput in newremoteoutputs)
                {
                    activenode.CreateOutputPlug(newoutput);
                }
            }

            //Remove missing nodes that have disappeared from the remote endpoint
            var missingnodes = remoteEndpoint.Nodes.Where(p => !remoteupdates.Any(l => p.Name == l.node.Name));

            foreach (Node node in missingnodes)
            {
                node.Dispose();
            }

            Nodes.RemoveAll(n => missingnodes.Any(o => o.Name == n.Name));
        }
Esempio n. 5
0
        public override void PlugConnectionRequest(InputPlug input, OutputPlug output)
        {
            NetMQMessage msg = new NetMQMessage(3);

            msg.Append(Endpoint.Commands.PLUG_CONNECT.ToString());
            msg.Append(input.Path.ToString());
            msg.Append(output.Path.ToString());
            Whisper(Uuid, msg);
        }
Esempio n. 6
0
 public bool AddTarget(InputPlug plug)
 {
     if (plug.GetParent() != m_parent)               // not same node
     {
         m_targetPlugs.Add(plug);
         plug.SetSrcPlug(this);
         return(true);
     }
     return(false);
 }
Esempio n. 7
0
        public InputPlug CreateInputPlug(string plugname)
        {
            if (Inputs.Any(p => p.Name == plugname))
            {
                throw new ArgumentException("Input plug already exists!");
            }

            Endpoint.Log(String.Format("Creating input {0} for {1}", plugname, _name));
            InputPlug input = new InputPlug(plugname, this);

            _inputs.Add(input);
            Endpoint.UpdateGraph(this, GraphUpdate.UpdateType.UPDATED);
            return(input);
        }
Esempio n. 8
0
        public InputPlug CreateInputPlug(InputPlug plug)
        {
            if (!Inputs.Any(p => p.Name == plug.Name))
            {
                plug.Owner = this;
                Inputs.Add(plug);
            }
            else
            {
                InputPlug existing = Inputs.Find(p => p.Name == plug.Name);
                if (existing.Owner == null)
                {
                    existing.Owner = this;
                }
                return(existing);
            }

            return(plug);
        }
    void preset()
    {
        Node       node1 = AddNode("Node1");
        OutputPlug plug1 = node1.AddOutput("OutABC");

        node1.SetPos(10, 100);
        node1.AddInput("InABC");

        Node node2 = AddNode("Node2");

        node2.SetPos(250, 150);
        node2.AddOutput("OutDDD");
        InputPlug plug2 = node2.AddInput("InFFF");

        node2.AddInput("InGGG");

        plug1.AddTarget(plug2);         // Link

        Node node3 = AddNode("Node3");

        node3.AddOutput("OutHHH");
        node3.SetPos(10, 300);
    }
Esempio n. 10
0
        public void RegisterListener(InputPlug input, OutputPlug output)
        {
            if (!ConnectedInputs.ContainsKey(output.Path.ToString()))
            {
                ConnectedInputs.Add(output.Path.ToString(), new List <InputPlug>());
            }

            if (!ConnectedInputs[output.Path.ToString()].Contains(input))
            {
                ConnectedInputs[output.Path.ToString()].Add(input);
                Endpoint.RegisterListenerNode(this);
                Endpoint.CheckPolling();

                if (input.Owner.Endpoint != output.Owner.Endpoint)
                {
                    Endpoint.Log("In plug connection request");
                    Endpoint.PlugConnectionRequest(input, output);
                }
            }
            else
            {
                Endpoint.Log("Plug is already connected");
            }
        }
Esempio n. 11
0
 public void RemoveTarget(InputPlug plug)
 {
     m_targetPlugs.Remove(plug);
     plug.SetSrcPlug(null);
 }
Esempio n. 12
0
 public abstract void PlugConnectionRequest(InputPlug input, OutputPlug output);
Esempio n. 13
0
 public override void PlugConnectionRequest(InputPlug input, OutputPlug output)
 {
     Log("Local endpoint trying to initiate remote plug connection. Triggered from remote endpoint connection. Can safely ignore.");
 }
Esempio n. 14
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();
            }
        }