Пример #1
0
        private void OnContextMenuActivated(object sender, RoutedEventArgs args)
        {
            MenuItem menuItem = sender as MenuItem;

            Debug.Assert(menuItem != null);
            Library library = menuItem.CommandParameter as Library;

            Debug.Assert(library != null);

            switch (menuItem.Tag.ToString())
            {
            case "DeleteTag":
                if (MessageBox.Show(FileLanguage.QUESTION_REMOVE_LIBRARY, FileLanguage.ARE_YOU_SURE, MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    App.Engine.DeleteLibrary(library);
                }
                break;

            case "CheckForUpdatesTag":
            {
                ProgressBarOverlay.Show(FileLanguage.ProgressOverlay_UpdatingLibrary);

                longRunningOperation = App.Engine.UpdateLibrary(library)
                                       .Finally(ProgressBarOverlay.Close)
                                       .Subscribe <Library>(
                    result => { /*no implementation needed*/ },
                    Utils.StandardErrorHandler
                    );
            }
            break;

            case "DownloadAllTag":
            {
                string libraryId = library.ServerId;
                if (library.CatalogueCount == -1)
                {
                    ProgressBarOverlay.Show(FileLanguage.MainPage_DownloadingLib);

                    longRunningOperation = App.Engine.DownloadLibrary(library)
                                           .Finally(ProgressBarOverlay.Close)
                                           .Subscribe <Library>(
                        libraryParam =>
                        {
                            ProgressBarOverlay.Close();
                            if (!App.Engine.LibraryModel.IsLoaded() || App.Engine.LibraryModel.LibraryId != libraryId)
                            {
                                App.Engine.LibraryModel.LoadLibrary(libraryId);
                            }
                            DownloadAllCommand.GetCommand().Execute(libraryId);
                        },
                        Utils.StandardErrorHandler
                        );
                }
                else
                {
                    if (!App.Engine.LibraryModel.IsLoaded() || App.Engine.LibraryModel.LibraryId != libraryId)
                    {
                        App.Engine.LibraryModel.LoadLibrary(libraryId);
                    }
                    DownloadAllCommand.GetCommand().Execute(libraryId);
                }
            }
            break;

            case "SearchTag":
            {
                string libraryId = library.ServerId;
                if (library.CatalogueCount == -1)
                {
                    ProgressBarOverlay.Show(FileLanguage.MainPage_DownloadingLib);

                    longRunningOperation = App.Engine.DownloadLibrary(library)
                                           .Finally(ProgressBarOverlay.Close)
                                           .Subscribe <Library>(
                        libraryParam =>
                        {
                            ProgressBarOverlay.Close();
                            if (!App.Engine.LibraryModel.IsLoaded() || App.Engine.LibraryModel.LibraryId != libraryId)
                            {
                                App.Engine.LibraryModel.LoadLibrary(libraryId);
                            }
                            (Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/SearchPage.xaml?rootId=" + libraryId, UriKind.Relative));
                        },
                        Utils.StandardErrorHandler
                        );
                }
                else
                {
                    if (!App.Engine.LibraryModel.IsLoaded() || App.Engine.LibraryModel.LibraryId != libraryId)
                    {
                        App.Engine.LibraryModel.LoadLibrary(libraryId);
                    }
                    (Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/SearchPage.xaml?rootId=" + libraryId, UriKind.Relative));
                }
            }
            break;
            }
        }
 private void OnDownloadAllClicked(object sender, EventArgs args)
 {
     DownloadAllCommand.GetCommand().Execute(ContentId);
 }