Beispiel #1
0
        public void Start()
        {
            TcpClient client = new TcpClient(_hostname, _port);

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

            _channel = new MessageChannel(_xport, _format);
            _channel.MessageReceived += OnMessageReceived;
        }
Beispiel #2
0
 public RequestContext(MessageChannel channel, int ackNumber)
 {
     _channel = channel;
     _ackNumber = ackNumber;
 }
Beispiel #3
0
 private void OnChannelClosed(MessageChannel channel)
 {
     Console.WriteLine("channel closed.");
     _channels.Remove(channel);
 }
Beispiel #4
0
        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);
        }