Пример #1
0
        private void SearchVolumeAsync(ISearchCriteria criteria, System.Action onsearchcompled)
        {
            // delegate that will be called
            // when asynchronous volume searching has been finished.
            AsyncCallback cb = (IAsyncResult ar) => {
                if (windowDeleted)
                {
                    return;
                }

                try {
                    Volume[] volumes = database.EndSearchVolume(ar);

                    Application.Invoke(delegate {
                        tvVolumes.Fill(volumes);
                        SetStatus(string.Empty);

                        // remember last successful searchcriteria
                        // (that has been used to successfully fill the treeview).
                        // (set in gtk thread to avoid race conditions.)
                        lastSuccessfulSearchCriteria = (ISearchCriteria)ar.AsyncState;
                    });
                } catch (Exception e) {
                    if (e is TimeoutException)
                    {
                        // couldn't get connection lock
                        Application.Invoke(delegate {
                            SetStatus(S._("Timeout: another search is probably still in progress."));
                        });
                    }
                    else
                    {
                        Application.Invoke(delegate {
                            //SetStatus(Util.FormatExceptionMsg(e));
                            SetStatus(string.Empty);
                        });
                        throw;
                    }
                } finally {
                    if (onsearchcompled != null)
                    {
                        onsearchcompled();
                    }
                }
            };

            try {
                SetStatus(S._("Searching..."));

                if (criteria != null)
                {
                    database.BeginSearchVolume(criteria, cb, criteria);
                }
                else
                {
                    database.BeginSearchVolume(cb, null);
                }
            } catch (Exception) {
                SetStatus(string.Empty);
                throw;
            }
        }
Пример #2
0
        private void OpenDB(string path, bool createNew, bool loadAsync, System.Action onsuccess)
        {
            EnableGui(false); // will be re-enabled after opening AND loading has been completed successfully
            SetWindowTitle(null);

            // clear views
            tvVolumes.Clear();
            tvItems.Clear();
            itemInfo.Clear();
            itemInfo.Hide();

            if (database != null)
                database.Close();

            lastSuccessfulSearchCriteria = null;

            try {
                database = new VolumeDatabase(path, createNew);
                database.SearchItemResultsLimit = App.SEARCH_RESULTS_LIMIT;
            } catch (UnsupportedDbVersionException) {
                MsgDialog.ShowError(this,
                                    S._("Unsupported database version"),
                                    S._("This database version is not supported."));
                return;
            }

            // load volumes

            Action<Volume[]> updateGui = (Volume[] volumes) => {
                tvVolumes.Fill(volumes);

                // select first volume
                /*
                // this clearly harms startup time.
                TreeIter iter;
                if (tvVolumes.Model.GetIterFirst(out iter))
                    tvVolumes.Selection.SelectIter(iter);
                */

                EnableGui(true);
                SetWindowTitle(path);
                SetTempStatus(string.Format(S._("{0} volumes loaded."), volumes.Length));

                recentManager.AddFull("file://" + path, recentData);

                App.Settings.MostRecentDBPath = path;
                App.Settings.Save();

                if (onsuccess != null)
                    onsuccess();  // must be called on the gui thread
            };

            if (loadAsync) {
                // delegate that will be called
                // when asynchronous volume loading (searching) has been finished.
                AsyncCallback cb = (IAsyncResult ar) => {
                    Volume[] volumes;

                    try {
                        volumes = database.EndSearchVolume(ar);
                    } catch (Exception ex) {
                        Application.Invoke(delegate {
                            SetStatus(string.Format(S._("An error occured while loading the volume list: {0}"),
                                                    ex.Message));
                        });
                        return;
                    }

                    Application.Invoke(delegate {
                        updateGui(volumes);
                    });
                };

                database.BeginSearchVolume(cb, null); // returns immediately

            } else {
                Volume[] volumes = database.SearchVolume();
                updateGui(volumes);
            }
        }
Пример #3
0
        private void OpenDB(string path, bool createNew, bool loadAsync, System.Action onsuccess)
        {
            EnableGui(false);             // will be re-enabled after opening AND loading has been completed successfully
            SetWindowTitle(null);

            // clear views
            tvVolumes.Clear();
            tvItems.Clear();
            itemInfo.Clear();
            itemInfo.Hide();

            if (database != null)
            {
                database.Close();
            }

            lastSuccessfulSearchCriteria = null;

            try {
                database = new VolumeDatabase(path, createNew);
                database.SearchItemResultsLimit = App.SEARCH_RESULTS_LIMIT;
            } catch (UnsupportedDbVersionException) {
                MsgDialog.ShowError(this,
                                    S._("Unsupported database version"),
                                    S._("This database version is not supported."));
                return;
            }

            // load volumes

            Action <Volume[]> updateGui = (Volume[] volumes) => {
                tvVolumes.Fill(volumes);

                // select first volume

                /*
                 * // this clearly harms startup time.
                 * TreeIter iter;
                 * if (tvVolumes.Model.GetIterFirst(out iter))
                 *      tvVolumes.Selection.SelectIter(iter);
                 */

                EnableGui(true);
                SetWindowTitle(path);
                SetTempStatus(string.Format(S._("{0} volumes loaded."), volumes.Length));

                recentManager.AddFull("file://" + path, recentData);

                App.Settings.MostRecentDBPath = path;
                App.Settings.Save();

                if (onsuccess != null)
                {
                    onsuccess();                      // must be called on the gui thread
                }
            };

            if (loadAsync)
            {
                // delegate that will be called
                // when asynchronous volume loading (searching) has been finished.
                AsyncCallback cb = (IAsyncResult ar) => {
                    Volume[] volumes;

                    try {
                        volumes = database.EndSearchVolume(ar);
                    } catch (Exception ex) {
                        Application.Invoke(delegate {
                            SetStatus(string.Format(S._("An error occured while loading the volume list: {0}"),
                                                    ex.Message));
                        });
                        return;
                    }

                    Application.Invoke(delegate {
                        updateGui(volumes);
                    });
                };

                database.BeginSearchVolume(cb, null);                 // returns immediately
            }
            else
            {
                Volume[] volumes = database.SearchVolume();
                updateGui(volumes);
            }
        }