/// <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); } }
/// <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); } }
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(); } }
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; }
public void StrategiesContainsOBTypeMappingStrategy() { WCSFBuilder builder = new WCSFBuilder(); IBuilderStrategyChain chain = builder.Strategies.MakeStrategyChain(); IBuilderStrategy head = chain.Head; Assert.IsTrue(head is TypeMappingStrategy); }
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; }
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; }
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); }
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); } }
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); }
/// <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(); } }
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); }
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); }
/// <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); }
public SpyExtension(IBuilderStrategy strategy, UnityBuildStage stage) { this.strategy = strategy; this.stage = stage; }
/// <summary> /// See <see cref="IBuilderContext.GetNextInChain"/> for more information. /// </summary> public IBuilderStrategy GetNextInChain(IBuilderStrategy currentStrategy) { return(chain.GetNext(currentStrategy)); }
public void RegisterStrategy(IBuilderStrategy strategy, BuilderStage stage) { strategies.Add(strategy, stage); }
/// <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); }