Example #1
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="flowNodeIndex">所在流程图节点的索引</param>
        /// <param name="activityName">节点名称</param>
        /// <param name="actions">可执行的操作</param>
        /// <param name="slotCount">默认为-1,将忽略该设置</param>
        /// <param name="slotMode">slot分发模式</param>
        /// <param name="startRule">不设置则留空</param>
        /// <param name="actionerRule"></param>
        /// <param name="finishRule">不设置则留空</param>
        /// <param name="escalationRule">不设置则留空</param>
        /// <param name="isChildOfActivity">是否是子节点</param>
        public HumanSetting(int flowNodeIndex
                            , string activityName
                            , string[] actions
                            , int slotCount
                            , SlotDistributionMode slotMode
                            , string url
                            , StartRule startRule
                            , HumanActionerRule actionerRule
                            , FinishRule finishRule
                            , HumanEscalationRule escalationRule
                            , bool isChildOfActivity)
            : base(flowNodeIndex
                   , activityName
                   , startRule
                   , finishRule
                   , isChildOfActivity)
        {
            this.Actions        = actions;
            this.SlotCount      = slotCount;
            this.SlotMode       = slotMode;
            this.Url            = url;
            this.ActionerRule   = actionerRule;
            this.EscalationRule = escalationRule;

            this.Validate();
        }
Example #2
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="flowNodeIndex">所在流程图节点的索引</param>
        /// <param name="activityName">节点名称</param>
        /// <param name="actions">可执行的操作</param>
        /// <param name="slotCount">默认为-1,将忽略该设置</param>
        /// <param name="slotMode">slot分发模式</param>
        /// <param name="startRule">不设置则留空</param>
        /// <param name="actionerRule"></param>
        /// <param name="finishRule">不设置则留空</param>
        /// <param name="escalationRule">不设置则留空</param>
        /// <param name="isChildOfActivity">是否是子节点</param>
        public HumanSetting(int flowNodeIndex
            , string activityName
            , string[] actions
            , int slotCount
            , SlotDistributionMode slotMode
            , string url
            , StartRule startRule
            , HumanActionerRule actionerRule
            , FinishRule finishRule
            , HumanEscalationRule escalationRule
            , bool isChildOfActivity)
            : base(flowNodeIndex
            , activityName
            , startRule
            , finishRule
            , isChildOfActivity)
        {
            this.Actions = actions;
            this.SlotCount = slotCount;
            this.SlotMode = slotMode;
            this.Url = url;
            this.ActionerRule = actionerRule;
            this.EscalationRule = escalationRule;

            this.Validate();
        }
Example #3
0
        //通过自定义活动文本描述解析自定义活动列表 用于首次发布时解析
        private IList<ActivitySetting> ParseActivitySettings(string activitySettingsDefinition
            , List<XElement> variableElements)
        {
            var timeZoneService = DependencyResolver.Resolve<ITimeZoneService>();

            var activitySettings = new List<ActivitySetting>();
            var rootElement = XElement.Parse(activitySettingsDefinition);
            rootElement.Descendants("human").ToList().ForEach(element =>
            {
                #region human
                var activityName = element.Attribute("name").Value;
                var actions = element.Descendants("actions")
                    .Descendants("action")
                    .Select(o => o.Value)
                    .ToList();
                var actioners = element.Descendants("actioners")
                    .Descendants("actioner")
                    .Select(o => o.Value)
                    .ToArray();
                var actionerRules = actioners;
                var slotCount = element.Attribute("slot") != null ? element.Attribute("slot").Value : "-1";
                var slotMode = element.Attribute("slotMode") != null ? element.Attribute("slotMode").Value : "allatonce";

                var url = element.Attribute("url") != null ? element.Attribute("url").Value : string.Empty;
                //HACK:设计器变量替换url占位符
                variableElements.ForEach(variableElement => 
                {
                    url = url.Replace("{" + variableElement.Attribute("Name").Value + "}", variableElement.Attribute("Value").Value);
                });

                #region 开始规则解析
                string startRule_At = null, startRule_afterMinutes = null, startRule_timeZoneName = null, startRule_unlimited = null;
                Nullable<DateTime> nullTime = null;
                Nullable<Int32> nullInt = null;
                Nullable<Double> nullDouble = null;
                StartRule startRule = null;
                if (element.Element("start") != null)
                {
                    var startRuleElement = element.Element("start");
                    startRule_At = startRuleElement.Attribute("at") != null ? startRuleElement.Attribute("at").Value : null;
                    startRule_afterMinutes = startRuleElement.Attribute("after") != null ? startRuleElement.Attribute("after").Value : null;
                    startRule_timeZoneName = startRuleElement.Attribute("zone") != null ? startRuleElement.Attribute("zone").Value : null;
                    //无限期延迟标记
                    startRule_unlimited = startRuleElement.Attribute("unlimited") != null ? startRuleElement.Attribute("unlimited").Value : null;
                    bool unlimited;
                    if (bool.TryParse(startRule_unlimited, out unlimited) && unlimited)
                        startRule = StartRule.UnlimitedDelay();
                    else if (startRule_At != null || startRule_afterMinutes != null || startRule_timeZoneName != null)
                        startRule = new StartRule(!string.IsNullOrEmpty(startRule_At) ? Convert.ToDateTime(startRule_At) : nullTime
                            , !string.IsNullOrEmpty(startRule_afterMinutes) ? Convert.ToInt32(startRule_afterMinutes) : nullInt
                            , string.IsNullOrEmpty(startRule_timeZoneName) ? null : timeZoneService.GetTimeZone(startRule_timeZoneName));
                }
                #endregion

                #region 完成规则解析
                var scripts = element.Descendants("finish")
                    .Descendants("line")
                    .ToDictionary(o => o.Attribute("name").Value
                        , o => o.Value);
                #endregion

                bool isChildOfActivity;
                bool.TryParse(element.Attribute("isChildOfActivity") == null
                    ? "False" : element.Attribute("isChildOfActivity").Value, out isChildOfActivity);

                #region 超时升级规则解析
                HumanEscalationRule escalationRule = null;
                if (element.Element("escalation") != null)
                {
                    var escalationRuleElement = element.Element("escalation");
                    string escalationRule_timeZoneName = escalationRuleElement.Attribute("zone") != null ? escalationRuleElement.Attribute("zone").Value : null;
                    TimeZone escalationRuleTimeZone = null;
                    if (!string.IsNullOrEmpty(escalationRule_timeZoneName))
                        escalationRuleTimeZone = timeZoneService.GetTimeZone(escalationRule_timeZoneName);
                    var escalationRule_ExpirationMinute = escalationRuleElement.Attribute("expiration") != null ? escalationRuleElement.Attribute("expiration").Value : null;
                    double? expirationMinute = !string.IsNullOrEmpty(escalationRule_ExpirationMinute) ? Convert.ToDouble(escalationRule_ExpirationMinute) : nullDouble;
                    var escalationRule_NotifyRepeatMinutes = escalationRuleElement.Attribute("repeat") != null ? escalationRuleElement.Attribute("repeat").Value : null;
                    double? repeatMinutes = !string.IsNullOrEmpty(escalationRule_NotifyRepeatMinutes) ? Convert.ToDouble(escalationRule_NotifyRepeatMinutes) : nullDouble;
                    var escalationRule_NotifyEmailTemplateName = escalationRuleElement.Attribute("notifyTemplateName") != null && !string.IsNullOrEmpty(escalationRuleElement.Attribute("notifyTemplateName").Value) ? escalationRuleElement.Attribute("notifyTemplateName").Value : null;
                    var escalationRule_GotoActivityName = escalationRuleElement.Attribute("gotoActivityName") != null && !string.IsNullOrEmpty(escalationRuleElement.Attribute("gotoActivityName").Value) ? escalationRuleElement.Attribute("gotoActivityName").Value : null;
                    var escalationRule_RedirectTo = escalationRuleElement.Attribute("redirectTo") != null && !string.IsNullOrEmpty(escalationRuleElement.Attribute("redirectTo").Value) ? escalationRuleElement.Attribute("redirectTo").Value : null;
                    //构造超时升级规则
                    escalationRule = new HumanEscalationRule(expirationMinute
                        , escalationRuleTimeZone
                        , repeatMinutes
                        , escalationRule_NotifyEmailTemplateName
                        , escalationRule_GotoActivityName
                        , escalationRule_RedirectTo);
                }
                #endregion

                activitySettings.Add(new HumanSetting(WorkflowBuilder.Default_FlowNodeIndex//HACK:设置默认索引,用于临时标记
                    , activityName
                    , actions.ToArray()
                    , Convert.ToInt32(slotCount)
                    , slotMode.ToLower() == "oneatonce" ? HumanSetting.SlotDistributionMode.OneAtOnce : HumanSetting.SlotDistributionMode.AllAtOnce
                    , url
                    , startRule
                    , new HumanActionerRule(actionerRules)
                    , new FinishRule(scripts)
                    , escalationRule
                    , isChildOfActivity));
                #endregion
            });
            rootElement.Descendants("server").ToList().ForEach(element =>
            {
                #region server
                var activityName = element.Attribute("name").Value;
                string startRule_At = null, startRule_afterMinutes = null, startRule_timeZoneName = null, startRule_unlimited = null;
                Nullable<DateTime> nullTime = null;
                Nullable<Int32> nullInt = null;
                StartRule startRule = null;
                if (element.Element("start") != null)
                {
                    var startRuleElement = element.Element("start");
                    startRule_At = startRuleElement.Attribute("at") != null ? startRuleElement.Attribute("at").Value : null;
                    startRule_afterMinutes = startRuleElement.Attribute("after") != null ? startRuleElement.Attribute("after").Value : null;
                    startRule_timeZoneName = startRuleElement.Attribute("zone") != null ? startRuleElement.Attribute("zone").Value : null;
                    //无限期延迟标记
                    startRule_unlimited = startRuleElement.Attribute("unlimited") != null ? startRuleElement.Attribute("unlimited").Value : null;
                    bool unlimited;
                    if (bool.TryParse(startRule_unlimited, out unlimited) && unlimited)
                        startRule = StartRule.UnlimitedDelay();
                    else if (startRule_At != null || startRule_afterMinutes != null || startRule_timeZoneName != null)
                        startRule = new StartRule(!string.IsNullOrEmpty(startRule_At) ? Convert.ToDateTime(startRule_At) : nullTime
                            , !string.IsNullOrEmpty(startRule_afterMinutes) ? Convert.ToInt32(startRule_afterMinutes) : nullInt
                            , string.IsNullOrEmpty(startRule_timeZoneName) ? null : timeZoneService.GetTimeZone(startRule_timeZoneName));
                }

                var scripts = element.Descendants("finish")
                    .Descendants("line")
                    .ToDictionary(o => o.Attribute("name").Value
                        , o => o.Value);
                var serverScript = element.Element("script") != null ? element.Element("script").Value : string.Empty;
                var resultTo = element.Attribute("resultTo") != null ? element.Attribute("resultTo").Value : string.Empty;

                bool isChildOfActivity;
                bool.TryParse(element.Attribute("isChildOfActivity") == null
                    ? "False" : element.Attribute("isChildOfActivity").Value, out isChildOfActivity);

                activitySettings.Add(new ServerSetting(WorkflowBuilder.Default_FlowNodeIndex
                    , activityName
                    , serverScript
                    , resultTo
                    , startRule
                    , new FinishRule(scripts)
                    , isChildOfActivity));
                #endregion
            });
            rootElement.Descendants("subprocess").ToList().ForEach(element =>
            {
                #region subprocess
                var activityName = element.Attribute("name").Value;
                var subProcessTypeName = element.Attribute("processTypeName").Value;

                string startRule_At = null, startRule_afterMinutes = null, startRule_timeZoneName = null, startRule_unlimited = null;
                Nullable<DateTime> nullTime = null;
                Nullable<Int32> nullInt = null;
                StartRule startRule = null;
                if (element.Element("start") != null)
                {
                    var startRuleElement = element.Element("start");
                    startRule_At = startRuleElement.Attribute("at") != null ? startRuleElement.Attribute("at").Value : null;
                    startRule_afterMinutes = startRuleElement.Attribute("after") != null ? startRuleElement.Attribute("after").Value : null;
                    startRule_timeZoneName = startRuleElement.Attribute("zone") != null ? startRuleElement.Attribute("zone").Value : null;
                    //无限期延迟标记
                    startRule_unlimited = startRuleElement.Attribute("unlimited") != null ? startRuleElement.Attribute("unlimited").Value : null;
                    bool unlimited;
                    if (bool.TryParse(startRule_unlimited, out unlimited) && unlimited)
                        startRule = StartRule.UnlimitedDelay();
                    else if (startRule_At != null || startRule_afterMinutes != null || startRule_timeZoneName != null)
                        startRule = new StartRule(!string.IsNullOrEmpty(startRule_At) ? Convert.ToDateTime(startRule_At) : nullTime
                            , !string.IsNullOrEmpty(startRule_afterMinutes) ? Convert.ToInt32(startRule_afterMinutes) : nullInt
                            , string.IsNullOrEmpty(startRule_timeZoneName) ? null : new Taobao.Workflow.Activities.TimeZone(startRule_timeZoneName));
                }

                var scripts = element.Descendants("finish")
                    .Descendants("line")
                    .ToDictionary(o => o.Attribute("name").Value
                        , o => o.Value);

                bool isChildOfActivity;
                bool.TryParse(element.Attribute("isChildOfActivity") == null
                    ? "False" : element.Attribute("isChildOfActivity").Value, out isChildOfActivity);

                activitySettings.Add(new SubProcessSetting(WorkflowBuilder.Default_FlowNodeIndex//HACK:设置默认索引,用于临时标记
                    , subProcessTypeName
                    , activityName
                    , startRule
                    , new FinishRule(scripts)
                    , isChildOfActivity));
                #endregion
            });
            rootElement.Descendants("parallel").ToList().ForEach(element =>
            {
                #region parallel
                var activityName = element.Attribute("name").Value;
                var completionCondition = element.Element("condition") != null ? element.Element("condition").Value : string.Empty;
                bool isChildOfActivity;
                bool.TryParse(element.Attribute("isChildOfActivity") == null
                    ? "False" : element.Attribute("isChildOfActivity").Value, out isChildOfActivity);
                activitySettings.Add(new ParallelSetting(WorkflowBuilder.Default_FlowNodeIndex
                    , activityName
                    , completionCondition
                    , isChildOfActivity));
                #endregion
            });
            return activitySettings;
        }