Пример #1
0
 /// <summary>
 /// Returns the uri for the proper image format requested. If the requested format isn't found, we sliently return nothing.
 /// </summary>
 /// <param name="WantedImageType"></param>
 /// <param name="displayCatalogModel"></param>
 /// <returns></returns>
 public static Uri GetImageUri(ImagePurpose WantedImageType, DisplayCatalogModel displayCatalogModel)
 {
     foreach (StoreLib.Models.Image image in displayCatalogModel.Product.LocalizedProperties[0].Images)
     {
         Uri imageUri;
         if (image.ImagePurpose == Enum.GetName(typeof(ImagePurpose), WantedImageType))
         {
             if (image.Uri.StartsWith("//")) //For whatever reason, uris for images from UWP listings will start with "//", i.e //store-images.s-microsoft.com. Checking for that and adding http: to the beginning if they do to create a valid url.
             {
                 imageUri = new Uri("http:" + image.Uri);
                 return(imageUri);
             }
             imageUri = new Uri(image.Uri);
             return(imageUri);
         }
     }
     return(null);
 }
Пример #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()}");
            }
        }
Пример #3
0
        private static async Task BuildReply(DisplayCatalogModel displayCatalogModel, SocketMessage message)
        {
            StringBuilder MoreDetailsHelper = new StringBuilder();
            await Utilities.Log($"{message.Content.Substring(1, 12)} - {displayCatalogModel.Product.LocalizedProperties[0].ProductTitle} was queried by {message.Author.Username}#{message.Author.Id} at {message.Channel.Name}");

            MoreDetailsHelper.AppendLine($"`{displayCatalogModel.Product.LocalizedProperties[0].ProductTitle} - {displayCatalogModel.Product.LocalizedProperties[0].PublisherName}");
            MoreDetailsHelper.AppendLine($"Rating: {displayCatalogModel.Product.MarketProperties[0].UsageData[0].AverageRating} Stars");
            MoreDetailsHelper.AppendLine($"Last Modified: {displayCatalogModel.Product.LastModifiedDate}");
            MoreDetailsHelper.AppendLine($"Original Release: {displayCatalogModel.Product.MarketProperties[0].OriginalReleaseDate}");
            MoreDetailsHelper.AppendLine($"Product Type: {displayCatalogModel.Product.ProductType}");
            MoreDetailsHelper.AppendLine($"Is a Microsoft Listing: {displayCatalogModel.Product.IsMicrosoftProduct}");
            if (displayCatalogModel.Product.ValidationData != null)
            {
                MoreDetailsHelper.AppendLine($"Validation Info: {displayCatalogModel.Product.ValidationData.RevisionId}");
            }
            if (displayCatalogModel.Product.SandboxID != null)
            {
                MoreDetailsHelper.AppendLine($"SandBoxID: {displayCatalogModel.Product.SandboxID}");
            }

            foreach (AlternateId ID in displayCatalogModel.Product.AlternateIds) //Dynamicly add any other ID(s) that might be present rather than doing a ton of null checks.
            {
                MoreDetailsHelper.AppendLine($"{ID.IdType}: {ID.Value}");
            }
            if (displayCatalogModel.Product.DisplaySkuAvailabilities[0].Sku.Properties.FulfillmentData != null)
            {
                MoreDetailsHelper.AppendLine($"WuCategoryID: {displayCatalogModel.Product.DisplaySkuAvailabilities[0].Sku.Properties.FulfillmentData.WuCategoryId}");
                MoreDetailsHelper.AppendLine($"EAppx Key ID: {displayCatalogModel.Product.DisplaySkuAvailabilities[0].Sku.Properties.Packages[0].KeyId}");
            }
            MoreDetailsHelper.AppendLine("`");
            IList <PackageInstance> packageInstances = await dcat.GetPackagesForProductAsync();

#if DEBUG
            await message.Channel.SendMessageAsync($"Found {packageInstances.Count} packages.");
#endif
            MoreDetailsHelper.AppendLine($"Packages: (1/3)\n");
            await message.Channel.SendMessageAsync(MoreDetailsHelper.ToString());

            StringBuilder packages    = new StringBuilder();
            List <string> packagelist = new List <string>(Regex.Split(packages.ToString(), @"(?<=\G.{1999})", RegexOptions.Singleline));

            /*
             * if (displayCatalogModel.Product.DisplaySkuAvailabilities[0].Sku.Properties.Packages.Count > 0)
             * {
             *  Debug.WriteLine(displayCatalogModel.Product.DisplaySkuAvailabilities[0].Sku.Properties.Packages.Count);
             *  try
             *  {
             *      foreach (var Package in displayCatalogModel.Product.DisplaySkuAvailabilities[0].Sku.Properties.Packages[0].PackageDownloadUris)
             *      {
             *          packages.AppendLine($"Xbox Live Package: {Package.Uri}");
             *      }
             *  }
             *  catch { }
             * }
             */
            /*
             *
             */
            packages.AppendLine($"(2/3)");
            await message.Channel.SendMessageAsync(packages.ToString());

            foreach (PackageInstance package in packageInstances)
            {
                try
                {
                    await message.Channel.SendMessageAsync($"{package.PackageMoniker} : {package.PackageType} : {package.PackageUri}");
                }
                catch { }
            }

            await message.Channel.SendMessageAsync("(3/3)");
        }