コード例 #1
0
        public static void RunDynamic(string input)
        {
            var name = input.Split(' ')[0];

            var local = CommandsReflector.GetLocalCommand(name);

            if (local.Item1 != null)
            {
                var localCommand = local.Item1;
                var attribute    = local.Item2;

                var args = ReverseStringFormat(attribute.Template, input).ToArray();

                localCommand.Run(args);
            }
            else
            {
                var global = CommandsReflector.GetGlobalCommand(name);

                if (global.Item1 != null)
                {
                    var globalCommand = global.Item1;
                    var attribute     = global.Item2;

                    var args = ReverseStringFormat(attribute.Template, input).ToArray();

                    if (globalCommand.ValidateInput(args))
                    {
                        requestFabric.MakeRequest(name, args, globalCommand, attribute);
                    }
                }
            }
        }
コード例 #2
0
        public void ReceiveResponse(SocketDataBody data)
        {
            var commandName = data.CommandName;

            var command = CommandsReflector.GetGlobalCommand(commandName).Item1;

            command.Receive(data);
        }
コード例 #3
0
        public void ReadCallback(IAsyncResult ar)
        {
            SocketDataBody content = null;

            // Retrieve the state object and the handler socket
            // from the asynchronous state object.
            StateObject state   = (StateObject)ar.AsyncState;
            Socket      handler = state.workSocket;

            // Read data from the client socket.
            int bytesRead = handler.EndReceive(ar);

            if (bytesRead > 0)
            {
                // There  might be more data, so store the data received so far.
                state.sb.Append(Encoding.ASCII.GetString(
                                    state.buffer, 0, bytesRead));

                // Check for end-of-file tag. If it is not there, read
                // more data.

                content = JsonConvert.DeserializeObject <SocketDataBody>(state.sb.ToString());

                if (content != null)
                {
                    this.responseFabric.ReceiveResponse(content);

                    var body = CommandsReflector.GetGlobalCommand(content.CommandName).Item1.Aggregate(content);
                    content.Body = body;
                    content.Type = SocketDataType.Receive;

                    Send(handler, content);
                }
                else
                {
                    // Not all data received. Get more.
                    handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
                                         new AsyncCallback(ReadCallback), state);
                }
            }
        }