public async Task AfterHandlerAsync <TAction>(IDispatchContext <TAction> context, IActionHandler <TAction> actionHandler, CancellationToken cancellationToken) where TAction : IAction { foreach (var hook in _afterActionHooks) { await hook.AfterHandlerAsync(context, actionHandler, cancellationToken); } }
public async Task BeforeHandlerAsync <TAction>(IDispatchContext <TAction> context, IAfterEffects <TAction> afterEffect, CancellationToken cancellationToken) where TAction : IAction { foreach (var hook in _beforeAfterEffectHooks) { await hook.BeforeHandlerAsync(context, afterEffect, cancellationToken); } }
public Task Notify(IDispatchContext context) { foreach (var operation in context.Operations) { Console.WriteLine($"Dispatched {operation.Message.MessageId} to {Read(operation.AddressTag)}"); } return(Task.CompletedTask); }
public async Task AfterReducerAsync <TAction, TState>(IDispatchContext <TAction> context, IState <TState> state, IReducer <TAction, TState> reducer, CancellationToken cancellationToken) where TAction : IAction where TState : StateBase { foreach (var hook in _afterReducerHooks) { await hook.AfterReducerAsync(context, state, reducer, cancellationToken); } }
// ReSharper disable once UnusedParameter.Local private static void AssertCanStartDispatch(IDispatchContext dispatchContext) { var currentDispatchId = GetCurrentDispatchContextId(); if (currentDispatchId != null) throw new InvalidOperationException("Dispatch {0} is already in progress in this Logical CallContext. Did you forget to Dispose it?" .FormatWith(currentDispatchId)); if (dispatchContext is InitialDispatchContext) throw new InvalidOperationException("Don't start a Dispatch with a {0}, use a new {1} instead." .FormatWith(typeof (InitialDispatchContext).Name, typeof (SubsequentDispatchContext).Name)); }
public async Task HandleAsync(IDispatchContext <TAction> context, CancellationToken cancellationToken) { foreach (var reducer in _reducers) { await _hooks.BeforeReducerAsync(context, _state, reducer, cancellationToken); _state.Set(reducer.Reduce(context.Action, _state.Current)); await _hooks.AfterReducerAsync(context, _state, reducer, cancellationToken); } _state.Notify(); }
public void WireDefaultRoutes <T>(IDispatchContext dispatchContext) where T : class, new() { //Register Queries dispatchContext.Register <IList <T> >(App.AppContext.Get, new Func <IList <T> >(this.Crud.Get <T>), GenericFeedback); dispatchContext.Register <T>(App.AppContext.GetById, new Func <string, T>(this.Crud.GetById <T>), GenericFeedback); //Register Command(s) dispatchContext.Register <T>(App.AppContext.Add, this.Crud.Add, App.AppContext.OnAdd, GenericFeedback); dispatchContext.Register <T>(App.AppContext.Update, this.Crud.UpdateById, App.AppContext.OnUpdate, GenericFeedback); dispatchContext.Register <IList <T> >(App.AppContext.UpdateAll, new Func <List <T>, IList <T> >(this.Crud.Update <T>), App.AppContext.OnUpdateAll, GenericFeedback); dispatchContext.Register <T>(App.AppContext.Remove, this.Crud.Remove, App.AppContext.OnRemove, GenericFeedback); }
public IDisposable StartNewDispatchContext(IDispatchContext dispatchContext) { AssertCanStartDispatch(dispatchContext); if (!_store.TryAdd(dispatchContext.DispatchId, (SubsequentDispatchContext) dispatchContext)) throw new InvalidOperationException("Cannot add duplicate {0} {1} to the {0} store." .FormatWith(typeof (SubsequentDispatchContext).Name, dispatchContext.DispatchId)); SetCurrentDispatchId(dispatchContext.DispatchId); return new DispatchContextWrapper(this, dispatchContext.DispatchId); }
public IDisposable StartNewDispatchContext(IDispatchContext dispatchContext) { AssertCanStartDispatch(dispatchContext); if (!_store.TryAdd(dispatchContext.DispatchId, (SubsequentDispatchContext)dispatchContext)) { throw new InvalidOperationException("Cannot add duplicate {0} {1} to the {0} store." .FormatWith(typeof(SubsequentDispatchContext).Name, dispatchContext.DispatchId)); } SetCurrentDispatchId(dispatchContext.DispatchId); return(new DispatchContextWrapper(this, dispatchContext.DispatchId)); }
// ReSharper disable once UnusedParameter.Local private static void AssertCanStartDispatch(IDispatchContext dispatchContext) { var currentDispatchId = GetCurrentDispatchContextId(); if (currentDispatchId != null) { throw new InvalidOperationException("Dispatch {0} is already in progress in this Logical CallContext. Did you forget to Dispose it?" .FormatWith(currentDispatchId)); } if (dispatchContext is InitialDispatchContext) { throw new InvalidOperationException("Don't start a Dispatch with a {0}, use a new {1} instead." .FormatWith(typeof(InitialDispatchContext).Name, typeof(SubsequentDispatchContext).Name)); } }
public async Task DispatchAsync <TAction>(IDispatchContext <TAction> dispatchContext, CancellationToken cancellationToken) where TAction : IAction { var interceptors = _serviceProvider.GetServices <IInterceptor <TAction> >().ToList(); foreach (var interceptor in interceptors) { if (dispatchContext.StopInterception) { break; } await _hooks.BeforeHandlerAsync(dispatchContext, interceptor, cancellationToken); await interceptor.InterceptAsync(dispatchContext, cancellationToken); await _hooks.AfterHandlerAsync(dispatchContext, interceptor, cancellationToken); } }
public async Task DispatchAsync <TAction>(IDispatchContext <TAction> dispatchContext, CancellationToken cancellationToken) where TAction : IAction { var reducerHandlers = _serviceProvider.GetServices <IActionHandler <TAction> >().ToList(); foreach (var handler in reducerHandlers) { if (dispatchContext.StopReduce) { break; } await _hooksCollection.BeforeHandlerAsync(dispatchContext, handler, cancellationToken); await handler.HandleAsync(dispatchContext, cancellationToken); await _hooksCollection.AfterHandlerAsync(dispatchContext, handler, cancellationToken); } }
public async Task DispatchAsync <TAction>(IDispatchContext <TAction> dispatchContext, CancellationToken cancellationToken) where TAction : IAction { var afterEffects = _serviceProvider.GetServices <IAfterEffects <TAction> >().ToList(); foreach (var afterEffect in afterEffects) { if (dispatchContext.StopAfterEffect) { break; } await _hooks.BeforeHandlerAsync(dispatchContext, afterEffect, cancellationToken); await afterEffect.HandleAfterEffectAsync(dispatchContext, cancellationToken); await _hooks.AfterHandlerAsync(dispatchContext, afterEffect, cancellationToken); } }
public static void DoFilter(AoEquipment eqp, IList <IHandlingBatch> wips, IDispatchContext ctx) { //if (eqp.EqpID == "THPHL700" && eqp.NowDT >= LcdHelper.StringToDateTime("20200115 073000")) // Console.WriteLine("B"); for (int i = wips.Count - 1; i >= 0; i--) { var hb = wips[i]; if (hb.HasContents) { var hbs = hb.Contents; for (int j = hbs.Count - 1; j >= 0; j--) { var lot = hbs[j] as FabLot; if (IsLoadable(eqp, lot) == false) { hbs.RemoveAt(j); continue; } } if (hb.Contents.Count == 0) { wips.RemoveAt(i); continue; } } else { if (IsLoadable(eqp, hb.ToFabLot()) == false) { wips.RemoveAt(i); continue; } } } }
/// <summary> /// </summary> /// <param name="dc"/> /// <param name="aeqp"/> /// <param name="wips"/> /// <param name="handled"/> public void UPDATE_CONTEXT0(IDispatchContext dc, AoEquipment aeqp, IList <IHandlingBatch> wips, ref bool handled) { //////20161122075408 //if (aeqp.EqpID == "8APPH02" && aeqp.NowDT == new DateTime(2016, 12, 12, 8, 42, 14)) // Console.WriteLine("T"); List <JobFilterInfo> joblist = dc.Get <List <JobFilterInfo> >(Constants.JobGroup, null); if (aeqp.Preset == null) { return; } double maxRequireEqp; if (WeightHelper.TryGetMaxRequiredEqp(aeqp, joblist, out maxRequireEqp)) { dc.Set(Constants.WF_MAX_REQUIRED_EQP_COUNT, maxRequireEqp); } LayerStats sts = WeightHelper.CalcLayerBalance(aeqp); dc.Set(Constants.WF_LAYER_BALANCE_PRIORITY, sts); //투입을 위한 waiting wip infomation(unpack 설비 ) Dictionary <string, WaitingWipInfo> waitingInfos = WeightHelper.SetWatingWipInfo(aeqp, joblist); dc.Set(Constants.WF_WAITING_WIP_INFO, waitingInfos); dc.Set(Constants.WF_MINMAX_VALUE_INFOS, WeightHelper.SetMinMaxVaule_WF(aeqp, joblist)); if (wips.Count > 0) { dc.Set(Constants.WF_LOT_PRIORITY, wips.Max(x => x.ToFabLot().Priority)); } DispatchLogHelper.InitLotLogDetail(wips); }
/// <summary> /// </summary> /// <param name="eqp"/> /// <param name="wips"/> /// <param name="ctx"/> /// <param name="handled"/> /// <param name="prevReturnValue"/> /// <returns/> public IList <Mozart.SeePlan.Simulation.IHandlingBatch> DO_FILTER1(Mozart.SeePlan.Simulation.AoEquipment eqp, IList <IHandlingBatch> wips, IDispatchContext ctx, ref bool handled, IList <IHandlingBatch> prevReturnValue) { #if DEBUG if (eqp.EqpID == "DA03") { Console.WriteLine(); } #endif return(wips); }
public static void DoGroupFilter(AoEquipment aeqp, IList <IHandlingBatch> wips, IDispatchContext ctx, List <IHandlingBatch> revaluation) { var eqp = aeqp.ToFabAoEquipment(); FilterHelper.BuildJobFilterInfo(eqp, wips, ctx); List <JobFilterInfo> list = ctx.Get <List <JobFilterInfo> >(Constants.JobGroup, null); if (list == null) { return; } EvaluateJobFilter(eqp, list); for (int i = wips.Count - 1; i >= 0; i--) { var hb = wips[i]; bool isRemove = false; if (hb.HasContents) { for (int j = hb.Contents.Count - 1; j >= 0; j--) { var lot = hb.Contents[j] as FabLot; if (DoGroupFilterMore(aeqp, lot, revaluation)) { hb.Contents.RemoveAt(j); continue; } } isRemove = hb.Contents.Count == 0; } else { isRemove = DoGroupFilterMore(eqp, hb.ToFabLot(), revaluation); } if (isRemove) { wips.RemoveAt(i); continue; } } }
internal static List <FabLot> WaitForPrevStepWip_Dummy(IDispatchContext ctx, FabAoEquipment eqp) { List <JobFilterInfo> jobList = ctx.Get <List <JobFilterInfo> >(Constants.JobGroup, null); if (jobList == null) { return(null); } FabPlanInfo last = eqp.GetLastPlan(); //eqp.LastPlan as FabPlanInfo; if (last == null) { return(null); } //if (eqp.EqpID == "THWEM200" && LcdHelper.StringToDateTime("20191021235617") <= eqp.NowDT) // Console.WriteLine(); JobState state = InFlowMaster.GetJobState(last.ProductID, last.OwnerType); if (state == null) { return(null); } var holdWips = state.GetHoldWipList(last.FabStep, last.ProductVersion); var prvRunWips = state.GetPrevStepRunWipList(last.FabStep, last.ProductVersion); JobFilterInfo minSetupJobFilter = null; List <JobFilterInfo> filteredList = new List <JobFilterInfo>(); Dictionary <string, JobFilterInfo> current = new Dictionary <string, JobFilterInfo>(); foreach (var info in jobList) { if (info.IsEmpty) { continue; } string key = FilterHelper.GetJobFilterKey(info); current.Add(key, info); if (FilterHelper.CheckIsRunning(eqp, info)) { filteredList.Add(info); continue; } if (info.FilterType != DispatchFilter.None) { filteredList.Add(info); continue; } if (info.SetupTime == 0) { continue; } if (minSetupJobFilter == null) { minSetupJobFilter = info; } if (minSetupJobFilter.SetupTime > info.SetupTime) { minSetupJobFilter = info; } } if (minSetupJobFilter == null) { return(null); } Dictionary <string, FabLot> avableLots = new Dictionary <string, FabLot>(); foreach (var lot in holdWips) { if (eqp.IsLastPlan(lot.CurrentShopID, last.StepID, lot.CurrentProductID, lot.CurrentProductVersion, lot.OwnerType, lot.OwnerID)) { continue; } string key = FilterHelper.GetJobFilterKey(lot.CurrentShopID, last.StepID, lot.CurrentProductID, lot.CurrentProductVersion, lot.OwnerType); if (current.ContainsKey(key)) { continue; } Time remainHold = lot.HoldTime - (eqp.NowDT - lot.HoldStartTime); float setupTime = SetupMaster.GetSetupTime(eqp, lot); if (remainHold.TotalMinutes + setupTime < minSetupJobFilter.SetupTime) { if (avableLots.ContainsKey(key) == false) { avableLots.Add(key, lot); } } } foreach (var lot in prvRunWips) { string lastShopID = last.ShopID; string lastStepID = last.StepID; string currProductID = lot.CurrentProductID; string origProductVersion = lot.OrigProductVersion; string ownerType = lot.OwnerType; string ownerID = lot.OwnerID; //TODO : bong - product version ?? if (eqp.IsLastPlan(lastShopID, lastStepID, currProductID, origProductVersion, ownerType, ownerID)) { continue; } string key = FilterHelper.GetJobFilterKey(lastShopID, lastStepID, currProductID, origProductVersion, ownerType); if (current.ContainsKey(key)) { continue; } Time tranferTime = TransferMaster.GetTransferTime(lot, eqp); Time setupTime = SetupMaster.GetSetupTime(eqp, lastShopID, lastStepID, currProductID, origProductVersion, ownerType, ownerID); if (tranferTime + setupTime < minSetupJobFilter.SetupTime) { if (avableLots.ContainsKey(key) == false) { avableLots.Add(key, lot); } } } Dictionary <string, List <FabAoEquipment> > workingEqps = ResHelper.GetWorkingEqpInfos(eqp, true); List <FabLot> list = new List <FabLot>(); foreach (var lot in avableLots.Values) { FabPlanInfo plan = EntityControl.Instance.CreateLoadInfo(lot, last.Step) as FabPlanInfo; FabLot dummy = CreateHelper.CreateDispatchDummyLot(last.FabStep, plan); dummy.LotID = "DUMMY_PREVSTEP"; JobFilterInfo jobfilter = CreateHelper.CreateDispatchFilterInfo(last.Step as FabStep, lot.CurrentProductID, lot.OrigProductVersion, lot.OwnerType, lot.OwnerID); jobfilter.InitJobFilterInfo(eqp, workingEqps); jobfilter.LotList.Add(dummy); dummy.DispatchFilterInfo = jobfilter; list.Add(dummy); } return(list); }
public WeightValue CU_DENSITY_3402(ISimEntity entity, DateTime now, ActiveObject target, WeightFactor factor, IDispatchContext ctx) { if (factor.Factor == 0) { return(new WeightValue(0)); } FabAoEquipment eqp = target as FabAoEquipment; FabLot lot = entity as FabLot; FabStep step = lot.CurrentFabStep; string targetStep = "3402"; int limitDensity = (int)factor.Criteria[0]; if (limitDensity == 0) { return(new WeightValue(0)); } float currDensity = eqp.AcidDensity == null ? 0 : eqp.AcidDensity.CurrentAcid; string desc = string.Format("[Density:{0}, Limit:{1}]", currDensity, limitDensity); float score = 0f; if (step.StepID == targetStep && currDensity < limitDensity) { score = 1f; } return(new WeightValue(score * factor.Factor, desc)); }
public WeightValue SMALL_LOT(ISimEntity entity, DateTime now, ActiveObject target, WeightFactor factor, IDispatchContext ctx) { if (factor.Factor == 0) { return(new WeightValue(0)); } FabAoEquipment eqp = target as FabAoEquipment; FabLot lot = entity as FabLot; int smallSize = (int)factor.Criteria[0]; if (smallSize == 0) { return(new WeightValue(0)); } int stepCount = (int)factor.Criteria[1]; if (stepCount == 0) { return(new WeightValue(0)); } var job = InFlowMaster.GetJobState(lot); if (job == null) { return(new WeightValue(0)); } int currentUnitQty = lot.UnitQty; string shopID = lot.CurrentShopID; string productID = lot.CurrentProductID; string productVer = lot.CurrentProductVersion; bool isLastPlan = ResHelper.IsLastPlan(eqp, lot); float score = 0f; if (isLastPlan) { score = 1f; } FabStep step = lot.CurrentFabStep; string stepType = step.StepType; int cnt = 0; int runQty = 0; int waitQty = 0; int total = 0; while (cnt < stepCount) { List <FabStep> preSteps = step.GetPrevSteps(productID); List <FabLot> runWips = job.GetPrevStepWipList(step, WipType.Run, productVer); List <FabLot> waitWips = job.GetPrevStepWipList(step, WipType.Wait, productVer); if (runWips.Count <= 0 && waitWips.Count <= 0) { cnt++; continue; } int prevRunQty = runWips.Sum(x => x.UnitQty); int preWaitQty = waitWips.Sum(x => x.UnitQty); runQty += prevRunQty; waitQty += preWaitQty; total += runQty + waitQty; foreach (FabStep prevStep in preSteps) { if (prevStep.StepType == "MAIN") { step = prevStep; } if (step == null) { continue; } } cnt++; } int compareQty = currentUnitQty + total; string desc = string.Format("[SmallSize:{0}, CompareQty:{1}, IsLast:{2}]", smallSize, compareQty, isLastPlan); if (compareQty > smallSize) { score = 1f; } return(new WeightValue(score * factor.Factor, desc)); }
public IList <IHandlingBatch> SORT_LOT_GROUP_CONTENTS1(DispatcherBase db, IList <IHandlingBatch> list, IDispatchContext ctx, ref bool handled, IList <IHandlingBatch> prevReturnValue) { list.QuickSort(LotGroupSorter); return(list); }
public WeightValue OWNER_TYPE_PRIORITY(ISimEntity entity, DateTime now, ActiveObject target, WeightFactor factor, IDispatchContext ctx) { if (factor.Factor == 0) { return(new WeightValue(0)); } FabLot lot = entity as FabLot; float score = 0f; string desc = string.Empty; string ownerType = lot.OwnerType; if (factor.Criteria != null && factor.Criteria.Length > 0) { string[] types = (string[])factor.Criteria; if (types.Length > 0) { if (ownerType == types[0]) { score = 1f; } } if (types.Length > 1) { if (ownerType == types[1]) { score = 0.5f; } } if (types.Length > 2) { if (ownerType == types[2]) { score = 0f; } } } return(new WeightValue(score * factor.Factor, desc)); }
public WeightValue ALLOW_RUN_DOWN_TIME(ISimEntity entity, DateTime now, ActiveObject target, WeightFactor factor, IDispatchContext ctx) { FabAoEquipment eqp = target as FabAoEquipment; FabLot lot = entity as FabLot; var wf = WeightHelper.GetWeightFactor(eqp.Target.Preset, Constants.WF_ALLOW_RUN_DOWN_TIME); if (wf == null || wf.Factor == 0) { return(new WeightValue(0)); } decimal inflowHour = (decimal)wf.Criteria[0]; var idleTime = eqp.GetIdleRunTime(); decimal adjustHour = inflowHour - Convert.ToDecimal(idleTime.TotalHours); if (adjustHour < 0) { return(new WeightValue(0)); } var inflowQty = InFlowMaster.GetAllowRunDownWip(eqp, lot.CurrentProductID, lot.OrigProductVersion, lot.OwnerType, lot.CurrentStep as FabStep, adjustHour); float score = 0f; if (inflowQty > 0) { score = 1f; } string desc = string.Format("[inflow:{0}]", inflowQty); return(new WeightValue(score * factor.Factor, desc)); }
public static void Clear() { _receivedMessageProperties = null; _receivedDispatchContext = null; }
public async Task Handle(SomeOtherCommand busCommand) { _receivedMessageProperties = MessageProperties; _receivedDispatchContext = DispatchContext; MethodCallCounter.ForInstance(BusId).RecordCall <SomeOtherCommandHandler>(ch => ch.Handle(busCommand)); }
public static void BuildJobFilterInfo(AoEquipment eqp, IList <IHandlingBatch> wips, IDispatchContext ctx) { if (eqp.Dispatcher is FifoDispatcher) { return; } List <JobFilterInfo> joblist = FilterHelper.CreateJobList(eqp, wips); ctx.Set(Constants.JobGroup, joblist); }
/// <summary> /// </summary> /// <param name="db"/> /// <param name="wips"/> /// <param name="ctx"/> /// <param name="handled"/> /// <param name="prevReturnValue"/> /// <returns/> public IList <IHandlingBatch> EVALUATE0(DispatcherBase db, IList <IHandlingBatch> wips, IDispatchContext ctx, ref bool handled, IList <IHandlingBatch> prevReturnValue) { try { wips.QuickSort(new ComparerHelper.LotCompare()); return(wips); } catch (Exception e) { WriteHelper.WriteErrorHistory(ErrorLevel.FATAL, string.Format("ErrorMessage : {0} MethodName : {1}", e.Message, System.Reflection.MethodInfo.GetCurrentMethod().Name)); return(default(IList <IHandlingBatch>)); } }
public WeightValue NEXT_STEP_RUN_PRIORITY(ISimEntity entity, DateTime now, ActiveObject target, WeightFactor factor, IDispatchContext ctx) { if (factor.Factor == 0) { return(new WeightValue(0)); } float criteria0 = WeightHelper.GetCriteria(factor, 0, 0.5f); FabAoEquipment eqp = target as FabAoEquipment; FabLot lot = entity as FabLot; FabStep nextStep = BopHelper.GetNextMandatoryStep(lot); float score = 0f; int workingCnt = 0; int adv = 0; if (nextStep != null && nextStep.IsMandatoryStep) { bool checkProductVersion = true; var workingEqps = nextStep.StdStep.GetWorkingEqpList(lot, checkProductVersion); //checkProductVersion = false if (workingEqps == null || workingEqps.Count == 0) { checkProductVersion = false; workingEqps = nextStep.StdStep.GetWorkingEqpList(lot, checkProductVersion); } workingCnt = workingEqps == null ? 0 : workingEqps.Count; if (workingCnt > 0) { score = checkProductVersion ? 1f : criteria0; } var hasDummy = workingEqps.Find(t => t.IsDummyWait) != null; if (hasDummy) { adv = 2; score *= adv; } } string nextStepID = nextStep != null ? nextStep.StepID : Constants.NULL_ID; string desc = string.Format("[Next:{0}, Working:{1}, Adv:{2}]", nextStepID, workingCnt, adv); return(new WeightValue(score * factor.Factor, desc)); }