Пример #1
0
        /// <summary>
        /// Creates a new <see cref="DomainObject"/> instance of the same type and with the same property values as the given <paramref name="source"/>.
        /// Referenced objects are cloned according to the given strategy.
        /// </summary>
        /// <returns>A clone of the given <paramref name="source"/> object.</returns>
        /// <typeparam name="T">The static <see cref="DomainObject"/> type to be cloned. The actual (dynamic) type of the cloned object
        /// is the type defined by <paramref name="source"/>'s <see cref="ClassDefinition"/>.</typeparam>
        /// <param name="source">The <see cref="DomainObject"/> to be cloned.</param>
        /// <param name="strategy">The <see cref="ICloneStrategy"/> to be used when cloning the object's references.</param>
        /// <remarks>
        /// The clone is created in the c<see cref="CloneTransaction"/>. No constructor is called on the clone object; property or relation get and set events are
        /// raised as needed by the cloner.
        /// </remarks>
        public T CreateClone <T> (T source, ICloneStrategy strategy)
            where T : DomainObject
        {
            ArgumentUtility.CheckNotNull("source", source);
            ArgumentUtility.CheckNotNull("strategy", strategy);

            return(CreateClone(source, strategy, new CloneContext(this)));
        }
Пример #2
0
 public TruncatedCloneAll(ICloneStrategyProvider cloneStrategyProvider)
 {
     _composite = new CompositeCloneStrategy(
         cloneStrategyProvider.GetCloneStrategy(CloneMode.CloneTemplates),
         cloneStrategyProvider.GetCloneStrategy(CloneMode.CloneContentPositionsLinks),
         cloneStrategyProvider.GetCloneStrategy(CloneMode.CloneRemarksWithCategories),
         cloneStrategyProvider.GetCloneStrategy(CloneMode.TruncatedCloneAdvertisements));
 }
Пример #3
0
        private void CopyProperties <T> (T source, T clone, ICloneStrategy strategy, CloneContext context)
            where T : IDomainObject
        {
            var sourceTransaction = source.GetDefaultTransactionContext().ClientTransaction;
            var sourceProperties  = new PropertyIndexer(source);
            var cloneProperties   = new PropertyIndexer(clone);

            CopyProperties(sourceProperties, sourceTransaction, cloneProperties.AsEnumerable(CloneTransaction), strategy, context);
        }
Пример #4
0
 private void ExpectHandleReference(ICloneStrategy strategyMock, TestDomainBase original, TestDomainBase clone, string propertyName,
                                    ClientTransaction sourceTransaction, ClientTransaction cloneTransaction)
 {
     strategyMock.HandleReference(new PropertyAccessor(), new PropertyAccessor(), null);
     LastCall.Constraints(
         Rhino.Mocks.Constraints.Is.Equal(original.Properties[original.GetPublicDomainObjectType(), propertyName, sourceTransaction]),
         Rhino.Mocks.Constraints.Is.Equal(clone.Properties[clone.GetPublicDomainObjectType(), propertyName, cloneTransaction]),
         Rhino.Mocks.Constraints.Is.Anything());
 }
 /// <summary>
 /// Constructs a new SearchContext.
 /// </summary>
 /// <param name="domain"><see cref="SearchContext{D, P, A, S, Sol, N}.Domain"/></param>
 /// <param name="source"><see cref="SearchContext{D, P, A, S, Sol, N}.Source"/></param>
 /// <param name="target"><see cref="SearchContext{D, P, A, S, Sol, N}.Target"/></param>
 /// <param name="subject"><see cref="SearchContext{D, P, A, S, Sol, N}.Subject"/></param>
 /// <param name="solution"><see cref="SearchContext{D, P, A, S, Sol, N}.Solution"/></param>
 /// <param name="status"><see cref="SearchContext{D, P, A, S, Sol, N}.Status"/></param>
 /// <param name="startNode"><see cref="SearchContext{D, P, A, S, Sol, N}.StartNode"/></param>
 /// <param name="search"><see cref="SearchContext{D, P, A, S, Sol, N}.Search"/></param>
 /// <param name="expansion"><see cref="SearchContext{D, P, A, S, Sol, N}.Expansion"/></param>
 /// <param name="application"><see cref="SearchContext{D, P, A, S, Sol, N}.Application"/></param>
 /// <param name="evaluation"><see cref="SearchContext{D, P, A, S, Sol, N}.Evaluation"/></param>
 /// <param name="goal"><see cref="SearchContext{D, P, A, S, Sol, N}.Goal"/></param>
 /// <param name="cloner"><see cref="SearchContext{D, P, A, S, Sol, N}.Cloner"/></param>
 public SearchContext(D domain, P source, P target, S subject, Sol solution, SearchStatus status, SearchNode <P, A> startNode, ISearchStrategy <D, P, A, S, Sol> search, IExpansionStrategy <D, P, A, S, Sol, A> expansion, IApplicationStrategy <D, P, A, S, Sol> application, IEvaluationStrategy <D, P, A, S, Sol> evaluation, IGoalStrategy <D, P, A, S, Sol> goal, ICloneStrategy <P> cloner)
 {
     Domain      = domain;
     Source      = source?.Copy();
     Target      = target?.Copy();
     Subject     = subject;
     Solution    = solution;
     Status      = status;
     StartNode   = startNode?.Copy();
     Search      = search;
     Expansion   = expansion;
     Application = application;
     Evaluation  = evaluation;
     Goal        = goal;
     Cloner      = cloner;
 }
Пример #6
0
 private void CopyProperties(
     PropertyIndexer sourceProperties,
     ClientTransaction sourceTransaction,
     IEnumerable <PropertyAccessor> cloneProperties,
     ICloneStrategy strategy,
     CloneContext context)
 {
     foreach (PropertyAccessor cloneProperty in cloneProperties)
     {
         PropertyAccessor sourceProperty = sourceProperties[cloneProperty.PropertyData.PropertyIdentifier, sourceTransaction];
         if (cloneProperty.PropertyData.Kind == PropertyKind.PropertyValue)
         {
             object sourceValue = sourceProperty.GetValueWithoutTypeCheck();
             cloneProperty.SetValueWithoutTypeCheck(sourceValue);
         }
         else if (strategy != null && !cloneProperty.HasBeenTouched)
         {
             strategy.HandleReference(sourceProperty, cloneProperty, context);
         }
     }
 }
Пример #7
0
        /// <summary>
        /// Creates a new <see cref="DomainObject"/> instance of the same type and with the same property values as the given <paramref name="source"/>.
        /// Referenced objects are cloned according to the given strategy, the given context is used instead of creating a new one.
        /// </summary>
        /// <returns>A clone of the given <paramref name="source"/> object.</returns>
        /// <typeparam name="T">The static <see cref="DomainObject"/> type to be cloned. The actual (dynamic) type of the cloned object
        /// is the type defined by <paramref name="source"/>'s <see cref="ClassDefinition"/>.</typeparam>
        /// <param name="source">The <see cref="DomainObject"/> to be cloned.</param>
        /// <param name="strategy">The <see cref="ICloneStrategy"/> to be used when cloning the object's references.</param>
        /// <param name="context">The <see cref="CloneContext"/> to be used by the cloner. (Must have been created for this <see cref="DomainObjectCloner"/>.</param>
        /// <remarks>
        /// The clone is created in the <see cref="CloneTransaction"/>. No constructor is called on the clone object; property or relation get and set events are
        /// raised as needed by the cloner.
        /// </remarks>
        public T CreateClone <T> (T source, ICloneStrategy strategy, CloneContext context)
            where T : DomainObject
        {
            ArgumentUtility.CheckNotNull("source", source);
            ArgumentUtility.CheckNotNull("strategy", strategy);
            ArgumentUtility.CheckNotNull("context", context);

            if (context.Cloner != this)
            {
                throw new ArgumentException("The given CloneContext must have been created for this DomainObjectCloner.", "context");
            }

            T clone = context.GetCloneFor(source);

            while (context.CloneHulls.Count > 0)
            {
                var shallowClone = context.CloneHulls.Dequeue();
                CopyProperties(source: shallowClone.Item1, clone: shallowClone.Item2, strategy: strategy, context: context);
                InvokeClonerCallback(source: shallowClone.Item1, clone: shallowClone.Item2, cloneTransaction: _cloneTransaction);
            }
            return(clone);
        }
Пример #8
0
 public CloneAll(ICloneStrategyProvider cloneStrategyProvider)
 {
     _composite = new CompositeCloneStrategy(cloneStrategyProvider.GetCloneStrategy(CloneMode.CloneTemplates),
                                             cloneStrategyProvider.GetCloneStrategy(CloneMode.CloneContentPositionsLinks),
                                             cloneStrategyProvider.GetCloneStrategy(CloneMode.CloneAdvertisements));
 }