private void TryExportBillDemand(MultipleExportBillDemandState multipleExportBillDemandState) { if (!multipleExportBillDemandState.BillDemandBusinessService.CheckPaymentPlanFilled(multipleExportBillDemandState.InstanceId)) { AddPaymentPlanNotSelectedResult(multipleExportBillDemandState); } else { try { RaiseExportBillDemand(multipleExportBillDemandState); if (WorkflowStateService.GetCurrentState(multipleExportBillDemandState.InstanceId) == WorkflowState.BillDemandInAccountingWithExport) { AddErrorResult(multipleExportBillDemandState); } else { AddOkResult(multipleExportBillDemandState); } } catch (Exception ex) { AddErrorResult(multipleExportBillDemandState); } } }
public IEnumerable <CommandExecutionStatus> MassExportBillDemands(ApiMassCommandEventArg arg) { AuthenticationService.Authenticate(arg.SecurityToken); if (!AuthenticationService.IsAuthenticated()) { return(GetErrorExecutionStatuses(arg)); } if (!AuthorizationService.IsAllowedToExecuteCommand(arg.InstanceIds, WorkflowCommandType.Export)) { GetErrorExecutionStatuses(arg); } var states = new MultiThreadedPersistance <CommandExecutionStatus>(); var handles = new List <WaitHandle>(); foreach (var instanceId in arg.InstanceIds) { var handle = new AutoResetEvent(false); handles.Add(handle); var state = new MultipleExportBillDemandState { InstanceId = instanceId, States = states, WaitHandle = handle, BillDemandBusinessService = BillDemandBuinessService, Identity = AuthenticationService.GetCurrentIdentity(), Comment = arg.Comment }; ThreadPool.QueueUserWorkItem(RaiseBillDemandExportTask, state); } WaitHandle.WaitAll(handles.ToArray(), new TimeSpan(0, 0, 10, 0)); return(states.Items); }
private void AddPaymentPlanNotSelectedResult(MultipleExportBillDemandState multipleExportBillDemandState) { multipleExportBillDemandState.States.AddItem(new CommandExecutionStatus() { InstanceId = multipleExportBillDemandState.InstanceId, Result = CommandExecutionResult.BillDemandExportPaymentPlanNotSelected }); }
private void RaiseExportBillDemand(MultipleExportBillDemandState multipleExportBillDemandState) { FireCommandWithWaiting(multipleExportBillDemandState.InstanceId, delegate(Guid arg1) { using ( var sync = GetWorkflowSync( arg1)) { WorkflowInitService. RaiseExport(arg1, multipleExportBillDemandState.Identity); sync.WaitHandle.WaitOne (60000); } }, arg2 => arg2); }