コード例 #1
0
ファイル: Client.cs プロジェクト: vogon/Demotic
        public void Start()
        {
            TcpClient client = new TcpClient(_hostname, _port);

            _xport = new TcpMessageTransport(client);
            _format = new DipMessageFormat();

            _channel = new MessageChannel(_xport, _format);
            _channel.MessageReceived += OnMessageReceived;
        }
コード例 #2
0
ファイル: RequestContext.cs プロジェクト: vogon/Demotic
 public RequestContext(MessageChannel channel, int ackNumber)
 {
     _channel = channel;
     _ackNumber = ackNumber;
 }
コード例 #3
0
ファイル: Server.cs プロジェクト: vogon/Demotic
 private void OnChannelClosed(MessageChannel channel)
 {
     Console.WriteLine("channel closed.");
     _channels.Remove(channel);
 }
コード例 #4
0
ファイル: Server.cs プロジェクト: vogon/Demotic
        private void MakeActionAndDispatch(Message msg, MessageChannel channel)
        {
            UserAction request = null;
            RequestContext context = new RequestContext(channel, msg.SequenceNumber);

            if (msg.OpCode == MessageOpCode.GetObject)
            {
                string path = GetString(msg, "path");

                if (path == null) context.NegativeAcknowledge();

                request = new GetObjectAction(context, path);
            }
            else if (msg.OpCode == MessageOpCode.PutObject)
            {
                string path = GetString(msg, "path");
                DObject value = GetObject(msg, "value");

                if (path == null) context.NegativeAcknowledge();
                if (value == null) context.NegativeAcknowledge();

                request = new PutObjectAction(context, path, value);
            }
            else if (msg.OpCode == MessageOpCode.DoScript)
            {
                string trigger = GetString(msg, "when");
                string body = GetString(msg, "do");

                if (trigger == null) context.NegativeAcknowledge();
                if (body == null) context.NegativeAcknowledge();

                request = new DoScriptAction(context, trigger, body);
            }
            else if (msg.OpCode == MessageOpCode.NG ||
                     msg.OpCode == MessageOpCode.OK ||
                     msg.OpCode == MessageOpCode.Quote)
            {
                // drop it on the floor; not expecting these.
                return;
            }
            else
            {
                throw new NotImplementedException();
            }

            Debug.Assert(request != null);
            _worker.Dispatch(request, context);
        }