/// <inheritdoc/>
        public override NetworkCredential GetCredential(Uri uri, string authType)
        {
            #region Sanity checks
            if (uri == null) throw new ArgumentNullException(nameof(uri));
            #endregion

            if (!Interactive) return null;

            Log.Debug("Prompt for credentials on command-line: " + uri.ToStringRfc());
            if (WasReportedInvalid(uri))
                Log.Error(string.Format(Resources.InvalidCredentials, uri.ToStringRfc()));
            Console.Error.WriteLine(Resources.PleasEnterCredentials, uri.ToStringRfc());
            return new NetworkCredential(
                CliUtils.ReadString(Resources.UserName),
                CliUtils.ReadPassword(Resources.Password));
        }
        /// <inheritdoc/>
        public override NetworkCredential GetCredential(Uri uri, string authType)
        {
            #region Sanity checks
            if (uri == null) throw new ArgumentNullException(nameof(uri));
            #endregion

            string target = uri.ToStringRfc();

            if (!Interactive && !WindowsCredentials.IsCredentialStored(target))
                return null;

            var flags = WindowsCredentialsFlags.GenericCredentials | WindowsCredentialsFlags.ExcludeCertificates | WindowsCredentialsFlags.ShowSaveCheckBox;
            if (WasReportedInvalid(uri))
                flags |= WindowsCredentialsFlags.IncorrectPassword | WindowsCredentialsFlags.AlwaysShowUI;

            return Prompt(target, flags);
        }
Example #3
0
        /// <summary>
        /// Performs a feed search query using the <see cref="Config.FeedMirror"/>.
        /// </summary>
        /// <param name="config">The current configuration determining which mirror server to query.</param>
        /// <param name="keywords">The keywords to search for.</param>
        public static SearchQuery Perform([NotNull] Config config, [CanBeNull] string keywords)
        {
            #region Sanity checks
            if (config == null) throw new ArgumentNullException(nameof(config));
            #endregion

            if (string.IsNullOrEmpty(keywords)) return new SearchQuery();

            var url = new Uri(
                config.FeedMirror.EnsureTrailingSlash(),
                new Uri("search/?q=" + Uri.EscapeUriString(keywords), UriKind.Relative));

            Log.Info("Performing search query: " + url.ToStringRfc());
            using (var webClient = new WebClientTimeout())
            {
                var result = XmlStorage.FromXmlString<SearchQuery>(webClient.DownloadString(url));
                result.Keywords = keywords;
                return result;
            }
        }