Exemplo n.º 1
0
        /// <summary>Loads a collection of entity objects into the collection.Not supported by the WCF Data Services 5.0 client for Silverlight.</summary>
        /// <param name="items">Collection of entity objects to be added to the <see cref="T:Microsoft.OData.Client.DataServiceCollection`1" />.</param>
        /// <remarks>
        /// When tracking is enabled, the behavior of Load would be to attach all those entities that are not already tracked by the context
        /// associated with the collection. The operation will go deep into the input entities so that all related
        /// entities are attached to the context if not already present. All entities in <paramref name="items"/>
        /// will be tracked after Load is done.
        /// Load method checks for duplication. The collection will ignore any duplicated items been loaded.
        /// For large amount of items, consider DataServiceContext.LoadProperty instead.
        /// </remarks>
        public void Load(IEnumerable <T> items)
        {
            DataServiceCollection <T> .ValidateIteratorParameter(items);

            if (this.trackingOnLoad)
            {
                // This throws if no context can be obtained, no need to check here
                DataServiceContext context = DataServiceCollection <T> .GetContextFromItems(items);

                this.trackingOnLoad = false;

                this.StartTracking(context, items, this.entitySetName, this.entityChangedCallback, this.collectionChangedCallback);
            }
            else
            {
                this.StartLoading();
                try
                {
                    this.InternalLoadCollection(items);
                }
                finally
                {
                    this.FinishLoading();
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>Verifies the absence of observer for an DataServiceCollection</summary>
        /// <typeparam name="T">Type of DataServiceCollection</typeparam>
        /// <param name="oec">Non-typed collection object</param>
        /// <param name="sourceProperty">Collection property of the source object which is being assigned to</param>
        /// <param name="sourceType">Type of the source object</param>
        internal static void VerifyObserverNotPresent <T>(object oec, string sourceProperty, Type sourceType)
#endif
        {
#if DEBUG
            Debug.Assert(BindingEntityInfo.IsDataServiceCollection(oec.GetType(), model), "Must be an DataServiceCollection.");
#endif
            DataServiceCollection <T> typedCollection = oec as DataServiceCollection <T>;

            if (typedCollection.Observer != null)
            {
                throw new InvalidOperationException(Strings.DataBinding_CollectionPropertySetterValueHasObserver(sourceProperty, sourceType));
            }
        }
Exemplo n.º 3
0
        /// <summary>Initializes a new instance of the <see cref="T:Microsoft.OData.Client.DataServiceCollection`1" /> class based on query execution, with the supplied change method delegates, and that uses the supplied <see cref="T:Microsoft.OData.Client.DataServiceContext" />.</summary>
        /// <param name="context">The <see cref="T:Microsoft.OData.Client.DataServiceContext" /> used to track items in the collection.</param>
        /// <param name="items">A <see cref="T:Microsoft.OData.Client.DataServiceQuery`1" /> or LINQ query that returns an <see cref="T:System.Collections.Generic.IEnumerable`1" /> collection of objects that are used to initialize the collection.</param>
        /// <param name="trackingMode">A <see cref="T:Microsoft.OData.Client.TrackingMode" /> value that indicated whether or not changes made to items in the collection are automatically tracked.</param>
        /// <param name="entitySetName">The entity set of the objects in the collection.</param>
        /// <param name="entityChangedCallback">A delegate that encapsulates a method that is called when an entity changes.</param>
        /// <param name="collectionChangedCallback">A delegate that encapsulates a method that is called when the collection of entities changes.</param>
        public DataServiceCollection(
            DataServiceContext context,
            IEnumerable <T> items,
            TrackingMode trackingMode,
            string entitySetName,
            Func <EntityChangedParams, bool> entityChangedCallback,
            Func <EntityCollectionChangedParams, bool> collectionChangedCallback)
        {
            if (trackingMode == TrackingMode.AutoChangeTracking)
            {
                if (context == null)
                {
                    if (items == null)
                    {
                        // Enable tracking on first Load/LoadAsync call, when we can obtain a context
                        this.trackingOnLoad = true;

                        // Save off these for when we enable tracking later
                        this.entitySetName             = entitySetName;
                        this.entityChangedCallback     = entityChangedCallback;
                        this.collectionChangedCallback = collectionChangedCallback;
                    }
                    else
                    {
                        // This throws if no context can be obtained, no need to check here
                        context = DataServiceCollection <T> .GetContextFromItems(items);
                    }
                }

                if (!this.trackingOnLoad)
                {
                    if (items != null)
                    {
                        DataServiceCollection <T> .ValidateIteratorParameter(items);
                    }

                    this.StartTracking(context, items, entitySetName, entityChangedCallback, collectionChangedCallback);
                }
            }
            else if (items != null)
            {
                this.Load(items);
            }
        }