138 lines
6.0 KiB
C#
138 lines
6.0 KiB
C#
|
|
using MainShell.Common;
|
|||
|
|
using MainShell.Recipe.Models;
|
|||
|
|
using MW.WorkFlow;
|
|||
|
|
using System;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
|
|||
|
|
namespace MainShell.Process
|
|||
|
|
{
|
|||
|
|
public class ChipUnloadActivity : ActivityAbstractBase
|
|||
|
|
{
|
|||
|
|
private readonly TimeSpan _timeout;
|
|||
|
|
|
|||
|
|
public ChipUnloadActivity(string name, TimeSpan? timeout = null)
|
|||
|
|
: base(name)
|
|||
|
|
{
|
|||
|
|
_timeout = timeout ?? TimeSpan.FromSeconds(30);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
protected override async Task<ActivityResult> OnExecuteAsync(WorkflowContext context, ActivityControl activityControl)
|
|||
|
|
{
|
|||
|
|
activityControl.ThrowIfCancellationRequested();
|
|||
|
|
|
|||
|
|
PreparationAreaService preparationAreaService;
|
|||
|
|
if (!context.TryGetData<PreparationAreaService>(WorkflowContextKeys.PreparationAreaService, out preparationAreaService) || preparationAreaService == null)
|
|||
|
|
{
|
|||
|
|
throw new InvalidOperationException("δ<>ڹ<EFBFBD><DAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
CurrentChipStateService currentChipStateService;
|
|||
|
|
if (!context.TryGetData<CurrentChipStateService>(WorkflowContextKeys.CurrentChipStateService, out currentChipStateService) || currentChipStateService == null)
|
|||
|
|
{
|
|||
|
|
throw new InvalidOperationException("δ<>ڹ<EFBFBD><DAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD>ǰоƬ״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
AutoProductionRuntimeStateService autoProductionRuntimeStateService;
|
|||
|
|
if (!context.TryGetData<AutoProductionRuntimeStateService>(WorkflowContextKeys.AutoProductionRuntimeStateService, out autoProductionRuntimeStateService) || autoProductionRuntimeStateService == null)
|
|||
|
|
{
|
|||
|
|
throw new InvalidOperationException("δ<>ڹ<EFBFBD><DAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (currentChipStateService.CurrentState == CurrentChipLifecycleState.Empty)
|
|||
|
|
{
|
|||
|
|
autoProductionRuntimeStateService.SetCurrentChipRemainingCount(0);
|
|||
|
|
context.SetData(WorkflowContextKeys.CurrentChipState, CurrentChipLifecycleState.Empty);
|
|||
|
|
context.SetData(WorkflowContextKeys.PendingChipLoad, true);
|
|||
|
|
context.SetData(WorkflowContextKeys.PreparationAreaStatus, preparationAreaService.CurrentStatus);
|
|||
|
|
context.SetData(WorkflowContextKeys.CurrentChipRemainingCount, autoProductionRuntimeStateService.CurrentChipRemainingCount);
|
|||
|
|
return ActivityResult.Success;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
currentChipStateService.SetState(CurrentChipLifecycleState.Unloading);
|
|||
|
|
context.SetData(WorkflowContextKeys.CurrentChipState, CurrentChipLifecycleState.Unloading);
|
|||
|
|
|
|||
|
|
ChipPreparationRequest request = new ChipPreparationRequest
|
|||
|
|
{
|
|||
|
|
RecipeName = ResolveRecipeName(context),
|
|||
|
|
Action = ChipPreparationAction.Unload,
|
|||
|
|
SourceStepId = ResolveSourceStepId(context)
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
string rejectReason;
|
|||
|
|
if (!preparationAreaService.TryRequestPrepare(request, out rejectReason))
|
|||
|
|
{
|
|||
|
|
return Fail(
|
|||
|
|
context,
|
|||
|
|
MessageKey.ProcessStepFailedWithReason,
|
|||
|
|
new object[]
|
|||
|
|
{
|
|||
|
|
Name,
|
|||
|
|
string.IsNullOrWhiteSpace(rejectReason) ? "оƬ<D0BE><C6AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܡ<EFBFBD>" : rejectReason
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ChipPreparationWaitResult waitResult = await preparationAreaService.WaitUntilReadyAsync(_timeout, activityControl.CancellationToken).ConfigureAwait(false);
|
|||
|
|
if (!waitResult.Success)
|
|||
|
|
{
|
|||
|
|
if (waitResult.IsCanceled)
|
|||
|
|
{
|
|||
|
|
SetWorkflowFailure(context, string.IsNullOrWhiteSpace(waitResult.ErrorMessage) ? "оƬ<D0BE><C6AC><EFBFBD>ϵȴ<CFB5><C8B4><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>" : waitResult.ErrorMessage);
|
|||
|
|
return ActivityResult.Canceled;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return Fail(
|
|||
|
|
context,
|
|||
|
|
MessageKey.ProcessStepFailedWithReason,
|
|||
|
|
new object[]
|
|||
|
|
{
|
|||
|
|
Name,
|
|||
|
|
string.IsNullOrWhiteSpace(waitResult.ErrorMessage) ? "оƬ<D0BE><C6AC><EFBFBD>ϵȴ<CFB5>ʧ<EFBFBD>ܡ<EFBFBD>" : waitResult.ErrorMessage
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (!preparationAreaService.TryConsumeReady(out rejectReason))
|
|||
|
|
{
|
|||
|
|
return Fail(
|
|||
|
|
context,
|
|||
|
|
MessageKey.ProcessStepFailedWithReason,
|
|||
|
|
new object[]
|
|||
|
|
{
|
|||
|
|
Name,
|
|||
|
|
string.IsNullOrWhiteSpace(rejectReason) ? "оƬ<D0BE><C6AC><EFBFBD>Ͻ<EFBFBD><CFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܡ<EFBFBD>" : rejectReason
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
currentChipStateService.SetState(CurrentChipLifecycleState.Empty);
|
|||
|
|
autoProductionRuntimeStateService.SetCurrentChipRemainingCount(0);
|
|||
|
|
context.SetData(WorkflowContextKeys.PreparationAreaStatus, preparationAreaService.CurrentStatus);
|
|||
|
|
context.SetData(WorkflowContextKeys.CurrentChipState, CurrentChipLifecycleState.Empty);
|
|||
|
|
context.SetData(WorkflowContextKeys.PendingChipLoad, true);
|
|||
|
|
context.SetData(WorkflowContextKeys.CurrentChipRemainingCount, autoProductionRuntimeStateService.CurrentChipRemainingCount);
|
|||
|
|
return ActivityResult.Success;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private static string ResolveRecipeName(WorkflowContext context)
|
|||
|
|
{
|
|||
|
|
RecipeManager recipeManager;
|
|||
|
|
if (context.TryGetData<RecipeManager>(WorkflowContextKeys.RecipeManager, out recipeManager) &&
|
|||
|
|
recipeManager != null &&
|
|||
|
|
recipeManager.CurrentWaferRecipe != null)
|
|||
|
|
{
|
|||
|
|
return recipeManager.CurrentWaferRecipe.RecipeName;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return string.Empty;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private static string ResolveSourceStepId(WorkflowContext context)
|
|||
|
|
{
|
|||
|
|
string stepId;
|
|||
|
|
if (context.TryGetData<string>(WorkflowContextKeys.CurrentStepId, out stepId))
|
|||
|
|
{
|
|||
|
|
return stepId;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return string.Empty;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|