Exemple #1
0
        public void SearchRequestEventArgs_Instantiates_With_Context(string username, int token, string query)
        {
            var e = new SearchRequestEventArgs(username, token, query);

            Assert.Equal(username, e.Username);
            Assert.Equal(token, e.Token);
            Assert.Equal(query, e.Query);
        }
Exemple #2
0
        private void ViewModelOnSearchRequested(object sender, SearchRequestEventArgs e)
        {
            ModelVersionCreated version = latestVersion;
            object modelObject          = (object)version?.Model.Agents.FirstOrDefault(a => a.Name.Equals(e.SearchTerm))
                                          ?? version?.Model.Messages.FirstOrDefault(a => a.Name.Equals(e.SearchTerm));

            if (modelObject != null)
            {
                OnMessage(new SelectedModelObjectChanged(modelObject, version, SelectionSource.Internal));
            }
        }
Exemple #3
0
        private void HubSearchRequest(object sender, SearchRequestEventArgs e)
        {
            var ea = new EngineSearchRequestEventArgs
            {
                HubConnection = (HubConnection)sender,
                Message       = e.Message
            };

            OnSearchRequest(ea);

            if (ea.Cancel)
            {
                return;
            }

            if (Share != null && e.Message.SearchType == SearchType.TTH)
            {
                _searchesAverage.Update(1);

                var results = Share.Search(new SearchQuery {
                    Query = e.Message.SearchRequest, SearchType = SearchType.TTH
                });
                if (results.Count > 0)
                {
                    var result = results[0];
                    var hub    = (HubConnection)sender;
                    var res    = new SRMessage
                    {
                        FileName  = result.VirtualPath,
                        FileSize  = result.Magnet.Size,
                        Nickname  = hub.Settings.Nickname,
                        FreeSlots =
                            Settings.MaxUploadThreads > 0
                                              ? Settings.MaxUploadThreads - TransferManager.TransfersCount
                                              : 0,
                        HubAddress = hub.RemoteAddressString,
                        HubName    = "TTH:" + result.Magnet.TTH,
                        TotalSlots = Settings.MaxUploadThreads
                    };

                    if (e.Message.SearchAddress.StartsWith("Hub:"))
                    {
                        res.TargetNickname = e.Message.SearchAddress.Remove(0, 4);
                        hub.SendMessage(res.Raw);
                    }
                    else
                    {
                        UdpConnection.SendMessage(res.Raw, e.Message.SearchAddress);
                    }
                }
            }
        }
Exemple #4
0
        public async Task TryRespondAsync_Raises_RequestReceived(string username, int token, string query)
        {
            var(responder, _) = GetFixture();

            SearchRequestEventArgs args = null;

            responder.RequestReceived += (sender, e) => args = e;

            var responded = await responder.TryRespondAsync(username, token, query);

            Assert.False(responded);
            Assert.NotNull(args);
            Assert.Equal(username, args.Username);
            Assert.Equal(token, args.Token);
            Assert.Equal(query, args.Query);
        }
Exemple #5
0
 private void OnSearchRequest(SearchRequestEventArgs e)
 {
     SearchRequest?.Invoke(this, e);
 }