Beispiel #1
0
        //public static void Validate(Parent parent)
        //{
        //    // Simulate a validation pass that enumerates all children.
        //    foreach (Child child in parent.Children)
        //    {
        //        foreach (GrandChild grandChild in child.Children)
        //        {
        //            GreatGrandChild greatGrandChild = grandChild.Child;
        //        }
        //    }
        //}

        /// <summary>
        /// Create  compositional hierarchy that includes both
        /// collection and singleton compositions
        /// </summary>
        public static List <CI_Parent> CreateCompositionHierarchy()
        {
            int parentKey = 1;
            int childKey  = 1;

            // Create 3 Parents with children.
            List <CI_Parent> parents = new List <CI_Parent>();

            for (int i = 0; i < 3; i++)
            {
                // one of these is a derived parent type
                CI_Parent p = i == 1 ? new CI_SpecialParent() : new CI_Parent();

                p.ID = parentKey++;
                parents.Add(p);

                // Create 2 natural children and 2 adopted children
                // It is critical for these scenarios to have the potential
                // for both modified and unmodified derived composition children
                // in a changeset
                for (int j = 0; j < 2; j++)
                {
                    CI_Child c = new CI_Child
                    {
                        ID       = childKey++,
                        ParentID = p.ID,
                        Parent   = p
                    };
                    p.Children.Add(c);
                }
                for (int j = 0; j < 2; j++)
                {
                    CI_AdoptedChild c = new CI_AdoptedChild
                    {
                        ID       = childKey++,
                        ParentID = p.ID,
                        Parent   = p
                    };
                    p.Children.Add(c);
                }
            }

            return(parents);
        }
Beispiel #2
0
 public void CustomOp_Child(CI_Child child)
 {
     this.SetOperationInvoked(child, "CustomOp_Child");
     child.OperationResult += ",CustomOp_Child";
 }
Beispiel #3
0
        public void DeleteChild(CI_Child child)
        {
            SetOperationInvoked(child);

            child.OperationResult = "Delete";
        }
Beispiel #4
0
        public void UpdateChild(CI_Child child)
        {
            SetOperationInvoked(child);

            child.OperationResult = "Update";
        }
Beispiel #5
0
        public void InsertChild(CI_Child child)
        {
            SetOperationInvoked(child);

            child.OperationResult = "Insert";
        }
Beispiel #6
0
        /// <summary>
        /// Use the changeset composition APIs to navigate all child updates
        /// </summary>
        /// <param name="parent"></param>
        private void NavigateChildChanges(CI_Parent parent)
        {
            // if the parent has had property modifications, original will
            // be non-null
            if (this.ChangeSet.GetChangeOperation(parent) != ChangeOperation.Insert)
            {
                CI_Parent originalParent = this.ChangeSet.GetOriginal(parent);
            }

            // navigate all child changes w/o specifying operation type
            Dictionary <object, ChangeOperation> changeOperationMap = new Dictionary <object, ChangeOperation>();

            foreach (CI_Child child in this.ChangeSet.GetAssociatedChanges(parent, p => p.Children))
            {
                ChangeOperation op = this.ChangeSet.GetChangeOperation(child);
                changeOperationMap[child] = op;

                if (this.ChangeSet.GetChangeOperation(child) != ChangeOperation.Insert)
                {
                    CI_Child originalChild = this.ChangeSet.GetOriginal(child);
                }

                if (op == ChangeOperation.None)
                {
                }
                else if (op == ChangeOperation.Insert)
                {
                    CompositionInheritanceHelper.Assert(this.ChangeSet.ChangeSetEntries.SingleOrDefault(p => p.Entity == child && p.Operation == DomainOperation.Insert) != null,
                                                        "Expected corresponding insert operation not found.");
                }
                else if (op == ChangeOperation.Update)
                {
                    CompositionInheritanceHelper.Assert(this.ChangeSet.ChangeSetEntries.SingleOrDefault(p => p.Entity == child && p.Operation == DomainOperation.Update) != null,
                                                        "Expected corresponding update operation not found.");
                }
                else if (op == ChangeOperation.Delete)
                {
                    CompositionInheritanceHelper.Assert(this.ChangeSet.ChangeSetEntries.SingleOrDefault(p => p.Entity == child && p.Operation == DomainOperation.Delete) != null,
                                                        "Expected corresponding delete operation not found.");
                }
            }

            // verify all child operations against the map we built up during enumeration
            // of associated changes to ensure all operations were returned
            foreach (ChangeSetEntry operation in this.ChangeSet.ChangeSetEntries.Where(p => p.Entity.GetType() != typeof(CI_Parent)))
            {
                switch (operation.Operation)
                {
                case DomainOperation.Insert:
                    CompositionHelper.Assert(changeOperationMap.ContainsKey(operation.Entity) &&
                                             changeOperationMap[operation.Entity] == ChangeOperation.Insert,
                                             "Expected insert operation was not returned from GetAssociatedChanges.");
                    break;

                case DomainOperation.Update:
                    CompositionHelper.Assert(changeOperationMap.ContainsKey(operation.Entity) &&
                                             changeOperationMap[operation.Entity] == ChangeOperation.Update,
                                             "Expected update operation was not returned from GetAssociatedChanges.");
                    break;

                case DomainOperation.Delete:
                    CompositionHelper.Assert(
                        changeOperationMap.ContainsKey(operation.Entity) &&
                        changeOperationMap[operation.Entity] == ChangeOperation.Delete,
                        "Expected delete operation was not returned from GetAssociatedChanges.");
                    break;
                }
            }

            // navigate all child changes specifying operation type
            foreach (CI_Child child in this.ChangeSet.GetAssociatedChanges(parent, p => p.Children, ChangeOperation.None))
            {
            }
            foreach (CI_Child child in this.ChangeSet.GetAssociatedChanges(parent, p => p.Children, ChangeOperation.Insert))
            {
            }
            foreach (CI_Child child in this.ChangeSet.GetAssociatedChanges(parent, p => p.Children, ChangeOperation.Update))
            {
            }
            foreach (CI_Child child in this.ChangeSet.GetAssociatedChanges(parent, p => p.Children, ChangeOperation.Delete))
            {
            }
        }
 private bool FilterChildren(CI_Child entity)
 {
     return (entity.ParentID == this.ID);
 }
 /// <summary>
 /// Invokes the 'CustomOp_Child' method of the specified <see cref="CI_Child"/> entity.
 /// </summary>
 /// <param name="child">The <see cref="CI_Child"/> entity instance.</param>
 public void CustomOp_Child(CI_Child child)
 {
     child.CustomOp_Child();
 }
 private void AttachChildren(CI_Child entity)
 {
     entity.Parent = this;
 }
 private void DetachChildren(CI_Child entity)
 {
     entity.Parent = null;
 }
 public void CustomOp_Child(CI_Child child)
 {
     this.SetOperationInvoked(child, "CustomOp_Child");
     child.OperationResult += ",CustomOp_Child";
 }
        public void DeleteChild(CI_Child child)
        {
            SetOperationInvoked(child);

            child.OperationResult = "Delete";
        }
        public void UpdateChild(CI_Child child)
        {
            SetOperationInvoked(child);

           child.OperationResult = "Update";
        }
        public void InsertChild(CI_Child child)
        {
            SetOperationInvoked(child);

            child.OperationResult = "Insert";
        }
        //public static void Validate(Parent parent)
        //{
        //    // Simulate a validation pass that enumerates all children.
        //    foreach (Child child in parent.Children)
        //    {
        //        foreach (GrandChild grandChild in child.Children)
        //        {
        //            GreatGrandChild greatGrandChild = grandChild.Child;
        //        }
        //    }
        //}

        /// <summary>
        /// Create  compositional hierarchy that includes both
        /// collection and singleton compositions
        /// </summary>
        public static List<CI_Parent> CreateCompositionHierarchy()
        {
            int parentKey = 1;
            int childKey = 1;

            // Create 3 Parents with children.
            List<CI_Parent> parents = new List<CI_Parent>();
            for (int i = 0; i < 3; i++)
            {
                // one of these is a derived parent type
                CI_Parent p = i == 1 ? new CI_SpecialParent() : new CI_Parent();
                
                p.ID = parentKey++;
                parents.Add(p);

                // Create 2 natural children and 2 adopted children
                // It is critical for these scenarios to have the potential
                // for both modified and unmodified derived composition children
                // in a changeset
                for (int j = 0; j < 2; j++)
                {
                    CI_Child c = new CI_Child
                    {
                        ID = childKey++,
                        ParentID = p.ID,
                        Parent = p
                    };
                    p.Children.Add(c);
                }
                for (int j = 0; j < 2; j++)
                {
                    CI_AdoptedChild c = new CI_AdoptedChild
                    {
                        ID = childKey++,
                        ParentID = p.ID,
                        Parent = p
                    };
                    p.Children.Add(c);
                }
            }

            return parents;
        }