예제 #1
0
		private void AddSerializableObject(ProcessInstancesTree processTree, List<dynamic> items)
		{
			SerializableSubprocessTree serializableSubprocessTree = new SerializableSubprocessTree()
			{
				Id = processTree.Id,
				Name = processTree.Name,
				Children = (
					from c in processTree.Children
					select c.Id).Distinct<Guid>().ToList<Guid>()
			};
			items.Add(serializableSubprocessTree);
			foreach (ProcessInstancesTree child in processTree.Children)
			{
				this.AddSerializableObject(child, items);
			}
		}
예제 #2
0
		public static ProcessInstancesTree RestoreFromSerializableObject(List<SerializableSubprocessTree> objects, WorkflowRuntime runtime)
		{
			Dictionary<Guid, ProcessInstancesTree> guids = new Dictionary<Guid, ProcessInstancesTree>();
			foreach (SerializableSubprocessTree @object in objects)
			{
				ProcessInstancesTree processInstancesTree = new ProcessInstancesTree(@object.Id, @object.Name);
				guids.Add(processInstancesTree.Id, processInstancesTree);
			}
			foreach (SerializableSubprocessTree serializableSubprocessTree in objects)
			{
				if (!serializableSubprocessTree.Children.Any<Guid>())
				{
					continue;
				}
				ProcessInstancesTree ıtem = guids[serializableSubprocessTree.Id];
				foreach (Guid child in serializableSubprocessTree.Children)
				{
					ıtem.AddChild(guids[child]);
				}
			}
			if (!guids.Any<KeyValuePair<Guid, ProcessInstancesTree>>())
			{
				return null;
			}
			return guids.First<KeyValuePair<Guid, ProcessInstancesTree>>().Value.Root;
		}
예제 #3
0
		public void AddChild(ProcessInstancesTree instancesTree)
		{
			instancesTree.Parent = this;
			this._children.AddOrUpdate(instancesTree.Id, instancesTree, (Guid k, ProcessInstancesTree v) => v);
		}
예제 #4
0
 private void DropProcesses(List<Guid> ids, ProcessInstancesTree processInstancesTree)
 {
     if (!ids.Any<Guid>())
     {
         return;
     }
     List<Guid> guids = new List<Guid>();
     foreach (Guid id in ids)
     {
         guids.Add(id);
         ProcessInstancesTree nodeById = processInstancesTree.GetNodeById(id, true);
         List<Guid> allChildrenIds = nodeById.GetAllChildrenIds(1, null);
         if (allChildrenIds.Any<Guid>())
         {
             guids.AddRange(allChildrenIds);
         }
         nodeById.Remove();
     }
     Guid[] array = guids.Distinct<Guid>().ToArray<Guid>();
     this.PersistenceProvider.DeleteProcess(array);
 }
예제 #5
0
		public void RemoveChild(ProcessInstancesTree instancesTree)
		{
			ProcessInstancesTree processInstancesTree;
			instancesTree.Parent = null;
			this._children.TryRemove(instancesTree.Id, out processInstancesTree);
		}
예제 #6
0
 private void CreateSubprocesses(ProcessInstance processInstance, List<TransitionDefinition> transitions, ProcessInstancesTree processInstancesTree = null)
 {
     Guid rootProcessId = processInstance.RootProcessId;
     if (processInstancesTree == null)
     {
         processInstancesTree = this.GetProcessInstancesTree(rootProcessId);
     }
     foreach (TransitionDefinition transition in transitions)
     {
         this.CreateSubprocess(processInstance, transition, processInstancesTree);
     }
 }
예제 #7
0
 private void DeleteProcessInstancesTree(ProcessInstancesTree tree)
 {
     IPersistenceProvider persistenceProvider = this.PersistenceProvider;
     Guid ıd = tree.Root.Id;
     persistenceProvider.DeleteGlobalParameters("ProcessTree", ıd.ToString("N"));
 }
예제 #8
0
 private void CreateSubprocess(ProcessInstance parentProcessInstance, TransitionDefinition startTransition, ProcessInstancesTree processInstancesTree)
 {
     Guid processId = parentProcessInstance.ProcessId;
     Guid guid = Guid.NewGuid();
     ProcessInstancesTree nodeById = processInstancesTree.GetNodeById(processId, true);
     if (nodeById.HaveChildWithName(startTransition.Name))
     {
         return;
     }
     ProcessInstancesTree processInstancesTree1 = new ProcessInstancesTree(guid, startTransition.Name);
     nodeById.AddChild(processInstancesTree1);
     this.SaveProcessInstancesTree(nodeById);
     try
     {
         ProcessInstance processInstance = this.Builder.CreateNewSubprocess(guid, parentProcessInstance, startTransition);
         this.InitCreatedProcess(processInstance.IdentityId, processInstance.ImpersonatedIdentityId, processInstance, processInstancesTree1);
     }
     catch (Exception exception)
     {
         nodeById.RemoveChild(processInstancesTree1);
         throw;
     }
 }
예제 #9
0
        private void UpdateChildrenSchemes(ProcessInstancesTree currentNode, ProcessDefinition oldRootScheme, ProcessDefinition newRootScheme, List<SchemaWasChangedEventArgs> changes)
        {
            if (!currentNode.Children.Any<ProcessInstancesTree>())
            {
                return;
            }
            foreach (ProcessInstancesTree child in currentNode.Children)
            {
                ProcessInstance processInstance = this.Builder.GetProcessInstance(child.Id);
                bool flag = false;
                try
                {
                    this.SetProcessNewStatus(processInstance, ProcessStatus.Running);
                    this.PersistenceProvider.FillSystemProcessParameters(processInstance);
                    if (processInstance.CurrentActivity.IsAutoSchemeUpdate)
                    {
                        TransitionDefinition transitionDefinition = null;
                        try
                        {
                            transitionDefinition = newRootScheme.FindTransition(child.Name);
                        }
                        catch (TransitionNotFoundException transitionNotFoundException)
                        {
                        }
                        if (transitionDefinition != null)
                        {
                            ProcessDefinition processDefinition = this.Builder.CreateNewSubprocessScheme(newRootScheme, transitionDefinition);
                            this.BindProcessToNewScheme(processInstance, processDefinition, changes);
                        }
                        else if (this.OnStartingTransitionNotFound == null)
                        {
                            this.DropProcesses(new List<Guid>()
							{
								processInstance.ProcessId
							}, currentNode);
                            flag = true;
                            continue;
                        }
                        else
                        {
                            StartingTransitionNotFoundEventArgs startingTransitionNotFoundEventArg = new StartingTransitionNotFoundEventArgs(processInstance.ProcessId, processInstance.RootProcessId, oldRootScheme, newRootScheme, child.Name);
                            this.OnStartingTransitionNotFound(this, startingTransitionNotFoundEventArg);
                            if (startingTransitionNotFoundEventArg.Decision == StartingTransitionNotFoundEventArgs.SubprocessUpdateDecision.DropProcess)
                            {
                                this.DropProcesses(new List<Guid>()
								{
									processInstance.ProcessId
								}, currentNode);
                                flag = true;
                                continue;
                            }
                            else if (startingTransitionNotFoundEventArg.Decision == StartingTransitionNotFoundEventArgs.SubprocessUpdateDecision.Ignore)
                            {
                                continue;
                            }
                            else if (startingTransitionNotFoundEventArg.Decision == StartingTransitionNotFoundEventArgs.SubprocessUpdateDecision.StartWithNewTransition)
                            {
                                transitionDefinition = newRootScheme.FindTransition(startingTransitionNotFoundEventArg.NewTransitionName);
                                ProcessDefinition processDefinition1 = this.Builder.CreateNewSubprocessScheme(newRootScheme, transitionDefinition);
                                this.BindProcessToNewScheme(processInstance, processDefinition1, changes);
                            }
                        }
                    }
                    this.UpdateChildrenSchemes(child, oldRootScheme, newRootScheme, changes);
                }
                finally
                {
                    if (!flag)
                    {
                        this.SetIdledStatusAfterSchemaUpdated(processInstance);
                    }
                }
            }
        }
예제 #10
0
 private void SaveProcessInstancesTree(ProcessInstancesTree tree)
 {
     List<object> serializableObject = tree.GetSerializableObject();
     IPersistenceProvider persistenceProvider = this.PersistenceProvider;
     Guid ıd = tree.Root.Id;
     persistenceProvider.SaveGlobalParameter<List<object>>("ProcessTree", ıd.ToString("N"), serializableObject);
 }
예제 #11
0
 private void InitCreatedProcess(string identityId, string impersonatedIdentityId, ProcessInstance processInstance, ProcessInstancesTree processInstancesTree = null)
 {
     this.PersistenceProvider.InitializeProcess(processInstance);
     this.SetProcessNewStatus(processInstance, ProcessStatus.Initialized);
     bool haveImplementation = processInstance.ProcessScheme.InitialActivity.HaveImplementation;
     List<TransitionDefinition> list = processInstance.ProcessScheme.GetAutoTransitionForActivity(processInstance.ProcessScheme.InitialActivity, ForkTransitionSearchType.NotFork).ToList<TransitionDefinition>();
     bool flag = list.Any<TransitionDefinition>();
     List<TransitionDefinition> transitionDefinitions = processInstance.ProcessScheme.GetAutoTransitionForActivity(processInstance.ProcessScheme.InitialActivity, ForkTransitionSearchType.Fork).ToList<TransitionDefinition>();
     bool flag1 = transitionDefinitions.Any<TransitionDefinition>();
     processInstance.CurrentActivityName = processInstance.ProcessScheme.InitialActivity.Name;
     processInstance.CurrentState = processInstance.ProcessScheme.InitialActivity.State;
     processInstance.IdentityId = identityId;
     processInstance.ImpersonatedIdentityId = impersonatedIdentityId;
     try
     {
         try
         {
             if (haveImplementation || flag || flag1)
             {
                 this.SetProcessNewStatus(processInstance, ProcessStatus.Running);
                 if (haveImplementation)
                 {
                     this.ExecuteRootActivity(processInstance);
                 }
                 if (flag1)
                 {
                     this.CreateSubprocesses(processInstance, transitionDefinitions, processInstancesTree);
                 }
                 if (!flag)
                 {
                     this.SetProcessNewStatus(processInstance, ProcessStatus.Idled);
                     if (this.TimerManager != null)
                     {
                         this.TimerManager.ClearAndRegisterTimers(processInstance);
                     }
                 }
                 else
                 {
                     processInstance.SetStartTransitionalProcessActivity();
                     List<ExecutionRequestParameters> executionRequestParameters = new List<ExecutionRequestParameters>();
                     executionRequestParameters.AddRange(
                         from at in list
                         select ExecutionRequestParameters.Create(processInstance, at));
                     this.Bus.QueueExecution(executionRequestParameters);
                 }
             }
             else
             {
                 this.SetProcessNewStatus(processInstance, ProcessStatus.Idled);
                 if (this.TimerManager != null)
                 {
                     this.TimerManager.ClearAndRegisterTimers(processInstance);
                 }
             }
         }
         catch (Exception exception1)
         {
             Exception exception = exception1;
             throw new Exception(string.Format("Create instace of process Id={0}", processInstance.ProcessId), exception);
         }
     }
     finally
     {
         this.SetProcessNewStatus(processInstance, ProcessStatus.Idled);
     }
 }
예제 #12
0
        private List<WorkflowCommand> GetCommands(ProcessInstance processInstance, IEnumerable<string> identityIds, string commandNameFilter, string mainIdentityId, ProcessInstancesTree processInstancesTree)
        {
            List<TransitionDefinition> transitionDefinitions;
            List<string> list;
            if (!string.IsNullOrWhiteSpace(mainIdentityId))
            {
                List<string> strs = new List<string>()
				{
					mainIdentityId
				};
                list = identityIds.Except<string>(strs).ToList<string>();
            }
            else
            {
                list = identityIds.ToList<string>();
            }
            List<string> strs1 = list;
            Guid processId = processInstance.ProcessId;
            ActivityDefinition activityDefinition = processInstance.ProcessScheme.FindActivity(processInstance.CurrentActivityName);
            transitionDefinitions = (!string.IsNullOrEmpty(commandNameFilter) ? (
                from c in processInstance.ProcessScheme.GetCommandTransitions(activityDefinition, ForkTransitionSearchType.Both)
                where c.Trigger.Command.Name == commandNameFilter
                select c).ToList<TransitionDefinition>() : processInstance.ProcessScheme.GetCommandTransitions(activityDefinition, ForkTransitionSearchType.Both).ToList<TransitionDefinition>());
            List<WorkflowCommand> workflowCommands = new List<WorkflowCommand>();
            foreach (TransitionDefinition transitionDefinition in transitionDefinitions.OrderBy<TransitionDefinition, int>((TransitionDefinition t) =>
            {
                if (t.Classifier == TransitionClassifier.Direct)
                {
                    return 0;
                }
                if (t.Classifier != TransitionClassifier.Reverse)
                {
                    return 2;
                }
                return 1;
            }).ThenBy<TransitionDefinition, string>((TransitionDefinition t) => t.Trigger.Command.Name))
            {
                if (transitionDefinition.ForkType == TransitionForkType.ForkStart && processInstancesTree.GetNodeById(processId, true).HaveChildWithName(transitionDefinition.Name))
                {
                    continue;
                }
                List<string> list1 = null;
                if (!string.IsNullOrWhiteSpace(mainIdentityId) && this.ValidateActor(processInstance, mainIdentityId, transitionDefinition))
                {
                    list1 = new List<string>()
					{
						mainIdentityId
					};
                }
                if (list1 == null)
                {
                    list1 = (
                        from id in strs1
                        where this.ValidateActor(processInstance, id, transitionDefinition)
                        select id).ToList<string>();
                }
                if (!list1.Any<string>())
                {
                    continue;
                }
                WorkflowCommand workflowCommand = WorkflowCommand.Create(processId, transitionDefinition, processInstance.ProcessScheme);
                foreach (string str in list1)
                {
                    workflowCommand.AddIdentity(str);
                }
                workflowCommands.Add(workflowCommand);
            }
            return workflowCommands;
        }