RunTask() public method

public RunTask ( ITask task ) : void
task ITask
return void
Esempio n. 1
0
        private void pageExistingCryptoKey_Commit(object sender, WizardPageConfirmEventArgs e)
        {
            _cryptoKey = textBoxCryptoKey.Text;

            try
            {
                using (var handler = new DialogTaskHandler(this))
                    handler.RunTask(new SimpleTask(Text, CheckCryptoKey));
            }
                #region Error handling
            catch (WebException ex)
            {
                Log.Warn(ex);
                Msg.Inform(this, ex.Message, MsgSeverity.Warn);
                e.Cancel = true;
            }
            catch (InvalidDataException ex)
            {
                Log.Warn(ex);
                Msg.Inform(this, ex.Message, MsgSeverity.Warn);
                e.Cancel = true;
            }
            catch (OperationCanceledException)
            {
                e.Cancel = true;
            }
            #endregion

            pageExistingCryptoKey.NextPage = _troubleshooting ? pageChangeCryptoKey : pageSetupFinished;
        }
Esempio n. 2
0
        /// <summary>
        /// Signs a number of <see cref="Feed"/>s with a single <see cref="OpenPgpSecretKey"/>.
        /// </summary>
        /// <param name="secretKey">The private key to use for signing the files.</param>
        /// <param name="passphrase">The passphrase to use to unlock the key.</param>
        /// <exception cref="IOException">The feed file could not be read or written.</exception>
        /// <exception cref="UnauthorizedAccessException">Read or write access to the feed file is not permitted.</exception>
        private void SignFiles(OpenPgpSecretKey secretKey, string passphrase)
        {
            var task = ForEachTask.Create("Signing feeds", _files, file =>
            {
                SignedFeed signedFeed;
                try
                {
                    signedFeed = SignedFeed.Load(file.FullName);
                }
                    #region Error handling
                catch (UnauthorizedAccessException ex)
                {
                    // Wrap exception since only certain exception types are allowed
                    throw new IOException(ex.Message, ex);
                }
                catch (InvalidDataException ex)
                {
                    // Wrap exception since only certain exception types are allowed
                    throw new IOException(ex.Message + (ex.InnerException == null ? "" : Environment.NewLine + ex.InnerException.Message), ex);
                }
                #endregion

                signedFeed.SecretKey = secretKey;
                try
                {
                    signedFeed.Save(file.FullName, passphrase);
                }
                    #region Error handling
                catch (UnauthorizedAccessException ex)
                {
                    // Wrap exception since only certain exception types are allowed
                    throw new IOException(ex.Message, ex);
                }
                catch (KeyNotFoundException ex)
                {
                    // Wrap exception since only certain exception types are allowed
                    throw new IOException(ex.Message, ex);
                }
                catch (WrongPassphraseException ex)
                {
                    // Wrap exception since only certain exception types are allowed
                    throw new IOException(ex.Message, ex);
                }
                #endregion
            });
            using (var handler = new DialogTaskHandler(this)) handler.RunTask(task);
            Msg.Inform(this, "Successfully signed files.", MsgSeverity.Info);
        }
Esempio n. 3
0
        private void pageCredentials_Commit(object sender, WizardPageConfirmEventArgs e)
        {
            _server.Username = textBoxUsername.Text;
            _server.Password = textBoxPassword.Text;

            try
            {
                using (var handler = new DialogTaskHandler(this))
                    handler.RunTask(new SimpleTask(Text, CheckCredentials));
            }
                #region Error handling
            catch (WebException ex)
            {
                Log.Warn(ex);
                Msg.Inform(this, ex.Message, MsgSeverity.Warn);
                e.Cancel = true;
                return;
            }
            catch (OperationCanceledException)
            {
                e.Cancel = true;
                return;
            }
            #endregion

            pageCredentials.NextPage = _existingAccount ? pageExistingCryptoKey : pageNewCryptoKey;
        }
Esempio n. 4
0
        /// <summary>
        /// Adds a feed to the list of custom feeds.
        /// </summary>
        private void AddCustomFeed(string input)
        {
            FeedUri feedUri;
            try
            {
                feedUri = new FeedUri(input);
            }
            catch (UriFormatException ex)
            {
                Msg.Inform(this, ex.Message, MsgSeverity.Error);
                return;
            }

            if (_interfaceUri.IsFile)
            {
                if (!File.Exists(_interfaceUri.LocalPath))
                {
                    Msg.Inform(this, string.Format(Resources.FileOrDirNotFound, _interfaceUri.LocalPath), MsgSeverity.Warn);
                    return;
                }
            }
            else
            {
                Feed feed = null;
                try
                {
                    using (var handler = new DialogTaskHandler(this))
                    {
                        handler.RunTask(new SimpleTask(Resources.CheckingFeed,
                            delegate
                            {
                                using (var webClient = new WebClientTimeout())
                                    feed = XmlStorage.FromXmlString<Feed>(webClient.DownloadString(feedUri));
                            }));
                    }
                }
                    #region Error handling
                catch (OperationCanceledException)
                {
                    return;
                }
                catch (IOException ex)
                {
                    Msg.Inform(this, ex.Message, MsgSeverity.Error);
                    return;
                }
                catch (InvalidDataException ex)
                {
                    Msg.Inform(this, ex.Message, MsgSeverity.Error);
                    return;
                }
                catch (WebException ex)
                {
                    Msg.Inform(this, ex.Message, MsgSeverity.Error);
                    return;
                }
                catch (UnauthorizedAccessException ex)
                {
                    Msg.Inform(this, ex.Message, MsgSeverity.Error);
                    return;
                }
                #endregion

                // Ensure a matching <feed-for> is present for online feeds
                if (feed.FeedFor.All(entry => entry.Target != _interfaceUri))
                    if (!Msg.YesNo(this, Resources.IgnoreMissingFeedFor, MsgSeverity.Warn)) return;
            }

            var reference = new FeedReference {Source = feedUri};
            if (_interfacePreferences.Feeds.Contains(reference)) return;
            _interfacePreferences.Feeds.Add(reference);
            listBoxFeeds.Items.Add(reference);
        }