private void InternalLoadCollection(IEnumerable <T> items) { DataServiceQuery <T> query = items as DataServiceQuery <T>; if (query != null) { items = query.Execute() as QueryOperationResponse <T>; } foreach (T local in items) { if (!base.Contains(local)) { base.Add(local); } } QueryOperationResponse <T> response = items as QueryOperationResponse <T>; if (response != null) { this.continuation = response.GetContinuation(); } else { this.continuation = null; } }
internal virtual DataServiceQueryContinuation GetContinuation(IEnumerable key) { Debug.Assert(this.materializer != null, "Materializer is null!"); DataServiceQueryContinuation result; if (key == null) { if ((this.expectingSingleValue && !this.moved) || (!this.expectingSingleValue && !this.materializer.IsEndOfStream)) { throw new InvalidOperationException(Strings.MaterializeFromAtom_TopLevelLinkNotAvailable); } if (this.expectingSingleValue || this.materializer.CurrentFeed == null) { result = null; } else { result = DataServiceQueryContinuation.Create( this.materializer.CurrentFeed.NextLink, this.materializer.MaterializeEntryPlan); } } else { if (!this.materializer.NextLinkTable.TryGetValue(key, out result)) { throw new ArgumentException(Strings.MaterializeFromAtom_CollectionKeyNotPresentInLinkTable); } } return(result); }
private void InternalLoadCollection(IEnumerable <T> items) { Debug.Assert(items != null, "items != null"); #if !ASTORIA_LIGHT 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.Contains(item)) { this.Add(item); } } QueryOperationResponse <T> response = items as QueryOperationResponse <T>; if (response != null) { this.continuation = response.GetContinuation(); } else { this.continuation = null; } }
internal static void SetNextLinkForCollection(object collection, DataServiceQueryContinuation continuation) { foreach (PropertyInfo info in collection.GetType().GetPublicProperties(true)) { if ((!(info.Name != "Continuation") && info.CanWrite) && typeof(DataServiceQueryContinuation).IsAssignableFrom(info.PropertyType)) { info.SetValue(collection, continuation, null); } } }
internal static void SetNextLinkForCollection(object collection, DataServiceQueryContinuation continuation) { Debug.Assert(collection != null, "collection != null"); foreach (var property in collection.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public)) { if (property.Name != "Continuation" || !property.CanWrite) { continue; } if (typeof(DataServiceQueryContinuation).IsAssignableFrom(property.PropertyType)) { property.SetValue(collection, continuation, null); } } }
public async Task<IEnumerable<ChocolateyPackage>> LoadFirstPage() { var query = this._feedClient.Packages.Where(p => p.IsLatestVersion) as DataServiceQuery<FeedPackage>; var retrievePackagesTask = this.ExecuteQuery(query); var installedPackages = await this._installedPackages.RetrieveInstalledPackages(); var queryResult = await retrievePackagesTask as QueryOperationResponse<FeedPackage>; var convertedPackages = queryResult.Select(package => this.ConvertToPackage(package, installedPackages)).ToList(); this.MergePackagesIntoCache(convertedPackages); this._nextPage = queryResult.GetContinuation(); return convertedPackages; }
/// <summary>Set the continuation for the following results for a collection.</summary> /// <param name="collection">The collection to set the links to</param> /// <param name="continuation">The continuation for the collection.</param> internal static void SetNextLinkForCollection(object collection, DataServiceQueryContinuation continuation) { Debug.Assert(collection != null, "collection != null"); // We do a convention call for setting Continuation. We'll invoke this // for all properties named 'Continuation' that is a DataServiceQueryContinuation // (assigning to a single one would make it inconsistent if reflection // order is changed). foreach (var property in collection.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public)) { if (property.Name != "Continuation" || !property.CanWrite) { continue; } if (typeof(DataServiceQueryContinuation).IsAssignableFrom(property.PropertyType)) { property.SetValue(collection, continuation, null); } } }
/// <summary> /// Returns the next link URI for the collection key /// </summary> /// <param name="key">The collection for which the Uri is returned, or null, if the top level link is to be returned</param> /// <returns>An Uri pointing to the next page for the collection</returns> internal virtual DataServiceQueryContinuation GetContinuation(IEnumerable key) { Debug.Assert(this.materializer != null, "Materializer is null!"); DataServiceQueryContinuation result; if (key == null) { if ((this.expectingPrimitiveValue && !this.moved) || (!this.expectingPrimitiveValue && !this.materializer.IsEndOfStream)) { // expectingSingleValue && !moved : haven't started parsing single value (single value should not have next link anyway) // !expectingSingleValue && !IsEndOfStream : collection type feed did not finish parsing yet throw new InvalidOperationException(Strings.MaterializeFromAtom_TopLevelLinkNotAvailable); } // we have already moved to the end of stream // are we singleton or just an entry? if (this.expectingPrimitiveValue || this.materializer.CurrentFeed == null) { result = null; } else { // DEVNOTE(pqian): The next link uri should never be edited by the client, and therefore it must be absolute result = DataServiceQueryContinuation.Create( this.materializer.CurrentFeed.NextPageLink, this.materializer.MaterializeEntryPlan); } } else { if (!this.materializer.NextLinkTable.TryGetValue(key, out result)) { // someone has asked for a collection that's "out of scope" or doesn't exist throw new ArgumentException(Strings.MaterializeFromAtom_CollectionKeyNotPresentInLinkTable); } } return(result); }
internal virtual DataServiceQueryContinuation GetContinuation(IEnumerable key) { DataServiceQueryContinuation continuation; if (key == null) { if ((this.expectingPrimitiveValue && !this.moved) || (!this.expectingPrimitiveValue && !this.materializer.IsEndOfStream)) { throw new InvalidOperationException(System.Data.Services.Client.Strings.MaterializeFromAtom_TopLevelLinkNotAvailable); } if (this.expectingPrimitiveValue || (this.materializer.CurrentFeed == null)) { return(null); } return(DataServiceQueryContinuation.Create(this.materializer.CurrentFeed.NextPageLink, this.materializer.MaterializeEntryPlan)); } if (!this.materializer.NextLinkTable.TryGetValue(key, out continuation)) { throw new ArgumentException(System.Data.Services.Client.Strings.MaterializeFromAtom_CollectionKeyNotPresentInLinkTable); } return(continuation); }
public async Task<IEnumerable<ChocolateyPackage>> GetNextPage() { if (this._nextPage == null) { throw new InvalidOperationException("No page to retireve packages from."); } var retrievePackagesTask = Task.Factory.FromAsync<IEnumerable<FeedPackage>>( this._feedClient.BeginExecute<FeedPackage>(this._nextPage, null, null), queryAsyncResult => this._feedClient.EndExecute<FeedPackage>(queryAsyncResult)); var installedPackages = await this._installedPackages.RetrieveInstalledPackages(); var queryOperation = await retrievePackagesTask as QueryOperationResponse<FeedPackage>; var convertedPackages = queryOperation.Select(package => this.ConvertToPackage(package, installedPackages)).ToList(); this.MergePackagesIntoCache(convertedPackages); this._nextPage = queryOperation.GetContinuation(); return this._packageCache; }
/// <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 !ASTORIA_LIGHT // 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; } }
/// <summary> /// Creates a wrapper for raw results /// </summary> /// <param name="context">Context of expression to analyze.</param> /// <param name="results">the results to wrap</param> /// <param name="continuation">The continuation for this query.</param> internal ResultsWrapper(DataServiceContext context, IEnumerable results, DataServiceQueryContinuation continuation) { this.context = context; this.results = results ?? new object[0]; this.continuation = continuation; }
private MaterializeAtom ReadPropertyFromAtom(EntityDescriptor box, ClientPropertyAnnotation property) { MaterializeAtom atom2; DataServiceContext source = (DataServiceContext)base.Source; bool applyingChanges = source.ApplyingChanges; try { source.ApplyingChanges = true; bool flag2 = EntityStates.Deleted == box.State; bool instanceCreated = false; object instance = null; if (property.IsEntityCollection) { instance = this.GetCollectionInstance(property, out instanceCreated); } Type type = property.IsEntityCollection ? property.EntityCollectionItemType : property.NullablePropertyType; IList results = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(new Type[] { type })); DataServiceQueryContinuation continuation = null; using (MaterializeAtom atom = base.GetMaterializer(this.plan)) { bool flag4 = property.EdmProperty.PropertyKind == EdmPropertyKind.Navigation; int num = 0; foreach (object obj3 in atom) { if (property.IsEntityCollection) { property.SetValue(instance, obj3, this.propertyName, true); results.Add(obj3); } else if (property.IsPrimitiveOrComplexCollection) { object obj4 = property.GetValue(this.entity); if (obj4 == null) { obj4 = Activator.CreateInstance(obj3.GetType()); property.SetValue(this.entity, obj4, this.propertyName, false); } else { property.ClearBackingICollectionInstance(obj4); } foreach (object obj5 in (IEnumerable)obj3) { property.AddValueToBackingICollectionInstance(obj4, obj5); } results.Add(obj4); } else { property.SetValue(this.entity, obj3, this.propertyName, false); results.Add(obj3); } num++; if (((obj3 != null) && (MergeOption.NoTracking != atom.MergeOptionValue)) && flag4) { if (flag2) { source.DeleteLink(this.entity, this.propertyName, obj3); } else { source.AttachLink(this.entity, this.propertyName, obj3, atom.MergeOptionValue); } } } continuation = atom.GetContinuation(null); Util.SetNextLinkForCollection(property.IsEntityCollection ? instance : this.entity, continuation); } if (instanceCreated) { property.SetValue(this.entity, instance, this.propertyName, false); } atom2 = MaterializeAtom.CreateWrapper(source, results, continuation); } finally { source.ApplyingChanges = applyingChanges; } return(atom2); }
/// <summary>Creates a materializer for partial result sets.</summary> /// <param name="context">Context of expression to analyze.</param> /// <param name="results">The current page of results</param> /// <param name="continuation">The continuation for the results.</param> /// <returns>A new materializer.</returns> internal static MaterializeAtom CreateWrapper(DataServiceContext context, IEnumerable results, DataServiceQueryContinuation continuation) { return(new ResultsWrapper(context, results, continuation)); }
private async Task<IEnumerable<ChocolateyPackage>> RetrievePackagesInternal( DataServiceQueryContinuation<FeedPackage> query, IList<ChocolateyPackage> currentPackages, CancellationToken cancellationToken) { if (query == null || cancellationToken.IsCancellationRequested) { return currentPackages; } var retrievePackagesTask = new TaskFactory(cancellationToken).FromAsync<IEnumerable<FeedPackage>>( this._feedClient.BeginExecute<FeedPackage>(query, null, null), queryAsyncResult => this._feedClient.EndExecute<FeedPackage>(queryAsyncResult)); if (cancellationToken.IsCancellationRequested) { return currentPackages; } var installedPackages = await this._installedPackages.RetrieveInstalledPackages(); var queryOperation = await retrievePackagesTask as QueryOperationResponse<FeedPackage>; foreach (var feedPackage in queryOperation) { currentPackages.Add(ConvertToPackage(feedPackage, installedPackages)); } this.RaisePageOfPackagesLoaded(currentPackages); var nextQuery = queryOperation.GetContinuation(); return await this.RetrievePackagesInternal(nextQuery, currentPackages, cancellationToken); }
private async Task<IEnumerable<ChocolateyPackageVersion>> RetrievePackagesInternal( DataServiceQueryContinuation<FeedPackage> query, IList<ChocolateyPackageVersion> currentPackages) { if (query == null) { return currentPackages; } var retrievePackagesTask = Task.Factory.FromAsync<IEnumerable<FeedPackage>>( this._feedClient.BeginExecute<FeedPackage>(query, null, null), queryAsyncResult => this._feedClient.EndExecute<FeedPackage>(queryAsyncResult)); var queryOperation = await retrievePackagesTask as QueryOperationResponse<FeedPackage>; foreach (var feedPackage in queryOperation) { currentPackages.Add(ConvertToPackageVersion(feedPackage)); } var nextQuery = queryOperation.GetContinuation(); return await this.RetrievePackagesInternal(nextQuery, currentPackages); }
internal static MaterializeAtom CreateWrapper(DataServiceContext context, IEnumerable results, DataServiceQueryContinuation continuation) { return new ResultsWrapper(context, results, continuation); }
private MaterializeAtom ReadPropertyFromAtom(ClientPropertyAnnotation property) { DataServiceContext context = (DataServiceContext)this.Source; bool merging = context.ApplyingChanges; try { context.ApplyingChanges = true; // store the results so that they can be there in the response body. Type elementType = property.IsEntityCollection ? property.EntityCollectionItemType : property.NullablePropertyType; IList results = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(elementType)); DataServiceQueryContinuation continuation = null; // elementType.ElementType has Nullable stripped away, use nestedType for materializer using (MaterializeAtom materializer = this.GetMaterializer(this.plan)) { Debug.Assert(materializer != null, "materializer != null -- otherwise GetMaterializer() returned null rather than empty"); #if ASTORIA_OPEN_OBJECT object openProperties = null; #endif foreach (object child in materializer) { if (property.IsEntityCollection) { results.Add(child); } else if (property.IsPrimitiveOrComplexCollection) { Debug.Assert(property.PropertyType.IsAssignableFrom(child.GetType()), "Created instance for storing collection items has to be compatible with the actual one."); // Collection materialization rules requires to clear the collection if not null or set the property first and then add the collection items object collectionInstance = property.GetValue(this.entity); if (collectionInstance == null) { // type of child has been resolved as per rules for collections so it is the correct type to instantiate collectionInstance = Activator.CreateInstance(child.GetType()); // allowAdd is false - we need to assign instance as the new property value property.SetValue(this.entity, collectionInstance, this.propertyName, false /* allowAdd? */); } else { // Clear existing collection property.ClearBackingICollectionInstance(collectionInstance); } foreach (var collectionItem in (IEnumerable)child) { Debug.Assert(property.PrimitiveOrComplexCollectionItemType.IsAssignableFrom(collectionItem.GetType()), "Type of materialized collection items have to be compatible with the type of collection items in the actual collection property."); property.AddValueToBackingICollectionInstance(collectionInstance, collectionItem); } results.Add(collectionInstance); } else { #if ASTORIA_OPEN_OBJECT property.SetValue(this.entity, child, this.propertyName, ref openProperties, false); #else // it is either primitive type, complex type or 1..1 navigation property so we just allow setting the value but not adding. property.SetValue(this.entity, child, this.propertyName, false); results.Add(child); #endif } } continuation = materializer.GetContinuation(null); } return(MaterializeAtom.CreateWrapper(context, results, continuation)); } finally { context.ApplyingChanges = merging; } }
internal ResultsWrapper(DataServiceContext context, IEnumerable results, DataServiceQueryContinuation continuation) { this.context = context; this.results = results ?? new object[0]; this.continuation = continuation; }