private IEnumerable <CommandExecutionStatus> ExecuteMassCommand(IMassCommand 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 MultipleExportState { InstanceId = instanceId, States = states, WaitHandle = handle, AuthorizationService = AuthorizationService, Identity = AuthenticationService.GetCurrentIdentity(), Comment = arg.Comment, CommandToExecute = arg.Command, StateToSet = (arg is IContainsStateName) ? (arg as IContainsStateName).StateNameToSet : null }; ThreadPool.QueueUserWorkItem(RaiseCommandTask, state); } WaitHandle.WaitAll(handles.ToArray(), new TimeSpan(0, 0, 10, 0)); return(states.Items); }
private void AddErrorResult(MultipleExportState multipleExportState) { multipleExportState.States.AddItem(new CommandExecutionStatus() { InstanceId = multipleExportState.InstanceId, Result = CommandExecutionResult.Error }); }
private void RaiseAction(MultipleExportState multipleExportState, Action <Guid, ServiceIdentity> action) { FireCommandWithWaiting(multipleExportState.InstanceId, delegate(Guid arg1) { using (var sync = GetWorkflowSync(arg1)) { action.Invoke(arg1, multipleExportState.Identity); sync.WaitHandle.WaitOne(60000); } }, arg2 => arg2); }
private void RaiseSetStateAction(MultipleExportState multipleExportState) { FireCommandWithWaiting(multipleExportState.InstanceId, delegate(Guid arg1) { using (var sync = GetWorkflowSync(arg1)) { WorkflowInitService.SetWorkflowState(arg1, multipleExportState.Identity, multipleExportState.StateToSet, multipleExportState.Comment); sync.WaitHandle.WaitOne(60000); } }, arg2 => arg2); }
private void TryRaiseCommand(MultipleExportState multipleExportState) { if (multipleExportState.CommandToExecute != WorkflowCommandType.SetWorkflowState && !multipleExportState.AuthorizationService.IsAllowedToExecuteCommand(multipleExportState.InstanceId, multipleExportState.CommandToExecute)) { AddErrorResult(multipleExportState); } else { try { switch (multipleExportState.CommandToExecute) { case WorkflowCommandType.Sighting: RaiseAction(multipleExportState, WorkflowInitService.RaiseSighting); break; case WorkflowCommandType.StartProcessing: WorkflowInitService.CreateWorkflowIfNotExists(multipleExportState.InstanceId); using (var sync = GetWorkflowSync(multipleExportState.InstanceId)) { sync.WaitHandle.WaitOne(4000); } RaiseAction(multipleExportState, WorkflowInitService.RaiseStartProcessing); break; case WorkflowCommandType.Denial: RaiseActionWithComment(multipleExportState, WorkflowInitService.RaiseDenial); break; case WorkflowCommandType.Rollback: RaiseActionWithComment(multipleExportState, WorkflowInitService.RaiseRollback); break; case WorkflowCommandType.SetWorkflowState: RaiseSetStateAction(multipleExportState); break; default: throw new ActionNotSupportedException(); } } catch (Exception ex) { AddErrorResult(multipleExportState); throw; } AddOkResult(multipleExportState); } }