예제 #1
0
 /// <summary>
 /// Add a strategy to the list.
 /// </summary>
 /// <param name="strategy">The strategy to be added.</param>
 /// <param name="stage">The stage to add the strategy to.</param>
 public void Add(IBuilderStrategy strategy, TStageEnum stage)
 {
     lock (lockObject)
     {
         stages[stage].Add(strategy);
     }
 }
예제 #2
0
 /// <summary>
 /// Adds a strategy to the chain at a particular stage.
 /// </summary>
 /// <param name="strategy">The strategy to add to the chain.</param>
 /// <param name="stage">The stage to add the strategy.</param>
 public void Add(IBuilderStrategy strategy, TStageEnum stage)
 {
     lock (_lockObject)
     {
         _stages[Convert.ToInt32(stage)].Add(strategy);
     }
 }
예제 #3
0
        public T ExecuteSingle <T>(IBuilderStrategy builderStrategy, IEnumerable <TableObjectMapping> tableObjectMappings)
            where T : class, new()
        {
            Guard.ThrowIfNull("builderStrategy", builderStrategy);

            dynamic parameters = new ExpandoObject();

            parameters.TableObjectMappings = tableObjectMappings;

            try
            {
                var value = default(T);

                VerifyCommandText();

                using (var connection = new SqlConnection(_connectionString))
                {
                    connection.Open();

                    using (var command = GetCommand(_commandText, _queryType, connection))
                    {
                        using (var reader = command.ExecuteReader())
                        {
                            value = builderStrategy.BuildItems <T>(parameters, reader);
                        }
                    }
                }

                return(value);
            }
            finally
            {
                ClearParameters();
            }
        }
예제 #4
0
 public SpyExtension(IBuilderStrategy strategy, UnityBuildStage stage, IBuilderPolicy policy, Type policyType)
 {
     this.strategy = strategy;
     this.stage = stage;
     this.policy = policy;
     this.policyType = policyType;
 }
예제 #5
0
 public SpyExtension(IBuilderStrategy strategy, UnityBuildStage stage, IBuilderPolicy policy, Type policyType)
 {
     this.strategy   = strategy;
     this.stage      = stage;
     this.policy     = policy;
     this.policyType = policyType;
 }
        /// <summary>
        /// See <see cref="IBuilderStrategyChain.GetNext"/> for more information.
        /// </summary>
        public IBuilderStrategy GetNext(IBuilderStrategy currentStrategy)
        {
            for (int idx = 0; idx < strategies.Count - 1; idx++)
                if (ReferenceEquals(currentStrategy, strategies[idx]))
                    return strategies[idx + 1];

            return null;
        }
예제 #7
0
        public void StrategiesContainsOBTypeMappingStrategy()
        {
            WCSFBuilder           builder = new WCSFBuilder();
            IBuilderStrategyChain chain   = builder.Strategies.MakeStrategyChain();
            IBuilderStrategy      head    = chain.Head;

            Assert.IsTrue(head is TypeMappingStrategy);
        }
예제 #8
0
        static void AssertOrder(IStrategyChain chain,
                                params FakeStrategy[] strategies)
        {
            IBuilderStrategy current = chain.Head;

            foreach (FakeStrategy strategy in strategies)
            {
                Assert.Same(strategy, current);
                current = chain.GetNext(current);
            }
        }
 /// <summary>
 /// Create a new <see cref="BuildFailedException"/> instance containing
 /// the information about the currently executing strategy that caused
 /// the exception.
 /// </summary>
 /// <param name="executingStrategy">The <see cref="IBuilderStrategy"/> that was
 /// executing at the time the exception was thrown.</param>
 /// <param name="executingStrategyIndex">The index of the current strategy in its
 /// strategy chain.</param>
 /// <param name="buildKey">The build key being built up.</param>
 /// <param name="innerException">Underlying exception.</param>
 public BuildFailedException(
     IBuilderStrategy executingStrategy,
     int executingStrategyIndex,
     object buildKey,
     Exception innerException)
     : base(null, innerException)
 {
     this.executingStrategy      = executingStrategy;
     this.executingStrategyIndex = executingStrategyIndex;
     this.buildKey = buildKey;
 }
예제 #10
0
 /// <summary>
 /// Create a new <see cref="BuildFailedException"/> instance containing
 /// the information about the currently executing strategy that caused
 /// the exception.
 /// </summary>
 /// <param name="executingStrategy">The <see cref="IBuilderStrategy"/> that was
 /// executing at the time the exception was thrown.</param>
 /// <param name="executingStrategyIndex">The index of the current strategy in its
 /// strategy chain.</param>
 /// <param name="buildKey">The build key being built up.</param>
 /// <param name="innerException">Underlying exception.</param>
 public BuildFailedException(
     IBuilderStrategy executingStrategy, 
     int executingStrategyIndex, 
     object buildKey, 
     Exception innerException)
     : base(null, innerException)
 {
     this.executingStrategy = executingStrategy;
     this.executingStrategyIndex = executingStrategyIndex;
     this.buildKey = buildKey;
 }
예제 #11
0
 public IBuilderStrategy GetNext(IBuilderStrategy currentStrategy)
 {
     for (int i = 0; i < (this.strategies.Count - 1); i++)
     {
         if (object.ReferenceEquals(currentStrategy, this.strategies[i]))
         {
             return this.strategies[i + 1];
         }
     }
     return null;
 }
예제 #12
0
        public IBuilderStrategy GetNext(IBuilderStrategy currentStrategy)
        {
            for (int idx = 0; idx < strategies.Count - 1; idx++)
            {
                if (ReferenceEquals(currentStrategy, strategies[idx]))
                {
                    return(strategies[idx + 1]);
                }
            }

            return(null);
        }
예제 #13
0
        public virtual object TearDown(IBuilderContext context,
                                       object item)
        {
            IBuilderStrategy next = context.GetNextInChain(this);

            if (next != null)
            {
                return(next.TearDown(context, item));
            }

            return(item);
        }
        /// <summary>
        /// See <see cref="IBuilderStrategy.BuildUp"/> for more information.
        /// </summary>
        public virtual object BuildUp(IBuilderContext context, Type typeToBuild, object existing, string idToBuild)
        {
            IBuilderStrategy next = context.GetNextInChain(this);

            if (next != null)
            {
                return(next.BuildUp(context, typeToBuild, existing, idToBuild));
            }
            else
            {
                return(existing);
            }
        }
예제 #15
0
        public virtual object BuildUp(IBuilderContext context,
                                      object buildKey,
                                      object existing)
        {
            IBuilderStrategy next = context.GetNextInChain(this);

            if (next != null)
            {
                return(next.BuildUp(context, buildKey, existing));
            }

            return(existing);
        }
예제 #16
0
        /// <summary>
        /// Create a new <see cref="BuildFailedException"/> instance containing
        /// the information about the currently executing strategy that caused
        /// the exception.
        /// </summary>
        /// <param name="executingStrategy">The <see cref="IBuilderStrategy"/> that was
        /// executing at the time the exception was thrown.</param>
        /// <param name="executingStrategyIndex">The index of the current strategy in its
        /// strategy chain.</param>
        /// <param name="buildKey">The build key being built up.</param>
        /// <param name="innerException">Underlying exception.</param>
        public BuildFailedException(
            IBuilderStrategy executingStrategy,
            int executingStrategyIndex,
            object buildKey,
            Exception innerException)
            : base(null, innerException)
        {
            if (executingStrategy != null)
            {
                executingStrategyTypeName = executingStrategy.GetType().Name;
            }
            this.executingStrategyIndex = executingStrategyIndex;

            if (buildKey != null)
            {
                this.buildKey = buildKey.ToString();
            }
        }
예제 #17
0
        public void StrategiesContainsCustomBuildPlanStrategy()
        {
            WCSFBuilder           builder = new WCSFBuilder();
            IBuilderStrategyChain chain   = builder.Strategies.MakeStrategyChain();
            bool foundCorrectStrategyType = false;

            IBuilderStrategy current = chain.Head;

            do
            {
                if (current is BuildPlanStrategy)
                {
                    foundCorrectStrategyType = true;
                }
                current = chain.GetNext(current);
            } while ((current != null) && (foundCorrectStrategyType == false));
            Assert.IsTrue(foundCorrectStrategyType);
        }
예제 #18
0
            public IBuilderStrategy FindStrategy(Predicate <IBuilderStrategy> match)
            {
                // TODO: This is pretty non-optimal; chains should be enumerable, even staged chains

                StrategyChain    chain    = strategies.MakeStrategyChain();
                IBuilderStrategy strategy = chain.Head;

                while (strategy != null)
                {
                    if (match(strategy))
                    {
                        return(strategy);
                    }

                    strategy = chain.GetNext(strategy);
                }

                return(null);
            }
예제 #19
0
 /// <summary>
 /// See <see cref="IBuilderStrategyChain.Add"/> for more information.
 /// </summary>
 public void Add(IBuilderStrategy strategy)
 {
     strategies.Add(strategy);
 }
 public IBuilderStrategy GetNextInChain(IBuilderStrategy currentStrategy)
 {
     return chain.GetNext(currentStrategy);
 }
예제 #21
0
 public SpyExtension(IBuilderStrategy strategy, UnityBuildStage stage)
 {
     this.strategy = strategy;
     this.stage = stage;
 }
예제 #22
0
 /// <summary>
 /// See <see cref="IBuilderContext.GetNextInChain"/> for more information.
 /// </summary>
 public IBuilderStrategy GetNextInChain(IBuilderStrategy currentStrategy)
 {
     return(chain.GetNext(currentStrategy));
 }
예제 #23
0
 public void RegisterStrategy(IBuilderStrategy strategy,
                              BuilderStage stage)
 {
     strategies.Add(strategy, stage);
 }
예제 #24
0
 /// <summary>
 /// Adds a strategy to the chain.
 /// </summary>
 /// <param name="strategy">The strategy to add to the chain.</param>
 public void Add(IBuilderStrategy strategy)
 {
     strategies.Add(strategy);
 }
예제 #25
0
 public SpyExtension(IBuilderStrategy strategy, UnityBuildStage stage)
 {
     this.strategy = strategy;
     this.stage    = stage;
 }