internal void OnCollectionChanged(object collection, NotifyCollectionChangedEventArgs eventArgs)
        {
            Util.CheckArgumentNull(collection, "collection");
            Util.CheckArgumentNull(eventArgs, "eventArgs");

            Debug.Assert(BindingEntityInfo.IsDataServiceCollection(collection.GetType()), "We only register this event for DataServiceCollections.");
#if DEBUG
            Debug.Assert(this.bindingGraph.IsTracking(collection), "Collection must be part of the graph if it has the event notification registered.");
#endif
            object source;
            string sourceProperty;
            string sourceEntitySet;
            string targetEntitySet;

            this.bindingGraph.GetEntityCollectionInfo(
                collection,
                out source,
                out sourceProperty,
                out sourceEntitySet,
                out targetEntitySet);

            switch (eventArgs.Action)
            {
            case NotifyCollectionChangedAction.Add:
                this.OnAddToCollection(
                    eventArgs,
                    source,
                    sourceProperty,
                    targetEntitySet,
                    collection);
                break;

            case NotifyCollectionChangedAction.Remove:
                this.OnDeleteFromCollection(
                    eventArgs,
                    source,
                    sourceProperty,
                    collection);
                break;

            case NotifyCollectionChangedAction.Replace:
                this.OnDeleteFromCollection(
                    eventArgs,
                    source,
                    sourceProperty,
                    collection);

                this.OnAddToCollection(
                    eventArgs,
                    source,
                    sourceProperty,
                    targetEntitySet,
                    collection);
                break;

            case NotifyCollectionChangedAction.Reset:
                if (this.DetachBehavior)
                {
                    this.RemoveWithDetachCollection(collection);
                }
                else
                {
                    this.bindingGraph.RemoveCollection(collection);
                }

                break;

#if !ASTORIA_LIGHT
            case NotifyCollectionChangedAction.Move:
                break;
#endif

            default:
                throw new InvalidOperationException(Strings.DataBinding_CollectionChangedUnknownAction(eventArgs.Action));
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a new MediaEntryAttribute attribute and sets the name
 /// of the member that contains the actual data of the media entry
 /// (e.g. a byte[] containing a picture, a string containing HTML, etc.)
 /// </summary>
 /// <param name="mediaMemberName">Name of the member that contains the data for the media entry</param>
 public MediaEntryAttribute(string mediaMemberName)
 {
     Util.CheckArgumentNull(mediaMemberName, "mediaMemberName");
     this.mediaMemberName = mediaMemberName;
 }
        internal void OnPropertyChanged(object source, PropertyChangedEventArgs eventArgs)
        {
            Util.CheckArgumentNull(source, "source");
            Util.CheckArgumentNull(eventArgs, "eventArgs");

#if DEBUG
            Debug.Assert(this.bindingGraph.IsTracking(source), "Entity must be part of the graph if it has the event notification registered.");
#endif
            string sourceProperty = eventArgs.PropertyName;

            if (String.IsNullOrEmpty(sourceProperty))
            {
                this.HandleUpdateEntity(
                    source,
                    null,
                    null);
            }
            else
            {
                BindingEntityInfo.BindingPropertyInfo bpi;

                object sourcePropertyValue = BindingEntityInfo.GetPropertyValue(source, sourceProperty, out bpi);

                if (bpi != null)
                {
                    this.bindingGraph.RemoveRelation(source, sourceProperty);

                    switch (bpi.PropertyKind)
                    {
                    case BindingPropertyKind.BindingPropertyKindCollection:
                        if (sourcePropertyValue != null)
                        {
                            try
                            {
                                typeof(BindingUtils)
                                .GetMethod("VerifyObserverNotPresent", BindingFlags.NonPublic | BindingFlags.Static)
                                .MakeGenericMethod(bpi.PropertyInfo.CollectionType)
                                .Invoke(null, new object[] { sourcePropertyValue, sourceProperty, source.GetType() });
                            }
                            catch (TargetInvocationException tie)
                            {
                                throw tie.InnerException;
                            }

                            try
                            {
                                this.AttachBehavior = true;
                                this.bindingGraph.AddCollection(
                                    source,
                                    sourceProperty,
                                    sourcePropertyValue,
                                    null);
                            }
                            finally
                            {
                                this.AttachBehavior = false;
                            }
                        }

                        break;

                    case BindingPropertyKind.BindingPropertyKindEntity:
                        this.bindingGraph.AddEntity(
                            source,
                            sourceProperty,
                            sourcePropertyValue,
                            null,
                            source);
                        break;

                    default:
                        Debug.Assert(bpi.PropertyKind == BindingPropertyKind.BindingPropertyKindComplex, "Must be complex type if PropertyKind is not entity or collection.");

                        if (sourcePropertyValue != null)
                        {
                            this.bindingGraph.AddComplexProperty(
                                source,
                                sourceProperty,
                                sourcePropertyValue);
                        }

                        this.HandleUpdateEntity(
                            source,
                            sourceProperty,
                            sourcePropertyValue);
                        break;
                    }
                }
                else
                {
                    this.HandleUpdateEntity(
                        source,
                        sourceProperty,
                        sourcePropertyValue);
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>Initializes a new instance of the <see cref="T:System.Data.Services.Client.DataServiceRequest`1" /> class. </summary>
 /// <param name="requestUri">The URI object that contains the request string.</param>
 public DataServiceRequest(Uri requestUri)
 {
     Util.CheckArgumentNull(requestUri, "requestUri");
     this.requestUri = requestUri;
 }
Exemplo n.º 5
0
 /// <summary>Creates and executes a DataServiceQuery based on the passed in expression</summary>
 /// <typeparam name="TResult">generic type</typeparam>
 /// <param name="expression">The expression for the new query</param>
 /// <returns>the results</returns>
 public TResult Execute <TResult>(Expression expression)
 {
     Util.CheckArgumentNull(expression, "expression");
     return(ReturnSingleton <TResult>(expression));
 }
Exemplo n.º 6
0
 /// <summary>Factory method for creating DataServiceOrderedQuery based on expression </summary>
 /// <typeparam name="TElement">generic type</typeparam>
 /// <param name="expression">The expression for the new query</param>
 /// <returns>new DataServiceQuery</returns>
 public IQueryable <TElement> CreateQuery <TElement>(Expression expression)
 {
     Util.CheckArgumentNull(expression, "expression");
     return(new DataServiceQuery <TElement> .DataServiceOrderedQuery(expression, this));
 }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ReadingNavigationLinkArgs" /> class.
 /// </summary>
 /// <param name="link">The link.</param>
 public ReadingNavigationLinkArgs(ODataNavigationLink link)
 {
     Util.CheckArgumentNull(link, "link");
     this.Link = link;
 }