Ejemplo n.º 1
0
 public void ExecuteBuildSearchIndex(ICommandContext context)
 {
     using (var bif = new BuildIndexForm(context))
         bif.ShowDialog(
             context
                 .GetRequiredService<IUIShell>()
                 .GetMainWindowParent());
 }
 public void ExecuteBuildSearchIndex(ICommandContext context)
 {
     using (var bif = new BuildIndexForm(context))
         bif.ShowDialog(
             context
             .GetRequiredService <IUIShell>()
             .GetMainWindowParent());
 }
        private void BtnSearchClick(object sender, EventArgs e)
        {
            var searchText = comboSearchEntry.Text.Trim();

            #region Проверка пустой строки поиска
            if (searchText.Trim().Length == 0 &&
                !Config.Instance.AdvancedSearch)
            {
                var text = SR.Search.NoParams;
                _serviceManager.LogInfo(text);

                MessageBox.Show(text, SR.Search.Title,
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            #endregion

            #region Проверка строки поиска
            //TODO валится при вводе ]test[
            // нужно бы еще эту ситуацию доработать
            var cntLeftSquare  = 0;
            var cntRightSquare = 0;

            foreach (var t in searchText)
            {
                switch (t)
                {
                case '[':
                    cntLeftSquare++;
                    break;

                case ']':
                    cntRightSquare++;
                    break;
                }
            }

            if (cntLeftSquare != cntRightSquare)
            {
                var text = SR.Search.EntryContainsBadCode;
                _serviceManager.LogInfo(text);

                MessageBox.Show(text, SR.Search.Title,
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                comboSearchEntry.Focus();
                return;
            }
            #endregion

            Config.Instance.SearchText = searchText;

            // Чтобы последняя срока поиска была вверху и не дублировалась
            if (comboSearchEntry.Items.Contains(searchText))
            {
                comboSearchEntry.Items.Remove(searchText);
            }

            comboSearchEntry.Items.Insert(0, searchText);
            comboSearchEntry.Text = searchText;

            // Защита от переполнения списка, он не безразмерный
            while (comboSearchEntry.Items.Count > comboSearchEntry.MaxDropDownItems)
            {
                comboSearchEntry.Items.RemoveAt(comboSearchEntry.Items.Count - 1);
            }

            // Сохраним список сразу в конфиг
            Config.Instance.SearchList = new string[comboSearchEntry.Items.Count];
            comboSearchEntry.Items.CopyTo(Config.Instance.SearchList, 0);
            var searchFromValue = searchFromDate.Checked ? searchFromDate.Value : new DateTime(0);
            var searchToValue   = searchToDate.Checked ? searchToDate.Value : new DateTime(0);

            List <MsgBase> msgs = null;
            ProgressWorker.Run(_serviceManager, false,
                               pi =>
            {
                pi.SetProgressText(SR.Search.Searching);

                try
                {
                    msgs =
                        SearchHelper
                        .SearchMessagesByLucene(
                            _serviceManager,
                            Config.Instance.AdvancedSearch ? Config.Instance.SearchForumId : -1,
                            Config.Instance.SearchText,
                            Config.Instance.SearchInText,
                            Config.Instance.SearchInSubject,
                            Config.Instance.SearchAuthor,
                            Config.Instance.SearchInMarked,
                            Config.Instance.SearchInMyMessages,
                            Config.Instance.SearchAnyWord,
                            Config.Instance.SearchInQuestions,
                            searchFromValue,
                            searchToValue);
                }
                catch (FileNotFoundException)
                {
                    _asyncOperation.Post(
                        () =>
                    {
                        if (MessageBox.Show(
                                this,
                                Search.Search.NoSearchIndexQuestion,
                                Application.ProductName,
                                MessageBoxButtons.YesNo,
                                MessageBoxIcon.Exclamation) == DialogResult.Yes)
                        {
                            using (var bif = new BuildIndexForm(_serviceManager))
                                bif.ShowDialog(this);
                        }
                    });

                    msgs = new List <MsgBase>();
                }

                if (searchInOverquoting.Checked)
                {
                    FilterOverquoting(msgs);
                }

                _serviceManager
                .LogInfo(
                    msgs.Count > 0
                                                                ? string.Format(SR.Search.LogFound, msgs.Count)
                                                                : SR.Search.LogNotFound);

                pi.SetProgressText(SR.Search.OutResults);
            },
                               () => FillGrid(msgs));
        }
Ejemplo n.º 4
0
        private void BtnSearchClick(object sender, EventArgs e)
        {
            var searchText = comboSearchEntry.Text.Trim();

            #region Проверка пустой строки поиска
            if (searchText.Trim().Length == 0
                && !Config.Instance.AdvancedSearch)
            {
                var text = SR.Search.NoParams;
                _serviceManager.LogInfo(text);

                MessageBox.Show(text, SR.Search.Title,
                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            #endregion

            #region Проверка строки поиска
            //TODO валится при вводе ]test[
            // нужно бы еще эту ситуацию доработать
            var cntLeftSquare = 0;
            var cntRightSquare = 0;

            foreach (var t in searchText)
                switch (t)
                {
                    case '[':
                        cntLeftSquare++;
                        break;
                    case ']':
                        cntRightSquare++;
                        break;
                }

            if (cntLeftSquare != cntRightSquare)
            {
                var text = SR.Search.EntryContainsBadCode;
                _serviceManager.LogInfo(text);

                MessageBox.Show(text, SR.Search.Title,
                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                comboSearchEntry.Focus();
                return;
            }
            #endregion

            Config.Instance.SearchText = searchText;

            // Чтобы последняя срока поиска была вверху и не дублировалась
            if (comboSearchEntry.Items.Contains(searchText))
                comboSearchEntry.Items.Remove(searchText);

            comboSearchEntry.Items.Insert(0, searchText);
            comboSearchEntry.Text = searchText;

            // Защита от переполнения списка, он не безразмерный
            while (comboSearchEntry.Items.Count > comboSearchEntry.MaxDropDownItems)
                comboSearchEntry.Items.RemoveAt(comboSearchEntry.Items.Count - 1);

            // Сохраним список сразу в конфиг
            Config.Instance.SearchList = new string[comboSearchEntry.Items.Count];
            comboSearchEntry.Items.CopyTo(Config.Instance.SearchList, 0);
            var searchFromValue = searchFromDate.Checked ? searchFromDate.Value : new DateTime(0);
            var searchToValue = searchToDate.Checked ? searchToDate.Value : new DateTime(0);

            List<MsgBase> msgs = null;
            ProgressWorker.Run(_serviceManager, false,
                pi =>
                {
                    pi.SetProgressText(SR.Search.Searching);

                    try
                    {
                        msgs =
                            SearchHelper
                                .SearchMessagesByLucene(
                                    _serviceManager,
                                    Config.Instance.AdvancedSearch ? Config.Instance.SearchForumId : -1,
                                    Config.Instance.SearchText,
                                    Config.Instance.SearchInText,
                                    Config.Instance.SearchInSubject,
                                    Config.Instance.SearchAuthor,
                                    Config.Instance.SearchInMarked,
                                    Config.Instance.SearchInMyMessages,
                                    Config.Instance.SearchAnyWord,
                                    Config.Instance.SearchInQuestions,
                                    searchFromValue,
                                    searchToValue);
                    }
                    catch (FileNotFoundException)
                    {
                        _asyncOperation.Post(
                            () =>
                            {
                                if (MessageBox.Show(
                                        this,
                                        Search.Search.NoSearchIndexQuestion,
                                        Application.ProductName,
                                        MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Exclamation) == DialogResult.Yes)
                                    using (var bif = new BuildIndexForm(_serviceManager))
                                        bif.ShowDialog(this);
                            });

                        msgs = new List<MsgBase>();
                    }

                    if (searchInOverquoting.Checked)
                        FilterOverquoting(msgs);

                    _serviceManager
                        .LogInfo(
                            msgs.Count > 0
                                ? string.Format(SR.Search.LogFound, msgs.Count)
                                : SR.Search.LogNotFound);

                    pi.SetProgressText(SR.Search.OutResults);
                },
                () => FillGrid(msgs));
        }