Exemplo n.º 1
0
        public void HelloWorld0()
        {
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load("Definitions\\HelloWorld0.xml");

            using (var unitWork = UnitOfWork.Start())
            {
                ProcessDefinitionCreationContext creationContext = new ProcessDefinitionCreationContext();
                ProcessDefinition processDefinition = creationContext.CreateProcessDefinition(xmlDocument);
                creationContext.ResolveReferences();

                var processBlockRepository = new EFRepository <ProcessBlock>();
                processBlockRepository.Add(processDefinition);
                unitWork.Flush();
            }
            using (var unitWork = UnitOfWork.Start())
            {
                var processDefinitionRepository     = new EFRepository <ProcessDefinition>();
                ProcessDefinition processDefinition = processDefinitionRepository.With(w => w.Nodes).First();
                ExecutionContext  executionContext  = new ExecutionContext(new User("ae"), processDefinition);
                ProcessInstance   processInstance   = executionContext.StartProcess();

                var processInstanceRepository = new EFRepository <ProcessInstance>();
                processInstanceRepository.Add(processInstance);
                unitWork.Flush();
            }
        }
Exemplo n.º 2
0
        public void HelloWorld1()
        {
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load("Definitions\\HelloWorld1.xml");

            using (var unitWork = UnitOfWork.Start())
            {
                ProcessDefinitionCreationContext creationContext = new ProcessDefinitionCreationContext();
                ProcessDefinition processDefinition = creationContext.CreateProcessDefinition(xmlDocument);
                creationContext.ResolveReferences();

                Assert.AreEqual("Hello world 1", processDefinition.Name);
                Assert.AreEqual("This is the simples process.", processDefinition.Description);
                Assert.AreEqual(3, processDefinition.Nodes.Count);
                Node          start = null, end = null;
                ActivityState activityState = null;
                foreach (Node node in processDefinition.Nodes)
                {
                    if (node.Name == "start")
                    {
                        start = node;
                    }
                    else if (node.Name == "first activity state")
                    {
                        activityState = node as ActivityState;
                    }
                    else if (node.Name == "end")
                    {
                        end = node;
                    }
                }
                Assert.IsNotNull(start);
                Assert.AreEqual(1, start.LeavingTransitions.Count);
                foreach (Transition transition in start.LeavingTransitions)
                {
                    Assert.AreEqual(start, transition.From);
                    Assert.AreEqual(activityState, transition.To);
                }

                Assert.IsNotNull(activityState);
                Assert.AreEqual("this is the first state", activityState.Description);
                Assert.IsNotNull(activityState.AssignmentDelegation);

                Assert.AreEqual(1, activityState.LeavingTransitions.Count);
                foreach (Transition transition in activityState.LeavingTransitions)
                {
                    Assert.AreEqual(activityState, transition.From);
                    Assert.AreEqual(end, transition.To);
                }

                var processBlockRepository = new EFRepository <ProcessBlock>();
                processBlockRepository.Add(processDefinition);
                unitWork.Flush();
            }
        }
Exemplo n.º 3
0
        public static ProcessDefinition getHoliday()
        {
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load("Definitions\\Holiday.xml");

            ProcessDefinitionCreationContext creationContext = new ProcessDefinitionCreationContext();
            ProcessDefinition processDefinition = creationContext.CreateProcessDefinition(xmlDocument);

            creationContext.ResolveReferences();

            return(processDefinition);
        }
Exemplo n.º 4
0
        public void HolidayTest()
        {
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load("Definitions\\Holiday.xml");

            using (var unitWork = UnitOfWork.Start())
            {
                ProcessDefinitionCreationContext creationContext = new ProcessDefinitionCreationContext();
                ProcessDefinition processDefinition = creationContext.CreateProcessDefinition(xmlDocument);
                creationContext.ResolveReferences();

                Assert.AreEqual(1, processDefinition.ChildBlocks.Count);
                ProcessBlock concurrentProcessBlock = processDefinition.ChildBlocks.First();

                Node          fork = null, join = null;
                ActivityState hrNotify = null, approvalNotify = null;
                foreach (Node node in concurrentProcessBlock.Nodes)
                {
                    if (node.Name == "approved holiday fork")
                    {
                        fork = node;
                    }
                    else if (node.Name == "join before finish")
                    {
                        join = node;
                    }
                    else if (node.Name == "HR notification")
                    {
                        hrNotify = node as ActivityState;
                    }
                    else if (node.Name == "approval notification")
                    {
                        approvalNotify = node as ActivityState;
                    }
                }

                Assert.IsNotNull(fork);
                Assert.IsNotNull(join);
                Assert.IsNotNull(hrNotify);
                Assert.IsNotNull(approvalNotify);
                Assert.IsNotNull(fork.LeavingTransitions.First().To);

                var processBlockRepository = new EFRepository <ProcessBlock>();
                processBlockRepository.Add(processDefinition);
                unitWork.Flush();
            }
        }
Exemplo n.º 5
0
        public void DeployProcessArchive(string path)
        {
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load(path);
            using (var scope = new UnitOfWorkScope())
            {
                ProcessDefinitionCreationContext creationContext = new ProcessDefinitionCreationContext();
                ProcessDefinition processDefinition = creationContext.CreateProcessDefinition(xmlDocument);
                creationContext.ResolveReferences();

                var processBlockRepository = ServiceLocator.Current.GetInstance <IRepository <ProcessBlock> >();
                processBlockRepository.Add(processDefinition);

                scope.Commit();
            }
        }
Exemplo n.º 6
0
        public void HelloWorld2()
        {
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load("Definitions\\HelloWorld2.xml");

            using (var unitWork = UnitOfWork.Start())
            {
                ProcessDefinitionCreationContext creationContext = new ProcessDefinitionCreationContext();
                ProcessDefinition processDefinition = creationContext.CreateProcessDefinition(xmlDocument);
                creationContext.ResolveReferences();

                Node          start = null, end = null;
                ActivityState activityState = null;
                foreach (Node node in processDefinition.Nodes)
                {
                    if (node.Name == "start")
                    {
                        start = node;
                    }
                    else if (node.Name == "first activity state")
                    {
                        activityState = node as ActivityState;
                    }
                    else if (node.Name == "end")
                    {
                        end = node;
                    }
                }
                Assert.IsNotNull(start);
                Assert.IsNotNull(activityState);
                Assert.IsNotNull(activityState.AssignmentDelegation);

                DelegationDef delegationDef = activityState.AssignmentDelegation;
                Assert.AreEqual("ActorAssignment", delegationDef.ClassName);

                Assert.AreEqual("<cfg><parametername=\"expression\">processInitiator</parameter></cfg>", Regex.Replace(delegationDef.Configuration, @"\s|\t|\n|\r", ""));

                var processBlockRepository = new EFRepository <ProcessBlock>();
                processBlockRepository.Add(processDefinition);
                unitWork.Flush();
            }
        }
Exemplo n.º 7
0
        public void HelloWorld3()
        {
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load("Definitions\\HelloWorld3.xml");

            using (var unitWork = UnitOfWork.Start())
            {
                ProcessDefinitionCreationContext creationContext = new ProcessDefinitionCreationContext();
                ProcessDefinition processDefinition = creationContext.CreateProcessDefinition(xmlDocument);
                creationContext.ResolveReferences();

                AttributeDef evaluation = null, text = null;
                foreach (AttributeDef attribute in processDefinition.Attributes)
                {
                    if (attribute.Name == "evaluation result")
                    {
                        evaluation = attribute;
                    }
                    else if (attribute.Name == "the text attrib")
                    {
                        text = attribute;
                    }
                }

                Assert.IsNotNull(evaluation);
                Assert.IsNotNull(evaluation.SerializerDelegation);
                Assert.AreEqual("EvaluationSerializer", evaluation.SerializerDelegation.ClassName);

                Assert.IsNotNull(text);
                Assert.IsNotNull(text.SerializerDelegation);
                Assert.AreEqual("TextSerializer", text.SerializerDelegation.ClassName);
                Assert.AreEqual(":-)", text.InitialValue);

                var processBlockRepository = new EFRepository <ProcessBlock>();
                processBlockRepository.Add(processDefinition);
                unitWork.Flush();
            }
        }
Exemplo n.º 8
0
        public void HelloWorld2()
        {
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load("Definitions\\HelloWorld2.xml");
            ProcessDefinition processDefinition = new ProcessDefinition();
            ProcessInstance   processInstance   = new ProcessInstance();
            var user = new User("h.c");

            #region no use

            using (var unitWork = UnitOfWork.Start())
            {
                ProcessDefinitionCreationContext creationContext = new ProcessDefinitionCreationContext();
                processDefinition = creationContext.CreateProcessDefinition(xmlDocument);
                creationContext.ResolveReferences();

                var processBlockRepository = new EFRepository <ProcessBlock>();
                if (!processBlockRepository.Any(s => s.Name == processDefinition.Name))
                {
                    processBlockRepository.Add(processDefinition);
                }
                unitWork.Flush();
            }
            // 准备processInstance
            using (var unitWork = UnitOfWork.Start())
            {
                var processDefinitionRepository = new EFRepository <ProcessDefinition>();
                processDefinition =
                    processDefinitionRepository.With(w => w.Nodes).With(w => w.Attributes).FirstOrDefault(s => s.Name == "Hello world 2");
                //ProcessInstance processInstance = new ProcessInstance(new User("ae"), processDefinition);
                //ExecutionContext executionContext = new ExecutionContext(processDefinition, processInstance);
                var userContext = new EFRepository <User>();
                user = userContext.FirstOrDefault(s => s.UniqueName == user.UniqueName);
                ExecutionContext executionContext = new ExecutionContext(user, processDefinition);
                //ProcessInstance processInstance = executionContext.StartProcess();
                //var processInstanceRepository = new EFRepository<ProcessInstance>();
                //processInstanceRepository.Add(processInstance);
                processInstance = executionContext.StartProcess();

                var processInstanceRepository = new EFRepository <ProcessInstance>();
                processInstanceRepository.Add(processInstance);
                unitWork.Flush();
            }

            #endregion
            using (var unitWork = UnitOfWork.Start())
            {
                //var processDefinitionRepository = new EFRepository<ProcessDefinition>();
                //ProcessDefinition processDefinition = processDefinitionRepository.Where(s => s.Name == "Hello world 2").FirstOrDefault();
                var processInstanceRepository = new EFRepository <ProcessInstance>();
                // 获得第一个进程实例,该方法无法获得预定(helloworld2)
                // processInstance = processInstanceRepository.With(w => w.RootFlow).FirstOrDefault(s => s.ProcessDefinitionId == processDefinition.Id);

                IRepository <Flow> flowRepository = new EFRepository <Flow>();
                var rootFlow =
                    flowRepository.With(w => w.Node)
                    .With(w => w.AttributeInstances)
                    .Single(q => q.ProcessInstanceId == processInstance.Id);

                ExecutionContext executionContext = new ExecutionContext(user, processDefinition, processInstance, rootFlow);

                IDictionary <string, object> attributeValues = new Dictionary <string, object>();
                attributeValues.Add("the text attrib", ":-(");
                executionContext.PerformActivity(attributeValues);
                processInstanceRepository.Save(processInstance);
                unitWork.Flush();
            }
        }