Ejemplo n.º 1
0
        /// <summary>
        /// Convert the provided DcatEndpoint enum to its matching Uri.
        /// </summary>
        /// <param name="EnumEndpoint"></param>
        /// <returns></returns>
        public static Uri EnumToUri(DCatEndpoint EnumEndpoint)
        {
            switch (EnumEndpoint)
            {
            case DCatEndpoint.Production:
                return(Endpoints.DCATProd);

            case DCatEndpoint.Dev:
                return(Endpoints.DCATDev);

            case DCatEndpoint.Int:
                return(Endpoints.DCATInt);

            case DCatEndpoint.Xbox:
                return(Endpoints.DCATXbox);

            case DCatEndpoint.XboxInt:
                return(Endpoints.DCATXboxInt);

            case DCatEndpoint.OneP:
                return(Endpoints.DCATOneP);

            case DCatEndpoint.OnePInt:
                return(Endpoints.DCATOnePInt);

            default:
                return(Endpoints.DCATProd);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create and format the DCat request uri based on the provided endpoint, id, id type and locale.
        /// </summary>
        /// <param name="endpoint"></param>
        /// <param name="ID"></param>
        /// <param name="IDType"></param>
        /// <param name="locale"></param>
        /// <returns></returns>
        public static Uri CreateAlternateDCatUri(DCatEndpoint endpoint, string ID, IdentiferType IDType, Services.Locale locale)
        {
            switch (IDType)
            {
            case IdentiferType.ContentID:
                return(new Uri($"{TypeHelpers.EnumToUri(endpoint)}lookup?alternateId=CONTENTID&Value={ID}&{locale.DCatTrail}&fieldsTemplate=Details"));

            case IdentiferType.LegacyWindowsPhoneProductID:
                return(new Uri($"{TypeHelpers.EnumToUri(endpoint)}lookup?alternateId=LegacyWindowsPhoneProductID&Value={ID}&{locale.DCatTrail}&fieldsTemplate=Details"));

            case IdentiferType.LegacyWindowsStoreProductID:
                return(new Uri($"{TypeHelpers.EnumToUri(endpoint)}lookup?alternateId=LegacyWindowsStoreProductID&Value={ID}&{locale.DCatTrail}&fieldsTemplate=Details"));

            case IdentiferType.LegacyXboxProductID:
                return(new Uri($"{TypeHelpers.EnumToUri(endpoint)}lookup?alternateId=LegacyXboxProductID&Value={ID}&{locale.DCatTrail}&fieldsTemplate=Details"));

            case IdentiferType.PackageFamilyName:
                return(new Uri($"{TypeHelpers.EnumToUri(endpoint)}lookup?alternateId=PackageFamilyName&Value={ID}&{locale.DCatTrail}&fieldsTemplate=Details"));

            case IdentiferType.XboxTitleID:
                return(new Uri($"{TypeHelpers.EnumToUri(endpoint)}lookup?alternateId=XboxTitleID&Value={ID}&{locale.DCatTrail}&fieldsTemplate=Details"));

            case IdentiferType.ProductID:
                return(new Uri($"{TypeHelpers.EnumToUri(endpoint)}{ID}?{locale.DCatTrail}"));

            default:
                throw new Exception("CreateAlternateDCatUri: Unknown IdentifierType was passed, an update is likely required, please report this issue.");
            }
        }
Ejemplo n.º 3
0
        public DisplayCatalogHandler(DCatEndpoint SelectedEndpoint, Locale Locale)
        {
            //Adds needed headers for MS related requests. See MS_httpClient.cs
            this._httpClient = new MSHttpClient();

            this.SelectedEndpoint = SelectedEndpoint;
            this.SelectedLocale   = Locale;
        }
Ejemplo n.º 4
0
        public static Uri EnumToSearchUri(DCatEndpoint Endpoint)
        {
            switch (Endpoint)
            {
            case DCatEndpoint.Production:
                return(Endpoints.DisplayCatalogSearch);

            case DCatEndpoint.Int:
                return(Endpoints.DisplayCatalogSearchInt);

            default:
                return(Endpoints.DisplayCatalogSearch);
            }
        }
Ejemplo n.º 5
0
        public async Task Query(string ProductID, DCatEndpoint endpoint)
        {
            string result = await StoreService.QueryProduct(ProductID, endpoint);

            if (String.IsNullOrEmpty(result))
            {
                await Context.Channel.SendMessageAsync("No listing found.");
            }
            string[] messages = result.Split('#', StringSplitOptions.RemoveEmptyEntries);
            foreach (string m in messages)
            {
                List <string> packagelist = new List <string>(Regex.Split(m.ToString(), @"(?<=\G.{1999})", RegexOptions.Singleline));
                foreach (string s in packagelist)
                {
                    await Context.Channel.SendMessageAsync(s);
                }
            }
        }
Ejemplo n.º 6
0
        public static async Task <string> QueryProduct(string ProductID, DCatEndpoint DCatEndpoint)
        {
            DisplayCatalogHandler dcat = new DisplayCatalogHandler(DCatEndpoint, new Locale(Market.US, Lang.en, true));
            await dcat.QueryDCATAsync(ProductID);

            if (!dcat.IsFound)
            {
                return("");
            }
            StringBuilder MoreDetailsHelper = new StringBuilder();

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

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

            StringBuilder packages = new StringBuilder();

            if (dcat.ProductListing.Product.DisplaySkuAvailabilities[0].Sku.Properties.Packages.Count > 0)
            {
                if (dcat.ProductListing.Product.DisplaySkuAvailabilities[0].Sku.Properties.Packages.Count != 0)
                {
                    //For some weird reason, some listings report having packages when really they don't have one hosted. This checks the child to see if the package is really null or not.
                    if (!object.ReferenceEquals(dcat.ProductListing.Product.DisplaySkuAvailabilities[0].Sku.Properties.Packages[0].PackageDownloadUris, null))
                    {
                        foreach (var Package in dcat.ProductListing.Product.DisplaySkuAvailabilities[0].Sku.Properties.Packages[0].PackageDownloadUris)
                        {
                            packages.AppendLine($"Xbox Live Package: {Package.Uri}");
                        }
                    }
                }
            }
            StringBuilder fe3packages = new StringBuilder();

            foreach (PackageInstance package in packageInstances)
            {
                try
                {
                    fe3packages.AppendLine($"{package.PackageMoniker} : {package.PackageType} : {package.PackageUri}");
                }
                catch { }
            }
            return(MoreDetailsHelper.ToString() + "#" + packages.ToString() + "#" + fe3packages.ToString());
        }