예제 #1
0
        /// <summary>
        /// Returns raw xml containing various (Revision, Update, Package) IDs and info.
        /// </summary>
        /// <param name="WuCategoryID"></param>
        /// <returns></returns>
        public static async Task <string> SyncUpdatesAsync(string WuCategoryID)
        {
            HttpContent        httpContent = new StringContent(String.Format(GetResourceTextFile("WUIDRequest.xml"), await GetCookieAsync(), WuCategoryID), Encoding.UTF8, "application/soap+xml"); //Load in the Xml for this FE3 request and format it a cookie and the provided WuCategoryID.
            HttpRequestMessage httpRequest = new HttpRequestMessage();

            httpRequest.RequestUri = Endpoints.FE3Delivery;
            httpRequest.Content    = httpContent;
            httpRequest.Method     = HttpMethod.Post;
            HttpResponseMessage httpResponse = await _httpClient.SendAsync(httpRequest, new System.Threading.CancellationToken());

            string content = await httpResponse.Content.ReadAsStringAsync();

            content = HttpUtility.HtmlDecode(content);
            return(content);
        }
예제 #2
0
        /// <summary>
        /// Queries DisplayCatalog for the provided ID. The resulting possibly found product is reflected in DisplayCatalogHandlerInstance.ProductListing. If the product isn't found, that variable will be null, check IsFound and Result.
        /// The provided Auth Token is also sent allowing for flighted or sandboxed listings. The resulting possibly found product is reflected in DisplayCatalogHandlerInstance.ProductListing. If the product isn't found, that variable will be null, check IsFound and Res
        /// </summary>
        /// <param name="ID">The ID, type specified in DCatHandler Instance.</param>
        /// <param name="IDType">Type of ID being passed.</param>
        /// <param name="AuthenticationToken"></param>
        /// <returns></returns>
        public async Task QueryDCATAsync(string ID, IdentiferType IDType = IdentiferType.ProductID, string AuthenticationToken = null) //Optional Authentication Token used for Sandbox and Flighting Queries.
        {
            this.ID             = ID;
            this.ConstructedUri = Utilities.UriHelpers.CreateAlternateDCatUri(SelectedEndpoint, ID, IDType, SelectedLocale);
            Result = new DisplayCatalogResult(); //We need to clear the result incase someone queries a product, then queries a not found one, the wrong product will be returned.
            HttpResponseMessage httpResponse = new HttpResponseMessage();
            HttpRequestMessage  httpRequestMessage;

            //We need to build the request URL based on the requested EndPoint;
            httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, ConstructedUri);

            if (!String.IsNullOrEmpty(AuthenticationToken))
            {
                httpRequestMessage.Headers.TryAddWithoutValidation("Authentication", AuthenticationToken);
            }

            try
            {
                httpResponse = await _httpClient.SendAsync(httpRequestMessage, new System.Threading.CancellationToken());
            }
            catch (TaskCanceledException)
            {
                Result = DisplayCatalogResult.TimedOut;
            }
            if (httpResponse.IsSuccessStatusCode)
            {
                string content = await httpResponse.Content.ReadAsStringAsync();

                Result         = DisplayCatalogResult.Found;
                IsFound        = true;
                ProductListing = DisplayCatalogModel.FromJson(content);
            }
            else if (httpResponse.StatusCode == System.Net.HttpStatusCode.NotFound)
            {
                Result = DisplayCatalogResult.NotFound;
            }
            else
            {
                throw new Exception($"Failed to query DisplayCatalog Endpoint: {SelectedEndpoint.ToString()} Status Code: {httpResponse.StatusCode} Returned Data: {await httpResponse.Content.ReadAsStringAsync()}");
            }
        }