Beispiel #1
0
        private ProcessInstance UpdateScheme(Guid processId, ProcessInstance processInstance)
        {
            if (processInstance.CurrentActivity.IsAutoSchemeUpdate && (processInstance.IsSchemeObsolete || processInstance.IsDeterminingParametersChanged) &&
                OnNeedDeterminingParameters != null)
            {
                try
                {
                    SetProcessNewStatus(processInstance, ProcessStatus.Running);
                    processInstance = Builder.GetProcessInstance(processId);
                    PersistenceProvider.FillSystemProcessParameters(processInstance);

                    var isSchemeObsolete = processInstance.IsSchemeObsolete;
                    var isDeterminingParametersChanged = processInstance.IsDeterminingParametersChanged;

                    if (processInstance.CurrentActivity.IsAutoSchemeUpdate && (isSchemeObsolete || isDeterminingParametersChanged) &&
                        OnNeedDeterminingParameters != null)
                    {
                        var args = new NeedDeterminingParametersEventArgs {
                            ProcessId = processId
                        };
                        OnNeedDeterminingParameters(this, args);
                        if (args.DeterminingParameters == null)
                        {
                            args.DeterminingParameters = new Dictionary <string, IEnumerable <object> >();
                        }

                        processInstance = Builder.CreateNewProcessScheme(processId, processInstance.ProcessScheme.Name,
                                                                         args.DeterminingParameters);
                        PersistenceProvider.BindProcessToNewScheme(processInstance, true);
                        if (OnSchemaWasChanged != null)
                        {
                            OnSchemaWasChanged(this,
                                               new SchemaWasChangedEventArgs
                            {
                                DeterminingParametersWasChanged = isDeterminingParametersChanged,
                                ProcessId         = processId,
                                SchemeId          = processInstance.SchemeId,
                                SchemaWasObsolete = isSchemeObsolete
                            });
                        }
                        PersistenceProvider.FillSystemProcessParameters(processInstance);
                    }
                }
                finally
                {
                    SetProcessNewStatus(processInstance, ProcessStatus.Idled);
                }
            }
            return(processInstance);
        }
Beispiel #2
0
 private static void _runtime_OnNeedDeterminingParameters(object sender, NeedDeterminingParametersEventArgs e)
 {
     var budgetItem =
         DynamicRepository.GetByEntity("BudgetItem", FilterCriteriaSet.And.Equal(e.ProcessId, "Id"))
             .FirstOrDefault();
     if (budgetItem != null)
     {
         e.DeterminingParameters = new Dictionary<string, object> {{"EntityRouteId", budgetItem.EntityRouteId}};
     }
 }
Beispiel #3
0
        private ProcessInstance UpdateScheme(Guid processId, ProcessInstance processInstance)
        {
            if (processInstance.CurrentActivity.IsAutoSchemeUpdate && (processInstance.IsSchemeObsolete || processInstance.IsDeterminingParametersChanged) &&
                OnNeedDeterminingParameters != null)
            {
                try
                {
                    SetProcessNewStatus(processInstance, ProcessStatus.Running);
                    processInstance = Builder.GetProcessInstance(processId);
                    PersistenceProvider.FillSystemProcessParameters(processInstance);

                    var isSchemeObsolete = processInstance.IsSchemeObsolete;
                    var isDeterminingParametersChanged = processInstance.IsDeterminingParametersChanged;

                    if (processInstance.CurrentActivity.IsAutoSchemeUpdate && (isSchemeObsolete || isDeterminingParametersChanged) &&
                        OnNeedDeterminingParameters != null)
                    {
                        var args = new NeedDeterminingParametersEventArgs { ProcessId = processId };
                        OnNeedDeterminingParameters(this, args);
                        if (args.DeterminingParameters == null)
                            args.DeterminingParameters = new Dictionary<string, IEnumerable<object>>();

                        processInstance = Builder.CreateNewProcessScheme(processId, processInstance.ProcessScheme.Name,
                                                                          args.DeterminingParameters);
                        PersistenceProvider.BindProcessToNewScheme(processInstance,true);
                        if (OnSchemaWasChanged != null)
                            OnSchemaWasChanged(this,
                                               new SchemaWasChangedEventArgs
                                                   {
                                                       DeterminingParametersWasChanged = isDeterminingParametersChanged,
                                                       ProcessId = processId,
                                                       SchemeId = processInstance.SchemeId,
                                                       SchemaWasObsolete = isSchemeObsolete
                                                   });
                        PersistenceProvider.FillSystemProcessParameters(processInstance);
                    }
                }
                finally
                {
                    SetProcessNewStatus(processInstance, ProcessStatus.Idled);
                }
            }
            return processInstance;
        }
Beispiel #4
0
        private ProcessInstance UpdateScheme(ProcessInstance processInstance, IDictionary<string, object> parameters = null)
        {
            ProcessDefinition processDefinition;
            ProcessDefinition processScheme;
            ProcessInstance processInstance1;
            string str;
            if (!processInstance.CurrentActivity.IsAutoSchemeUpdate || !processInstance.IsSchemeObsolete && !processInstance.IsDeterminingParametersChanged)
            {
                return processInstance;
            }
            List<SchemaWasChangedEventArgs> schemaWasChangedEventArgs = new List<SchemaWasChangedEventArgs>();
            bool flag = false;
            try
            {
                this.SetProcessNewStatus(processInstance, ProcessStatus.Running);
                ProcessInstancesTree processInstancesTree = this.GetProcessInstancesTree(processInstance);
                ProcessInstancesTree nodeById = processInstancesTree.GetNodeById(processInstance.ProcessId, true);
                if (parameters == null)
                {
                    NeedDeterminingParametersEventArgs needDeterminingParametersEventArg = new NeedDeterminingParametersEventArgs()
                    {
                        ProcessId = processInstance.RootProcessId
                    };
                    if (this.OnNeedDeterminingParameters != null)
                    {
                        this.OnNeedDeterminingParameters(this, needDeterminingParametersEventArg);
                    }
                    if (needDeterminingParametersEventArg.DeterminingParameters == null)
                    {
                        needDeterminingParametersEventArg.DeterminingParameters = new Dictionary<string, object>();
                    }
                    parameters = needDeterminingParametersEventArg.DeterminingParameters;
                }
                str = (string.IsNullOrEmpty(processInstance.ProcessScheme.RootSchemeCode) ? processInstance.ProcessScheme.Name : processInstance.ProcessScheme.RootSchemeCode);
                ProcessDefinition processDefinition1 = this.Builder.CreateNewProcessScheme(str, parameters);
                if (processInstance.IsSubprocess)
                {
                    string name = nodeById.Name;
                    TransitionDefinition transitionDefinition = null;
                    try
                    {
                        transitionDefinition = processDefinition1.FindTransition(name);
                    }
                    catch (TransitionNotFoundException transitionNotFoundException)
                    {
                    }
                    ProcessInstance processInstance2 = this.Builder.GetProcessInstance(processInstancesTree.Root.Id);
                    processScheme = processInstance2.ProcessScheme;
                    if (transitionDefinition == null)
                    {
                        if (this.OnStartingTransitionNotFound == null)
                        {
                            this.DropProcesses(new List<Guid>()
							{
								processInstance.ProcessId
							}, processInstancesTree);
                            this.SaveProcessInstancesTree(processInstancesTree);
                            flag = true;
                            processInstance1 = null;
                            return processInstance1;
                        }
                        else
                        {
                            StartingTransitionNotFoundEventArgs startingTransitionNotFoundEventArg = new StartingTransitionNotFoundEventArgs(processInstance.ProcessId, processInstancesTree.Root.Id, processScheme, processDefinition1, name);
                            this.OnStartingTransitionNotFound(this, startingTransitionNotFoundEventArg);
                            if (startingTransitionNotFoundEventArg.Decision == StartingTransitionNotFoundEventArgs.SubprocessUpdateDecision.DropProcess)
                            {
                                this.DropProcesses(new List<Guid>()
								{
									processInstance.ProcessId
								}, processInstancesTree);
                                this.SaveProcessInstancesTree(processInstancesTree);
                                flag = true;
                                processInstance1 = null;
                                return processInstance1;
                            }
                            else if (startingTransitionNotFoundEventArg.Decision == StartingTransitionNotFoundEventArgs.SubprocessUpdateDecision.Ignore)
                            {
                                processInstance1 = processInstance;
                                return processInstance1;
                            }
                            else if (startingTransitionNotFoundEventArg.Decision == StartingTransitionNotFoundEventArgs.SubprocessUpdateDecision.StartWithNewTransition)
                            {
                                transitionDefinition = processDefinition1.FindTransition(startingTransitionNotFoundEventArg.NewTransitionName);
                            }
                        }
                    }
                    processDefinition = this.Builder.CreateNewSubprocessScheme(processDefinition1, transitionDefinition);
                }
                else
                {
                    processScheme = processInstance.ProcessScheme;
                    processDefinition = processDefinition1;
                }
                this.BindProcessToNewScheme(processInstance, processDefinition, schemaWasChangedEventArgs);
                this.UpdateChildrenSchemes(nodeById, processScheme, processDefinition1, schemaWasChangedEventArgs);
                this.SaveProcessInstancesTree(nodeById);
                if (this.OnSchemaWasChanged != null)
                {
                    foreach (SchemaWasChangedEventArgs schemaWasChangedEventArg in schemaWasChangedEventArgs)
                    {
                        this.OnSchemaWasChanged(this, schemaWasChangedEventArg);
                    }
                }
                this.PersistenceProvider.FillProcessParameters(processInstance);
                return processInstance;
            }
            finally
            {
                if (!flag)
                {
                    this.SetIdledStatusAfterSchemaUpdated(processInstance);
                }
            }
            return processInstance1;
        }