Ejemplo n.º 1
0
        private void ExecuteThread()
        {
            NetworkChannel channel = null;

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

                // Request
                JsonSearchRequestMessage jsonRequestMessage = new JsonSearchRequestMessage();

                JsonSearch jsonSearch = new JsonSearch()
                {
                    Keyword = Keyword, Filter = Filter
                };
                JsonSearchRequestData jsonRequestData = new JsonSearchRequestData()
                {
                    Search = jsonSearch
                };
                JsonPacket jsonRequest = new JsonPacket(jsonRequestMessage, Group.Encrypt(jsonRequestData));

                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));
                    JsonSearchResponseMessage jsonResponseMessage = JsonSearchResponseMessage.Parse(jsonResponse.Message);
                    Debug.Assert(!string.IsNullOrEmpty(jsonResponseMessage.Id));

                    // Data
                    SearchList.Id = jsonResponseMessage.Id;
#if DEBUG
                    Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse);
#endif
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (channel != null)
                {
                    channel.Shutdown();
                }
            }
        }
Ejemplo n.º 2
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
        }