示例#1
0
        /// <summary>
        /// Creates all commands needed to perform a bidirectional remove operation from this collection end point.
        /// </summary>
        /// <remarks>
        /// A remove operation of the form "customer.Orders.Remove (RemovedOrder)" needs two steps:
        /// <list type="bullet">
        ///   <item>RemovedOrder.Customer = null and</item>
        ///   <item>customer.Orders.Remove (removedOrder).</item>
        /// </list>
        /// </remarks>
        public override ExpandedCommand ExpandToAllRelatedObjects()
        {
            var removedEndPoint = GetOppositeEndPoint(ModifiedEndPoint, OldRelatedObject, _endPointProvider);

            return(new ExpandedCommand(
                       removedEndPoint.CreateRemoveCommand(ModifiedEndPoint.GetDomainObject()),
                       this));
        }
        /// <summary>
        /// Creates all commands needed to perform a bidirectional 1:n set operation on this <see cref="ObjectEndPoint"/>. One of the steps is
        /// this command, the other steps are the opposite commands on the new/old related objects.
        /// </summary>
        /// <remarks>
        /// A 1:n set operation of the form "order.Customer = newCustomer" needs three steps:
        /// <list type="bullet">
        ///   <item>order.Customer = newCustomer,</item>
        ///   <item>newCustomer.Orders.Add (order), and</item>
        ///   <item>oldCustomer.Orders.Remove (order).</item>
        /// </list>
        /// </remarks>
        public override ExpandedCommand ExpandToAllRelatedObjects()
        {
            var newRelatedEndPoint = (ICollectionEndPoint)GetOppositeEndPoint(ModifiedEndPoint, NewRelatedObject, _endPointProvider);
            var oldRelatedEndPoint = (ICollectionEndPoint)GetOppositeEndPoint(ModifiedEndPoint, OldRelatedObject, _endPointProvider);

            var bidirectionalModification = new ExpandedCommand(
                // => order.Customer = newCustomer
                this,
                // => newCustomer.Orders.Add (order)
                newRelatedEndPoint.CreateAddCommand(ModifiedEndPoint.GetDomainObject()),
                // => oldCustomer.Orders.Remove (order) (remove)
                oldRelatedEndPoint.CreateRemoveCommand(ModifiedEndPoint.GetDomainObject()));

            return(bidirectionalModification);
        }
示例#3
0
        /// <summary>
        /// Creates all commands needed to perform a bidirectional insert operation into this collection end point.
        /// </summary>
        /// <remarks>
        /// An insert operation of the form "customer.Orders.Insert (insertedOrder, index)" needs three steps:
        /// <list type="bullet">
        ///   <item>insertedOrder.Customer = customer,</item>
        ///   <item>customer.Orders.Insert (insertedOrder, index), and</item>
        ///   <item>oldCustomer.Orders.Remove (insertedOrder) - with oldCustomer being the old customer of the inserted order (if non-null).</item>
        /// </list>
        /// </remarks>
        public override ExpandedCommand ExpandToAllRelatedObjects()
        {
            // the end point that will be linked to the collection end point after the operation
            var insertedObjectEndPoint = (IRealObjectEndPoint)GetOppositeEndPoint(ModifiedEndPoint, NewRelatedObject, _endPointProvider);
            // the object that was linked to the new related object before the operation
            var oldRelatedObjectOfInsertedObject = insertedObjectEndPoint.GetOppositeObject();
            // the end point that was linked to the new related object before the operation
            var oldRelatedEndPointOfInsertedObject = GetOppositeEndPoint(insertedObjectEndPoint, oldRelatedObjectOfInsertedObject, _endPointProvider);

            return(new ExpandedCommand(
                       // insertedOrder.Customer = customer (previously oldCustomer)
                       insertedObjectEndPoint.CreateSetCommand(ModifiedEndPoint.GetDomainObject()),
                       // customer.Orders.Insert (insertedOrder, index)
                       this,
                       // oldCustomer.Orders.Remove (insertedOrder)
                       oldRelatedEndPointOfInsertedObject.CreateRemoveCommand(NewRelatedObject)));
        }
        /// <summary>
        /// Creates all commands needed to perform a bidirectional replace operation within this collection end point.
        /// </summary>
        /// <remarks>
        /// A replace operation of the form "customer.Orders[index] = newOrder" needs four steps:
        /// <list type="bullet">
        ///   <item>customer.Order[index].Customer = null,</item>
        ///   <item>newOrder.Customer = customer,</item>
        ///   <item>customer.Orders[index] = newOrder,</item>
        ///   <item>oldCustomer.Orders.Remove (insertedOrder) - with oldCustomer being the old customer of the new order (if non-null).</item>
        /// </list>
        /// </remarks>
        public override ExpandedCommand ExpandToAllRelatedObjects()
        {
            // the end point that will be linked to the collection end point after the operation
            var endPointOfNewObject = ModifiedEndPoint.GetEndPointWithOppositeDefinition <IRealObjectEndPoint> (NewRelatedObject);
            // the end point that was linked to the collection end point before the operation
            var endPointOfOldObject = ModifiedEndPoint.GetEndPointWithOppositeDefinition <IRealObjectEndPoint> (OldRelatedObject);
            // the object that was linked to the new related object before the operation
            var oldRelatedObjectOfNewObject = endPointOfNewObject.GetOppositeObject();
            // the end point that was linked to the new related object before the operation
            var oldRelatedEndPointOfNewObject = endPointOfNewObject.GetEndPointWithOppositeDefinition <ICollectionEndPoint> (oldRelatedObjectOfNewObject);

            return(new ExpandedCommand(
                       // customer.Order[index].Customer = null
                       endPointOfOldObject.CreateRemoveCommand(ModifiedEndPoint.GetDomainObject()),
                       // newOrder.Customer = customer
                       endPointOfNewObject.CreateSetCommand(ModifiedEndPoint.GetDomainObject()),
                       // customer.Orders[index] = newOrder
                       this,
                       // oldCustomer.Orders.Remove (insertedOrder)
                       oldRelatedEndPointOfNewObject.CreateRemoveCommand(NewRelatedObject)));
        }