Ejemplo n.º 1
0
        /// <summary>
        /// Called when the load books button is clicked. Load the list of available books for the selected
        /// language
        /// </summary>
        /// <param name="sender">
        /// The parameter is not used.
        /// </param>
        /// <param name="e">
        /// The parameter is not used.
        /// </param>
        private void LoadBooksClick( object sender, EventArgs e )
        {
            string path = ((Locale)languageSelection.SelectedItem).CatalogLink;

            SetBusyState();
            downloadProgress.Style = ProgressBarStyle.Marquee;
            startupTip.Visible = false;
            loadingBooksTip.Visible = true;

            Task.Factory.StartNew(
                () =>
                    {
                        using ( Downloader downloader = new Downloader() )
                        {
                            return downloader.LoadBooksInformation( path );
                        }
                    } ).ContinueWith(
                        t =>
                            {
                                if ( t.Status == TaskStatus.Faulted )
                                {
                                    string message = string.Format(
                                        CultureInfo.CurrentCulture,
                                        "Failed to retrieve book information - {0}",
                                        t.Exception == null ? "Unknown error" : t.Exception.GetBaseException().Message );
                                    MessageBox.Show(
                                        message,
                                        Application.ProductName,
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error,
                                        MessageBoxDefaultButton.Button1,
                                        0 );
                                }
                                else
                                {
                                    products = t.Result;
                                    DisplayBooks();
                                }

                                ClearBusyState();
                            },
                        TaskScheduler.FromCurrentSynchronizationContext() );
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Called to update the available locales for the selected version of visual studio
        /// </summary>
        private void UpdateLocales()
        {
            if ( vsVersion.SelectedIndex == -1 )
            {
                return;
            }

            string[] vsVersions = { "visualstudio11", "visualstudio12", "dev14" };
            string version = vsVersions[vsVersion.SelectedIndex];
            loadingBooksTip.Visible = true;
            startupTip.Visible = false;
            languageSelection.Items.Clear();
            downloadProgress.Style = ProgressBarStyle.Marquee;
            Task.Factory.StartNew(
                () =>
                {
                    using (Downloader downloader = new Downloader())
                    {
                        return downloader.LoadAvailableLocales( version );
                    }
                })
            .ContinueWith(
                        t =>
                        {
                            languageSelection.DisplayMember = "Name";
                            t.Result.ForEach(x => languageSelection.Items.Add(x));
                            ClearBusyState();
                            startupTip.Visible = true;
                        },
                        TaskScheduler.FromCurrentSynchronizationContext());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Called when the download books button is clicked. Start downloading in a background thread
        /// </summary>
        /// <param name="sender">
        /// The parameter is not used.
        /// </param>
        /// <param name="e">
        /// The parameter is not used.
        /// </param>
        private void DownloadBooksClick( object sender, EventArgs e )
        {
            SetBusyState();
            downloadProgress.Style = ProgressBarStyle.Continuous;
            downloadProgress.Value = 0;
            Task.Factory.StartNew(
                () =>
                    {
                        using ( Downloader downloader = new Downloader() )
                        {
                            downloader.DownloadBooks( products, cacheDirectory.Text, OrangeCHelpFileDirectory, (Locale)languageSelection.SelectedItem, this );
                        }
                    } )
            .ContinueWith(
                        t =>
                            {
                                if ( t.Status == TaskStatus.Faulted )
                                {
                                    string message = string.Format(
                                        CultureInfo.CurrentCulture,
                                        "Download failed - {0}",
                                        t.Exception == null ? "Unknown error" : t.Exception.GetBaseException().Message );
                                    MessageBox.Show(
                                        message,
                                        Application.ProductName,
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error,
                                        MessageBoxDefaultButton.Button1,
                                        0 );
                                }
                                else
                                {
                                    MessageBox.Show(
                                        "Download completed successfully",
                                        Application.ProductName,
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information,
                                        MessageBoxDefaultButton.Button1,
                                        0 );
                                }

                                ClearBusyState();
                                DisplayBooks();
                                downloadProgress.Value = 0;
                            },
                        TaskScheduler.FromCurrentSynchronizationContext() );
        }