示例#1
0
 public static T FromBytes <T>(IServerRequest <T> response, byte[] responseBytes)
 {
     using (MemoryStream ms = new MemoryStream(responseBytes))
     {
         return(response.GetRequest(ms));
     }
 }
示例#2
0
        public void ResponseFromServer(IServerRequest serverRequest)
        {
            var response = _activeRequests[serverRequest.RequestId];

            _activeRequests.Remove(serverRequest.RequestId);
            response(serverRequest);
        }
示例#3
0
        private static void HandleServerRequest(string value)
        {
            value = value.Trim();
            string instruction = value;
            string args        = null;

            // Check if we got parameters with the instruction
            if (value.IndexOf(' ') > -1)
            {
                instruction = value.SplitCommand()[0];
                args        = value.SplitCommand()[1];
            }

            // Is request registered?
            IServerRequest request = ServerRequestRegistry.GetHandler(instruction);

            if (request != null)
            {
                request.Run(args);
            }
            else
            {
                // Protocol request unknown, inform client
                ClientMessage.Info($"Unknown protocol value: {value}");
            }
        }
示例#4
0
        private void HandleCommand(User user, string value)
        {
            // Default return message
            string response = "ERROR Unknown command";

            value = value.Trim();
            string instruction = value;
            string args        = null;

            // Check if we got parameters with the instruction
            if (value.IndexOf(' ') > -1)
            {
                instruction = value.SplitCommand()[0];
                args        = value.SplitCommand()[1];
            }

            IServerRequest request = CommandRegistry.GetCommand(instruction);

            if (request != null)
            {
                request.Run(user, args);
            }
            else
            {
                // Unknown command, inform client
                user.WriteLine(response);
            }
        }
示例#5
0
        public void MakeRequest(IServerRequest request, Action<IServerRequest> response)
        {
            request.RequestId = _requestId++;

            _activeRequests.Add(request.RequestId, response);

            SendServerRequest(request);
        }
示例#6
0
        public void MakeRequest(IServerRequest request, Action <IServerRequest> response)
        {
            request.RequestId = _requestId++;

            _activeRequests.Add(request.RequestId, response);

            SendServerRequest(request);
        }
示例#7
0
        protected void SendServerRequest(IServerRequest serverRequest)
        {
            var myEvent = SendRequestToServer;

            if (myEvent == null)
                throw new Exception("There is no subscribtion of Server Request Engine");

            myEvent(this, new EventArgs<IServerRequest>(serverRequest));
        }
		private byte[] GetResponseBytes(IServerRequest request)
		{
			var udpClient = new UdpClient(_server.Address.ToString(), _server.Port);
			udpClient.Send(request);

			var remoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
			var bytesReceived = udpClient.Receive(ref remoteIpEndPoint);

			return bytesReceived;
		}
示例#9
0
        protected void SendServerRequest(IServerRequest serverRequest)
        {
            var myEvent = SendRequestToServer;

            if (myEvent == null)
            {
                throw new Exception("There is no subscribtion of Server Request Engine");
            }

            myEvent(this, new EventArgs <IServerRequest>(serverRequest));
        }
示例#10
0
        private async Task <string> SendRequest(IServerRequest requestPayload)
        {
            try
            {
                HttpResponseMessage response = await webClient.PostAsync(
                    requestPayload.getEndpoint(),
                    new StringContent(requestPayload.getPayload(), Encoding.UTF8, "application/json"));

                Console.WriteLine(response.Content.ReadAsStringAsync().Result);
                return(await response.Content.ReadAsStringAsync());
            }
            catch (TimeoutException e)
            {
                Console.WriteLine(e.StackTrace);
                return(null);
            }
        }
示例#11
0
 public static void RegisterCommand(string command, IServerRequest handler)
 {
     command = command.ToUpper();
     Commands.Add(command, handler);
 }
示例#12
0
 public void ResponseFromServer(IServerRequest serverRequest)
 {
     var response = _activeRequests[serverRequest.RequestId];
     _activeRequests.Remove(serverRequest.RequestId);
     response(serverRequest);
 }
		public static int Send(this UdpClient udpClient, IServerRequest request)
		{
			var bytes = request.ToBytes();
			return udpClient.Send(bytes, bytes.Length);
		}