public bool AddActionsToCreateEntity(EntityTemplToInst templToInst, PropTemplRuleActionBase action) { List <PropTemplRuleActionBase> listAction = new List <PropTemplRuleActionBase>(); listAction.Add(action); return(AddActionsToCreateEntity(templToInst, listAction)); }
/// <summary> /// Continue the execution of the entity. /// Pendind rules should be feed with matching actions. /// /// TODO: non, n'est plus utile!! /// </summary> /// <param name="entityTemplToInst"></param> /// <returns></returns> //public bool ContinueCreateEntity(EntityTemplToInst templToInst) //{ // // really need to continue? // if (templToInst.NextStep != TemplToInstStep.NeedAction) // return true; // if(templToInst.State != TemplToInstState.InProgress) // return true; // // TODO: non, plus utile!! // templToInst.SetNextStep(TemplToInstStep.Ends); // templToInst.SetState(TemplToInstState.Failed); // return false; //} #endregion #region Private match action-rule methods /// <summary> /// Match actions to rules to execute. /// </summary> /// <param name="templToInst"></param> /// <param name="listRuleToExec"></param> /// <param name="listAction"></param> /// <returns></returns> private bool MatchActionsToRules(List <PropTemplRuleBase> listRuleToExec, List <PropTemplRuleActionBase> listAction, out List <PropTemplRuleBase> listRuleToExecWithoutAction, out List <PropTemplRuleActionBase> listActionMatches) { listRuleToExecWithoutAction = new List <PropTemplRuleBase>(); listActionMatches = new List <PropTemplRuleActionBase>(); // scan each rule, must have a corresponding action foreach (PropTemplRuleBase rule in listRuleToExec) { // find the action PropTemplRuleActionBase action = listAction.Find(a => a.RuleId.Equals(rule.Id)); if (action == null) { listRuleToExecWithoutAction.Add(rule); } else { listActionMatches.Add(action); } } if (listRuleToExecWithoutAction.Count > 0) { return(false); } return(true); }
//public IValue CreatePropValueFromTempl(IValue propTemplValue) //{ // ici(); // PropValueTemplString propValueTemplString = propTemplValue as PropValueTemplString; // if (propValueTemplString != null) // { // PropertyValueString propValueString = new PropertyValueString(); // propValueString.Value = propValueTemplString.Value; // return propValueString; // } // PropValueTemplTextCode propValueTemplTextCode = propTemplValue as PropValueTemplTextCode; // if (propValueTemplTextCode != null) // { // PropertyValueTextCode propValueTextCode = new PropertyValueTextCode(); // propValueTextCode.TextCodeId = propValueTemplTextCode.TextCodeId; // return propValueTextCode; // } // throw new Exception("property Value type not yet implemented!"); //} #region Private methods /// <summary> /// 1- Create the key by copy from the template /// 2- has no action -> exit, need action /// 3- has action /// 3.1- Create the value by provided in the action /// /// </summary> /// <param name="propTempl"></param> /// <param name="ruleValueSetOnInst"></param> /// <returns></returns> private bool ExecPropTemplRuleValueSetOnInst(PropTempl propTempl, PropertyGroup propGroupParent, PropTemplRuleValueToSet ruleValueSetOnInst, List <PropTemplRuleActionBase> listAction, List <PropTemplRuleBase> listRulesNeedActions) { Property property = new Property(); property.PropGroupParentId = propGroupParent.Id; propGroupParent.AddProperty(property); // 1- create the key by copy from the template PropertyKeyBase propKey = CreatePropKeyFromTempl(propTempl); property.SetKeyValue(propKey, null); // an action on this rule is provided? PropTemplRuleActionBase action = listAction.Find(a => a.RuleId.Equals(ruleValueSetOnInst.Id)); if (action == null) { // no action provided for this rule!, need an action on this rule listRulesNeedActions.Add(ruleValueSetOnInst); // stops return(true); } // check the type of the action, must match the rule type! PropTemplRuleActionValueToSet actionSetOnInst = action as PropTemplRuleActionValueToSet; if (actionSetOnInst == null) { // error! action type is wrong return(false); } // move the rule in the list of rules executed/done //propTempl.MoveRuleToExecuted(ruleValueSetOnInst); // execute the action: create the prop Value //PropertyValueBase propValue = CreatePropValueFromAction(actionSetOnInst, ruleValueSetOnInst); IValue value = CreatePropValueFromAction(actionSetOnInst, ruleValueSetOnInst); // set the prop value, the key is set before property.SetValue(value); return(true); }