示例#1
0
    void HandleTcpMessage(ITcpMessage msg)
    {
        switch (msg)
        {
        case ObjectCreatedMessage objMsg:
        {
            var id = objMsg.ObjectId;
            Objects[id] = new SyncObject(this, id, objMsg.OriginalNodeId);

            if (creationQueue.Count > 0 && objMsg.OriginalNodeId == NodeId)
            {
                lock (creationQueue)
                {
                    creationQueue.Dequeue().SetResult(id);
                }
            }

            Logger.Debug("Client", $"Received ObjectId={id}");

            InvokeObjectCreated(id);

            break;
        }

        case ObjectDeletedMessage delMsg:
        {
            var id = delMsg.ObjectId;
            Objects.Remove(id);

            Logger.Debug("Client", $"Received Deletion of ObjectId={id}");

            InvokeObjectDeleted(id);

            break;
        }

        case SymbolRegisteredMessage symMsg:
        {
            SymbolTable.Add(symMsg.Symbol, symMsg.SymbolId);
            if (symbolNotifier.IsWaiting(symMsg.Symbol))
            {
                symbolNotifier.Notify(symMsg.Symbol, symMsg.SymbolId);
            }

            Logger.Debug("Client", $"Received Symbol {symMsg.Symbol}->{symMsg.SymbolId}");
            break;
        }

        case EventSentMessage eventSentMessage:
        {
            HandleEventSentMessage(
                eventSentMessage.Name,
                eventSentMessage.Sender, eventSentMessage.Receiver,
                eventSentMessage.Args
                );
            break;
        }
        }
    }