Beispiel #1
0
        public HttpCode Execute()
        {
            Clear();

            // Connect
            NetworkChannel channel = null;

            try
            {
                channel = new NetworkChannel(Connection);

                // Request
                JsonPingRequestMessage jsonRequestMessage = new JsonPingRequestMessage();
                JsonPacket             jsonRequest        = new JsonPacket(jsonRequestMessage);

                HttpRequest httpRequest = new HttpRequest(Session.Id)
                {
                    Data = Session.Encrypt(jsonRequest)
                };

                // Response
                HttpResponse httpResponse;

                if (Owner)
                {
                    channel.Send(httpRequest);
                    channel.Receive(out httpResponse);
                }
                else
                {
                    lock (Socket)
                    {
                        channel.Send(httpRequest);
                        channel.Receive(out httpResponse);
                    }
                }

                Code = httpResponse.Code;

                if (httpResponse.Ok)
                {
                    JsonPacket jsonResponse = JsonPacket.Parse(Session.Decrypt(httpResponse.Data));
#if DEBUG
                    Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse);
#endif
                }
            }
            finally
            {
                if (channel != null)
                {
                    channel.Shutdown();
                }
            }

            return(Code);
        }
Beispiel #2
0
        private void ExecuteThread()
        {
            // Connect
            NetworkChannel channel = null;

            try
            {
                channel = new NetworkChannel(Connection);

                // Request
                JsonPingRequestMessage jsonRequestMessage = new JsonPingRequestMessage();
                JsonPacket             jsonRequest        = new JsonPacket(jsonRequestMessage);

                HttpRequest httpRequest = new HttpRequest(Session.Id)
                {
                    Data = Session.Encrypt(jsonRequest)
                };
                channel.Send(httpRequest);

                // Response
                HttpResponse httpResponse;
                channel.Receive(out httpResponse);
                Code = httpResponse.Code;

                if (httpResponse.Ok)
                {
                    JsonPacket jsonResponse = JsonPacket.Parse(Session.Decrypt(httpResponse.Data));
#if DEBUG
                    Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse);
#endif
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);

                if (Owner && Machine != null)
                {
                    Machine.Restart();
                }
            }
            finally
            {
                if (channel != null)
                {
                    channel.Shutdown();
                }
            }
        }
Beispiel #3
0
        public void Execute(HttpRequest httpRequest, JsonPacket jsonRequest)
        {
            // Connect
            NetworkChannel channel = new NetworkChannel(Connection);

            // Request
            JsonPingRequestMessage jsonRequestMessage = JsonPingRequestMessage.Parse(jsonRequest.Message);

            // Response
            JsonPingResponseMessage jsonResponseMessage = new JsonPingResponseMessage();
            JsonPacket jsonResponse = new JsonPacket(jsonResponseMessage);

            HttpResponse httpResponse = new HttpResponse()
            {
                Data = Session.Encrypt(jsonResponse)
            };

            channel.Send(httpResponse);
#if DEBUG
            Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse);
#endif
        }
Beispiel #4
0
        public void Execute(HttpRequest httpRequest, JsonPacket jsonRequest, SessionComponent session)
        {
            // Connect
            NetworkChannel channel = new NetworkChannel(Connection);

            // Request
            JsonPingRequestMessage jsonRequestMessage = JsonPingRequestMessage.Parse(jsonRequest.Message);

            // Data
            HttpCode        code   = HttpCode.Ok;
            Entity          entity = session.Owner;
            TunnelComponent tunnel = entity.Get <TunnelComponent>();

            if (tunnel != null)
            {
                PingRequestCommand command = new PingRequestCommand(entity, tunnel.Connection);
                code = command.Execute();
                if (code == HttpCode.Ok)
                {
                    entity.Update();
                }
            }

            // Response
            JsonPingResponseMessage jsonResponseMessage = new JsonPingResponseMessage();
            JsonPacket jsonResponse = new JsonPacket(jsonResponseMessage);

            HttpResponse httpResponse = new HttpResponse(code)
            {
                Data = session.Encrypt(jsonResponse)
            };

            channel.Send(httpResponse);
#if DEBUG
            Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse);
#endif
        }