예제 #1
0
        private void Async_PerformSearch(Object arg)
        {
            if (arg == null)
            {
                return;
            }

            var par = (SearchAsyncParam)arg;

            // new request was added - this one is outdated
            if (par.SequenceNumber < _requestSequenceNumber)
            {
                return;
            }

            if (SameAsPreviousSearch(par))
            {
                return;
            }

            SetStatus("Searching '" + par.Text + "' in " + par.Database, true);

            var result = StudioController.Find(par.Srv, par.Database, par.Text, _cfg.LimitSearch);

            // new request was added - this one is outdated
            if (par.SequenceNumber < _requestSequenceNumber)
            {
                log.Info("Cancelled search request because new request was added. " + par.Text);
                return;
            }

            SetStatus("Found " + result.Count + " objects");

            InvokeInUI(() =>
            {
                log.Info("Updating UI items");
                var analyzer = new PerformanceAnalyzer();

                var items = ItemFactory.BuildFromEntries(result);

                itemsControl.ItemsSource   = items;
                itemsControl.SelectedIndex = -1;
                itemsControl.ScrollIntoView(itemsControl.SelectedItem);

                if (items.Count == 0)
                {
                    gridEmptyResult.Visibility = System.Windows.Visibility.Visible;
                    itemsControl.Visibility    = System.Windows.Visibility.Collapsed;
                }
                else
                {
                    gridEmptyResult.Visibility = System.Windows.Visibility.Collapsed;
                    itemsControl.Visibility    = System.Windows.Visibility.Visible;
                }

                log.Performance("UI items updated", analyzer.Result);
                analyzer.Stop();
            });

            if (result.Count == 0)
            {
                SetStatus("Found nothing. Try to refresh");
            }
            else if (result.Count == 1)
            {
                SetStatus("Found exactly one object");
            }
            else
            {
                SetStatus("Found " + result.Count + " objects ");
            }
        }
예제 #2
0
        void ReloadDatabaseList(bool keepSameDatabase, bool setFocus = true)
        {
            string databaseName = string.Empty;

            try
            {
                var sel = SelectedServer;

                if (keepSameDatabase)
                {
                    databaseName = SelectedDatabase;
                }

                if (sel != null)
                {
                    cbDatabase.ItemsSource = ItemFactory.BuildDatabase(StudioController.ListDatabase(sel));

                    _databaseChangedByUser = false;

                    // changed server - try to restore database user worked with last time
                    if (string.IsNullOrEmpty(databaseName))
                    {
                        databaseName = _userPref.GetByName(UserPref_ServerDatabase + sel.ServerName);
                    }
                    var previousDatabaseWasFound = false;

                    if ((databaseName != null) && (cbDatabase.Items != null))
                    {
                        foreach (Item item in cbDatabase.ItemsSource)
                        {
                            if (item.Name == databaseName)
                            {
                                cbDatabase.SelectedValue = item;
                                previousDatabaseWasFound = true;
                                break;
                            }
                        }
                    }

                    // select the first database if a database previously chosen by user does not exist on a server any more
                    if (!previousDatabaseWasFound && (cbDatabase.Items != null) && (cbDatabase.Items.Count > 0))
                    {
                        cbDatabase.SelectedIndex = 0;
                    }

                    _databaseChangedByUser = true;
                    _userPref.StoreByName(UserPref_LastSelectedServer, sel.ServerName);
                    _userPref.Save();

                    if (previousDatabaseWasFound)
                    {
                        // we managed to find our database - restore search text
                        RestoreLastSearchTextFromUserProfile();
                        if (setFocus)
                        {
                            txtSearch.Focus();
                        }
                    }
                    else
                    {
                        ClearSearchText();
                        if (setFocus)
                        {
                            cbDatabase.Focus();
                        }
                    }
                }
                else
                {
                    ClearSearchText();
                }
            }
            catch (Exception ex)
            {
                log.Error("Server Selection:" + ex.Message, ex);
            }
        }