コード例 #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();
                }
            }
        }
コード例 #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);
        }