Ejemplo n.º 1
0
        public void SetValueWithoutTypeCheck(PropertyAccessor propertyAccessor, ClientTransaction transaction, object value)
        {
            ArgumentUtility.CheckNotNull("propertyAccessor", propertyAccessor);
            ArgumentUtility.CheckNotNull("transaction", transaction);
            var newRelatedObject = ArgumentUtility.CheckType <DomainObject> ("value", value);

            var endPointID = CreateRelationEndPointID(propertyAccessor);
            var endPoint   = (IObjectEndPoint)transaction.DataManager.GetRelationEndPointWithLazyLoad(endPointID);

            if (newRelatedObject != null && transaction.RootTransaction != newRelatedObject.RootTransaction)
            {
                var formattedMessage = String.Format(
                    "Property '{1}' of DomainObject '{2}' cannot be set to DomainObject '{0}'.",
                    newRelatedObject.ID,
                    endPoint.Definition.PropertyName,
                    endPoint.ObjectID);
                throw new ClientTransactionsDifferException(formattedMessage + " The objects do not belong to the same ClientTransaction.");
            }

            DomainObjectCheckUtility.EnsureNotDeleted(endPoint.GetDomainObjectReference(), endPoint.ClientTransaction);
            if (newRelatedObject != null)
            {
                DomainObjectCheckUtility.EnsureNotDeleted(newRelatedObject, endPoint.ClientTransaction);
                CheckNewRelatedObjectType(endPoint, newRelatedObject);
            }

            var setCommand = endPoint.CreateSetCommand(newRelatedObject);
            var bidirectionalModification = setCommand.ExpandToAllRelatedObjects();

            bidirectionalModification.NotifyAndPerform();
        }
        public DomainObjectTransactionContext(DomainObject domainObject, ClientTransaction associatedTransaction)
        {
            ArgumentUtility.CheckNotNull("domainObject", domainObject);
            ArgumentUtility.CheckNotNull("associatedTransaction", associatedTransaction);
            DomainObjectCheckUtility.CheckIfRightTransaction(domainObject, associatedTransaction);

            _domainObject          = domainObject;
            _associatedTransaction = associatedTransaction;
        }
        /// <summary>
        /// Initializes the <see cref="PropertyAccessor"/> object.
        /// </summary>
        /// <param name="domainObject">The domain object whose property is to be encapsulated.</param>
        /// <param name="propertyData">a <see cref="PropertyAccessorData"/> object describing the property to be accessed.</param>
        /// <param name="clientTransaction">The transaction to be used for accessing the property.</param>
        /// <exception cref="ArgumentNullException">One of the parameters passed to the constructor is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentException">The domain object does not have a property with the given identifier.</exception>
        public PropertyAccessor(IDomainObject domainObject, PropertyAccessorData propertyData, ClientTransaction clientTransaction)
        {
            ArgumentUtility.CheckNotNull("domainObject", domainObject);
            ArgumentUtility.CheckNotNull("propertyData", propertyData);
            ArgumentUtility.CheckNotNull("clientTransaction", clientTransaction);
            DomainObjectCheckUtility.CheckIfRightTransaction(domainObject, clientTransaction);

            _domainObject      = domainObject;
            _clientTransaction = clientTransaction;
            _propertyData      = propertyData;
        }
Ejemplo n.º 4
0
        public IEnumerable <PropertyAccessor> AsEnumerable([NotNull] ClientTransaction transaction)
        {
            ArgumentUtility.CheckNotNull("transaction", transaction);
            DomainObjectCheckUtility.CheckIfRightTransaction(_domainObject, transaction);

            foreach (PropertyDefinition propertyDefinition in ClassDefinition.GetPropertyDefinitions())
            {
                yield return(this[propertyDefinition.PropertyName, transaction]);
            }

            foreach (IRelationEndPointDefinition endPointDefinition in ClassDefinition.GetRelationEndPointDefinitions())
            {
                if (endPointDefinition.IsVirtual)
                {
                    yield return(this[endPointDefinition.PropertyName, transaction]);
                }
            }
        }
Ejemplo n.º 5
0
        public void SetValueWithoutTypeCheck(PropertyAccessor propertyAccessor, ClientTransaction transaction, object value)
        {
            ArgumentUtility.CheckNotNull("propertyAccessor", propertyAccessor);
            ArgumentUtility.CheckNotNull("transaction", transaction);
            var newCollection = ArgumentUtility.CheckNotNullAndType <DomainObjectCollection> ("value", value);

            DomainObjectCheckUtility.EnsureNotDeleted(propertyAccessor.DomainObject, transaction);

            RelationEndPointID id = CreateRelationEndPointID(propertyAccessor);
            var endPoint          = (ICollectionEndPoint)transaction.DataManager.GetRelationEndPointWithLazyLoad(id);

            if (newCollection.AssociatedEndPointID != null && newCollection.AssociatedEndPointID != endPoint.ID)
            {
                throw new ArgumentException("The given collection is already associated with an end point.", "value");
            }

            if (newCollection.RequiredItemType != endPoint.Collection.RequiredItemType &&
                !newCollection.IsReadOnly &&
                !endPoint.Collection.IsReadOnly)
            {
                throw new InvalidOperationException("The given collection has a different item type than the end point's current opposite collection.");
            }

            if (newCollection.GetType() != endPoint.Collection.GetType())
            {
                var message = string.Format(
                    "The given collection ('{0}') is not of the same type as the end point's current opposite collection ('{1}').",
                    newCollection.GetType(),
                    endPoint.Collection.GetType());
                throw new InvalidOperationException(message);
            }

            var command = endPoint.CreateSetCollectionCommand(newCollection);
            var bidirectionalModification = command.ExpandToAllRelatedObjects();

            bidirectionalModification.NotifyAndPerform();
        }
 private void CheckTransactionalStatus(ClientTransaction clientTransaction)
 {
     Assertion.DebugAssert(ReferenceEquals(ClientTransaction, clientTransaction));
     DomainObjectCheckUtility.EnsureNotInvalid(_domainObject, clientTransaction);
 }