Esempio n. 1
0
        /// <summary>
        /// 模拟一步流程执行
        /// </summary>
        /// <param name="process"></param>
        /// <param name="simulationContext"></param>
        /// <returns></returns>
        public static WfSimulationResult MoveToSimulation(string processID, WfSimulationParameters simulationParameters)
        {
            bool oldValue = WfRuntime.ProcessContext.EnableSimulation;

            try
            {
                WfRuntime.ProcessContext.EnableSimulation = true;
                InitSimulationContext(simulationParameters);

                IWfProcess process = WfRuntime.GetProcessByProcessID(processID);

                MergeVariablesToApplicationRuntimeParameters(process.ApplicationRuntimeParameters, simulationParameters.Variables);

                InnerMoveToSimulation(process, WfRuntime.ProcessContext.SimulationContext);

                //递归子流程,每个流程执行一步
                return(new WfSimulationResult(process)
                {
                    OutputString = WfRuntime.ProcessContext.SimulationContext.GetOutputString()
                });
            }
            finally
            {
                WfRuntime.ProcessContext.EnableSimulation = oldValue;
            }
        }
		public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)
		{
			WfSimulationParameters result = new WfSimulationParameters();

			result.EnableServiceCall = DictionaryHelper.GetValue(dictionary, "EnableServiceCall", true);

			if (dictionary.ContainsKey("Variables"))
				result.Variables.CopyFrom(JSONSerializerExecute.Deserialize<WfVariableDescriptor[]>(dictionary["Variables"]));

			if (dictionary.ContainsKey("Creator"))
				result.Creator = JSONSerializerExecute.Deserialize<OguUser>(dictionary["Creator"]);

			return result;
		}
		public void BranchProcessSimulation()
		{
			IWfProcessDescriptor processDesp = WfProcessTestCommon.CreateSimpleProcessDescriptorWithBranchTemplate();

			WfSimulationParameters simulationParameters = new WfSimulationParameters();
			WfSimulationResult result = WfSimulator.StartSimulation(processDesp, new WfSimulationParameters());

			Console.WriteLine(WfRuntime.ProcessContext.SimulationContext.GetOutputString());

			while (result.ProcessStatus != WfProcessStatus.Completed)
			{
				result = WfSimulator.MoveToSimulation(result.ProcessID, simulationParameters);

				Console.WriteLine(WfRuntime.ProcessContext.SimulationContext.GetOutputString());
			}
		}
Esempio n. 4
0
        public override IDictionary <string, object> Serialize(object obj, JavaScriptSerializer serializer)
        {
            WfSimulationParameters simulationParameters = (WfSimulationParameters)obj;

            IDictionary <string, object> dictionary = new Dictionary <string, object>();

            DictionaryHelper.AddNonDefaultValue <string, object>(dictionary, "EnableServiceCall", simulationParameters.EnableServiceCall);
            dictionary.Add("Variables", simulationParameters.Variables);

            if (OguBase.IsNotNullOrEmpty(simulationParameters.Creator))
            {
                dictionary.Add("Creator", simulationParameters.Creator);
            }

            return(dictionary);
        }
Esempio n. 5
0
        public override object Deserialize(IDictionary <string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            WfSimulationParameters result = new WfSimulationParameters();

            result.EnableServiceCall = DictionaryHelper.GetValue(dictionary, "EnableServiceCall", true);

            if (dictionary.ContainsKey("Variables"))
            {
                result.Variables.CopyFrom(JSONSerializerExecute.Deserialize <WfVariableDescriptor[]>(dictionary["Variables"]));
            }

            if (dictionary.ContainsKey("Creator"))
            {
                result.Creator = JSONSerializerExecute.Deserialize <OguUser>(dictionary["Creator"]);
            }

            return(result);
        }
		public void ConditionProcessSimulation()
		{
			IWfProcessDescriptor processDesp = WfProcessTestCommon.CreateSimpleProcessDescriptorWithCondition();

			WfSimulationParameters simulationParameters = new WfSimulationParameters();

			simulationParameters.Variables.Add(new WfVariableDescriptor("Amount", "10000", DataType.Int));

			WfSimulationResult result = WfSimulator.StartSimulation(processDesp, new WfSimulationParameters());

			Console.WriteLine(WfRuntime.ProcessContext.SimulationContext.GetOutputString());

			while (result.ProcessStatus != WfProcessStatus.Completed)
			{
				result = WfSimulator.MoveToSimulation(result.ProcessID, simulationParameters);

				Console.WriteLine(WfRuntime.ProcessContext.SimulationContext.GetOutputString());
			}
		}
		public void SimpleProcessSimulation()
		{
			IWfProcessDescriptor processDesp = WfProcessTestCommon.CreateSimpleProcessDescriptor();

			processDesp.Activities["NormalActivity"].Resources.Add(new WfUserResourceDescriptor((IUser)OguObjectSettings.GetConfig().Objects["approver1"].Object));
			processDesp.Activities["NormalActivity"].Resources.Add(new WfUserResourceDescriptor((IUser)OguObjectSettings.GetConfig().Objects["approver2"].Object));

			WfSimulationParameters simulationParameters = new WfSimulationParameters();
			WfSimulationResult result = WfSimulator.StartSimulation(processDesp, new WfSimulationParameters());

			Console.WriteLine(WfRuntime.ProcessContext.SimulationContext.GetOutputString());

			while (result.ProcessStatus != WfProcessStatus.Completed)
			{
				result = WfSimulator.MoveToSimulation(result.ProcessID, simulationParameters);

				Console.WriteLine(WfRuntime.ProcessContext.SimulationContext.GetOutputString());
			}
		}
Esempio n. 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="processDesp"></param>
        /// <param name="simulationParameters"></param>
        /// <returns></returns>
        public static WfSimulationResult StartSimulation(IWfProcessDescriptor processDesp, WfSimulationParameters simulationParameters)
        {
            bool oldValue = WfRuntime.ProcessContext.EnableSimulation;

            try
            {
                WfRuntime.ProcessContext.EnableSimulation = true;
                InitSimulationContext(simulationParameters);

                WfStartWorkflowExecutor executor = new WfStartWorkflowExecutor(
                    PrepareStartWorkflowParams(processDesp, WfRuntime.ProcessContext.SimulationContext));

                IWfProcess process = null;

                executor.AfterModifyWorkflow += (dataContext =>
                {
                    process = dataContext.CurrentProcess;
                });

                executor.Execute();

                return(new WfSimulationResult(process)
                {
                    OutputString = WfRuntime.ProcessContext.SimulationContext.GetOutputString()
                });
            }
            finally
            {
                WfRuntime.ProcessContext.EnableSimulation = oldValue;
            }
        }
Esempio n. 9
0
        private static void InitSimulationContext(WfSimulationParameters simulationParameters)
        {
            WfRuntime.ProcessContext.SimulationContext.Initialize();

            WfRuntime.ProcessContext.SimulationContext.SimulationParameters = simulationParameters;
        }
Esempio n. 10
0
 /// <summary>
 /// 启动流程仿真
 /// </summary>
 /// <param name="processDescKey"></param>
 /// <param name="simulationContext"></param>
 public static WfSimulationResult StartSimulation(string processDescKey, WfSimulationParameters simulationParameters)
 {
     return(StartSimulation(WfProcessDescriptorManager.GetDescriptor(processDescKey), simulationParameters));
 }