public static WfApplicationParametersContext CreateContext(IDictionary<string, object> parameters)
		{
			ObjectContextCache.Instance.ContainsKey(CacheKey).TrueThrow("WfApplicationParametersContext已经在使用中,不能嵌套使用");

			WfApplicationParametersContext context = new WfApplicationParametersContext();

			if (parameters != null)
				context.ApplicationRuntimeParameters.CopyFrom(parameters);

			ObjectContextCache.Instance.Add(CacheKey, context);

			return context;
		}
예제 #2
0
        public static WfApplicationParametersContext CreateContext(IDictionary <string, object> parameters)
        {
            ObjectContextCache.Instance.ContainsKey(CacheKey).TrueThrow("WfApplicationParametersContext已经在使用中,不能嵌套使用");

            WfApplicationParametersContext context = new WfApplicationParametersContext();

            if (parameters != null)
            {
                context.ApplicationRuntimeParameters.CopyFrom(parameters);
            }

            ObjectContextCache.Instance.Add(CacheKey, context);

            return(context);
        }
        private static object GetConditionValueFromAppRuntimeParameters(WfConditionDescriptor condition, string funcName)
        {
            WfApplicationParametersContext context = WfApplicationParametersContext.Current;

            object result = null;

            //首先从上下文中查找参数
            if (context != null)
            {
                result = context.ApplicationRuntimeParameters.GetValue(funcName, (object)null);
            }

            if (result == null && condition != null && condition.Owner != null)
            {
                result = GetProcessAppRuntimeParameters(condition.Owner.ProcessInstance, funcName);
            }

            return(result);
        }
예제 #4
0
        private WfProcessStartupParams PrepareOneBranchProcessStartupParams(WfBranchProcessTransferParams branchTransferParams, IWfBranchProcessGroup group, int index)
        {
            IWfBranchProcessTemplateDescriptor template            = branchTransferParams.Template;
            WfBranchProcessStartupParams       branchStartupParams = branchTransferParams.BranchParams[index];

            //准备启动子流程的参数
            //先检查有没有预定义好的分支流程
            IWfProcessDescriptor subProcessDesp = null;

            using (WfApplicationParametersContext apContext = WfApplicationParametersContext.CreateContext(branchStartupParams.ApplicationRuntimeParameters))
            {
                subProcessDesp = template.GetBranchProcessDescriptor();
            }

            if (template.DefaultProcessName.IsNotEmpty())
            {
                string runtimeProcessName = this.Process.ApplicationRuntimeParameters.GetMatchedString(template.DefaultProcessName);

                if (runtimeProcessName.IsNullOrEmpty())
                {
                    runtimeProcessName = template.DefaultProcessName;
                }

                if (runtimeProcessName.IsNullOrEmpty())
                {
                    ((WfProcessDescriptor)subProcessDesp).Name = runtimeProcessName;
                }

                if (subProcessDesp.InitialActivity != null && subProcessDesp.InitialActivity.Name.IsNullOrEmpty())
                {
                    ((WfActivityDescriptor)subProcessDesp.InitialActivity).Name = runtimeProcessName;
                }
            }

            if (template.DefaultTaskTitle.IsNotEmpty())
            {
                subProcessDesp.DefaultTaskTitle = template.DefaultTaskTitle;
            }

            if (template.DefaultUrl.IsNotEmpty())
            {
                subProcessDesp.Url = template.DefaultUrl;
            }

            if (subProcessDesp.Url.IsNullOrEmpty())
            {
                subProcessDesp.Url = this.Descriptor.Url.IsNotEmpty() ? this.Descriptor.Url : this.Descriptor.Process.Url;
            }

            WfProcessStartupParams startupParams = new WfProcessStartupParams();

            startupParams.Creator = this.Operator;

            if (branchStartupParams.Department == null)
            {
                startupParams.Department = this.Process.OwnerDepartment;
            }
            else
            {
                startupParams.Department = branchStartupParams.Department;
            }

            startupParams.Assignees.CopyFrom(branchStartupParams.Assignees);
            startupParams.ProcessDescriptor = subProcessDesp;

            if (branchStartupParams.DefaultTaskTitle.IsNullOrEmpty())
            {
                if (startupParams.DefaultTaskTitle.IsNullOrEmpty())
                {
                    if (subProcessDesp.DefaultTaskTitle.IsNotEmpty())
                    {
                        startupParams.DefaultTaskTitle = subProcessDesp.DefaultTaskTitle;
                    }
                    else
                    {
                        startupParams.DefaultTaskTitle = this.Process.Descriptor.DefaultTaskTitle;
                    }
                }
                else
                {
                    startupParams.DefaultTaskTitle = this.Descriptor.TaskTitle;
                }
            }
            else
            {
                startupParams.DefaultTaskTitle = branchStartupParams.DefaultTaskTitle;
            }

            if (branchStartupParams.ResourceID.IsNullOrEmpty())
            {
                WfSubProcessResourceMode mode = template.Properties.GetValue("CreateResourceMode", WfSubProcessResourceMode.DependsOnProcess);
                switch (mode)
                {
                case WfSubProcessResourceMode.DependsOnProcess:
                    if (subProcessDesp.Properties.GetValue("Independent", false))
                    {
                        startupParams.ResourceID = UuidHelper.NewUuidString();
                    }
                    else
                    {
                        startupParams.ResourceID = this.Process.ResourceID;
                    }
                    break;

                case WfSubProcessResourceMode.SameWithRoot:
                    startupParams.ResourceID = this.Process.ResourceID;
                    break;

                case WfSubProcessResourceMode.NewCreate:
                    startupParams.ResourceID = UuidHelper.NewUuidString();
                    break;
                }
            }
            else
            {
                startupParams.ResourceID = branchStartupParams.ResourceID;
            }

            if (branchStartupParams.RelativeParams.Count == 0)
            {
                startupParams.RelativeParams.CopyFrom(this.Process.RelativeParams);
            }
            else
            {
                startupParams.RelativeParams.CopyFrom(branchStartupParams.RelativeParams);
            }

            startupParams.BranchStartupParams = branchStartupParams;
            startupParams.Group            = group;
            startupParams.OwnerActivityID  = this.ID;
            startupParams.OwnerTemplateKey = template.Key;
            startupParams.Sequence         = index;
            startupParams.AutoCommit       = this.Process.Committed; //子流程的提交属性默认等于主流程的

            branchStartupParams.ApplicationRuntimeParameters.ForEach(kp => startupParams.ApplicationRuntimeParameters.Add(kp.Key, kp.Value));

            //如果是串行执行,且不是第一个流程,则不启动第一个活动,子流程处于未启动状态
            if (template.ExecuteSequence == WfBranchProcessExecuteSequence.Serial && index > 0)
            {
                startupParams.AutoStartInitialActivity = false;
            }

            return(startupParams);
        }