コード例 #1
0
 public void Stop()
 {// attempt to gracefully exit threads
     TimeoutCancelled = true;
     HasAcquired      = false;
     MonitorTimer.Change(Timeout.Infinite, Timeout.Infinite);
     SearchTimer.Change(Timeout.Infinite, Timeout.Infinite);
 }
コード例 #2
0
 public void Restart()
 {
     TimeoutCancelled = false;
     HasAcquired      = false;
     MonitorTimer.Change(0, Interval);
     SearchTimer.Change(Timeout.Infinite, Timeout.Infinite);
 }
コード例 #3
0
        private void StartStopSearchButton_Click(object sender, EventArgs e)
        {
            PushToSettings();

            if (SearchSettings.BadSettings())
            {
                MessageBox.Show("Ошибка! \nНужно задать корневую директорию и хотя бы один фильтр, и их длина должна быть не больше 50 символов.");
                return;
            }

            SearchStarted = !SearchStarted;

            if (SearchStarted)
            {
                DisableConfig();
                PauseResumeSearchButton.Enabled = true;
                StartStopSearchButton.Text      = "Stop";
                BackgroundSearcher.RunWorkerAsync();
                SearchTimer.Start();
            }
            else
            {
                BackgroundSearcher.CancelAsync();
                SearchPaused = false;
                EnableConfig();
                PauseResumeSearchButton.Text    = "Pause";
                PauseResumeSearchButton.Enabled = false;
                SearchTimer.Stop();
            }
        }
コード例 #4
0
        public static ProductReviewSearchResult GetWithReviews(this ISearchContext search, Guid productId)
        {
            var timer = new SearchTimer();

            var prd = FindOne(search, productId);

            if (prd == null)
            {
                return(null);
            }

            var reviews = search.ProductReviews
                          .Where(x => x.ProductId == productId)
                          .Where(x => x.DeletedOn == null)
                          .OrderBy(x => x.Score);

            var rtn = new ProductReviewSearchResult
            {
                Product       = ToSearchResult(search, prd),
                ReviewAverage = reviews.Average(x => x.Score),
                ReviewCount   = reviews.Count(),
                TopResults    = reviews.Take(3).Select(x => ToReviewSearchResult(x)),
                BottomResults = reviews.Skip(reviews.Count() - 3).Take(3).Select(x => ToReviewSearchResult(x))
            };

            return(rtn);
        }
コード例 #5
0
ファイル: MainWindow.xaml.cs プロジェクト: Wscar/NMusicPlayer
 /// <summary>
 /// Input on the search box changed,
 /// start searchTimer to validate and search.
 /// </summary>
 private void searchBox_TextChanged(object sender, TextChangedEventArgs e)
 {
     // No need to search if there is no data
     if (ViewModel.Collections.Count > 0)
     {
         SearchTimer.Stop();
         SearchTimer.Start();
     }
 }
コード例 #6
0
        private void OnProcessAcquired(ProcessMonitor m, ProcessEventArgs e)
        {
            ProcessUtils.Logger($"MONITOR@{ProcessName}",
                                $"Process acquired in {ProcessUtils.ElapsedToString(e.Elapsed)}: {e.ProcessName}.exe [{e.TargetProcess.Id}]");

            HasAcquired = true;
            MonitorTimer.Change(Timeout.Infinite, Timeout.Infinite);
            SearchTimer.Change(0, Interval);
            ProcessAcquired?.Invoke(m, e);
        }
コード例 #7
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            if (!IsWindows10())
            {
                this.Close();
            }

            SearchTimer.Start();
            SearchTimer.Interval = 10;
        }
コード例 #8
0
ファイル: MainWindow.xaml.cs プロジェクト: Wscar/NMusicPlayer
        public void Stop()
        {
            SearchTimer.Stop();
            SliderTimer.Stop();

            ViewModel.Status = SongStatus.Stopped;

            sliderControl.Value = 0;

            ViewModel.Player.Stop();
        }
コード例 #9
0
        public static PaginatedResult <ProductCategorySearchResult> GetCategories(this ISearchContext search, int pageCount, int pageSize)
        {
            var timer = new SearchTimer();

            var results = search.ProductCategories
                          .ElligibleProductCategories()
                          .OrderBy(x => x.Name);

            var rtn = ToPaginatedResult(search, pageCount, pageSize, timer.Duration, results);

            return(rtn);
        }
コード例 #10
0
        public static PaginatedResult <ProductSearchResult> GetByDiscount(this ISearchContext search, int pageCount, int pageSize)
        {
            var timer = new SearchTimer();

            var results = search.Products
                          .ElligibleProducts()
                          .OrderByDescending(x => x.Discount);

            var rtn = ToPaginatedResult(search, pageCount, pageSize, timer.Duration, results);

            return(rtn);
        }
コード例 #11
0
        public static PaginatedResult <ProductSearchResult> GetByText(this ISearchContext search, string text, int pageCount, int pageSize)
        {
            var timer = new SearchTimer();

            var results = search.Products
                          .ElligibleProducts()
                          .Where(x => x.Name.ToLower().Contains(text) || x.Description.ToLower().Contains(text))
                          .OrderByDescending(x => x.Price);

            var rtn = ToPaginatedResult(search, pageCount, pageSize, timer.Duration, results);

            return(rtn);
        }
コード例 #12
0
        public static PaginatedResult <ProductSearchResult> GetByStockLevels(this ISearchContext search, StockLevel[] stockLevels, int pageCount, int pageSize)
        {
            var timer = new SearchTimer();

            var results = search.Products
                          .ElligibleProducts()
                          .Where(x => stockLevels.Contains(x.StockLevel))
                          .OrderByDescending(x => x.Price);

            var rtn = ToPaginatedResult(search, pageCount, pageSize, timer.Duration, results);

            return(rtn);
        }
コード例 #13
0
        public static PaginatedResult <ProductSearchResult> GetByPrice(this ISearchContext search, decimal min, decimal max, int pageCount, int pageSize)
        {
            var timer = new SearchTimer();

            var results = search.Products
                          .ElligibleProducts()
                          .Where(x => x.Price >= min && x.Price <= max)
                          .OrderByDescending(x => x.Price);

            var rtn = ToPaginatedResult(search, pageCount, pageSize, timer.Duration, results);

            return(rtn);
        }
コード例 #14
0
        public static PaginatedResult <ProductSearchResult> GetByCategory(this ISearchContext search, Guid catId, int pageCount, int pageSize)
        {
            var timer = new SearchTimer();

            var results = search.Products
                          .ElligibleProducts()
                          .Where(x => x.CategoryId == catId)
                          .OrderByDescending(x => x.Price);

            var rtn = ToPaginatedResult(search, pageCount, pageSize, timer.Duration, results);

            return(rtn);
        }
コード例 #15
0
 public void Initialize(IEnumerable <ObjectLabel> labels, IEnumerable <ICmObject> selectedItems)
 {
     m_semdomRepo = Cache.ServiceLocator.GetInstance <ICmSemanticDomainRepository>();
     m_stylesheet = FontHeightAdjuster.StyleSheetFromMediator(Mediator);
     m_selectedItems.UnionWith(selectedItems);
     UpdateDomainTreeAndListLabels(labels);
     searchTextBox.WritingSystemFactory = Cache.LanguageWritingSystemFactoryAccessor;
     searchTextBox.AdjustForStyleSheet(m_stylesheet);
     m_SearchTimer = new SearchTimer(this, 500, SearchSemanticDomains, new List <Control> {
         domainTree, domainList
     });
     searchTextBox.TextChanged += m_SearchTimer.OnSearchTextChanged;
 }
コード例 #16
0
ファイル: MainWindow.xaml.cs プロジェクト: Wscar/NMusicPlayer
 /// <summary>
 /// Checks searchBox for valid input,
 /// in that case filters treeView content.
 /// </summary>
 private void SearchTimer_Tick(object sender, EventArgs e)
 {
     if (ViewModel.SearchField["Input"] == null) // If validation passed
     {
         if (ViewModel.SearchField.Input != MusicSearchField.InitialInputValue)
         {
             ViewModel.FilterSearch();
         }
     }
     else
     {
         ViewModel.RefreshBands();
     }
     SearchTimer.Stop();
 }
コード例 #17
0
        internal override void Init(Mediator mediator, XmlNode node)
        {
            base.Init(mediator, node);

            m_semDomRepo = m_cache.ServiceLocator.GetInstance <ICmSemanticDomainRepository>();
            var treeBarControl = GetTreeBarControl(mediator);

            SetupAndShowHeaderPanel(mediator, node, treeBarControl);
            m_searchTimer = new SearchTimer(treeBarControl, 500, HandleChangeInSearchText,
                                            new List <Control> {
                treeBarControl.TreeView, treeBarControl.ListView
            });
            m_textSearch.TextChanged += m_searchTimer.OnSearchTextChanged;
            m_treeView             = treeBarControl.TreeView;
            m_listView             = treeBarControl.ListView;
            m_listView.HeaderStyle = ColumnHeaderStyle.None;             // We don't want a secondary "Records" title bar
        }
コード例 #18
0
        /// <summary>
        /// Called whenever (and ONLY whenever) the user has either
        /// 1. selected an item from the result set
        /// 2. decided not to select an item from the result set
        /// 3. cleared the currently selected item
        /// </summary>
        private void OnUserEndedSearchEvent()
        {
            if (SearchTimer != null)
            {
                SearchTimer.Stop();
                //setting to null so that when a new search starts, we grab fresh values for the time interval
                SearchTimer = null;
            }

            if (SearchProvider != null)
            {
                SearchProvider.CancelAllSearches();
            }

            ShowResults           = false;
            noResultsPopup.IsOpen = false;
        }
コード例 #19
0
        protected virtual void Dispose(bool disposing)
        {
            if (Disposed)
            {
                return;
            }

            if (disposing)
            {
                MonitorTimer.Change(Timeout.Infinite, Timeout.Infinite);
                SearchTimer.Change(Timeout.Infinite, Timeout.Infinite);
                MonitorTimer.Dispose();
                SearchTimer.Dispose();
                MonitorLock.Dispose();
            }
            Disposed = true;
        }
コード例 #20
0
        private void BackgroundSearcher_DoWork(object sender, DoWorkEventArgs e)
        {
            ProcessCurrentDirectory(SearchSettings.RootDirPath);
            SearchPaused  = false;
            SearchStarted = false;
            this.Invoke(
                new MethodInvoker(delegate
            {
                EnableConfig();
                PauseResumeSearchButton.Text    = "Pause";
                PauseResumeSearchButton.Enabled = false;
                SearchTimer.Stop();
                StartStopSearchButton.Text = "Start";
            })
                );

            BackgroundSearcher.CancelAsync();
        }
コード例 #21
0
        private void OnProcessSoftExit(ProcessMonitor m, ProcessEventArgs e)
        {// attempt to gracefully switch modes (monitor -> search)
            if (HasAcquired && !string.IsNullOrWhiteSpace(e.ProcessName))
            {
                ProcessUtils.Logger($"MONITOR@{ProcessName}", $"Process exited, attempting to reacquire within {e.Timeout}s: {e.ProcessName}.exe");
            }
            else if (HasAcquired)  // can't get process details?
            {
                ProcessUtils.Logger($"MONITOR@{ProcessName}", $"Process exited, attempting to reacquire within {e.Timeout}s");
            }

            HasAcquired = false;
            // transition from monitoring -> searching
            MonitorTimer.Change(Timeout.Infinite, Timeout.Infinite);
            SearchTimer.Change(0, Interval);

            ProcessSoftExit?.Invoke(m, e);
        }
コード例 #22
0
        private void PauseResumeSearchButton_Click(object sender, EventArgs e)
        {
            SearchPaused = !SearchPaused;

            if (SearchPaused)
            {
                _busy.Reset();
                PauseResumeSearchButton.Text = "Resume";
                SearchTimer.Stop();
            }
            else
            {
                PauseResumeSearchButton.Text = "Pause";
                _busy.Set();
                SearchTimer.Start();
            }

            SearchSettings.SaveSettingsToConfig();
        }
コード例 #23
0
        /// <summary>
        /// TimerCallback delegate for threaded timer to reacquire a valid process by name
        /// </summary>
        private async void SearchProcess(object stateInfo)
        {// used when searching for a valid process within a timeout
            await MonitorLock.WaitAsync();

            try
            {// monitor with a shorter timeout for the search
                if (!TimeoutCancelled)
                {
                    await TimeoutWatcher(InnerTimeout);
                }
                else
                {
                    SearchTimer.Change(Timeout.Infinite, Timeout.Infinite);
                }
            }
            catch (Win32Exception) { }
            finally
            {
                MonitorLock.Release();
            }
        }
コード例 #24
0
 private void SearchTimer_Tick(object sender, EventArgs e)
 {
     if (hidden2)
     {
         pnlSearch.Width = pnlSearch.Width + 10;
         if (pnlSearch.Width >= panelWidth)
         {
             SearchTimer.Stop();
             hidden2 = false;
             this.Refresh();
             this.pnlSearch.BringToFront();
         }
     }
     else
     {
         pnlSearch.Width = pnlSearch.Width - 10;
         if (pnlSearch.Width <= 0)
         {
             SearchTimer.Stop();
             hidden2 = true;
             this.Refresh();
         }
     }
 }
コード例 #25
0
        protected List <Move>?startSearch(Position?position, SearchMode mode)
        {
            try {
                if (position is null)
                {
                    throw new PositionException("Null Position");
                }
                else if (SearchTimer is null)
                {
                    throw new PositionException("Null SearchTimer Stopwatch");
                }
                else
                {
                    SearchTimer.Reset();
                    IntervalNodes      =
                        HeartbeatNodes = (UInt64)NodeTotal;
                    LastBeatMS         = SearchTimer.ElapsedMilliseconds;
                }

                if (position.IsLegal())
                {
                    StartDepth = 0;     //[Init]
                    ClearSearchCounts();

                    if (UCI.IsDebug)
                    {
                        var dtStarted = DateTime.Now;
#if Herald
                        herald(dtStarted, position.Name);
#endif
#if NoteStartAndFinish
                        LogInfo(Level.note, $"Started at {dtStarted:yyyy-MM-dd HH:mm:ss.ff}");
#endif
                    }

                    SearchTimer.Start();

                    switch (mode)
                    {
                    case SearchMode.BestMove:
                        var mValue = position.IteratePlies(Bound);
                        break;

                    case SearchMode.Perft:
                        position.IterateCases();
                        break;
                    }
                }
                else
                {
                    throw new PositionException("Illegal Setup");
                }
            }
            catch (OperationCanceledException) {
                //
                // OperationCanceledException is thrown in MonitorBound() via ThrowIfCancellationRequested(),
                // when Cancel() has been called on the source of this Task's CancellationToken.  Catching
                // it here allows stack frames for an active search to return Position objects to the pool.
                //
            }
            catch (FinalPositionException ex) {
                LogInfo(Level.note, ex.Message);
            }
            catch (ApplicationException ex) {
#if StackTrace
                LogInfo(Level.error, ex.ToString());
#else
                LogInfo(Level.error, ex.Message);
#endif
            }
            catch (Exception ex) {
                LogInfo(Level.error, ex.ToString());
            }
            finally {
                if (SearchTimer.IsRunning)
                {
                    SearchTimer.Stop();
                }

                if (UCI.IsDebug)
                {
                    LogInfoNewLine(Level.note);
#if NoteStartAndFinish
                    LogInfo(Level.note, $"Finished at {DateTime.Now:yyyy-MM-dd HH:mm:ss.ff}");
#endif
                    var dElapsedMS = (Double)SearchTimer.ElapsedMilliseconds;
                    displayCounts(mode, dElapsedMS);
                }
            }

            //
            //[Optional]Repeat final bestmove report:
            //
            if (BestMoves is not null)
            {
                var sb = new StringBuilder();
                //[Note]refreshPV() has been called
                sb.BestMove(BestMoves, Rule);
                if (sb.Length > 0)
                {
                    LogLine(sb.ToString());
                }
            }

            return(BestMoves);
        }
コード例 #26
0
 private void SearchButton_Click(object sender, EventArgs e)
 {
     SearchTimer.Start();
 }
コード例 #27
0
 private void PinnedWatchTimer_Tick(object sender, EventArgs e)
 {
     foreach (PinnedTT dtt in PinnedTTs)
     {
         if ((dtt.NotifyAt != DateTime.MinValue) && (DateTime.Now >= dtt.NotifyAt))
         {
             this.ActivateMainWindow();
             dtt.NotifyAt = DateTime.MinValue;
             ShowBalloonWarning(dtt.Comment, $"{dtt.Code} - {dtt.Name}");
             TaskDialogOptions options = new TaskDialogOptions
             {
                 Owner           = this,
                 Title           = "DSList",
                 Content         = dtt.Comment,
                 MainInstruction = $"{dtt.Code} - {dtt.Name}",
                 MainIcon        = VistaTaskDialogIcon.Warning
             };
             options.CustomButtons           = new string[] { "ОК", "Открепить ТТ", "Открыть ТТ", "Отложить" };
             options.DefaultButtonIndex      = 0;
             options.AllowDialogCancellation = true;
             TaskDialogResult result = TaskDialog.Show(options);
             int?customButtonResult  = result.CustomButtonResult;
             int num = 1;
             if ((customButtonResult.GetValueOrDefault() == num) ? customButtonResult.HasValue : false)
             {
                 Customer tt = this.FindTTbyCode(dtt.Code, this.AllTT);
                 if (tt == null)
                 {
                     tt = new Customer(this)
                     {
                         NumberCVZ = int.Parse(dtt.Code),
                         //Owner = this
                     };
                 }
                 this.UnpinTT(tt, true);
                 this.PinnedWatchTimer_Tick(sender, e);
                 break;
             }
             customButtonResult = result.CustomButtonResult;
             num = 2;
             if ((customButtonResult.GetValueOrDefault() == num) ? customButtonResult.HasValue : false)
             {
                 if (dtt.Code == "0" && dtt.IPAddress != null)
                 {
                     SearchTimer.Stop();
                     // Проверка существования данного customer в ранее открытых
                     var getTab = (from i in OpenedTT where i.Lan_Ip == dtt.IPAddress select i).FirstOrDefault();
                     if (getTab != null)
                     {
                         /*getTab.Focus()*/;
                     }
                     else
                     {
                         //this.TextBoxSearch.Text = (this.ListViewPinned.SelectedItem as PinnedTT).Code;
                         //this.TextBoxSearch.Focus();
                         Customer curCustomer = CreateCustomerForType(CustomerTypes.SingleIP, new Customer(this) /*{ Owner = this }*/, dtt.IPAddress);
                         OpenTTinTab(curCustomer);
                         //OpenedTT.Add(curCustomer);
                         Log($"Открыт {curCustomer.Lan_Ip}");
                         /*curCustomer.Focus()*/;
                     }
                 }
                 Customer selected = this.FindTTbyCode(dtt.Code, this.AllTT);
                 if (selected != null)
                 {
                     selected.Comment = dtt.Comment;
                     Customer curCustomer = CreateCustomerForType(CustomerTypes.TTCVZ, selected);
                     OpenTTinTab(selected, true);
                     //if (selected.NumberCVZ.ToString()!="0")
                     //{
                     //    Customer curCustomer = CreateCustomerForType(CustomerTypes.TTCVZ, selected);
                     //    this.OpenTTinTab(selected, true);
                     //}
                     //else
                     //{
                     //    Customer curCustomer = CreateCustomerForType(CustomerTypes.SingleIP, selected);
                     //    this.OpenTTinTab(selected, true);
                     //}
                 }
             }
             customButtonResult = result.CustomButtonResult;
             num = 3;
             if ((customButtonResult.GetValueOrDefault() == num) ? customButtonResult.HasValue : false)
             {
                 options = new TaskDialogOptions
                 {
                     Owner           = this,
                     Title           = "DSList",
                     Content         = dtt.Comment,
                     MainInstruction = $"Отложить {dtt.Code} - {dtt.Name}"
                 };
                 options.CustomButtons           = new string[] { "Отмена" };
                 options.DefaultButtonIndex      = 0;
                 options.AllowDialogCancellation = true;
                 List <string> list = new List <string>();
                 for (int i = 1; i < this.NotifyMinutesComboBox.Items.Count; i++)
                 {
                     list.Add((this.NotifyMinutesComboBox.Items[i] as ComboBoxItem).Content.ToString());
                 }
                 options.CommandButtons = list.ToArray();
                 TaskDialogResult result2 = TaskDialog.Show(options);
                 if (!result2.CommandButtonResult.HasValue)
                 {
                     break;
                 }
                 int      num2 = int.Parse((this.NotifyMinutesComboBox.Items[result2.CommandButtonResult.Value + 1] as ComboBoxItem).Tag.ToString());
                 DateTime time = DateTime.Now.AddMinutes((double)num2);
                 dtt.NotifyAt = time;
             }
         }
     }
 }
コード例 #28
0
        /// <summary>
        /// Метод обработки нажатия левой кнопкой по закрепленному Customer
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Pinned_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (this.ListViewPinned.SelectedItem != null)
            {
                Customer selected = this.FindTTbyCode((this.ListViewPinned.SelectedItem as PinnedTT).Code, AllTT);
                if ((this.ListViewPinned.SelectedIndex != -1) && (selected != null))
                {
                    selected.Comment = (this.ListViewPinned.SelectedItem as PinnedTT).Comment;
                    try
                    {
                        // Проверка существования данного customer в ранее открытых
                        Customer getCustomer = FindTTbyCode(selected.NumberCVZ.ToString(), OpenedTT);
                        if (getCustomer != null)
                        {
                            foreach (var item in Tabs.Items)
                            {
                                if (item == getCustomer)
                                {
                                    Tabs.SelectedItem = item;
                                }
                            }
                            ;
                        }
                        else
                        {
                            Customer curCustomer;
                            //if (selected.Content == null)
                            //{
                            curCustomer = CreateCustomerForType(CustomerTypes.TTCVZ, selected);
                            //}
                            //else
                            curCustomer = selected;
                            OpenTTinTab(curCustomer, true);
                            Log($"Открыта {curCustomer.ToStringDisplay}");
                            //curCustomer.Focus();
                        }
                    }
                    catch (Exception ex)
                    {
                        Log("Ошибка при выводе закрепленной ЦВЗ. " + ex.Message, true, true, ex.StackTrace);
                    }
                }
                else
                {
                    SearchTimer.Stop();



                    // Проверка существования данного customer в ранее открытых
                    var getTab = (from i in OpenedTT where i.Lan_Ip == (ListViewPinned.SelectedItem as PinnedTT).IPAddress select i).FirstOrDefault();
                    if (getTab != null)
                    {
                        /*getTab.Focus()*/;
                    }
                    else
                    {
                        //IPAddress address;
                        //this.TextBoxSearch.Text = (this.ListViewPinned.SelectedItem as PinnedTT).Code;
                        //this.TextBoxSearch.Focus();
                        //if (IPAddress.TryParse(this.TextBoxSearch.Text, out address))
                        //{
                        //    this.OpenCustomTT();
                        //}
                        Customer curCustomer = CreateCustomerForType(CustomerTypes.SingleIP, new Customer(this) /*{ Owner = this }*/, (this.ListViewPinned.SelectedItem as PinnedTT).IPAddress);
                        OpenTTinTab(curCustomer);
                        //OpenedTT.Add(curCustomer);
                        Log($"Открыт {curCustomer.Lan_Ip}");
                        //curCustomer.Focus();
                    }


                    //IPAddress address;
                    //this.TextBoxSearch.Text = (this.ListViewPinned.SelectedItem as PinnedTT).Code;
                    //this.TextBoxSearch.Focus();
                    //if (IPAddress.TryParse(this.TextBoxSearch.Text, out address))
                    //{
                    //    this.OpenCustomTT();
                    //}
                }
            }
        }