Esempio n. 1
0
        private void StartSearch()
        {
            var list = _searchDescriptor == null ? new List <Film>() : _filmRepository.FindFilms(_searchDescriptor);

            _filmBindingList = new BindingList <FilmViewModel>(FilmsToViewModel(list));
            SearchComplete?.Invoke(this, EventArgs.Empty);
        }
Esempio n. 2
0
 /// <summary>
 /// Raises the search complete event.
 /// </summary>
 /// <param name="e">The event argument.</param>
 protected virtual void OnSearchComplete(SearchCompleteEventArgs e)
 {
     if (SearchComplete != null)
     {
         SearchComplete.GetInvocationList().InvokeEventGUIThreadSafe(this, e);
     }
 }
Esempio n. 3
0
        public void SearchAsync(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                throw new ArgumentNullException("text");
            }

            string query = string.Format(SearchUrl, WebUtility.HtmlEncode(text));

            // Do query
            WebClient wc = new WebClient();

            wc.DownloadStringCompleted += (sender, e) =>
            {
                if (e.Error == null)
                {
                    string resultText = e.Result;

                    // Parse results
                    var results = JsonConvert.DeserializeObject <SearchResult>(resultText);
                    SearchComplete?.Invoke(results.results, null);
                }
                else
                {
                    SearchComplete?.Invoke(null, e.Error);
                }
            };

            wc.DownloadStringAsync(new Uri(query));
        }
Esempio n. 4
0
    public void SearchHost(SearchComplete complete)
    {
        searchThread = new Thread(new ThreadStart(SearchHostThread));
        searchThread.Start();

        OnSearchComplete = complete;
    }
Esempio n. 5
0
        public void Search(IMatcher matcher)
        {
            cancelSource = new CancellationTokenSource();
            var cancelToken = new CancellationTokenSource().Token;

            var ig = IgnoredExtensions.ToDictionary(k => k, v => v);

            Task.Run(() =>
            {
                var watch = new Stopwatch();
                watch.Start();

                var files = FileScanner.GetFiles(ParentFolder, FilePattern, ig, SearchSubfolders);

                SearchStatusUpdate?.Invoke(new SearchStatus {
                    FilesComplete = 0, FilesRemaining = files.Count
                });

                var count = 1;

                Parallel.ForEach(files,
                                 (file, state) =>
                {
                    if (cancelSource.IsCancellationRequested)
                    {
                        state.Break();
                    }

                    matcher.Search(file, SearchTerm, ResultFound);

                    //throttle to speed things up
                    if (count++ % 30 == 0)
                    {
                        SearchStatusUpdate?.Invoke(
                            new SearchStatus {
                            FilesComplete = count, FilesRemaining = files.Count
                        });
                    }
                });

                SearchStatusUpdate?.Invoke(new SearchStatus {
                    FilesComplete = count, FilesRemaining = files.Count
                });

                watch.Stop();

                var metrics = new SearchMetrics
                {
                    ElapsedTime   = watch.Elapsed,
                    FilesSearched = files.Count
                };

                SearchComplete?.Invoke(metrics);
            }, cancelToken);
        }
Esempio n. 6
0
        private void StartOperation(string searchText, int maxResults = Search.DefaultMaxResults)
        {
            Stopwatch sw            = Stopwatch.StartNew();
            var       results       = ExecuteSearch(searchText, maxResults);
            bool      moreAvailable = results is System.Collections.ICollection collection && collection.Count >= maxResults;
            var       elapsed       = sw.Elapsed;

            if (latestSearch == searchText)
            {
                DisplayResults?.Invoke(results, moreAvailable);
                SearchComplete?.Invoke(searchText, results, elapsed);
            }
        }
Esempio n. 7
0
        private void StartOperation(string searchText)
        {
            Stopwatch sw      = Stopwatch.StartNew();
            var       results = ExecuteSearch(searchText);
            var       elapsed = sw.Elapsed;

            BuildControl.Elapsed = elapsed;
            if (latestSearch == searchText)
            {
                Application.Current.Dispatcher.InvokeAsync(() =>
                {
                    DisplayResults?.Invoke(results);
                    SearchComplete?.Invoke(searchText, results);
                });
            }
        }
Esempio n. 8
0
        private void StartOperation()
        {
            var cts = new CancellationTokenSource();

            Interlocked.Exchange(ref currentCancellationTokenSource, cts)?.Cancel();

            var localSearchText = searchText;
            var localMaxResults = maxResults;

            var sw      = Stopwatch.StartNew();
            var results = ExecuteSearch(localSearchText, localMaxResults, cts.Token);
            var elapsed = sw.Elapsed;

            var moreAvailable = results is System.Collections.ICollection collection && collection.Count >= localMaxResults;

            if (!cts.Token.IsCancellationRequested)
            {
                SearchComplete?.Invoke(localSearchText, results, elapsed);
                DisplayResults?.Invoke(results, moreAvailable);
            }
        }
Esempio n. 9
0
 public static Search Create(
     SpotifySession session,
     string query,
     int trackOffset,
     int trackCount,
     int albumOffset,
     int albumCount,
     int artistOffset,
     int artistCount,
     int playlistOffset,
     int playlistCount,
     SearchType searchType,
     SearchComplete callback,
     object userdata)
 {
     using (var utf8_query = SpotifyMarshalling.StringToUtf8(query))
     {
         IntPtr listenerToken = ListenerTable.PutUniqueObject(callback, userdata);
         IntPtr ptr           = NativeMethods.sp_search_create(
             session._handle,
             utf8_query.IntPtr,
             trackOffset,
             trackCount,
             albumOffset,
             albumCount,
             artistOffset,
             artistCount,
             playlistOffset,
             playlistCount,
             searchType,
             SearchCompleteDelegate,
             listenerToken);
         Search search = SearchTable.GetUniqueObject(ptr);
         search.ListenerToken = listenerToken;
         return(search);
     }
 }
Esempio n. 10
0
 public static Search Create(
     SpotifySession session,
     string query,
     int trackOffset,
     int trackCount,
     int albumOffset,
     int albumCount,
     int artistOffset,
     int artistCount,
     int playlistOffset,
     int playlistCount,
     SearchType searchType,
     SearchComplete callback,
     object userdata)
 {
     using (var utf8_query = SpotifyMarshalling.StringToUtf8(query))
     {
         IntPtr listenerToken = ListenerTable.PutUniqueObject(callback, userdata);
         IntPtr ptr = NativeMethods.sp_search_create(
             session._handle,
             utf8_query.IntPtr,
             trackOffset,
             trackCount,
             albumOffset,
             albumCount,
             artistOffset,
             artistCount,
             playlistOffset,
             playlistCount,
             searchType,
             SearchCompleteDelegate,
             listenerToken);
         Search search = SearchTable.GetUniqueObject(ptr);
         search.ListenerToken = listenerToken;
         return search;
     }
 }
Esempio n. 11
0
 /// <summary>
 /// 
 /// </summary>
 private void OnSearchComplete(TimeSpan duration, long matches, int numTerms, bool cancelled)
 {
     SearchComplete?.Invoke(this, this.FileName, duration, matches, numTerms, cancelled);
 }
Esempio n. 12
0
 protected virtual void OnSearchComplete()
 {
     SearchComplete?.Invoke(this, EventArgs.Empty);
 }
Esempio n. 13
0
 private void _OnSearchComplete(SearchResult results)
 {
     SearchComplete?.Invoke(this, results);
 }
Esempio n. 14
0
 /// <summary>
 /// Used to fire the <see cref="SearchComplete"/> event.
 /// </summary>
 protected void OnSearchComplete(OperationResult result) =>
 SearchComplete?.Invoke(this, new GenericEventArgs <OperationResult>(result));