Beispiel #1
0
 private bool HandleSearch(RequestEventArgs e, NetworkRequest req)
 {
     //We dont do this on a server..
     var verb = new SearchVerb(shareInfoService);
     NetworkRequest result = verb.ProcessRequest(req);
     byte[] data = Encoding.UTF8.GetBytes(result.Data);
     var generator = new ResponseWriter();
     e.Response.ContentLength.Value = data.Length;
     generator.SendHeaders(e.Context, e.Response);
     e.Context.Stream.Write(data, 0, data.Length);
     e.Context.Stream.Flush();
     data = null;
     return true;
 }
Beispiel #2
0
        private void RunAsync(object o)
        {
            var param = o as AsyncSearchParam;
            if (null != param && null != param.Node)
            {
                var client = new Client(model.LocalNode);
                var verb = new SearchVerb(null);
                verb.SearchString = viewModel.SearchString;

                switch (viewModel.SizeSearchType)
                {
                    case "Any Size":
                        break;
                    case "Less than":
                        verb.SmallerThan = GetSearchSize();
                        break;
                    case "Greater than":
                        verb.LargerThan = GetSearchSize();
                        break;
                }

                switch (viewModel.ModifiedSearchType)
                {
                    case "Any":
                        break;
                    case "Before":
                        verb.ModifiedBefore = (DateTime) viewModel.ModifiedDate;
                        break;
                    case "After":
                        verb.ModifiedAfter = (DateTime) viewModel.ModifiedDate;
                        break;
                }

                if (client.Execute(verb, param.Node))
                {
                    if (null != verb.Results)
                    {
                        //Set name
                        foreach (SearchResult result in verb.Results)
                        {
                            result.User = param.Node.Nickname;
                            result.ClientID = param.Node.ID;
                        }
                        param.Results.AddRange(verb.Results);
                    }
                }
            }
            lock (sync)
            {
                //If we still on the same search then update the UI.
                if (param.Results == currentResults)
                {
                    outstandingrequests--;
                    if (outstandingrequests < 1)
                    {
                        viewModel.UpperStatusMessage = "Search complete in " + (Environment.TickCount - startTime) +
                                                       " ms";
                        viewModel.LowerStatusMessage = currentResults.Count + " results.";
                    }
                    else
                    {
                        viewModel.LowerStatusMessage = outstandingrequests + " peers remaining..";
                    }
                }
            }
        }