/// <summary> /// check for new added inner object: missing id. /// property and rules. /// SetPropTemplAllMissingId /// </summary> /// <param name="propGroupTempl"></param> /// <returns></returns> private void SetPropTemplAllMissingId(PropGroupTempl propGroupTempl) { if (propGroupTempl.Id == null) { propGroupTempl.Id = Guid.NewGuid().ToString(); } // check rules SetRulesId(propGroupTempl); // check for childs foreach (PropTemplBase propTemplBase in propGroupTempl.ListProperty) { // check rules SetRulesId(propTemplBase); // the child is a group? PropGroupTempl propGroupTemplChild = propTemplBase as PropGroupTempl; if (propGroupTemplChild != null) { // yes, so set id on childs SetPropTemplAllMissingId(propGroupTemplChild); } } }
public PropTempl CreatePropTempl(EntityTempl entityTempl, PropGroupTempl propertyParent, TextCode tcKey, TextCode tcValue) { // check the entity parent if (entityTempl == null) { return(null); } // transform the key PropKeyTemplTextCode propKeyTextCode = new PropKeyTemplTextCode(); propKeyTextCode.TextCodeId = tcKey.Id; // transform the value ValTextCodeId valTextCodeId = null; if (tcValue != null) { valTextCodeId = new ValTextCodeId(); // can be null (to set on instantiation) valTextCodeId.TextCodeId = tcValue.Id; } PropValueTempl propValue = PropValueTemplTool.CreatePropValueTemplFromValue(valTextCodeId); return(CreatePropTempl(entityTempl, propertyParent, propKeyTextCode, propValue)); }
/// <summary> /// Check the consistency of the property template. /// Return the number of problems. /// cases: /// -key prop must exists (not null), /// -a null prop value -> a rule PropValueSetOnInstance must exists. /// </summary> /// <param name="entityTempl"></param> /// <param name="propTemplBase"></param> /// <returns></returns> private int CheckConsistencyPropTempl(EntityTempl entityTempl, PropTemplBase propTemplBase, List <PropTemplRuleBase> listRuleToExec) { int pbCount = 0; // is the property a group? PropGroupTempl propGroupTempl = propTemplBase as PropGroupTempl; if (propGroupTempl != null) { // get rules // TODO: strategie instancier child: Single, Several,... // check properties childs foreach (PropTemplBase propTemplChild in propGroupTempl.ListProperty) { pbCount += CheckConsistencyPropTempl(entityTempl, propTemplChild, listRuleToExec); } return(pbCount); } // is the property a final one? PropTempl propTempl = propTemplBase as PropTempl; if (propTempl != null) { return(CheckConsistencyPropTempl(entityTempl, propTempl, listRuleToExec)); } throw new Exception("PropTempl type not implemented!"); }
public void Ent_PropGroup_Prop_KString_VString() { EtagairCore core = Common.CreateCoreInMemory(); // create an entity template to instantiate EntityTempl templComputer = core.EditorTempl.CreateEntityTempl("TemplComputer"); // create the group Core PropGroupTempl propGroupTemplCore = core.EditorTempl.CreatePropGroupTempl(templComputer, "Core"); // under the propGroup Core, create the prop Type=Intel PropTempl propTemplType = core.EditorTempl.CreatePropTempl(templComputer, propGroupTemplCore, "Type", "Intel"); //====Instantiate EntityTemplToInst templToInst = core.ProcessTempl.CreateEntity(templComputer); // check that the execution finishes with success Assert.AreEqual(TemplToInstState.Success, templToInst.State, "the state should be sucess"); Assert.AreEqual(TemplToInstStep.Ends, templToInst.NextStep, "the next step should be ends"); //=====Check the creation //----check the prop group: Core PropertyBase propBase = core.Searcher.FindPropertyByKey(templToInst.Entity, templToInst.Entity.PropertyRoot, "Core", false); PropertyGroup propGroup = propBase as PropertyGroup; Assert.IsNotNull(propGroup, "the propgroup Core should exists"); // Check the prop group key PropertyKeyString propGroupKey = propGroup.Key as PropertyKeyString; Assert.IsNotNull(propGroupKey, "the propgroup key Core should exists"); Assert.AreEqual("Core", propGroupKey.Key, "the key should be Core"); //----check the property child: Type=Computer propBase = core.Searcher.FindPropertyByKey(templToInst.Entity, propGroup, "Type", false); Property prop = propBase as Property; Assert.IsNotNull(prop, "the prop child Type should exists"); // find the prop Intel (inside the group Core) from the root property PropertyBase propBaseTypeIntel = core.Searcher.FindPropertyByKey(templToInst.Entity, "Type", true); Property propTypeIntel = propBaseTypeIntel as Property; Assert.IsNotNull(propTypeIntel, "the prop child Type should exists (find from the root)"); // check the prop key: Type, find the prop from the parent PropertyKeyString propKeyString = prop.Key as PropertyKeyString; Assert.IsNotNull(propKeyString, "the prop key string Type should exists"); Assert.AreEqual("Type", propKeyString.Key, "the key should be Type"); // check the prop value //PropertyValueString propValueString = prop.Value as PropertyValueString; ValString propValueString = prop.Value as ValString; Assert.IsNotNull(propValueString, "the prop key string Type should exists"); Assert.AreEqual("Intel", propValueString.Value, "the value should be Intel"); }
/// <summary> /// Instantiate all properties childs of the group, from the template. /// </summary> /// <param name="entityTempl"></param> /// <param name="propToProcess"></param> /// <param name="entity"></param> /// <param name="property"></param> /// <param name="listRuleWithoutAction"></param> /// <returns></returns> public bool CreateAllPropGroupChildsFromTempl(EntityTempl entityTempl, PropGroupTempl propGroupTempl, Entity entity, PropertyGroup propGroupParent, List <PropTemplRuleActionBase> listAction, out List <PropTemplRuleBase> listRuleWithoutAction) { // get the rules of the group properties // propGroupTemplToProcess.ListRule // TODO: strategie?? OneOf, Several,... listRuleWithoutAction = new List <PropTemplRuleBase>(); List <PropGroupTempl> listPropGroupTemplChilds = new List <PropGroupTempl>(); // scan property childs of the template foreach (PropTemplBase propTemplBase in propGroupTempl.ListProperty) { // is it a group templ? PropGroupTempl propGroupTemplChild = propTemplBase as PropGroupTempl; if (propGroupTemplChild != null) { // saved, to be process after all direct finals properties listPropGroupTemplChilds.Add(propGroupTemplChild); continue; } // is it propTempl (final)? PropTempl propTemplChild = propTemplBase as PropTempl; if (propTemplChild != null) { CreatePropFromTempl(propTemplChild, propGroupParent, listAction, listRuleWithoutAction); } } // there are rules without action, need external actions, stops here if (listRuleWithoutAction.Count > 0) { return(true); } // now process all prop group templ childs foreach (PropGroupTempl propGroupTemplChild in listPropGroupTemplChilds) { PropertyGroup propGroupChild; // create first the propGroup from the template, is empty (no child) CreatePropGroupFromTempl(propGroupTemplChild, propGroupParent, listAction, listRuleWithoutAction, out propGroupChild); // save/update the entity, will create missing id _reposit.Builder.UpdateEntity(entity); // then create the prop childs of the group, from the template List <PropTemplRuleBase> listRuleWithoutActionChilds; CreateAllPropGroupChildsFromTempl(entityTempl, propGroupTemplChild, entity, propGroupChild, listAction, out listRuleWithoutActionChilds); listRuleWithoutAction.AddRange(listRuleWithoutActionChilds); } return(true); }
/// <summary> /// Find a property by the key "raw" string (can be a textCode). /// in direct childs. /// (not recursivly). /// </summary> /// <param name="entityTempl"></param> /// <param name="key"></param> /// <returns></returns> public PropTemplBase FindPropTemplBaseByKey(EntityTempl entityTempl, PropGroupTempl propertyTemplParent, string key) { if (entityTempl == null) { return(null); } if (propertyTemplParent == null) { return(null); } if (string.IsNullOrWhiteSpace(key)) { return(null); } // load the textCode of the key, if exists TextCode tcKey = _reposit.Finder.FindTextCodeByCode(key); // the key can be a string or a textCode foreach (var propertyBase in propertyTemplParent.ListProperty) { // is it a final property? PropTempl property = propertyBase as PropTempl; if (property != null) { // is the property key a textCode? if (IsKeyMatchProperty(property, key, tcKey)) { return(property); } // next property continue; } // is it a group property? PropGroupTempl propertyGroup = propertyBase as PropGroupTempl; if (propertyGroup != null) { // is the property key a textCode? if (IsKeyMatchProperty(propertyGroup, key, tcKey)) { return(propertyGroup); } // next property continue; } } // not found return(null); }
/// <summary> /// Create a property template. /// to set a value to null, provide this parameter: (TextCode)null. /// </summary> /// <param name="entityTempl"></param> /// <param name="tcKey"></param> /// <param name="tcValue"></param> /// <returns></returns> public PropTempl CreatePropTempl(EntityTempl entityTempl, TextCode tcKey, TextCode tcValue) { // check the entity parent if (entityTempl == null) { return(null); } // get the root group properties of the entity PropGroupTempl propertyParent = entityTempl.PropertyRoot; return(CreatePropTempl(entityTempl, propertyParent, tcKey, tcValue)); }
/// <summary> /// Create a property template. /// </summary> /// <param name="entityTempl"></param> /// <param name="tcKey"></param> /// <param name="tcValue"></param> /// <returns></returns> public PropTempl CreatePropTempl(EntityTempl entityTempl, string key, bool value) { // check the entity parent if (entityTempl == null) { return(null); } // get the root group properties of the entity PropGroupTempl propertyParent = entityTempl.PropertyRoot; return(CreatePropTempl(entityTempl, propertyParent, key, value)); }
/// <summary> /// Create a property group template. /// Under the prop root of the entity. /// </summary> /// <param name="entityTempl"></param> /// <param name="tcKey"></param> /// <param name="tcValue"></param> /// <returns></returns> public PropGroupTempl CreatePropGroupTempl(EntityTempl entityTempl, string key) { // check the entity parent if (entityTempl == null) { return(null); } // get the root group properties of the entity PropGroupTempl propertyParent = entityTempl.PropertyRoot; PropKeyTemplString propKeyString = new PropKeyTemplString(); propKeyString.Key = key; return(CreatePropGroupTempl(entityTempl, propertyParent, propKeyString)); }
public PropTempl CreatePropTempl(EntityTempl entityTempl, PropGroupTempl propertyParent, TextCode tcKey, string value) { // check the entity parent if (entityTempl == null) { return(null); } PropKeyTemplTextCode propKeyTextCode = new PropKeyTemplTextCode(); propKeyTextCode.TextCodeId = tcKey.Id; // create the property value template PropValueTempl propValue = PropValueTemplTool.CreatePropValueTemplFromValue(value); return(CreatePropTempl(entityTempl, propertyParent, propKeyTextCode, propValue)); }
/// <summary> /// Create a property template, under a property group parent. /// prop key is string, prop value is a bool. /// </summary> /// <param name="entityTempl"></param> /// <param name="tcKey"></param> /// <param name="tcValue"></param> /// <returns></returns> public PropTempl CreatePropTempl(EntityTempl entityTempl, PropGroupTempl propertyParent, string key, bool value) { // check the entity parent if (entityTempl == null) { return(null); } PropKeyTemplString propKeyString = new PropKeyTemplString(); propKeyString.Key = key; // create the property value template, can be null PropValueTempl propValue = PropValueTemplTool.CreatePropValueTemplFromValue(value); return(CreatePropTempl(entityTempl, propertyParent, propKeyString, propValue)); }
//====very generic (low-level) method public PropTempl CreatePropTempl(EntityTempl entityTempl, PropGroupTempl propGroupTemplParent, PropKeyTemplBase propKey, PropValueTempl propValue) { // check the entity parent if (entityTempl == null) { return(null); } if (propGroupTemplParent == null) { propGroupTemplParent = entityTempl.PropertyRoot; } if (propKey == null) { return(null); } string propKeyString = GetPropKeyTemplString(propKey); // check the key, not used by an existing property if (FindPropTemplBaseByKey(entityTempl, propGroupTemplParent, propKeyString) != null) { return(null); } // create the property, set the key and the value PropTempl propertyTempl = new PropTempl(); propertyTempl.PropGroupTemplParentId = propGroupTemplParent.Id; propertyTempl.SetKeyValue(propKey, propValue); // add the property under the root properties entityTempl.AddProperty(propGroupTemplParent, propertyTempl); // save the entity modification if (!_reposit.Builder.UpdateEntityTempl(entityTempl)) { return(null); } return(propertyTempl); }
/// <summary> /// create the propGroup from the template, is empty (no child). /// Childs will be created after that. /// </summary> /// <param name="propTempl"></param> /// <param name="propGroupParent"></param> /// <returns></returns> private bool CreatePropGroupFromTempl(PropGroupTempl propGroupTempl, PropertyGroup propGroupParent, List <PropTemplRuleActionBase> listAction, List <PropTemplRuleBase> listRulesNeedActions, out PropertyGroup propGroupChild) { // create the propGroup based on the template, add it under the propGroupParent propGroupChild = new PropertyGroup(); propGroupChild.PropGroupTemplId = propGroupTempl.Id; propGroupChild.PropGroupParentId = propGroupParent.Id; // create the key by copy from the template PropertyKeyBase propKey = _processEntPropTemplRules.CreatePropKeyFromTempl(propGroupTempl); propGroupChild.Key = propKey; // save it (will create id) // TODO: besoin? //_reposit.Builder.UpdateEntity(); // add it under the propGroupParent propGroupParent.AddProperty(propGroupChild); return(true); }
public void Ent_PropGroup_Prop_KString_VString_RULToSet() { EtagairCore core = Common.CreateCoreInMemory(); // create an entity template to instantiate EntityTempl entTemplComputer = core.EditorTempl.CreateEntityTempl("TemplComputer"); // create the group Core PropGroupTempl propGroupTemplCore = core.EditorTempl.CreatePropGroupTempl(entTemplComputer, "Core"); // create a property template without the value: will be created on the instantiation PropTempl propTemplType = core.EditorTempl.CreatePropTempl(entTemplComputer, propGroupTemplCore, "Type", (string)null); // On prop type, Add Rule: add property, V=RULE:ToSet, type= string PropTemplRuleValueToSet rule = new PropTemplRuleValueToSet(); rule.ValueType = PropValueType.String; core.EditorTempl.AddPropTemplRule(entTemplComputer, propTemplType, rule); //====Instantiate EntityTemplToInst templToInst = core.ProcessTempl.CreateEntity(entTemplComputer); Assert.AreEqual(TemplToInstState.InProgress, templToInst.State, "the state should be InProgress"); Assert.AreEqual(TemplToInstStep.NeedAction, templToInst.NextStep, "the next step should be NeedAction"); //---provide an action to the rule (to execute it automatically): Property value set on instantiation PropTemplRuleActionValueToSet action = new PropTemplRuleActionValueToSet(); action.SetRule(rule); action.SetValueString("Intel"); // adds actions to rules and create the entity core.ProcessTempl.AddActionsToCreateEntity(templToInst, action); Assert.AreEqual(TemplToInstState.InProgress, templToInst.State, "the state should be InProgress"); Assert.AreEqual(TemplToInstStep.Starts, templToInst.NextStep, "the next step should be NeedAction"); // create the entity, use action core.ProcessTempl.CompleteCreateEntity(templToInst); // check that the execution finishes with success Assert.AreEqual(TemplToInstState.Success, templToInst.State, "the state should be sucess"); Assert.AreEqual(TemplToInstStep.Ends, templToInst.NextStep, "the next step should be ends"); //=====Check the creation //----check the prop group: Core PropertyBase propBase = core.Searcher.FindPropertyByKey(templToInst.Entity, templToInst.Entity.PropertyRoot, "Core", false); PropertyGroup propGroup = propBase as PropertyGroup; Assert.IsNotNull(propGroup, "the propgroup Core should exists"); // Check the prop group key PropertyKeyString propGroupKey = propGroup.Key as PropertyKeyString; Assert.IsNotNull(propGroupKey, "the propgroup key Core should exists"); Assert.AreEqual("Core", propGroupKey.Key, "the key should be Core"); //----check the property child: Type=Computer propBase = core.Searcher.FindPropertyByKey(templToInst.Entity, propGroup, "Type", false); Property prop = propBase as Property; Assert.IsNotNull(prop, "the prop child Type should exists"); // find the prop Intel (inside the group Core) from the root property PropertyBase propBaseTypeIntel = core.Searcher.FindPropertyByKey(templToInst.Entity, "Type", true); Property propTypeIntel = propBaseTypeIntel as Property; Assert.IsNotNull(propTypeIntel, "the prop child Type should exists (find from the root)"); // check the prop key: Type, find the prop from the parent PropertyKeyString propKeyString = prop.Key as PropertyKeyString; Assert.IsNotNull(propKeyString, "the prop key string Type should exists"); Assert.AreEqual("Type", propKeyString.Key, "the key should be Type"); // check the prop value //PropertyValueString propValueString = prop.Value as PropertyValueString; ValString propValueString = prop.Value as ValString; Assert.IsNotNull(propValueString, "the prop key string Type should exists"); Assert.AreEqual("Intel", propValueString.Value, "the value should be Intel"); }