using MainShell.Common;
using MW.WorkFlow;
using System.Threading.Tasks;

namespace MainShell.Process
{
    public class SubstrateUnloadActivity : ActivityAbstractBase
    {
        public SubstrateUnloadActivity(string name)
            : base(name)
        {
        }

        protected override async Task<ActivityResult> OnExecuteAsync(WorkflowContext context, ActivityControl activityControl)
        {
            context.SetData(WorkflowContextKeys.SubstrateProcessState, SubstrateLifecycleState.Unloading);

            for (int index = 0; index < 10; index++)
            {
                activityControl.ThrowIfCancellationRequested();
                await activityControl.CheckPauseAsync().ConfigureAwait(false);
                await Task.Delay(100, activityControl.CancellationToken).ConfigureAwait(false);
            }

            context.SetData(WorkflowContextKeys.SubstrateProcessState, SubstrateLifecycleState.NotLoaded);
            return ActivityResult.Success;
        }
    }
}