Пример #1
0
        void IWaitingResumptionHandle.Resume(WaitingResumption waitingResumption)
        {
            var r            = waitingResumption as HumanEscalationResumption;
            var process      = r.Process;
            var activityName = r.HumanActivityInstance.ActivityName;
            var setting      = process.ProcessType.GetHumanSetting(activityName);
            var workItems    = this._workItemService.GetWorkItems(process, activityName);
            HumanEscalationRule          rule       = setting.EscalationRule;
            IDictionary <string, string> dataFields = process.GetDataFields();

            if (rule == null ||
                !rule.IsValid ||
                workItems.Count() == 0)
            {
                this._log.WarnFormat("流程“{0}”#{1}的节点“{2}”的超时事件升级规则无效或已经失效"
                                     , process.Title
                                     , process.ID
                                     , r.HumanActivityInstance.ActivityName);
                return;
            }
            string to;

            if (rule.NotifyTemplateName != null)
            {
                //消息通知
                this._helper.Notify(process, workItems, rule.NotifyTemplateName);
                //重复通知
                if (rule.NotifyRepeatMinutes.HasValue)
                {
                    //从当前开始计算
                    var at = DateTime.Now.AddMinutes(rule.NotifyRepeatMinutes.Value);
                    this._schedulerService.Add(new HumanEscalationResumption(r.Process, at, r.HumanActivityInstance));
                    this._log.InfoFormat("由于设置了重复通知,再次创建超时事件升级调度项,将于{0}激活", at);
                }
            }
            else if (!string.IsNullOrEmpty(rule.RedirectTo)
                     //HACK:【脚本使用】解析脚本获取实际转交目标
                     && !string.IsNullOrWhiteSpace(to = this.Evaluate(rule.RedirectTo, process)))
            {
                //将当前任务转交给其他人
                this._helper.Redirect(process, activityName, workItems, to);
            }
            else if (!string.IsNullOrEmpty(rule.GotoActivityName))
            {
                //强制跳转到指定节点
                this._helper.Goto(process, activityName, rule.GotoActivityName);
            }
        }
Пример #2
0
 private static ActivitySetting GetFirst(HumanEscalationRule rule)
 {
     return(new HumanSetting(0
                             , "节点1"
                             , new string[] { "同意", "否决" }
                             , -1
                             , HumanSetting.SlotDistributionMode.AllAtOnce
                             , ""
                             , new StartRule(null, null, null)
                             , new HumanActionerRule("originator")
                             , new FinishRule(new Dictionary <string, string>()
     {
         { "同意", "all('同意')" }
     })
                             , rule
                             , false));
 }
Пример #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);
        }
Пример #4
0
 private static ActivitySetting GetFirst(HumanEscalationRule rule)
 {
     return new HumanSetting(0
         , "节点1"
         , new string[] { "同意", "否决" }
         , -1
         , HumanSetting.SlotDistributionMode.AllAtOnce
         , ""
         , new StartRule(null, null, null)
         , new HumanActionerRule("originator")
         , new FinishRule(new Dictionary<string, string>() { { "同意", "all('同意')" } })
         , rule
         , false);
 }