public List <Project> GetProjIDs()
        {
            InfBaseModel infBaseModel = new InfBaseModel(uri);

            infBaseModel.SendingRequest2 += OnSendingRequest2;
            QueryOperationResponse <Project> qOR = (infBaseModel.Projects.Select(p => new Project()
            {
                Id = p.Id
            })
                                                    as DataServiceQuery <Project>)
                                                   .Execute() as QueryOperationResponse <Project>;
            DataServiceQueryContinuation <Project> token = null;
            List <Project> projects = new List <Project>();

            do
            {
                if (token != null)
                {
                    qOR = infBaseModel.Execute(token);
                }

                projects.AddRange(qOR);
            }while ((token = qOR.GetContinuation()) != null);

            return(projects);
        }
Beispiel #2
0
        private async static Task <IList> ExecuteQueryAsync <T>(IQueryable query, Expression expression, IReadOnlyList <LambdaExpression> navigationPropertyAccessors)
        {
            var items    = new List <T>();
            var newQuery = (DataServiceQuery <T>)query.Provider.CreateQuery <T>(expression);

            DataServiceQueryContinuation <T> continuation = null;

            for (var response = (QueryOperationResponse <T>) await newQuery.ExecuteAsync(); response != null;
                 continuation = response.GetContinuation(), response = continuation == null ? null : (QueryOperationResponse <T>) await newQuery.Context.ExecuteAsync(continuation))
            {
                foreach (T item in response)
                {
                    foreach (LambdaExpression navigationPropertyAccessor in navigationPropertyAccessors)
                    {
                        var propertyExpression = (MemberExpression)navigationPropertyAccessor.Body;
                        if (((PropertyInfo)propertyExpression.Member).GetValue(item) is IEnumerable property)
                        {
                            DataServiceQueryContinuation itemsContinuation = response.GetContinuation(property);
                            while (itemsContinuation != null)
                            {
                                QueryOperationResponse itemsResponse = await newQuery.Context.LoadPropertyAsync(item, propertyExpression.Member.Name, itemsContinuation);

                                itemsContinuation = itemsResponse.GetContinuation();
                            }
                        }
                    }
                    items.Add(item);
                }
            }

            return(items);
        }
Beispiel #3
0
 public PagedCollection(DataServiceContextWrapper context,
                        QueryOperationResponse <TConcrete> qor)
 {
     _context      = context;
     _currentPage  = (IReadOnlyList <TElement>)qor.ToList();
     _continuation = qor.GetContinuation();
 }
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Microsoft.Dynamics.Commerce.RetailProxy.PagedResult`1"/> class.
 /// </summary>
 /// <param name="response">The response returned by OData operations.</param>
 /// <remarks>Use for short, non-paged results only.</remarks>
 public PagedResult(QueryOperationResponse <T> response)
 {
     if (response != null)
     {
         this.Results     = new ObservableCollection <T>(response);
         this.HasNextPage = response.GetContinuation() != null;
     }
 }
Beispiel #5
0
        public IEnumerable <Incident> SearchIncidents(string topOption, string skipOption, string filterQueryOption)
        {
            string incidentsRouteUri = this.config.IcmClientConfig.OdataServiceBaseUri + "/incidents?$inlinecount=allpages";

            if (string.IsNullOrWhiteSpace(topOption) == false)
            {
                incidentsRouteUri += "&$top=" + topOption;
            }

            if (string.IsNullOrWhiteSpace(skipOption) == false)
            {
                incidentsRouteUri += "&$skip=" + skipOption;
            }

            filterQueryOption = string.Format("CreateDate gt datetime'{0}'", DateTime.UtcNow.AddDays(-30).ToString("yyyy-MM-ddTHH:mm:ss"));

            if (string.IsNullOrWhiteSpace(filterQueryOption) == false)
            {
                incidentsRouteUri += "&$filter=" + filterQueryOption;
            }

            QueryOperationResponse <Incident> response = null;

            try
            {
                Logger.InfoFormat("Executing request: '{0}'...", incidentsRouteUri);
                Uri request = new Uri(incidentsRouteUri);
                response = (QueryOperationResponse <Incident>)odataClient.Execute <Incident>(request);
            }
            catch (Exception ex)
            {
                Logger.ErrorFormat("Failed to execute request: {0}", ex.InnerException);
            }

            while (response != null)
            {
                foreach (Incident incident in response)
                {
                    yield return(incident);
                }

                var continuation = response.GetContinuation();
                if (continuation == null)
                {
                    yield break;
                }

                Logger.InfoFormat("Continue to next page of request...");
                response = odataClient.Execute(continuation);
            }

            Logger.InfoFormat("Completed executing request.");
        }
Beispiel #6
0
        public void PagingQueryTest()
        {
            this.RunOnAtomAndJsonFormats(
                this.CreateContext,
                (contextWrapper) =>
            {
                contextWrapper.Configurations.ResponsePipeline
                .OnFeedStarted(PipelineEventsTestsHelper.ModifyFeedId_ReadingFeed)
                .OnFeedEnded(PipelineEventsTestsHelper.ModifyNextlink_ReadingFeed);

                QueryOperationResponse <Customer> entryResultsLinq = contextWrapper.CreateQuery <Customer>("Customer").Execute() as QueryOperationResponse <Customer>;
                entryResultsLinq.ToArray();
                Assert.AreEqual("http://modifyfeedidmodifynextlink/", entryResultsLinq.GetContinuation().NextLinkUri.AbsoluteUri, "Unexpected next link");
            });
        }
        /// <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>();
            CatalogServiceReadOnlyDbContext      context            = new CatalogServiceReadOnlyDbContext(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);
        }
Beispiel #8
0
        /// <summary>
        /// Populate this collection with another collection of items
        /// </summary>
        /// <param name="items">The items to populate this collection with</param>
        private void InternalLoadCollection(IEnumerable <T> items)
        {
            Debug.Assert(items != null, "items != null");
#if !PORTABLELIB
            // For SDP, we must execute the Query implicitly
            DataServiceQuery <T> query = items as DataServiceQuery <T>;
            if (query != null)
            {
                items = query.Execute() as QueryOperationResponse <T>;
            }
#else
            Debug.Assert(!(items is DataServiceQuery), "SL Client using DSQ as items...should have been caught by ValidateIteratorParameter.");
#endif

            foreach (T item in items)
            {
                // if this is too slow, consider hashing the set
                // or just use LoadProperties
                if (!this.Contains(item))
                {
                    this.Add(item);
                }
            }

            QueryOperationResponse <T> response = items as QueryOperationResponse <T>;
            if (response != null)
            {
                // this should never be throwing (since we've enumerated already)!
                // Note: Inner collection's nextPartLinkUri is set by the materializer
                this.continuation = response.GetContinuation();
            }
            else
            {
                this.continuation = null;
            }
        }
        public void LoadPropertyRemoveElementUnChangedSource()
        {
            MergeOption original = this.context.MergeOption;

            try
            {
                foreach (MergeOption mo in new[] { MergeOption.OverwriteChanges, MergeOption.PreserveChanges })
                {
                    foreach (bool usePaging in new[] { false, true })
                    {
                        using (CustomDataContext.CreateChangeScope())
                            using (OpenWebDataServiceHelper.PageSizeCustomizer.Restore())
                            {
                                OpenWebDataServiceHelper.PageSizeCustomizer.Value = (config, type) => { config.SetEntitySetPageSize("Orders", usePaging ? 1 : 5); };
                                Customer c = new Customer()
                                {
                                    ID = 0
                                };
                                Customer c2 = new Customer()
                                {
                                    ID = 2
                                };
                                Order o = new Order()
                                {
                                    ID = 102
                                };

                                this.context.MergeOption = mo;

                                this.context.AttachTo("Customers", c);
                                this.context.AttachTo("Customers", c2);
                                this.context.AttachTo("Orders", o);

                                this.context.AddLink(c, "Orders", o);
                                this.context.SetLink(o, "Customer", c);
                                this.context.SaveChanges();

                                if (usePaging)
                                {
                                    DataServiceQueryContinuation continuation = null;
                                    do
                                    {
                                        QueryOperationResponse response = this.context.LoadProperty(c, "Orders", continuation);
                                        continuation = response.GetContinuation();
                                    }while (continuation != null);
                                }
                                else
                                {
                                    this.context.LoadProperty(c, "Orders");
                                }

                                this.context.LoadProperty(o, "Customer");

                                if (c.Orders != null)
                                {
                                    Assert.IsTrue(c.Orders.Contains(o));
                                }
                                if (o.Customer != null)
                                {
                                    Assert.IsTrue(o.Customer.ID == c.ID);
                                }

                                // Remove the link
                                this.context.DeleteLink(c, "Orders", o);
                                this.context.SetLink(o, "Customer", c2);

                                this.context.SaveChanges();

                                if (usePaging)
                                {
                                    DataServiceQueryContinuation continuation = null;
                                    do
                                    {
                                        QueryOperationResponse response = this.context.LoadProperty(c, "Orders", continuation);
                                        continuation = response.GetContinuation();
                                    }while (continuation != null);
                                }
                                else
                                {
                                    this.context.LoadProperty(c, "Orders");
                                }

                                this.context.LoadProperty(o, "Customer");

                                if (c.Orders != null)
                                {
                                    Assert.IsFalse(c.Orders.Contains(o));
                                }
                                if (o.Customer != null)
                                {
                                    Assert.IsFalse(o.Customer.ID == c.ID);
                                }
                            }

                        this.ClearContext();
                    }
                }
            }
            finally
            {
                this.context.MergeOption = original;
            }
        }