Ejemplo n.º 1
0
        /// <inheritdoc/>
        public void RegisterNode(Node node, NodeLibrary dependency)
        {
            _loadedAssemblies.Add(node.GetType().Assembly);
            var fullName = node.GetType().FullName ?? string.Empty;

            if (_availableNodeViewModels.Contains(node))
            {
                return;
            }

            if (_nodeNameToViewModelMap.ContainsKey(fullName))
            {
                return;
            }

            if (_dependencyMap.ContainsKey(fullName))
            {
                throw new InvalidOperationException($"Node registered twice with {GetType().AssemblyQualifiedName}");
            }

            _nodeNameToViewModelMap.Add(fullName, node.GetType());
            _availableNodeViewModels.Add(node);
            _dependencyMap.Add(fullName, dependency);

            NodeRegistered?.Invoke(node);
        }
Ejemplo n.º 2
0
        public void ProcessMessage(MessageData message)
        {
            switch (message.Type)
            {
            case MessageType.Common:
                OnNormalMessage();
                return;

            case MessageType.NodeSignal:
                OnNodeSignalMessage();
                return;

            case MessageType.NodeInitialization:
                OnNewNode();
                return;
            }


            void OnNewNode()
            {
                var nodeName = MessageCodec.DecodeNodeInitialization(message.Data);

                //var udpSigWorker = new NodeSignalsWorker(message.Identity, m_signalsProcessor.SendSignalBuffer);
                var tcpSigWorker = new NodeMainTCPSignalWorker(message.Identity, m_signalsProcessor.SendSignalBuffer);
                var cmdSigWorker = new NodeCommandSignalWorker(message.Identity, m_signalsProcessor.SendSignalBuffer);

                var node = new Node(message.Identity,
                                    nodeName,
                                    //udpSigWorker,
                                    tcpSigWorker,
                                    cmdSigWorker);

                m_nodes.Add(message.Identity, node);
                node.OutMessageBuffer.LinkTo(SendMessageBuffer);
                node.CommandOutMessageBuffer.LinkTo(SendCommandBuffer);

                NodeRegistered?.Invoke(this, new NodeRegisteredEventArgs(node));

                node.TCPSocketSignalsWorker.SendNullSignal();
            }

            void OnNodeSignalMessage()
            {
                if (m_nodes.TryGetValue(message.Identity, out var node))
                {
                    m_signalsProcessor.RecvSignalBuffer.Post((                                //(message.Protocol == TransportProtocol.TCP) ?
                                                                 node.TCPSocketSignalsWorker, //:
                                                                 //node.UDPSocketSignalsWorker,
                                                                 message.Data));
                }
                else
                {
                    OnUninitializedMessage();
                }
            }

            void OnNormalMessage()
            {
                if (m_nodes.TryGetValue(message.Identity, out var node))
                {
                    node.InMessageBuffer.Post(message.Data);
                }
                else
                {
                    OnUninitializedMessage();
                }
            }
        }