Example #1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="parentEntity">The <see cref="IDynamicEntity"/> that owns this list.</param>
        /// <param name="context">The <see cref="IDynamicEntityContext"/> or <c>null</c>.</param>
        /// <param name="jArray">The underlying <see cref="jArray"/>.</param>
        /// <param name="items">The initial items or <c>null</c> to initialize from <paramref name="jArray"/>.</param>
        public EntityListWrapper(IDynamicEntity parentEntity, IDynamicEntityContext context, JArray jArray, IEnumerable <TEntity> items)
        {
            Covenant.Requires <ArgumentNullException>(parentEntity != null);
            Covenant.Requires <ArgumentNullException>(jArray != null);

            this.parentEntity       = parentEntity;
            this.context            = context;
            this.jArray             = jArray;
            this.itemChangedHandler = new EventHandler <EventArgs>(OnItemChanged);
            this.list = new ObservableCollection <TEntity>();

            if (items != null)
            {
                Covenant.Assert(jArray.Count == 0);

                foreach (var item in items)
                {
                    Add(item);
                }
            }
            else
            {
                foreach (var jToken in jArray)
                {
                    if (jToken.Type == JTokenType.Object)
                    {
                        var item = DynamicEntity.Create <TEntity>((JObject)jToken, context);

                        item.Changed += itemChangedHandler;   // We need to bubble up nested change events
                        list.Add(item);
                    }
                    else
                    {
                        list.Add(null); // Ignore anything that's not an object.
                    }
                }
            }

            // We're going to listen to our own collection changed event to
            // bubble them up.

            list.CollectionChanged +=
                (s, a) =>
            {
                CollectionChanged?.Invoke(this, a);
                parentEntity._OnChanged();
            };
        }
Example #2
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="parentEntity">The <see cref="IDynamicEntity"/> that owns this list.</param>
        /// <param name="context">The <see cref="IDynamicEntityContext"/> or <c>null</c>.</param>
        /// <param name="jArray">The underlying <see cref="jArray"/>.</param>
        /// <param name="items">The initial items or <c>null</c> to initialize from <paramref name="jArray"/>.</param>
        public LinkListWrapper(IDynamicEntity parentEntity, IDynamicEntityContext context, JArray jArray, IEnumerable <TEntity> items)
        {
            Covenant.Requires <ArgumentNullException>(parentEntity != null);
            Covenant.Requires <ArgumentNullException>(jArray != null);

            this.parentEntity = parentEntity;
            this.context      = context;
            this.jArray       = jArray;
            this.list         = new ObservableCollection <LinkState>();

            if (items != null)
            {
                Covenant.Assert(jArray.Count == 0);

                foreach (var item in items)
                {
                    Add(item);
                }
            }
            else
            {
                foreach (var token in jArray)
                {
                    list.Add(new LinkState()
                    {
                        Link = GetLink(token)
                    });
                }
            }

            // We're going to listen to our own collection changed event to
            // bubble them up.

            list.CollectionChanged +=
                (s, a) =>
            {
                if (!notifyDisabled)
                {
                    CollectionChanged?.Invoke(this, a);
                    parentEntity._OnChanged();
                }
            };
        }
Example #3
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="parentEntity">The <see cref="IDynamicEntity"/> that owns this list.</param>
        /// <param name="jArray">The underlying <see cref="jArray"/>.</param>
        /// <param name="items">The initial items or <c>null</c> to initialize from <paramref name="jArray"/>.</param>
        public ListWrapper(IDynamicEntity parentEntity, JArray jArray, IEnumerable <TEntity> items)
        {
            Covenant.Requires <ArgumentNullException>(parentEntity != null);
            Covenant.Requires <ArgumentNullException>(jArray != null);

            this.parentEntity = parentEntity;
            this.jArray       = jArray;
            this.list         = new ObservableCollection <TEntity>();

            // Load the items.

            if (items != null)
            {
                Covenant.Assert(jArray.Count == 0);

                foreach (var item in items)
                {
                    Add(item);
                }
            }
            else
            {
                foreach (var jToken in jArray)
                {
                    list.Add(jToken.ToObject <TEntity>());
                }
            }

            // We're going to listen to our own collection changed event to
            // bubble them up.

            list.CollectionChanged +=
                (s, a) =>
            {
                CollectionChanged?.Invoke(this, a);
                parentEntity._OnChanged();
            };
        }
Example #4
0
 /// <summary>
 /// Called when any of the list item's <see cref="IDynamicEntity.Changed"/> event is
 /// raised.  This method will bubble the notifications to the parent entity.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="args">The event arguments.</param>
 private void OnItemChanged(object sender, EventArgs args)
 {
     parentEntity._OnChanged();
 }