60 lines
No EOL
2.3 KiB
C#
60 lines
No EOL
2.3 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using DjRedo.Controls;
|
|
using DjRedo.Views;
|
|
using NLog;
|
|
|
|
namespace DjRedo.Core
|
|
{
|
|
public class RunnableStepTaskCollection : ReadOnlyCollectionBase, IReadOnlyCollection<StepTask>
|
|
{
|
|
private static readonly ILogger Logs = LogManager.GetCurrentClassLogger();
|
|
public RunnableStepTaskCollection(IEnumerable<StepTask> stepTasks) : base()
|
|
{
|
|
base.InnerList.AddRange(stepTasks.ToArray());
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public new IEnumerator<StepTask> GetEnumerator()
|
|
{
|
|
return base.InnerList.Cast<StepTask>().GetEnumerator();
|
|
}
|
|
|
|
public async Task RunTasks()
|
|
{
|
|
object[] taskParameters = new object[0];
|
|
try
|
|
{
|
|
for (int i = 0; i < base.InnerList.Count; i++)
|
|
{
|
|
StepTask currentStep = base.InnerList.Cast<StepTask>().ElementAt(i);
|
|
taskParameters = await currentStep.RunTask(taskParameters);
|
|
|
|
switch (currentStep.StepData.State)
|
|
{
|
|
case DjRedoStepState.NotStarted:
|
|
case DjRedoStepState.Starting:
|
|
case DjRedoStepState.Started:
|
|
case DjRedoStepState.Ending:
|
|
case DjRedoStepState.Ended:
|
|
throw new Exception($"The current Step is not in the right State: {currentStep.StepData.State}. It should be one of this three: {DjRedoStepState.Failed};{DjRedoStepState.Successed};{DjRedoStepState.Stopped}");
|
|
case DjRedoStepState.Failed:
|
|
throw new Exception($"The step has failed. {currentStep.StepData}");
|
|
case DjRedoStepState.Stopped:
|
|
throw new Exception($"The step has been stopped. {currentStep.StepData}");
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
StringBuilder sb = new StringBuilder(ex.Message);
|
|
sb.Append(ex.StackTrace);
|
|
Logs.Debug(sb.ToString());
|
|
}
|
|
}
|
|
}
|
|
} |