/// <summary>
        /// Read all settings from App.config.
        /// </summary>
        /// <param name="settings">The parsed app.config settings.</param>
        protected virtual void ReadSettings(Hashtable settings)
        {
            // Common keys.
            string proxyUrl = ReadSetting(settings, PROXY_SERVER, "");

            if (!string.IsNullOrEmpty(proxyUrl))
            {
                WebProxy proxy = new WebProxy();
                proxy.Address = new Uri(proxyUrl);

                string proxyUser     = ReadSetting(settings, PROXY_USER, "");
                string proxyPassword = ReadSetting(settings, PROXY_PASSWORD, "");
                string proxyDomain   = ReadSetting(settings, PROXY_DOMAIN, "");

                if (!string.IsNullOrEmpty(proxyUrl))
                {
                    proxy.Credentials = new NetworkCredential(proxyUser,
                                                              proxyPassword, proxyDomain);
                }
                this.proxy = proxy;
            }
            else
            {
                // System.Net.WebRequest will find a proxy if needed.
                this.proxy = null;
            }
            maskCredentials = bool.Parse(ReadSetting(settings, MASK_CREDENTIALS,
                                                     maskCredentials.ToString()));

            try {
                oAuth2Mode = (OAuth2Flow)Enum.Parse(typeof(OAuth2Flow), ReadSetting(settings, OAUTH2_MODE,
                                                                                    oAuth2Mode.ToString()));
            } catch (Exception e) {
                // No action.
            }

            oAuth2ClientId            = ReadSetting(settings, OAUTH2_CLIENTID, oAuth2ClientId);
            oAuth2ClientSecret        = ReadSetting(settings, OAUTH2_CLIENTSECRET, oAuth2ClientSecret);
            oAuth2AccessToken         = ReadSetting(settings, OAUTH2_ACCESSTOKEN, oAuth2AccessToken);
            oAuth2RefreshToken        = ReadSetting(settings, OAUTH2_REFRESHTOKEN, oAuth2RefreshToken);
            oAuth2Scope               = ReadSetting(settings, OAUTH2_SCOPE, oAuth2Scope);
            oAuth2RedirectUri         = ReadSetting(settings, OAUTH2_REDIRECTURI, oAuth2RedirectUri);
            oAuth2ServiceAccountEmail = ReadSetting(settings, OAUTH2_SERVICEACCOUNT_EMAIL,
                                                    oAuth2ServiceAccountEmail);
            oAuth2PrnEmail = ReadSetting(settings, OAUTH2_PRN_EMAIL, oAuth2PrnEmail);

            oAuth2CertificatePath = ReadSetting(settings, OAUTH2_JWT_CERTIFICATE_PATH,
                                                oAuth2CertificatePath);
            oAuth2CertificatePassword = ReadSetting(settings, OAUTH2_JWT_CERTIFICATE_PASSWORD,
                                                    oAuth2CertificatePassword);

            email     = ReadSetting(settings, EMAIL, email);
            password  = ReadSetting(settings, PASSWORD, password);
            authToken = ReadSetting(settings, AUTHTOKEN, authToken);

            int.TryParse(ReadSetting(settings, TIMEOUT, timeout.ToString()), out timeout);
            int.TryParse(ReadSetting(settings, RETRYCOUNT, retryCount.ToString()), out retryCount);
            bool.TryParse(ReadSetting(settings, ENABLE_GZIP_COMPRESSION,
                                      enableGzipCompression.ToString()), out enableGzipCompression);
        }
예제 #2
0
        /// <summary>
        /// Read all settings from App.config.
        /// </summary>
        /// <param name="settings">The parsed app.config settings.</param>
        protected virtual void ReadSettings(Dictionary <string, string> settings)
        {
            // Common keys.
            string proxyUrl = ReadSetting(settings, PROXY_SERVER, "");

            if (!string.IsNullOrEmpty(proxyUrl))
            {
                WebProxy proxy = new WebProxy();
                proxy.Address = new Uri(proxyUrl);

                string proxyUser     = ReadSetting(settings, PROXY_USER, "");
                string proxyPassword = ReadSetting(settings, PROXY_PASSWORD, "");
                string proxyDomain   = ReadSetting(settings, PROXY_DOMAIN, "");

                if (!string.IsNullOrEmpty(proxyUrl))
                {
                    proxy.Credentials = new NetworkCredential(proxyUser,
                                                              proxyPassword, proxyDomain);
                }
                this.proxy = proxy;
            }
            else
            {
                // System.Net.WebRequest will find a proxy if needed.
                this.proxy = null;
            }
            maskCredentials = bool.Parse(ReadSetting(settings, MASK_CREDENTIALS,
                                                     maskCredentials.ToString()));

            Enum.TryParse <OAuth2Flow>(ReadSetting(settings, OAUTH2_MODE, oAuth2Mode.ToString()),
                                       out oAuth2Mode);

            oAuth2ServerUrl    = ReadSetting(settings, OAUTH2_SERVER_URL, oAuth2ServerUrl);
            oAuth2ClientId     = ReadSetting(settings, OAUTH2_CLIENTID, oAuth2ClientId);
            oAuth2ClientSecret = ReadSetting(settings, OAUTH2_CLIENTSECRET, oAuth2ClientSecret);
            oAuth2AccessToken  = ReadSetting(settings, OAUTH2_ACCESSTOKEN, oAuth2AccessToken);
            oAuth2RefreshToken = ReadSetting(settings, OAUTH2_REFRESHTOKEN, oAuth2RefreshToken);
            oAuth2Scope        = ReadSetting(settings, OAUTH2_SCOPE, oAuth2Scope);
            oAuth2RedirectUri  = ReadSetting(settings, OAUTH2_REDIRECTURI, oAuth2RedirectUri);

            // Read and parse the OAuth2 JSON secrets file if applicable.
            oAuth2SecretsJsonPath = ReadSetting(settings, OAUTH2_SECRETS_JSON_PATH,
                                                oAuth2SecretsJsonPath);

            if (!string.IsNullOrEmpty(oAuth2SecretsJsonPath))
            {
                LoadOAuth2SecretsFromFile();
            }

            oAuth2PrnEmail = ReadSetting(settings, OAUTH2_PRN_EMAIL, oAuth2PrnEmail);

            int.TryParse(ReadSetting(settings, TIMEOUT, timeout.ToString()), out timeout);
            int.TryParse(ReadSetting(settings, RETRYCOUNT, retryCount.ToString()), out retryCount);
            bool.TryParse(ReadSetting(settings, ENABLE_GZIP_COMPRESSION,
                                      enableGzipCompression.ToString()), out enableGzipCompression);

            bool.TryParse(ReadSetting(settings, INCLUDE_FEATURES_IN_USERAGENT,
                                      includeFeaturesInUserAgent.ToString()), out includeFeaturesInUserAgent);
        }