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 List <WorkflowStateInfo> GetAvailiableWorkflowStateToSet(ApiCommandArgument arg) { var infos = new List <WorkflowStateInfo>(); AuthenticationService.Authenticate(arg.SecurityToken); if (!AuthenticationService.IsAuthenticated()) { return(infos); } if (!SecurityEntityService.CheckTrusteeWithIdIsInRole(AuthenticationService.GetCurrentIdentity().Id, BudgetRole.FullControl)) { var permissions = SecurityEntityService.GetAlPermissionsForTrusteeAndworkflow(arg.SecurityToken) .Where(p => p.LinkedStateToSet != null) .Select(p => p.LinkedStateToSet); if (permissions.Count() < 1) { return(infos); } infos = WorkflowStateService.GetAllAvailiableStates(arg.InstanceId) .Where(i => permissions.Count(p => p.WorkflowStateName == i.StateSystemName && p.Type.Id == i.WorkflowTypeId) > 0) .ToList(); } else { infos = WorkflowStateService.GetAllAvailiableStates(arg.InstanceId); } return(infos); }
public void ExportBillDemand(ApiCommandArgument arg) { AuthenticationService.Authenticate(arg.SecurityToken); if (!AuthenticationService.IsAuthenticated()) { return; } if (!AuthorizationService.IsAllowedToExecuteCommand(arg.InstanceId, WorkflowCommandType.Export)) { return; } FireCommandWithWaiting(arg, delegate(ApiCommandArgument arg1) { using (var sync = GetWorkflowSync(arg1)) { WorkflowInitService.RaiseExport(arg1.InstanceId); sync.WaitHandle.WaitOne(60000); } }); var state = WorkflowStateService.GetCurrentState(arg.InstanceId); if (state == WorkflowState.BillDemandInAccountingWithExport) { var errorMessage = WorkflowParcelService.GetAndRemoveMessage(arg.InstanceId); throw new FaultException <BaseFault>(new BaseFault((int)ErrorCodes.BillDemandUploadError), new FaultReason(string.IsNullOrEmpty(errorMessage) ? "Не удалось выгрузить расходный документ. Попробуйте провести данную операцию еще раз. Если сообщение будет повторятся, обратитесь к Администратору." : errorMessage)); } }
//TODO Вынести имперсонацию отсюда public List <WorkflowCommandType> IsAllowedToExecuteCommand(Guid instanceUid, List <WorkflowCommandType> commandsToCheck) { var allowedOperations = new List <WorkflowCommandType>(commandsToCheck.Count); WorkflowState currentState; try { currentState = WorkflowStateService.GetCurrentState(instanceUid); } catch (ArgumentException) { return(allowedOperations); } WorkflowType workflowType = currentState == null ? WorkflowStateService.TryGetExpectedWorkflowType(instanceUid) : currentState.Type; if (workflowType == null) { return(allowedOperations); } IAuthorizationValidator validator; try { var validatorFactory = new AuthorizationValidatorFactory(workflowType, this); validator = validatorFactory.CreateValidator(); } catch (ArgumentException) { return(allowedOperations); } var identities = GetAllIdentities(); if (AuthorizeAccessAndImpersonateIfNecessary(identities, validator, currentState, instanceUid)) { allowedOperations.AddRange(commandsToCheck.Where(commandToCheck => validator.IsCommandSupportsInState(currentState, commandToCheck, instanceUid))); } //Добавление дополнительных команд специфичных для вф и не привязанных к паре пользователь-состояние allowedOperations = validator.AddAdditionalCommand(AuthenticationService.GetCurrentIdentity(), identities, currentState, instanceUid, allowedOperations); return(allowedOperations); }
public List <WorkflowCommandType> GetListOfAllowedOperations(ApiCommandArgument arg) { var allowedOperations = new List <WorkflowCommandType>(); AuthenticationService.Authenticate(arg.SecurityToken); if (!AuthenticationService.IsAuthenticated()) { return(allowedOperations); } var commandsToCheck = new List <WorkflowCommandType>() { WorkflowCommandType.StartProcessing, WorkflowCommandType.Sighting, WorkflowCommandType.Denial, WorkflowCommandType.DenialByTechnicalCauses, WorkflowCommandType.PostingAccounting, WorkflowCommandType.CheckStatus, WorkflowCommandType.SetDenialStatus, WorkflowCommandType.SetPaidStatus, WorkflowCommandType.Export }; allowedOperations = AuthorizationService.IsAllowedToExecuteCommand(arg.InstanceId, commandsToCheck); if (!SecurityEntityService.CheckTrusteeWithIdIsInRole(AuthenticationService.GetCurrentIdentity().Id, BudgetRole.FullControl)) { var type = WorkflowStateService.TryGetExpectedWorkflowType(arg.InstanceId); if (SecurityEntityService.GetAlPermissionsForTrusteeAndworkflow(arg.SecurityToken) .Count(p => p.LinkedStateToSet != null && p.LinkedStateToSet.Type.Id == type.Id) > 0) { allowedOperations.Add(WorkflowCommandType.SetWorkflowState); } } else { allowedOperations.Add(WorkflowCommandType.SetWorkflowState); } return(allowedOperations); }
public void SetWorkflowState(Guid instanceId, ServiceIdentity serviceIdentity, string stateName, string comment) { var workflowState = WorkflowStateService.GetWorkflowState(instanceId); if (workflowState.WorkflowStateName != stateName || workflowState.IsInitial) //Для черновиков устанавливаем всегда это временно { WorkflowSupportService.TryUpgradeWorkflow(Runtime, instanceId); WorkflowParcelService.AddParcel(instanceId, new WorkflowSetStateParcel() { Comment = comment, InitiatorId = serviceIdentity.Id, Command = WorkflowCommand.Unknown, PreviousWorkflowState = workflowState }); bool isIdled = true; using (var sync = new WorkflowSync(Runtime, instanceId)) { if (!WorkflowSupportService.CreateWorkflowIfNotExists(Runtime, instanceId, workflowState.Type)) //Это ожидание создания воркфлоу { sync.WaitHandle.WaitOne(600000); isIdled = sync.WasIdled; } } //Если воркфлоу не стало идленым - то его необходимо удалить полностью и создать заново if (!isIdled) { using (var context = this.CreateContext()) { context.DeleteWorkflowInPesistenceStore(instanceId); context.SubmitChanges(); } using (var sync = new WorkflowSync(Runtime, instanceId)) { if (!WorkflowSupportService.CreateWorkflowIfNotExists(Runtime, instanceId, workflowState.Type)) //Это ожидание создания воркфлоу { sync.WaitHandle.WaitOne(600000); } } } var instance = new StateMachineWorkflowInstance(Runtime, instanceId); var newWorkflowState = WorkflowStateService.GetWorkflowState(instanceId); if (newWorkflowState.WorkflowStateName != stateName) { using (var sync = new WorkflowSync(Runtime, instanceId)) //Это ожидание завершения установки состояния воркфлоу { instance.SetState(stateName); sync.WaitHandle.WaitOne(600000); } } WorkflowState state = WorkflowState.AllStates.First( ws => ws.WorkflowStateName == stateName && ws.Type.Id == workflowState.Type.Id); if (!state.IsFinal && !state.IsInitial) { WorkflowSupportService.RewriteWorkflow(instanceId, state); } //Для РД удаляем историю согласования if (workflowState.Type == WorkflowType.BillDemandWorkfow) { if (state == WorkflowState.BillLimitManagerSighting) { BillDemandBuinessService.LimitExecutorResetSights(instanceId); } BillDemandBuinessService.LimitExecutorResetSights(instanceId); BillDemandBuinessService.LimitManagerResetSights(instanceId); } } }