Beispiel #1
0
        private void ExecuteThread()
        {
            Clear();

            // Connect
            NetworkChannel channel = null;

            try
            {
                channel = new NetworkChannel(Connection);

                // Request
                JsonInfoRequestMessage jsonRequestMessage = new JsonInfoRequestMessage();
                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));
                    JsonInfoResponseMessage jsonResponseMessage = JsonInfoResponseMessage.Parse(jsonResponse.Message);

                    // Data
                    Server.Entities = jsonResponseMessage.Entities;
                    Server.Sessions = jsonResponseMessage.Sessions;
                    Server.Clients  = jsonResponseMessage.Clients;
                    Server.Groups   = jsonResponseMessage.Groups;
#if DEBUG
                    Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse);
#endif
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Machine.Status = DemonStatus.Warning;
            }
            finally
            {
                if (channel != null)
                {
                    channel.Shutdown();
                }
            }
        }
Beispiel #2
0
        public void Execute(HttpRequest httpRequest, JsonPacket jsonRequest, SessionComponent session)
        {
            // Connect
            NetworkChannel channel = new NetworkChannel(Connection);

            // Request
            JsonInfoRequestMessage jsonRequestMessage = JsonInfoRequestMessage.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
            JsonInfoResponseMessage jsonResponseMessage = new JsonInfoResponseMessage()
            {
                Entities = Server.Entities, Sessions = Server.Sessions, Clients = Server.Clients, Groups = Server.Groups
            };
            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
        }