private void SetWorkflowInstanceStatus(Guid instanceId, WorkflowInstanceStatus workflowInstanceStatus, bool newlyCreateOrLoaded)
        {
            using (_resourceLocker.Locker)
            {
                var resources = _resourceLocker.Resources;

                Action releaseIdleWaitSemaphore = () =>
                {
                    if (resources.WorkflowIdleWaitSemaphores.TryGetValue(instanceId, out var semaphore))
                    {
                        semaphore.Release();
                        resources.WorkflowIdleWaitSemaphores.Remove(instanceId);
                    }
                };

                switch (workflowInstanceStatus)
                {
                case WorkflowInstanceStatus.Idle:
                    releaseIdleWaitSemaphore();

                    resources.WorkflowStatusDictionary[instanceId] = WorkflowInstanceStatus.Idle;

                    PersistFormData(instanceId);

                    break;

                case WorkflowInstanceStatus.Running:
                    resources.WorkflowStatusDictionary[instanceId] = WorkflowInstanceStatus.Running;
                    break;

                case WorkflowInstanceStatus.Terminated:
                    releaseIdleWaitSemaphore();
                    resources.WorkflowStatusDictionary.Remove(instanceId);
                    break;

                default:
                    throw new InvalidOperationException("This line should not be reachable.");
                }
            }

            string identity = UserValidationFacade.IsLoggedIn() ? UserValidationFacade.GetUsername() : "(system process)";

            Log.LogVerbose(LogTitle, $"Workflow instance status changed to {workflowInstanceStatus}. Id = {instanceId}, User = {identity}");
        }
Пример #2
0
        private void SetWorkflowInstanceStatus(Guid instanceId, WorkflowInstanceStatus workflowInstanceStatus, bool newlyCreateOrLoaded)
        {
            using (_resourceLocker.Locker)
            {
                var resources = _resourceLocker.Resources;

                string identity = UserValidationFacade.IsLoggedIn() ? UserValidationFacade.GetUsername() : "(system process)";

                Action releaseIdleWaitSemaphore = () =>
                {
                    if (resources.WorkflowIdleWaitSemaphores.ContainsKey(instanceId))
                    {
                        resources.WorkflowIdleWaitSemaphores[instanceId].Release();
                        resources.WorkflowIdleWaitSemaphores.Remove(instanceId);
                    }
                };

                switch (workflowInstanceStatus)
                {
                    case WorkflowInstanceStatus.Idle:
                        releaseIdleWaitSemaphore();

                        if (!resources.WorkflowStatusDictionary.ContainsKey(instanceId) && newlyCreateOrLoaded)
                        {
                            resources.WorkflowStatusDictionary.Add(instanceId, WorkflowInstanceStatus.Idle);
                        }

                        resources.WorkflowStatusDictionary[instanceId] = WorkflowInstanceStatus.Idle;                        

                        PersistFormData(instanceId);

                        break;

                    case WorkflowInstanceStatus.Running:
                        resources.WorkflowStatusDictionary[instanceId] = WorkflowInstanceStatus.Running;
                        break;

                    case WorkflowInstanceStatus.Terminated:
                        releaseIdleWaitSemaphore();
                        resources.WorkflowStatusDictionary.Remove(instanceId);
                        break;
                    default:
                        throw new InvalidOperationException("This line should not be reachable.");
                }

                Log.LogVerbose(LogTitle, "Workflow instance status changed to {0}. Id = {1}, User = {2}", workflowInstanceStatus, instanceId, identity);
            }
        }