private void SetDefaultUserAgent() { SetUserAgent( MwsUtil.EscapeAppName(this.ApplicationName), MwsUtil.EscapeAppVersion(this.ApplicationVersion), MwsUtil.EscapeAttributeValue("C#"), new string[] { "CLI", Environment.Version.ToString(), "Platform", Environment.OSVersion.Platform.ToString() + "/" + Environment.OSVersion.Version, "MWSClientVersion", this.LibraryVersion }); }
/// <summary> /// Construct a user agent header - synchronized /// </summary> /// <param name="applicationName">Escaped application name</param> /// <param name="applicationVersion">Escaped application version</param> /// <param name="programmingLanguage">Escaped programming language</param> /// <param name="additionalNameValuePairs">Raw attribute name,value pair</param> public void SetUserAgent(string applicationName, string applicationVersion, string programmingLanguage, string[] additionalNameValuePairs) { lock (this.lockThis) { if (applicationName == null) { throw new ArgumentNullException("applicationName", "Value cannot be null."); } if (applicationVersion == null) { throw new ArgumentNullException("applicationVersion", "Value cannot be null."); } if (programmingLanguage == null) { throw new ArgumentNullException("programmingLanguage", "Value cannot be null."); } if (additionalNameValuePairs.Length % 2 != 0) { throw new ArgumentException("additionalNameValuePairs", "Every name must have a corresponding value."); } StringBuilder sb = new StringBuilder(); sb.Append(applicationName); sb.Append("/"); sb.Append(applicationVersion); sb.Append(" ("); sb.Append("Language="); sb.Append(programmingLanguage); int i = 0; while (i < additionalNameValuePairs.Length) { string name = additionalNameValuePairs[i]; string value = additionalNameValuePairs[++i]; sb.Append("; "); sb.Append(MwsUtil.EscapeAttributeName(name)); sb.Append("="); sb.Append(MwsUtil.EscapeAttributeValue(value)); i++; } sb.Append(")"); this.userAgent = sb.ToString(); } }