Exemplo n.º 1
0
        public List <BrowseComponent> Execute()
        {
            Clear();

            NetworkChannel         channel = null;
            List <BrowseComponent> list    = new List <BrowseComponent>();

            try
            {
                // Connect
                channel = new NetworkChannel(Connection);

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

                    if (jsonResponseMessage != null)
                    {
                        // Clients
                        foreach (JsonClient jsonClient in jsonResponseMessage.Clients)
                        {
                            BrowseComponent browse = new BrowseComponent(jsonClient.Name)
                            {
                                ClientId = jsonClient.Id, Owner = Entity
                            };
                            list.Add(browse);
                        }
                    }
#if DEBUG
                    Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse);
#endif
                }
            }
            finally
            {
                if (channel != null)
                {
                    channel.Shutdown();
                }
            }

            return(list);
        }
Exemplo n.º 2
0
        public void Execute(HttpRequest httpRequest, JsonPacket jsonRequest, SessionComponent session)
        {
            // Connect
            NetworkChannel channel = new NetworkChannel(Connection);

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

            // Data
            Entity         entity   = session.Owner;
            GroupComponent group    = entity.Get <GroupComponent>();
            EntityList     entities = GroupList.Get(group.Id);

            if (entities == null)
            {
                channel.SendNotFound();
                return;
            }

            List <JsonClient> jsonClients = new List <JsonClient>();

            lock (entities)
            {
                foreach (Entity e in entities)
                {
#if !DEBUG
                    if (entity.Id.Equals(e.Id))
                    {
                        continue;
                    }
#endif
                    ClientComponent c          = e.Get <ClientComponent>();
                    JsonClient      jsonClient = (JsonClient)c;
                    jsonClients.Add(jsonClient);
                }
            }

            if (jsonClients.Count == 0)
            {
                channel.SendNotFound();
                return;
            }

            jsonClients.Sort();

            // Response
            JsonGroupResponseMessage jsonResponseMessage = new JsonGroupResponseMessage()
            {
                Clients = jsonClients
            };
            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
        }