Exemplo n.º 1
0
        /// <summary>
        /// Gets available Windows Azure offers from the Marketplace.
        /// </summary>
        /// <param name="countryCode">The country two character code. Uses 'US' by default </param>
        /// <returns>The list of offers</returns>
        public virtual List<WindowsAzureOffer> GetAvailableWindowsAzureOffers(string countryCode)
        {
            countryCode = string.IsNullOrEmpty(countryCode) ? "US" : countryCode;
            List<WindowsAzureOffer> result = new List<WindowsAzureOffer>();
            List<Offer> windowsAzureOffers = new List<Offer>();
            CatalogServiceContext context = new CatalogServiceContext(new Uri(Resources.MarketplaceEndpoint));
            DataServiceQueryContinuation<Offer> nextOfferLink = null;

            do
            {
                DataServiceQuery<Offer> query = context.Offers
                    .AddQueryOption("$filter", "IsAvailableInAzureStores")
                    .Expand("Plans, Categories");
                QueryOperationResponse<Offer> offerResponse = query.Execute() as QueryOperationResponse<Offer>;
                foreach (Offer offer in offerResponse)
                {
                    List<Plan> allPlans = new List<Plan>(offer.Plans);
                    DataServiceQueryContinuation<Plan> nextPlanLink = null;

                    do
                    {
                        QueryOperationResponse<Plan> planResponse = context.LoadProperty(
                            offer,
                            "Plans",
                            nextPlanLink) as QueryOperationResponse<Plan>;
                        nextPlanLink = planResponse.GetContinuation();
                        allPlans.AddRange(offer.Plans);
                    } while (nextPlanLink != null);

                    IEnumerable<Plan> validPlans = offer.Plans.Where<Plan>(p => p.CountryCode == countryCode);
                    IEnumerable<string> offerLocations = offer.Categories.Select<Category, string>(c => c.Name)
                        .Intersect<string>(SubscriptionLocations);
                    if (validPlans.Count() > 0)
                    {
                        result.Add(new WindowsAzureOffer(
                            offer,
                            validPlans,
                            offerLocations.Count() == 0 ? SubscriptionLocations : offerLocations));
                    }
                }

                nextOfferLink = offerResponse.GetContinuation();
            } while (nextOfferLink != null);

            return result;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets instance of an offer.
        /// </summary>
        /// <param name="offerId">The offer identifier</param>
        /// <returns>The offer instance</returns>
        public virtual Offer GetOffer(string offerId)
        {
            CatalogServiceContext context = new CatalogServiceContext(new Uri(Resources.MarketplaceEndpoint));
            var offers = from o in context.Offers where o.OfferIdentifier == offerId select o;

            return offers.FirstOrDefault<Offer>();
        }