Esempio n. 1
0
 // File -> Open URL
 private void openUrlToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         using (OpenUrlForm ouf = new OpenUrlForm())
         {
             if (ouf.ShowDialog() == DialogResult.OK)
             {
                 Johnny.Controls.Windows.ExtendedWebBrowser.ExtendedWebBrowser brw = _windowManager.New(false);
                 brw.Navigate(ouf.Url);
             }
         }
     }
     catch (Exception ex)
     {
         Program.ShowMessageBox("FrmWebBrowser", ex);
     }
 }
Esempio n. 2
0
        private void mnuLoadCoverOpenUrl_Click(object sender, EventArgs e)
        {
            var dialog = new OpenUrlForm();

            if (dialog.ShowForm() != DialogResult.OK)
                return;

            var address = dialog.Address;

            var uiContext = TaskScheduler.FromCurrentSynchronizationContext();
            var cancellationTokenSource = new CancellationTokenSource();
            var cancellationToken = cancellationTokenSource.Token;

            var progressUI = Wizard.StartProgress(cancellationTokenSource);
            progressUI.Title = "Loading image...";
            progressUI.Begin(0);

            Task.Factory.StartNew(
                () =>
                {
                    try
                    {
                        progressUI.Advance(address.Authority);

                        using (var webClient = new WebClient())
                        {
                            var data = webClient.DownloadData(address);
                            var mimeType = webClient.ResponseHeaders["Content-Type"];

                            return new Picture(data, mimeType);
                        }
                    }
                    finally
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                    }
                },
                cancellationToken
                ).ContinueWith(
                    task =>
                    {
                        Wizard.StopProgress(progressUI);

                        if (task.IsCanceled)
                            return;

                        if (task.IsFaulted)
                        {
                            MessageBox.Show(task.Exception.InnerException.ToString(), Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }

                        var albumCover = task.Result;

                        Session.Album.Cover = albumCover;
                        SetCover();
                    },
                    uiContext);
        }