本文整理汇总了C#中IIntegrationResult.Merge方法的典型用法代码示例。如果您正苦于以下问题:C# IIntegrationResult.Merge方法的具体用法?C# IIntegrationResult.Merge怎么用?C# IIntegrationResult.Merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IIntegrationResult
的用法示例。
在下文中一共展示了IIntegrationResult.Merge方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
/// <summary>
/// Runs the task, given the specified <see cref="IIntegrationResult"/>, in the specified <see cref="IProject"/>.
/// </summary>
/// <param name="result"></param>
protected override bool Execute(IIntegrationResult result)
{
// Initialise the task
var logger = Logger ?? new DefaultLogger();
var numberOfTasks = Tasks.Length;
result.BuildProgressInformation.SignalStartRunTask(_getStatusInformation("", null));
logger.Info("Starting sequential task with {0} sub-task(s)", numberOfTasks);
// Launch each task
var successCount = 0;
var failureCount = 0;
for (var loop = 0; loop < numberOfTasks; loop++)
{
var taskName = string.Format(System.Globalization.CultureInfo.CurrentCulture,"{0} [{1}]", Tasks[loop].GetType().Name, loop);
logger.Debug("Starting task '{0}'", taskName);
try
{
// Start the actual task
var taskResult = result.Clone();
taskResult.BuildProgressInformation.OnStartupInformationUpdatedUserObject = new _RunningSubTaskDetails(loop, result);
taskResult.BuildProgressInformation.OnStartupInformationUpdated = SubTaskStartupInformationUpdated;
var task = Tasks[loop];
RunTask(task, taskResult);
result.Merge(taskResult);
}
catch (Exception error)
{
// Handle any error details
result.ExceptionResult = error;
result.Status = IntegrationStatus.Failure;
logger.Warning("Task '{0}' failed!", taskName);
}
// Record the results
if (result.Status == IntegrationStatus.Success)
{
successCount++;
}
else
{
failureCount++;
if (!ContinueOnFailure) break;
}
}
// Clean up
this.CancelTasks();
logger.Info("Sequential task completed: {0} successful, {1} failed", successCount, failureCount);
return failureCount == 0;
}
示例2: Execute
/// <summary>
/// Runs the task, given the specified <see cref="IIntegrationResult"/>, in the specified <see cref="IProject"/>.
/// </summary>
/// <param name="result"></param>
protected override bool Execute(IIntegrationResult result)
{
// Initialise the task
var logger = Logger ?? new DefaultLogger();
var numberOfTasks = Tasks.Length;
tasksDetails = new ParallelRunningSubTaskDetails[numberOfTasks];
result.BuildProgressInformation.SignalStartRunTask(GetStatusInformation(null));
logger.Info("Starting parallel task with {0} sub-task(s)", numberOfTasks);
// Initialise the arrays
var events = new ManualResetEvent[numberOfTasks];
var results = new IIntegrationResult[numberOfTasks];
for (var loop = 0; loop < numberOfTasks; loop++)
{
events[loop] = new ManualResetEvent(false);
results[loop] = result.Clone();
tasksDetails[loop] = new ParallelRunningSubTaskDetails(loop, result);
}
// Launch each task using the ThreadPool
var countLock = new object();
var successCount = 0;
var failureCount = 0;
for (var loop = 0; loop < numberOfTasks; loop++)
{
ThreadPool.QueueUserWorkItem((state) =>
{
var taskNumber = (int)state;
var taskName = string.Format(System.Globalization.CultureInfo.CurrentCulture,"{0} [{1}]", Tasks[taskNumber].GetType().Name, taskNumber);
try
{
Thread.CurrentThread.Name = string.Format(System.Globalization.CultureInfo.CurrentCulture,"{0} [Parallel-{1}]", result.ProjectName, taskNumber);
logger.Debug("Starting task '{0}'", taskName);
// Start the actual task
var task = Tasks[taskNumber];
var taskResult = results[taskNumber];
RunTask(task, taskResult, tasksDetails[taskNumber]);
}
catch (Exception error)
{
// Handle any error details
results[taskNumber].ExceptionResult = error;
results[taskNumber].Status = IntegrationStatus.Failure;
logger.Warning("Task '{0}' failed!", taskName);
}
// Record the results
lock (countLock)
{
if (results[taskNumber].Status == IntegrationStatus.Success)
{
successCount++;
}
else
{
failureCount++;
}
}
tasksDetails[taskNumber].Finished = true;
tasksDetails[taskNumber].ParentResult.BuildProgressInformation.UpdateStartupInformation(GetStatusInformation(tasksDetails[taskNumber]));
// Tell everyone the task is done
events[taskNumber].Set();
}, loop);
}
// Wait for all the tasks to complete
logger.Debug("Waiting for tasks to complete");
WaitHandle.WaitAll(events);
// Merge all the results
logger.Info("Merging task results");
foreach (var taskResult in results)
{
result.Merge(taskResult);
}
// Clean up
this.CancelTasks();
logger.Info("Parallel task completed: {0} successful, {1} failed", successCount, failureCount);
return true;
}
示例3: Execute
protected override bool Execute(IIntegrationResult result)
{
int loop = 0;
foreach (var task in Tasks)
{
var taskResult = result.Clone();
RunTask(task, taskResult, new RunningSubTaskDetails(loop, result));
result.Merge(taskResult);
loop++;
}
return true;
}
示例4: Execute
/// <summary>
/// Execute the actual task functionality.
/// </summary>
/// <param name="result">The result to use.</param>
/// <returns>
/// True if the task was successful, false otherwise.
/// </returns>
protected override bool Execute(IIntegrationResult result)
{
// Initialise the task
var logger = Logger ?? new DefaultLogger();
var numberOfTasks = Tasks.Length;
result.BuildProgressInformation.SignalStartRunTask(!string.IsNullOrEmpty(Description)
? Description
: string.Format(System.Globalization.CultureInfo.CurrentCulture, "Running tasks in synchronisation context({0} task(s))", numberOfTasks));
logger.Info("Starting synchronisation task with {0} sub-task(s)", numberOfTasks);
var contextToUse = this.ContextName ?? "DefaultSynchronisationContext";
// Make sure the context has been loaded
lock (lockObject)
{
if (!contexts.ContainsKey(contextToUse))
{
contexts.Add(contextToUse, new object());
}
}
// Attempt to enter the synchronisation context
if (Monitor.TryEnter(contexts[contextToUse], TimeoutPeriod * 1000))
{
try
{
// Launch each task
var successCount = 0;
var failureCount = 0;
for (var loop = 0; loop < numberOfTasks; loop++)
{
var taskName = string.Format(System.Globalization.CultureInfo.CurrentCulture, "{0} [{1}]", Tasks[loop].GetType().Name, loop);
logger.Debug("Starting task '{0}'", taskName);
try
{
// Start the actual task
var taskResult = result.Clone();
var task = Tasks[loop];
RunTask(task, taskResult);
result.Merge(taskResult);
}
catch (Exception error)
{
// Handle any error details
result.ExceptionResult = error;
result.Status = IntegrationStatus.Failure;
logger.Warning("Task '{0}' failed!", taskName);
}
// Record the results
if (result.Status == IntegrationStatus.Success)
{
successCount++;
}
else
{
failureCount++;
if (!ContinueOnFailure) break;
}
}
logger.Info("Parallel task completed: {0} successful, {1} failed", successCount, failureCount);
}
finally
{
Monitor.Exit(contexts[contextToUse]);
}
}
else
{
// Set the result as failed
logger.Warning("Unable to enter synchonisation context!");
result.Status = IntegrationStatus.Failure;
}
// Clean up
this.CancelTasks();
return (result.Status == IntegrationStatus.Success);
}
示例5: RunTasks
/// <summary>
/// Runs some tasks.
/// </summary>
/// <param name="tasks">The tasks.</param>
/// <param name="logger">The logger.</param>
/// <param name="runningIfTasks">true if running the "if" tasks.</param>
/// <param name="result">The result.</param>
/// <returns><c>true</c> if all the tasks are successul; <c>false</c> otherwise.</returns>
private bool RunTasks(ITask[] tasks, ILogger logger, bool runningIfTasks, IIntegrationResult result)
{
// Launch each task
var successCount = 0;
var failureCount = 0;
for (var loop = 0; loop < tasks.Length; loop++)
{
var taskName = string.Format(System.Globalization.CultureInfo.CurrentCulture,"{0} [{1}]", tasks[loop].GetType().Name, loop);
logger.Debug("Starting task '{0}'", taskName);
try
{
// Start the actual task
var taskResult = result.Clone();
var task = tasks[loop];
this.RunTask(task, taskResult, new RunningSubTaskDetails(loop, runningIfTasks, result));
result.Merge(taskResult);
}
catch (Exception error)
{
// Handle any error details
result.ExceptionResult = error;
result.Status = IntegrationStatus.Failure;
logger.Warning("Task '{0}' failed!", taskName);
}
// Record the results
if (result.Status == IntegrationStatus.Success)
{
successCount++;
}
else
{
failureCount++;
if (!ContinueOnFailure)
break;
}
}
logger.Info("Tasks completed: {0} successful, {1} failed", successCount, failureCount);
return failureCount == 0;
}
示例6: AddResultMockExpectedMerge
private void AddResultMockExpectedMerge(IIntegrationResult result)
{
Expect.Call(() => result.Merge(Arg<IIntegrationResult>.Is.NotNull)).
Do((Action<IIntegrationResult>)((otherResult) =>
{
result.Status = otherResult.Status;
}));
}
示例7: RunTaskAndMergeResult
private static void RunTaskAndMergeResult(ITask task, IIntegrationResult result)
{
IIntegrationResult subResult = result.Clone();
try
{
task.Run(subResult);
}
finally
{
result.Merge(subResult);
}
}
示例8: AddResultMockExpectedMerge
private void AddResultMockExpectedMerge(IIntegrationResult result)
{
Expect.Call(() => result.Merge(Arg<IIntegrationResult>.Is.NotNull)).
Do((Action<IIntegrationResult>)((otherResult) =>
{
// Apply some rules to the status merging - basically apply a hierachy of status codes
if ((otherResult.Status == IntegrationStatus.Exception) || (result.Status == IntegrationStatus.Unknown))
{
result.Status = otherResult.Status;
}
else if (((otherResult.Status == IntegrationStatus.Failure) ||
(otherResult.Status == IntegrationStatus.Cancelled)) &&
(result.Status != IntegrationStatus.Exception))
{
result.Status = otherResult.Status;
}
}));
}
示例9: Execute
/// <summary>
/// Runs the task, given the specified <see cref="IIntegrationResult"/>, in the specified <see cref="IProject"/>.
/// </summary>
/// <param name="result">The results of the current build.</param>
/// <returns><c>true</c> if the execution is successful; <c>false</c> otherwise.</returns>
protected override bool Execute(IIntegrationResult result)
{
// Initialise the publisher
var logger = this.Logger ?? new DefaultLogger();
result.BuildProgressInformation.SignalStartRunTask(!string.IsNullOrEmpty(Description)
? Description
: "Checking conditional publishers");
logger.Info("Checking conditional publishers");
// Check the conditions
var runPublishers = false;
foreach (var condition in this.Conditions ?? new IntegrationStatus[0])
{
runPublishers |= condition == result.Status;
}
if (runPublishers)
{
// Run each publisher
logger.Info("Conditions met - running publishers");
for (var loop = 0; loop < this.Tasks.Length; loop++)
{
logger.Debug("Running publisher #{0}", loop);
try
{
var taskResult = result.Clone();
var publisher = this.Tasks[loop];
RunTask(publisher, taskResult, new RunningSubTaskDetails(loop, result));
result.Merge(taskResult);
}
catch (Exception e)
{
logger.Error("Publisher threw exception: {0}", e.Message);
}
}
}
else
{
logger.Info("Conditions not met - publishers not run");
}
// Clean up
this.CancelTasks();
return true;
}