public void RaiseCheckStatus(Guid instanceId)
        {
            WorkflowSupportService.UpgradeWorkflow(Runtime, instanceId);
            var serviceIdentity = AuthenticationService.GetCurrentIdentity();

            BillDemandWorkflowService.RaiseCheckStatus(new WorkflowEventArgsWithInitiator(instanceId, serviceIdentity.Id, serviceIdentity.ImpersonatedId));
        }
 public void RaiseRollback(Guid instanceId, ServiceIdentity serviceIdentity, string comment)
 {
     WorkflowSupportService.UpgradeWorkflow(Runtime, instanceId);
     Rollback(null, new DenialCommandEventArgs(instanceId, serviceIdentity.Id, serviceIdentity.ImpersonatedId)
     {
         Comment = comment
     });
 }
        public void RaiseSetPaidStatus(Guid instanceId, DateTime?paymentDate, string documentNumber)
        {
            WorkflowSupportService.UpgradeWorkflow(Runtime, instanceId);
            var serviceIdentity = AuthenticationService.GetCurrentIdentity();

            BillDemandWorkflowService.RaiseSetPaidStatus(new PaidCommandEventArgs(instanceId, serviceIdentity.Id, serviceIdentity.ImpersonatedId)
            {
                DocumentNumber = documentNumber, PaymentDate = paymentDate
            });
        }
        public void RaiseDenial(Guid instanceId, ServiceIdentity serviceIdentity, string comment)
        {
            WorkflowSupportService.UpgradeWorkflow(Runtime, instanceId);
            var args = new DenialCommandEventArgs(instanceId, serviceIdentity.Id, serviceIdentity.ImpersonatedId)
            {
                Comment = comment
            };

            Denial(null, args);
        }
        public void RaiseExport(Guid instanceId)
        {
            if (!BillDemandBuinessService.IsBillDemandSupportExport(instanceId))
            {
                throw new ImpossibleToExecuteCommandException("Отправка документа в систему \"ФУС БОСС\" невозможна, т.к. в договоре контрагент заказчик указан не наш банк!");
            }
            WorkflowSupportService.UpgradeWorkflow(Runtime, instanceId);
            var serviceIdentity = AuthenticationService.GetCurrentIdentity();

            BillDemandWorkflowService.RaiseExport(new WorkflowEventArgsWithInitiator(instanceId, serviceIdentity.Id, serviceIdentity.ImpersonatedId));
        }
        public void RaiseSetDenialStatus(Guid instanceId, string comment)
        {
            WorkflowSupportService.UpgradeWorkflow(Runtime, instanceId);
            var serviceIdentity = AuthenticationService.GetCurrentIdentity();
            var args            = new DenialCommandEventArgs(instanceId, serviceIdentity.Id, serviceIdentity.ImpersonatedId)
            {
                Comment = comment
            };

            BillDemandWorkflowService.RaiseSetDenialStatus(args);
        }
        public void RaiseDenialByTechnicalCauses(Guid instanceId, string comment)
        {
            WorkflowSupportService.UpgradeWorkflow(Runtime, instanceId);
            var serviceIdentity = AuthenticationService.GetCurrentIdentity();
            var args            = new DenialCommandEventArgs(instanceId, serviceIdentity.Id, serviceIdentity.ImpersonatedId)
            {
                Comment = comment
            };

            DenialByTechnicalCauses(null, args);
        }
        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);
                }
            }
        }
 public void CreateWorkflowIfNotExists(Guid instanceId)
 {
     WorkflowSupportService.CreateWorkflowIfNotExists(Runtime, instanceId);
 }
 public void RaiseSighting(Guid instanceId, ServiceIdentity serviceIdentity)
 {
     WorkflowSupportService.UpgradeWorkflow(Runtime, instanceId);
     Sighting(null, new WorkflowEventArgsWithInitiator(instanceId, serviceIdentity.Id, serviceIdentity.ImpersonatedId));
 }