private XElement TransformRule(XElement ruleElement) { string value; if (!this.CheckElement(ruleElement, "rule") || !this.TryGetAttributeValue(ruleElement, "name", out value) || !RuleUtils.TryParseNullableDateTimeUtc(this.GetAttributeValue(ruleElement, "activationDate"), out this.activationDate) || !RuleUtils.TryParseNullableDateTimeUtc(this.GetAttributeValue(ruleElement, "expiryDate"), out this.expiryDate)) { return(null); } this.mode = this.TryParseAttribute <RuleMode>(ruleElement, "mode", new ETRToPNRTranslator.TryParse <RuleMode>(Enum.TryParse <RuleMode>), RuleMode.Enforce); if (this.mode == RuleMode.Audit) { return(null); } string attributeValue = this.GetAttributeValue(ruleElement, "enabled"); if (!string.IsNullOrEmpty(attributeValue) && !RuleConstants.TryParseEnabled(attributeValue, out this.enabled)) { this.enabled = RuleState.Disabled; } XElement xelement = this.CheckElement(ruleElement.FirstElement(), "version") ? this.TransformVersion(ruleElement.FirstElement()) : ETRToPNRTranslator.CreateXElement("version", new object[] { new XAttribute("minRequiredVersion", "15.0.3225.3000"), this.TransformRuleContents(ruleElement) }); return(ETRToPNRTranslator.CreateXElement("rule", new object[] { new XAttribute("name", value), xelement })); }
public bool CanAutoValidateActivity(WfActivityDefinition activityDefinition, object obj) { RuleConstants ruleConstants = _ruleManager.GetConstants(activityDefinition.WfwdId); bool ruleValid = _ruleManager.IsRuleValid((int)activityDefinition.WfadId, obj, ruleConstants); IList <AccountUser> accounts = _ruleManager.SelectAccounts((int)activityDefinition.WfadId, obj, ruleConstants); bool atLeastOnePerson = accounts.Count > 0; // If no rule is defined for validation or no one can validate this activity, we can autovalidate it. return(ruleValid == false || atLeastOnePerson == false); }
internal T FindChild <T>(RuleConstants child) where T : NonTerminalNode { return(m_children.OfType <T>().SingleOrDefault(node => node.Rule.Index == (int)child)); }
public SyntaxNodeAttribute(RuleConstants constant) { RuleConstant = constant; }
public void CustomRecalculation(IList <WfActivityDefinition> activityDefinitions, RuleConstants ruleConstants, WfWorkflow wf, IDictionary <int, List <RuleDefinition> > dicRules, IDictionary <int, List <RuleConditionDefinition> > dicConditions, IDictionary <int, List <SelectorDefinition> > dicSelectors, IDictionary <int, List <RuleFilterDefinition> > dicFilters, IDictionary <int, List <WfActivity> > dicActivities, IDictionary <int, List <WfDecision> > dicDecision, IDictionary <int, object> dicObjects, WfRecalculationOutput output) { object obj; dicObjects.TryGetValue(wf.ItemId.Value, out obj); if (obj == null) { // No item associated to this workflow. return; } List <WfActivity> allActivities; dicActivities.TryGetValue(wf.WfwId.Value, out allActivities); if (allActivities == null) { // No activity for this workflow. allActivities = new List <WfActivity>(); } IDictionary <int, WfActivity> activities = allActivities.ToDictionary(a => a.WfadId); WfActivity currentActivity = allActivities.Where(a => a.WfaId.Equals(wf.WfaId2.Value)).FirstOrDefault(); IList <WfActivityDefinition> nextActivityDefinitions; if (currentActivity != null) { nextActivityDefinitions = activityDefinitions.SkipWhile(ad => ad.WfadId.Equals(currentActivity.WfadId) == false).ToList(); } else { nextActivityDefinitions = activityDefinitions; } RuleContext ruleContext = new RuleContext(obj, ruleConstants); foreach (WfActivityDefinition ad in nextActivityDefinitions) { WfActivity activity; activities.TryGetValue(ad.WfadId.Value, out activity); int actDefId = ad.WfadId.Value; bool isManual = _ruleManager.IsRuleValid(actDefId, ruleContext, dicRules, dicConditions); if (isManual) { IList <AccountUser> accounts = _ruleManager.SelectAccounts(actDefId, ruleContext, dicSelectors, dicFilters); isManual = accounts.Count > 0; } if (isManual) { if (activity == null) { WfActivity wfActivity = GetNewActivity(ad, wf, false, false); output.AddActivitiesCreateUpdateCurrentActivity(wfActivity); break; } if (activity.IsValid == false) { wf.WfaId2 = activity.WfaId; output.AddWorkflowsUpdateCurrentActivity(wf); break; } } else { if (activity == null) { WfActivity wfActivity = GetNewActivity(ad, wf, true, false); output.AddActivitiesCreate(wfActivity); } else { activity.IsAuto = true; output.AddActivitiesUpdateIsAuto(activity); } } } }
public void SaveDecisionAndGoToNextActivity(WfWorkflow wfWorkflow, string transitionName, WfDecision wfDecision) { Debug.Assert(WfCodeStatusWorkflow.Sta.ToString().Equals(wfWorkflow.WfsCode), "A workflow must be started before saving decision"); //--- WfActivity currentActivity = _workflowStorePlugin.ReadActivity((int)wfWorkflow.WfaId2); // Updating the decision SaveDecision(wfWorkflow, wfDecision); WfActivityDefinition currentActivityDefinition = _workflowStorePlugin.ReadActivityDefinition(currentActivity.WfadId); WfCodeMultiplicityDefinition wfCodeMultiplicityDefinition = (WfCodeMultiplicityDefinition)Enum.Parse(typeof(WfCodeMultiplicityDefinition), currentActivityDefinition.WfmdCode); bool canGoToNextActivity = false; if (wfCodeMultiplicityDefinition == WfCodeMultiplicityDefinition.Mul) { IList <WfDecision> wfDecisions = _workflowStorePlugin.FindAllDecisionByActivity(currentActivity); object obj = _itemStorePlugin.ReadItem((int)wfWorkflow.ItemId); RuleConstants ruleConstants = _ruleManager.GetConstants((int)wfWorkflow.WfwdId); IList <AccountUser> accounts = _ruleManager.SelectAccounts(currentActivity.WfadId, obj, ruleConstants); //TODO : better impl than O(n²) int match = 0; foreach (AccountUser account in accounts) { foreach (WfDecision decision in wfDecisions) { if (account.Id.Equals(decision.User)) { match++; break; } } } if (match == accounts.Count) { canGoToNextActivity = true; } } else { canGoToNextActivity = true; } if (canGoToNextActivity) { if (_workflowStorePlugin.HasNextActivity(currentActivity, transitionName)) { WfActivityDefinition nextActivityDefinition = _workflowStorePlugin.FindNextActivity(currentActivity, transitionName); //Autovalidating next activities AutoValidateNextActivities(wfWorkflow, (int)nextActivityDefinition.WfadId); WfActivity lastAutoValidateActivity = _workflowStorePlugin.ReadActivity((int)wfWorkflow.WfaId2); WfActivityDefinition nextActivityDefinitionPrepare = _workflowStorePlugin.FindNextActivity(lastAutoValidateActivity); DateTime now = new DateTime(); // Creating the next activity to validate. WfActivity nextActivity = new WfActivity(); nextActivity.CreationDate = now; nextActivity.WfadId = (int)nextActivityDefinitionPrepare.WfadId; nextActivity.WfwId = (int)wfWorkflow.WfwId; _workflowStorePlugin.CreateActivity(nextActivity); wfWorkflow.WfaId2 = nextActivity.WfaId; _workflowStorePlugin.UpdateWorkflowInstance(wfWorkflow); } else { // No next activity to go. Ending the workflow wfWorkflow.WfsCode = WfCodeStatusWorkflow.End.ToString(); _workflowStorePlugin.UpdateWorkflowInstance(wfWorkflow); } } }
internal protected IEnumerable <T> FindChildren <T>(RuleConstants child) where T : NonTerminalNode { return(m_children.OfType <T>().Where(node => node.Rule.Index == (int)child)); }