/// <summary> /// Protected constructor. Use this version from a derived class if you want /// the library to use all settings from App.config. /// </summary> /// <remarks>This constructor exists for backward compatibility purposes. /// </remarks> protected AdsUser(AppConfigBase config, Dictionary<string, string> headers) { this.config = config; MergeValuesFromHeaders(config, headers); RegisterServices(GetServiceTypes()); if (this.config.EnableSoapExtension) { listeners.AddRange(GetDefaultListeners()); } SetHeadersFromConfig(); config.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "OAuth2Mode") { SetOAuthProvider(config); } }; SetOAuthProvider(config); }
/// <summary> /// Protected constructor. /// </summary> /// <param name="config">The config class.</param> protected TraceListener(AppConfigBase config) : base(config) { string logPath = ""; if (config.LogToFile) { logToFile = config.LogToFile; logPath = config.LogPath.TrimEnd('\\', '/') + Path.DirectorySeparatorChar; if (!Directory.Exists(logPath)) { Directory.CreateDirectory(logPath); } soapFileName = logPath + "soap_xml.log"; requestInfoFileName = logPath + "request_info.log"; } else { logPath = ""; // default location for SOAP logs } // should we log to console as well? logToConsole = config.LogToConsole; logErrorsOnly = config.LogErrorsOnly; }
/// <summary> /// Protected constructor. Use this version from a derived class if you want /// the library to use all settings from App.config. /// </summary> protected AdsUser(AppConfigBase config) : this(config, null) { }
/// <summary> /// Merges the values from headers and config into config instance. /// </summary> /// <param name="config">The appication configuration to use.</param> /// <param name="headers">The configuration headers.</param> private void MergeValuesFromHeaders(AppConfigBase config, Dictionary<string, string> headers) { if (headers != null) { Type configType = config.GetType(); foreach (string key in headers.Keys) { PropertyInfo propInfo = configType.GetProperty(key, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance); if (propInfo != null && propInfo.PropertyType == typeof(string)) { propInfo.SetValue(config, headers[key], null); } } } }
/// <summary> /// Sets the OAuth provider. /// </summary> /// <param name="config">The config.</param> private void SetOAuthProvider(AppConfigBase config) { if (config.OAuth2Mode == OAuth2Flow.APPLICATION) { this.OAuthProvider = new OAuth2ProviderForApplications(config); } else { this.OAuthProvider = new OAuth2ProviderForServiceAccounts(config); } }
/// <summary> /// Protected constructor. Use this version from a derived class if you want /// the library to use all settings from App.config. /// </summary> /// <remarks>This constructor exists for backward compatibility purposes. /// </remarks> protected AdsUser(AppConfigBase config, Dictionary<string, string> headers) { this.config = config; MergeValuesFromHeaders(config, headers); RegisterServices(GetServiceTypes()); listeners.AddRange(GetDefaultListeners()); SetHeadersFromConfig(); }
/// <summary> /// Reads the headers from App.config. /// </summary> /// <param name="config">The configuration class.</param> protected override void ReadHeadersFromConfig(AppConfigBase config) { AdWordsAppConfig awConfig = (AdWordsAppConfig) config; this.headers = new Dictionary<string, SoapHeader>(); this.headers["emailValue"] = MakeSoapHeader("email", awConfig.Email); this.headers["passwordValue"] = MakeSoapHeader("password", awConfig.Password); this.headers["clientEmailValue"] = MakeSoapHeader("clientEmail", awConfig.ClientEmail); if (string.IsNullOrEmpty(awConfig.ClientCustomerId)) { this.headers["clientCustomerIdValue"] = MakeSoapHeader("clientCustomerId", awConfig.ClientCustomerId); } this.headers["developerTokenValue"] = MakeSoapHeader("developerToken", awConfig.DeveloperToken); this.headers["applicationTokenValue"] = MakeSoapHeader("applicationToken", awConfig.ApplicationToken); this.headers["useragentValue"] = MakeSoapHeader("useragent", Useragent); }
/// <summary> /// Reads the headers from App.config. /// </summary> /// <param name="config">The configuration class.</param> protected override void ReadHeadersFromConfig(AppConfigBase config) { AdWordsAppConfig awConfig = (AdWordsAppConfig) config; this.requestHeader = new RequestHeader(); if (!string.IsNullOrEmpty(awConfig.ClientEmail)) { this.requestHeader.clientEmail = awConfig.ClientEmail; } else if (!string.IsNullOrEmpty(awConfig.ClientCustomerId)) { requestHeader.clientCustomerId = awConfig.ClientCustomerId; } requestHeader.developerToken = awConfig.DeveloperToken; requestHeader.userAgent = GetUseragent(awConfig); }
/// <summary> /// Public constructor. /// </summary> /// <param name="email">Email to be used for authentication.</param> /// <param name="password">Password to be used for authentication</param> /// <param name="config">The configuration object for use with this object. /// </param> /// <param name="service">The gaia service name for which tokens are being /// generated.</param> /// <param name="proxy">The HTTP web proxy for making HTTP calls.</param> /// <param name="timeout">Timeout in milliseconds for the web connection. /// </param> public AuthToken(AppConfigBase config, string service, string email, string password, WebProxy proxy, int timeout) { if (config == null) { throw new ArgumentNullException("config"); } this.email = email; this.password = password; this.service = service; this.SOURCE = string.Format(CultureInfo.InvariantCulture, "Google-{0}", config.Signature); this.proxy = proxy; this.timeout = timeout; }
/// <summary> /// Public constructor. /// </summary> /// <param name="email">Email to be used for authentication.</param> /// <param name="password">Password to be used for authentication</param> /// <param name="config">The configuration object for use with this object. /// </param> /// <param name="service">The gaia service name for which tokens are being /// generated.</param> /// <param name="proxy">The HTTP web proxy for making HTTP calls.</param> public AuthToken(AppConfigBase config, string service, string email, string password, WebProxy proxy) : this(config, service, email, password, proxy, config.Timeout) { }
/// <summary> /// Reads the headers from App.config. /// </summary> /// <param name="config">The configuration class.</param> protected abstract void ReadHeadersFromConfig(AppConfigBase config);
/// <summary> /// Protected constructor. /// </summary> /// <param name="config">The config class to be used with this class. /// </param> protected SoapListener(AppConfigBase config) { this.config = config; }