示例#1
0
        public void DeleteParent(CI_Parent parent)
        {
            //CompositionHelper.Validate(parent);
            SetOperationInvoked(parent);

            parent.OperationResult = "Delete";
        }
示例#2
0
        public void InsertParent(CI_Parent parent)
        {
            //CompositionHelper.Validate(parent);
            SetOperationInvoked(parent);

            parent.OperationResult = "Insert";
        }
        public void DeleteParent(CI_Parent parent)
        {
            //CompositionHelper.Validate(parent);
            SetOperationInvoked(parent);

            parent.OperationResult = "Delete";
        }
        public void InsertParent(CI_Parent parent)
        {
            //CompositionHelper.Validate(parent);
            SetOperationInvoked(parent);

            parent.OperationResult = "Insert";
        }
示例#5
0
        /// <summary>
        /// Overridden to do some pre-validation of the changeset
        /// </summary>
        protected override bool ExecuteChangeSet()
        {
            foreach (ChangeSetEntry operation in this.ChangeSet.ChangeSetEntries.Where(p => p.Entity.GetType() == typeof(CI_Parent)))
            {
                CI_Parent parent = (CI_Parent)operation.Entity;

                NavigateChildChanges(parent);

                // verify that all child collections contain unique instances
                // and contain valid operations
                HashSet <object> visited = new HashSet <object>();
                this.VerifyUniqueCollection(parent.Children);
            }

            return(base.ExecuteChangeSet());
        }
示例#6
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);
        }
示例#7
0
 public void CustomOp_Parent(CI_Parent parent)
 {
     //CompositionHelper.Validate(parent);
     this.SetOperationInvoked(parent, "CustomOp_Parent");
     parent.OperationResult += ",CustomOp_Parent";
 }
示例#8
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))
            {
            }
        }
 /// <summary>
 /// Invokes the 'CustomOp_Parent' method of the specified <see cref="CI_Parent"/> entity.
 /// </summary>
 /// <param name="parent">The <see cref="CI_Parent"/> entity instance.</param>
 public void CustomOp_Parent(CI_Parent parent)
 {
     parent.CustomOp_Parent();
 }
 private bool FilterParent(CI_Parent entity)
 {
     return (entity.ID == this.ParentID);
 }
 public void CustomOp_Parent(CI_Parent parent)
 {
     //CompositionHelper.Validate(parent);
     this.SetOperationInvoked(parent, "CustomOp_Parent");
     parent.OperationResult += ",CustomOp_Parent";
 }
        /// <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))
            {
            }
        }
 /// <summary>
 /// Verify that each node in the hierarchy has the expected children
 /// and all Parent back pointers are valid.
 /// </summary>
 private static void VerifyHierarchy(CI_Parent parent)
 {
     Assert.IsTrue(parent.Children.Count > 0);
     foreach (CI_Child c in parent.Children)
     {
         Assert.AreSame(parent, c.Parent);
     }
 }