/// <summary>
        /// Производит поиск радиокомпонентов в соответствие с
        /// фильтрами поиска, сообщает пользователю в
        /// <see cref="searchStatusLabel"/> статус поиска,
        /// деактивирует кнопку
        /// <see cref="searchRadioComponentsButton"/> и
        /// передает индексы найденных радиокомпонентов через
        /// событие <see cref="SearchFinished"/>
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SearchRadioComponentsButton_Click(
            object sender, EventArgs e)
        {
            const string searchFinishedText = "Поиск завершен.\n";

            int[]  foundIndices     = GetFilteredRadioComponentsIndices();
            string searchStatusText = searchFinishedText;

            if (foundIndices.Length == 0)
            {
                const string notFoundText = "Ничего не найдено.\n";
                searchStatusText += notFoundText;
            }
            else
            {
                const string foundText =
                    "Найденные радиокомпоненты подсвечены.\n";
                searchStatusText += foundText;
            }

            const string changeSearchParametersText =
                "Измените параметры для нового поиска.";

            searchStatusText      += changeSearchParametersText;
            searchStatusLabel.Text = searchStatusText;

            searchRadioComponentsButton.Enabled = false;

            SearchFinished?.Invoke(this,
                                   new SearchFinishedEventArgs(foundIndices));
        }
Пример #2
0
        private void SearchTx()
        {
            if (BluetoothAdapter.DefaultAdapter != null && BluetoothAdapter.DefaultAdapter.IsEnabled)
            {
                SerialAdapter.SearchAvailableDevices(() => { }, adress =>
                {
                    string deviceName = BluetoothAdapter.DefaultAdapter.GetRemoteDevice(adress).Name;

                    if (deviceName != null)
                    {
                        // Connecting to a bluetooth device while discovery is not possible (or very slow). Therefore we only check for a match in the device name.
                        Regex regex = new Regex(ValidateTxNameExpression);
                        if (regex.IsMatch(deviceName))
                        {
                            InterfaceFound?.Invoke(this,
                                                   new InterfaceFoundEventArgs(adress, deviceName, ControllerType.Tx));
                        }
                    }
                }, () =>
                {
                    SearchFinished?.Invoke(this, EventArgs.Empty);

                    _searching = false;
                    _waitForFinishedResetEvent.Set();
                });
            }
            else
            {
                _searching = false;
                _waitForFinishedResetEvent.Set();
            }
        }
Пример #3
0
 private void SearchProcessExited(int exitCode)
 {
     Log.Info($"Search process exited with exitcode {exitCode}");
     SearchFinished?.Invoke();
     DisposeProcess(_searchProcess);
     _searchProcess = null;
 }
Пример #4
0
        private void RunBeatmapScanner(CancellationToken token)
        {
            List <FileInfo> mapFiles = new List <FileInfo>();

            // Files that should be found in the result so they are not considered for removal
            HashSet <string> filesToRemove = new HashSet <string>(difficultyLastWriteTimes.Keys);

            // Scan folder layout
            foreach (var searchPath in searchPaths)
            {
                foreach (var file in Directory.EnumerateFiles(searchPath, "*.ksh", SearchOption.AllDirectories))
                {
                    if (token.IsCancellationRequested)
                    {
                        return;
                    }

                    var fileInfo = new FileInfo(file);
                    mapFiles.Add(fileInfo);
                    filesToRemove.Remove(fileInfo.FullName); // Do not remove this map, it still exists
                }
            }

            // Process removals
            databaseScheduler.Add(() => RemoveDifficulties(filesToRemove));

            // Process found map files
            foreach (var mapFile in mapFiles)
            {
                if (!IsDifficultyAddedOrChanged(mapFile))
                {
                    continue; // Skip unchanged maps
                }
                // Try to load map metadata
                try
                {
                    var             stream = File.OpenRead(mapFile.FullName);
                    BeatmapKsh      mapKsh = new BeatmapKsh(stream, true);
                    Beatmap.Beatmap map    = new Beatmap.Beatmap(mapKsh);
                    databaseScheduler.Add(() => { AddDifficulty(mapFile, map.Metadata); });
                }
                catch (BeatmapParserException)
                {
                    Debug.WriteLine($"Corrupted map [{mapFile.Name}], not adding it to the database");
                    if (difficultyLastWriteTimes.ContainsKey(mapFile.FullName))
                    {
                        // Difficulty existed, remove it now since it is corrupt
                        databaseScheduler.Add(() => RemoveDifficulties(new HashSet <string> {
                            mapFile.FullName
                        }));
                    }
                }
            }

            // Notify finished
            databaseScheduler.Add(() => SearchFinished?.Invoke(this, null));
            IsSearchRunning = false;
        }
Пример #5
0
        public async Task GetItems(string initialDirectory, string searchPattern, ObservableCollection <FileItem> items = null)
        {
            if (items != null)
            {
                items.Clear();
                BindingOperations.EnableCollectionSynchronization(items, _locker);
            }
            await Task.Run(() => GetFilesSave(initialDirectory, searchPattern, items), CancellationTokenSource.Token).ConfigureAwait(false);

            SearchFinished?.Invoke();
        }
Пример #6
0
 public SearchLister(Workspace workspace, Options options, CommandRepository commandRepository
                     ) : base(workspace, options, commandRepository)
 {
     Title = null;
     SearchItemProvider            = new SearchItemProvider();
     SearchItemProvider.ItemAdded += ItemProvider_ItemAdded;
     Items = new ObservableCollection <FileItem>();
     SearchItemProvider.SearchFinished += () =>
     {
         PathName += Canceled ? " - Canceled" : " - Finished";
         SearchFinished?.Invoke();
         LoadingStatus = LoadingStatus.Loaded;
     };
     Thumbnail = Utils.GetImageFromRessource("search.png");
 }
Пример #7
0
        public IEnumerable <FileSystemInfo> Search()
        {
            var startFinishEventArgs = new StartFinishEventArgs();

            SearchStarted?.Invoke(this, startFinishEventArgs);
            if (startFinishEventArgs.StopSearch)
            {
                SearchFinished?.Invoke(this, startFinishEventArgs);
                return(new List <FileSystemInfo>());
            }
            var result = GetFileSystemInfo(new DirectoryInfo(_startPath)).ToList();

            SearchFinished?.Invoke(this, startFinishEventArgs);
            return(result);
        }
Пример #8
0
        public FileSystemInfoCustomCollection <CustomFileItem> GetItemsRecursively(FilterMask filterMask)
        {
            isFirstFilteredFileFound = false;

            SearchStarted?.Invoke(this, new EventArgs());
            var output = GetItemsRecursively(DirectoryPath, filterMask);

            SearchFinished?.Invoke(this, new EventArgs());

            if (filterMask.HasFlag(FilterMask.SortByName))
            {
                output.Sort();
            }

            return(output);
        }
Пример #9
0
        public void Search()
        {
            AnalysisHandler.Reset();

            object result = DoSearch();

            if (SearchFinished != null)
            {
                SearchFinished.Invoke(result);
            }

            if (_searchType == SearchType.Any || _searchType == SearchType.MDToken || _searchType == SearchType.StringGlobal)
            {
                AnalysisHandler.SelectTab();
            }
        }
Пример #10
0
        public List <string> Search(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentException("path to directory is not valid");
            }
            SearchStarted?.Invoke();
            var items = new List <string>();

            try
            {
                foreach (var item in GetFiles(path))
                {
                    var itemFoundArgs = new ItemFoundArgs(item);
                    if (Filter(item))
                    {
                        FilteredItemFound?.Invoke(this, itemFoundArgs);
                    }
                    else
                    {
                        ItemFound?.Invoke(this, itemFoundArgs);
                    }
                    if (itemFoundArgs.RemoveItemFromResult && itemFoundArgs.EndSearch)
                    {
                        break;
                    }
                    if (itemFoundArgs.RemoveItemFromResult)
                    {
                        continue;
                    }
                    items.Add(item);
                    if (itemFoundArgs.EndSearch)
                    {
                        break;
                    }
                }
                return(items);
            }
            finally
            {
                SearchFinished?.Invoke();
            }
        }
Пример #11
0
        private IEnumerator SearchCoroutine(string query, int expectedResultCount = 20)
        {
            if (IsProcessRunning(_searchProcess))
            {
                DisposeProcess(_searchProcess);
            }

            SearchResults.Clear();
            Log.Debug($"Starting search with query {query}");

            var searchProcessArguments = $"\"ytsearch{expectedResultCount}:{query}\"" +
                                         " -j" +            //Instructs yt-dl to return json data without downloading anything
                                         " -i";             //Ignore errors

            _searchProcess = CreateProcess(searchProcessArguments);

            _searchProcess.OutputDataReceived += (sender, e) =>
                                                 UnityMainThreadTaskScheduler.Factory.StartNew(delegate { SearchProcessDataReceived(e); });

            _searchProcess.ErrorDataReceived += (sender, e) =>
                                                UnityMainThreadTaskScheduler.Factory.StartNew(delegate { SearchProcessErrorDataReceived(e); });

            _searchProcess.Exited += (sender, e) =>
                                     UnityMainThreadTaskScheduler.Factory.StartNew(delegate { SearchProcessExited(((Process)sender).ExitCode); });

            Log.Info($"Starting youtube-dl process with arguments: \"{_searchProcess.StartInfo.FileName}\" {_searchProcess.StartInfo.Arguments}");
            StartProcessThreaded(_searchProcess);
            var startProcessTimeout = new Timeout(10);

            yield return(new WaitUntil(() => IsProcessRunning(_searchProcess) || startProcessTimeout.HasTimedOut));

            startProcessTimeout.Stop();

            var timeout = new Timeout(45);

            yield return(new WaitUntil(() => !IsProcessRunning(_searchProcess) || timeout.HasTimedOut));

            timeout.Stop();

            SearchFinished?.Invoke();
            DisposeProcess(_searchProcess);
        }
Пример #12
0
 public void WalkDriveTree(DriveInfo drive, string searchMask)
 {
     WalkDirectoryTree(drive.RootDirectory, searchMask);
     SearchFinished?.Invoke(this, EventArgs.Empty);
 }
Пример #13
0
        protected override void OnPostExecute(object result)
        {
            base.OnPostExecute(result);

            SearchFinished?.Invoke(this, new SearchFinishedEventArgs((InterfaceViewModel[])result));
        }
Пример #14
0
 internal void OnSearchFinished(object sender, SearchFinishedEventArgs e)
 {
     SearchFinished?.Invoke(sender, e);
 }
 protected virtual void OnSearchFinished(EventArgs args)
 {
     SearchFinished?.Invoke(this, args);
 }
 protected virtual void OnSearchFinished()
 {
     SearchFinished?.Invoke();
 }
Пример #17
0
 public void OnSearchFinished(EventArgs e) => SearchFinished?.Invoke(this, e);
Пример #18
0
 private void RiseSearchFinished()
 {
     SearchFinished?.Invoke();
     RiseImagesCountChanged();
 }