Exemplo n.º 1
0
        /// <summary>
        /// Get available app versions from the server
        /// </summary>
        /// <returns></returns>
        public async Task <IEnumerable <IAppVersion> > GetAppVersionsAsync()
        {
            StringBuilder url = new StringBuilder(this.ApiBaseVersion2 + "apps/" + this.AppIdentifier + ".json");

            url.Append("?app_version=" + Uri.EscapeDataString(this.VersionInfo));
            if (!String.IsNullOrEmpty(this.Os))
            {
                url.Append("&os=" + Uri.EscapeDataString(this.Os));
            }
            if (!String.IsNullOrEmpty(this.OsVersion))
            {
                url.Append("&os_version=" + Uri.EscapeDataString(this.OsVersion));
            }
            if (!String.IsNullOrEmpty(this.Device))
            {
                url.Append("&device=" + Uri.EscapeDataString(this.Device));
            }
            if (!String.IsNullOrEmpty(this.Oem))
            {
                url.Append("&oem=" + Uri.EscapeDataString(this.Oem));
            }
            if (!String.IsNullOrEmpty(this.SdkName))
            {
                url.Append("&sdk=" + Uri.EscapeDataString(this.SdkName));
            }
            if (!String.IsNullOrEmpty(this.SdkVersion))
            {
                url.Append("&sdk_version=" + Uri.EscapeDataString(this.SdkVersion));
            }
            url.Append("&lang=" + Uri.EscapeDataString(System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName));

            if (!String.IsNullOrEmpty(this.Auid))
            {
                url.Append("&=auid" + Uri.EscapeDataString(this.Auid));
            }
            else if (!String.IsNullOrEmpty(this.Iuid))
            {
                url.Append("&=iuid" + Uri.EscapeDataString(this.Iuid));
            }
            else if (!String.IsNullOrEmpty(this.Uuid))
            {
                url.Append("&=duid" + Uri.EscapeDataString(this.Uuid));
            }

            var request = WebRequest.CreateHttp(new Uri(this.ApiBaseVersion2 + "apps/" + this.AppIdentifier + ".json", UriKind.Absolute));

            request.Method = "Get";
            request.SetHeader(HttpRequestHeader.UserAgent.ToString(), this.UserAgentString);
            var response = await request.GetResponseAsync();

            IEnumerable <AppVersion> appVersions = await TaskEx.Run(() => AppVersion.FromJson(response.GetResponseStream()));

            foreach (var ver in appVersions)
            {
                ver.PublicIdentifier = this.AppIdentifier; //the json response does not include the public app identifier
            }
            return(appVersions);
        }