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 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 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; }
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 MoveToOneStepWithOpinionThenSaveOpinion() { 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)); runtimeContext.Opinion = new WfClientOpinion() { Content = "我很高兴" }; processInfo = WfClientProcessRuntimeServiceProxy.Instance.SaveProcess(processInfo.ID, runtimeContext); Assert.IsNotNull(processInfo.CurrentOpinion); Assert.IsTrue(processInfo.CurrentOpinion.ID.IsNotEmpty()); runtimeContext.Opinion = processInfo.CurrentOpinion; runtimeContext.Opinion.Content = "我确实很高兴"; processInfo = WfClientProcessRuntimeServiceProxy.Instance.SaveProcess(processInfo.ID, runtimeContext); WfClientOpinionCollection opinions = WfClientProcessRuntimeServiceProxy.Instance.GetOpinionsByResourceID(processInfo.ResourceID); Assert.AreEqual(1, opinions.Count); Assert.AreEqual(runtimeContext.Opinion.ID, opinions.First().ID); Assert.AreEqual(runtimeContext.Opinion.Content, opinions.First().Content); }
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)); }
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); }
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); }