Пример #1
0
        public void Execute(HttpRequest httpRequest, JsonPacket jsonRequest)
        {
            Clear();

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

            // Request
            JsonSearchRequestMessage jsonRequestMessage = JsonSearchRequestMessage.Parse(jsonRequest.Message);
            JsonSearchRequestData    jsonRequestData    = JsonSearchRequestData.Parse(Group.Decrypt(jsonRequest.Data));
            JsonSearch jsonSearch = jsonRequestData.Search;

            // Data
            List <FileComponent> compFiles = FileMap.Search(jsonSearch);

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

            List <JsonFile> jsonFiles = new List <JsonFile>();

            foreach (FileComponent file in compFiles)
            {
                JsonFile jsonFile = (JsonFile)file;
                jsonFiles.Add(jsonFile);
            }

            // Response
            JsonSearchResponseMessage jsonResponseMessage = new JsonSearchResponseMessage();
            JsonSearchResponseData    jsonResponseData    = new JsonSearchResponseData()
            {
                Files = jsonFiles
            };
            JsonPacket jsonResponse = new JsonPacket(jsonResponseMessage, Group.Encrypt(jsonResponseData));

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

            channel.Send(httpResponse);
#if DEBUG
            Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse);
#endif
        }
Пример #2
0
        public List <FileComponent> Execute(HttpRequest httpRequest, JsonPacket jsonRequest)
        {
            Clear();

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

            // Response
            JsonSearchResponseMessage jsonResponseMessage = new JsonSearchResponseMessage();
            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
            // Request
            JsonSearchResponseMessage jsonRequestMessage = JsonSearchResponseMessage.Parse(jsonRequest.Message);
            string jsonId = jsonRequestMessage.Id;
            if (SearchList.Id != jsonId)
            {
                return(null);
            }

            JsonSearchResponseData jsonRequestData = JsonSearchResponseData.Parse(Group.Decrypt(jsonRequest.Data));
            List <JsonFile>        jsonFiles       = jsonRequestData.Files;
            List <FileComponent>   list            = new List <FileComponent>();

            // Data
            foreach (JsonFile jsonFile in jsonFiles)
            {
                FileComponent file = new FileComponent(jsonFile.Id, jsonFile.Name, jsonFile.Size)
                {
                    Owner = Entity
                };
                list.Add(file);
            }

            return(list);
        }