Exemplo n.º 1
0
        private static WfClientTransferParams PrepareClientTransferParams()
        {
            WfClientTransferParams transferParams = new WfClientTransferParams("N1");

            transferParams.Operator = Consts.Users["Requestor"];
            transferParams.FromTransitionDescriptorKey = "L1";
            transferParams.Assignees.Add(Consts.Users["Approver1"]);

            WfClientBranchProcessTemplateDescriptor template             = BranchProcessTemplateConverterTest.PrepareClientBranchProcessTemplate();
            WfClientBranchProcessTransferParams     branchTransferParams = new WfClientBranchProcessTransferParams(template);

            WfClientBranchProcessStartupParams branchStartupParams = new WfClientBranchProcessStartupParams(Consts.Users["CFO"]);

            branchStartupParams.DefaultTaskTitle = "Hello Branch";
            branchStartupParams.Department       = Consts.Departments["RequestorOrg"];
            branchStartupParams.ApplicationRuntimeParameters["Amount"] = 1024;
            branchStartupParams.ResourceID                 = UuidHelper.NewUuidString();
            branchStartupParams.StartupContext             = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            branchStartupParams.RelativeParams["Relative"] = "Hello world";

            branchTransferParams.BranchParams.Add(branchStartupParams);

            transferParams.BranchTransferParams.Add(branchTransferParams);

            return(transferParams);
        }
        public WfClientProcessInfo MoveTo(string processID, WfClientTransferParams clientTransferParams, WfClientRuntimeContext runtimeContext)
        {
            processID.CheckStringIsNullOrEmpty("processID");
            clientTransferParams.NullCheck("clientTransferParams");

            OperationContext.Current.FillContextToOguServiceContext();

            IWfProcess process = GetProcessByProcessID(processID, runtimeContext);

            MeregeRuntimeContext(process, runtimeContext);

            WfTransferParams transferParams = null;

            WfClientTransferParamsConverter.Instance.ClientToServer(clientTransferParams, process, ref transferParams);

            MergeTransferParams(transferParams, runtimeContext);

            IWfActivity originalActivity = process.CurrentActivity;

            ExecuteExecutor(process, runtimeContext, (p) =>
            {
                WfMoveToExecutor executor = new WfMoveToExecutor(p.CurrentActivity, p.CurrentActivity, transferParams);

                executor.SaveApplicationData += (dataContext) => SaveOpinion(runtimeContext.Opinion, originalActivity, transferParams);
                executor.PrepareMoveToTasks  += (dataContext, tasks) =>
                                                tasks.ForEach(task => task.Purpose = p.CurrentActivity.Descriptor.Name);

                return(executor);
            });

            return(process.ToClientProcessInfo(transferParams.Operator).FillCurrentOpinion(process.CurrentActivity, runtimeContext.Operator));
        }
        public void MoveToOneStepWithOpinion()
        {
            WfClientProcessInfo processInfo = OperationHelper.PreapreProcessWithConditionLinesInstance();

            WfClientTransferParams transferParams = new WfClientTransferParams("N2");

            transferParams.Assignees.Add(Consts.Users["CEO"]);

            WfClientRuntimeContext runtimeContext = new WfClientRuntimeContext();

            runtimeContext.Operator = Consts.Users["Requestor"];
            runtimeContext.Opinion  = new WfClientOpinion()
            {
                Content = "我很高兴"
            };

            processInfo = WfClientProcessRuntimeServiceProxy.Instance.MoveTo(processInfo.ID, transferParams, runtimeContext);

            processInfo.Output();

            Assert.AreEqual("N2", processInfo.CurrentActivity.Descriptor.Key);
            Assert.IsTrue(processInfo.CurrentActivity.Assignees.Contains(Consts.Users["CEO"].ID));

            WfClientProcessInfo prevProcessInfo = WfClientProcessRuntimeServiceProxy.Instance.GetProcessInfoByActivityID(processInfo.PreviousActivity.ID, runtimeContext.Operator);

            prevProcessInfo.Output();

            Assert.IsNotNull(prevProcessInfo.CurrentOpinion);

            WfClientOpinionCollection opinions = WfClientProcessRuntimeServiceProxy.Instance.GetOpinionsByResourceID(prevProcessInfo.ResourceID);

            Assert.IsTrue(opinions.Count > 0);
        }
Exemplo n.º 4
0
        public void StandardClientTransferParamsToServer()
        {
            WfClientTransferParams client = PrepareClientTransferParams();

            WfTransferParams server = null;

            WfClientTransferParamsConverter.Instance.ClientToServer(client, null, ref server);

            client.AreSame(server);
        }
Exemplo n.º 5
0
        public override object Deserialize(IDictionary <string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            WfClientTransferParams transferParams = new WfClientTransferParams();

            transferParams.NextActivityDescriptorKey   = dictionary.GetValue("nextActivityDescriptorKey", string.Empty);
            transferParams.FromTransitionDescriptorKey = dictionary.GetValue("fromTransitionDescriptorKey", string.Empty);
            transferParams.Operator = JSONSerializerExecute.Deserialize <WfClientUser>(dictionary.GetValue("operator", (object)null));

            JSONSerializerExecute.FillDeserializedCollection(dictionary["branchTransferParams"], transferParams.BranchTransferParams);
            JSONSerializerExecute.FillDeserializedCollection(dictionary["assignees"], transferParams.Assignees);

            return(transferParams);
        }
Exemplo n.º 6
0
        public static void AreSame(this WfClientTransferParams expected, WfTransferParams actual)
        {
            if (expected != null && actual != null)
            {
                expected.Operator.AreSame(actual.Operator);
                expected.Assignees.AreSame(actual.Assignees);

                expected.BranchTransferParams.AreSame(actual.BranchTransferParams);
            }
            else
            {
                Assert.AreEqual(expected, actual);
            }
        }
Exemplo n.º 7
0
        public void ClientTransferParamsSerializationTest()
        {
            WfClientJsonConverterHelper.Instance.RegisterConverters();

            WfClientTransferParams client = PrepareClientTransferParams();

            string data = JSONSerializerExecute.Serialize(client);

            Console.WriteLine(data);

            WfClientTransferParams deserialized = JSONSerializerExecute.Deserialize <WfClientTransferParams>(data);

            client.AreSame(deserialized);
        }
Exemplo n.º 8
0
        public override IDictionary <string, object> Serialize(object obj, JavaScriptSerializer serializer)
        {
            Dictionary <string, object> dictionary = new Dictionary <string, object>();

            WfClientTransferParams transferParams = (WfClientTransferParams)obj;

            dictionary.AddNonDefaultValue("nextActivityDescriptorKey", transferParams.NextActivityDescriptorKey);
            dictionary.AddNonDefaultValue("fromTransitionDescriptorKey", transferParams.FromTransitionDescriptorKey);
            dictionary["operator"] = transferParams.Operator;

            dictionary["branchTransferParams"] = transferParams.BranchTransferParams;
            dictionary["assignees"]            = transferParams.Assignees;

            return(dictionary);
        }
Exemplo n.º 9
0
        public static void AreSame(this WfClientTransferParams expected, WfClientTransferParams actual)
        {
            if (expected != null && actual != null)
            {
                AssertStringEqual(expected.NextActivityDescriptorKey, actual.NextActivityDescriptorKey);
                AssertStringEqual(expected.FromTransitionDescriptorKey, actual.FromTransitionDescriptorKey);

                expected.Operator.AreSame(actual.Operator);
                expected.Assignees.AreSame(actual.Assignees);

                expected.BranchTransferParams.AreSame(actual.BranchTransferParams);
            }
            else
            {
                Assert.AreEqual(expected, actual);
            }
        }
        public void MoveToOneStep()
        {
            WfClientProcessInfo processInfo = OperationHelper.PreapreProcessWithConditionLinesInstance();

            WfClientTransferParams transferParams = new WfClientTransferParams("N2");

            transferParams.Assignees.Add(Consts.Users["CEO"]);

            WfClientRuntimeContext runtimeContext = new WfClientRuntimeContext();

            runtimeContext.Operator = Consts.Users["Requestor"];

            processInfo = WfClientProcessRuntimeServiceProxy.Instance.MoveTo(processInfo.ID, transferParams, runtimeContext);

            processInfo.Output();

            Assert.AreEqual("N2", processInfo.CurrentActivity.Descriptor.Key);
            Assert.IsTrue(processInfo.CurrentActivity.Assignees.Contains(Consts.Users["CEO"].ID));
        }
Exemplo n.º 11
0
        public WfTransferParams ClientToServer(WfClientTransferParams client, IWfProcess process, ref WfTransferParams server)
        {
            client.NullCheck("client");

            if (server == null)
            {
                server = new WfTransferParams();
            }

            server.Context["NextActivityDescriptorKey"]   = client.NextActivityDescriptorKey;
            server.Context["FromTransitionDescriptorKey"] = client.FromTransitionDescriptorKey;

            if (process != null)
            {
                if (client.NextActivityDescriptorKey.IsNotEmpty())
                {
                    IWfActivity nextActivity = process.Activities.FindActivityByDescriptorKey(client.NextActivityDescriptorKey);

                    if (nextActivity != null)
                    {
                        server.NextActivityDescriptor = nextActivity.Descriptor;
                    }
                }

                if (client.FromTransitionDescriptorKey.IsNotEmpty())
                {
                    IWfTransitionDescriptor fromTransition = process.Descriptor.FindTransitionByKey(client.FromTransitionDescriptorKey);

                    server.FromTransitionDescriptor = fromTransition;
                }
            }

            server.Operator = (IUser)client.Operator.ToOguObject();
            WfClientBranchProcessTransferParamsCollectionConverter.Instance.ClientToServer(client.BranchTransferParams, server.BranchTransferParams);
            WfClientAssigneeCollectionConverter.Instance.ClientToServer(client.Assignees, server.Assignees);

            return(server);
        }
 public WfClientProcessInfo StartWorkflowAndMoveTo(WfClientProcessStartupParams clientStartupParams, WfClientTransferParams clientTransferParams, WfClientRuntimeContext runtimeContext)
 {
     return(this.SingleCall(action => action.StartWorkflowAndMoveTo(clientStartupParams, clientTransferParams, runtimeContext)));
 }
 public WfClientProcessInfo MoveTo(string processID, WfClientTransferParams clientTransferParams, WfClientRuntimeContext runtimeContext)
 {
     return(this.SingleCall(action => action.MoveTo(processID, clientTransferParams, runtimeContext)));
 }
        public WfClientProcessInfo StartWorkflowAndMoveTo(WfClientProcessStartupParams clientStartupParams, WfClientTransferParams clientTransferParams, WfClientRuntimeContext runtimeContext)
        {
            if (clientStartupParams == null)
            {
                throw new ApplicationException(Translator.Translate(Define.DefaultCulture, "流程的启动参数不能为空"));
            }

            //设置标准参数,优先使用外部参数
            if (!clientStartupParams.ApplicationRuntimeParameters.ContainsKey("ProcessRequestor"))
            {
                clientStartupParams.ApplicationRuntimeParameters["ProcessRequestor"] = clientStartupParams.Creator;
            }

            OperationContext.Current.FillContextToOguServiceContext();

            WfProcessStartupParams startupParams = null;

            WfClientProcessStartupParamsConverter.Instance.ClientToServer(clientStartupParams, ref startupParams);

            WfTransferParams transferParams = null;

            if (clientTransferParams != null)
            {
                WfClientTransferParamsConverter.Instance.ClientToServer(clientTransferParams, null, ref transferParams);

                MergeTransferParams(transferParams, runtimeContext);
            }

            IWfProcess process = null;

            DoPrincipalAction(startupParams.Creator, () =>
            {
                WfStartWorkflowExecutor executor = new WfStartWorkflowExecutor(null, startupParams, transferParams);

                executor.AfterModifyWorkflow += (dataContext =>
                {
                    dataContext.CurrentProcess.GenerateCandidatesFromResources();
                    clientStartupParams.ProcessContext.ForEach(kp => dataContext.CurrentProcess.Context[kp.Key] = kp.Value);

                    WfClientProcessInfoBaseConverter.Instance.FillOpinionInfoByProcessByActivity(
                        clientStartupParams.Opinion,
                        dataContext.CurrentProcess.InitialActivity,
                        clientStartupParams.Creator,
                        clientStartupParams.Creator);
                });

                WfClientOpinion opinion = clientStartupParams.Opinion;

                if (opinion == null)
                {
                    opinion = runtimeContext.Opinion;
                }

                executor.SaveApplicationData += (dataContext) => SaveOpinion(opinion, dataContext.CurrentProcess.InitialActivity, executor.TransferParams);

                if (clientStartupParams.AutoPersist)
                {
                    process = executor.Execute();
                }
                else
                {
                    process = executor.ExecuteNotPersist();
                }
            });

            return(process.ToClientProcessInfo(clientStartupParams.Creator).FillCurrentOpinion(process.CurrentActivity, clientStartupParams.Creator));
        }