/// <summary> /// The property key text can be a string or a textCode. /// If its a textCode, go in the repository to read the textCode by the id. /// </summary> /// <param name="propCritKeyTextWork"></param> /// <param name="propertyKeyBase"></param> /// <returns></returns> private bool GetKeyText(PropertyKeyBase propertyKeyBase, out string keyText) { PropertyKeyString propKeyString = propertyKeyBase as PropertyKeyString; if (propKeyString != null) { keyText = propKeyString.Key; // ok return(true); } keyText = ""; PropertyKeyTextCode propKeyTextCode = propertyKeyBase as PropertyKeyTextCode; if (propKeyTextCode == null) { // error! return(false); } // load the textCode TextCode textCode = _reposit.Finder.FindTextCodeById(propKeyTextCode.TextCodeId); if (textCode == null) { // error! return(false); } keyText = textCode.Code; return(true); }
public void CreateEntity_Prop_KeyTextCode_ValTextCode() { EtagairCore core = Common.CreateCore(RepositConfig); TextCode tcName = core.Editor.CreateTextCode("Name"); TextCode tcToshiba = core.Editor.CreateTextCode("Toshiba"); // create an ent Entity toshibaCoreI7 = core.Editor.CreateEntity(); // Add a property to an object: key - value Property propName = core.Editor.CreateProperty(toshibaCoreI7, tcName, tcToshiba); // check the property key (type and value) PropertyKeyTextCode propKeyTextCode = propName.Key as PropertyKeyTextCode; Assert.IsNotNull(propKeyTextCode, "the key should be a TextCode"); Assert.AreEqual(tcName.Id, propKeyTextCode.TextCodeId, "the key should be 'Name'"); // check the property value (type and value) ValTextCodeId propValueTextCode = propName.Value as ValTextCodeId; Assert.IsNotNull(propValueTextCode, "the value should be a TextCode"); Assert.AreEqual(tcToshiba.Id, propValueTextCode.TextCodeId, "the key should be 'Toshiba'"); }
private string GetPropKeyText(EtagairEngine engine, PropertyKeyBase propertyKeybase) { PropertyKeyString propKeyString = propertyKeybase as PropertyKeyString; if (propKeyString != null) { return("\"" + propKeyString.Key + "\""); } PropertyKeyTextCode propKeyTextCode = propertyKeybase as PropertyKeyTextCode; string propKeyText = "\"" + "tc/" + engine.Searcher.FindTextCodeById(propKeyTextCode.TextCodeId).Code + "\""; return(propKeyText); }
public PropertyGroup CreatePropertyGroup(Entity entity, PropertyGroup propertyParent, TextCode tcKey) { // check the entity parent if (entity == null) { return(null); } if (propertyParent == null) { propertyParent = entity.PropertyRoot; } if (tcKey == null) { return(null); } // check the key, not used by an existing property if (_searcher.FindPropertyByKey(entity, propertyParent, tcKey.Code, false) != null) { return(null); } PropertyKeyTextCode propertyKey = new PropertyKeyTextCode(); propertyKey.TextCodeId = tcKey.Id; // create the property, set the key and the value PropertyGroup property = new PropertyGroup(); property.PropGroupParentId = propertyParent.Id; property.Key = propertyKey; // add the property under the root properties entity.AddProperty(propertyParent, property); // save the entity modification if (!_reposit.Builder.UpdateEntity(entity)) { return(null); } return(property); }
/// <summary> /// Return the property key content as a string. /// can be a string or a textCodeId. /// </summary> /// <param name="propertyKeyBase"></param> /// <returns></returns> public static string GetPropertyKeyContent(PropertyKeyBase propertyKeyBase) { PropertyKeyString propKeyString = propertyKeyBase as PropertyKeyString; if (propKeyString != null) { return(propKeyString.Key); } PropertyKeyTextCode propKeyTextCode = propertyKeyBase as PropertyKeyTextCode; if (propKeyTextCode != null) { return(propKeyTextCode.TextCodeId); } return(null); }
/// <summary> /// low-level 2. /// </summary> /// <param name="entity"></param> /// <param name="propertyParent"></param> /// <param name="tcKey"></param> /// <param name="value"></param> /// <returns></returns> public Property CreateProperty(Entity entity, PropertyGroup propertyParent, TextCode tcKey, IValue value) { if (tcKey == null) { return(null); } // check the key, not used by an existing property if (_searcher.FindPropertyByKey(entity, propertyParent, tcKey.Code, false) != null) { return(null); } // create the property key PropertyKeyTextCode propertyKey = new PropertyKeyTextCode(); propertyKey.TextCodeId = tcKey.Id; return(CreateProperty(entity, propertyParent, propertyKey, value)); }
public void EntOneProp_KTextCode_VTextCode() { EtagairCore core = Common.CreateCore(RepositConfig); TextCode tcKeyType = core.Editor.CreateTextCode("Type"); TextCode tcValueType = core.Editor.CreateTextCode("Computer"); // create an entity template to instantiate EntityTempl templComputer = core.EditorTempl.CreateEntityTempl("TemplComputer"); // add property core.EditorTempl.CreatePropTempl(templComputer, tcKeyType, tcValueType); //====Instanciate the template, create an entity, under the root folder 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, get the property: Type=Computer PropertyBase propBase = core.Searcher.FindPropertyByKey(templToInst.Entity, templToInst.Entity.PropertyRoot, "Type", false); Assert.IsNotNull(propBase, "the propBase Type=Computer should exists"); Property prop = propBase as Property; Assert.IsNotNull(prop, "the prop Type=Computer should exists"); //----check the prop key PropertyKeyTextCode propKeyTextCode = prop.Key as PropertyKeyTextCode; Assert.IsNotNull(propKeyTextCode, "the prop key string Type should exists"); Assert.AreEqual(tcKeyType.Id, propKeyTextCode.TextCodeId, "the prop value should be the textCode id of the text Name"); //----check the prop value ValTextCodeId propValueTextCode = prop.Value as ValTextCodeId; Assert.IsNotNull(propValueTextCode, "the prop key string Typeshould exists"); Assert.AreEqual(tcValueType.Id, propValueTextCode.TextCodeId, "the prop value should be the textCode id of text Toshiba"); }
// is the property key a textCode? private bool IsKeyMatchProperty(PropertyBase property, string key, TextCode tcKey) { PropertyKeyTextCode keyTextCode = property.Key as PropertyKeyTextCode; if (keyTextCode != null) { if (tcKey != null) { // the key to find is a TextCode if (keyTextCode.TextCodeId.Equals(tcKey.Id)) { return(true); } } else { // the property key is a textCode, load it to get the code, because the key is a string TextCode tcPropKey = _reposit.Finder.FindTextCodeById(keyTextCode.TextCodeId); if (tcPropKey.Code.Equals(key)) { return(true); } } } // is the property key a string? PropertyKeyString keyString = property.Key as PropertyKeyString; if (keyString != null) { // compare strings if (keyString.Key.Equals(key)) { return(true); } } // the property doesn't match the key (string or TextCode) return(false); }
/// <summary> /// Create a property key, based on the template. /// </summary> /// <param name="propTempl"></param> /// <returns></returns> public PropertyKeyBase CreatePropKeyFromTempl(PropTemplBase propTempl) { // create the key of the property, from the template PropKeyTemplTextCode templKeyTextCode = propTempl.Key as PropKeyTemplTextCode; if (templKeyTextCode != null) { PropertyKeyTextCode propKey = new PropertyKeyTextCode(); propKey.TextCodeId = templKeyTextCode.TextCodeId; return(propKey); } PropKeyTemplString templKeyString = propTempl.Key as PropKeyTemplString; if (templKeyString != null) { PropertyKeyString propKey = new PropertyKeyString(); propKey.Key = templKeyString.Key; return(propKey); } throw new Exception("Property Key templ not yet implemented!"); }
public void EntOneProp_KeyTextCode_ValTextCode_RULToSet() { EtagairCore core = Common.CreateCoreInMemory(); TextCode tcKeyName = core.Editor.CreateTextCode("Name"); // create an entity template to instanciate EntityTempl templComputer = core.EditorTempl.CreateEntityTempl("TemplComputer"); // create a property template without the value: will be created on the instantiation PropTempl propTempl = core.EditorTempl.CreatePropTemplValueTextCodeNull(templComputer, tcKeyName); // Add Rule: add property, V=RULE:Toset, type= TextCode: to be set on instanciation PropTemplRuleValueToSet rule = new PropTemplRuleValueToSet(); rule.ValueType = PropValueType.TextCode; core.EditorTempl.AddPropTemplRule(templComputer, propTempl, rule); // provide an action to the rule (to execute it automatically): Property value set on instantiation TextCode tcNameValToshiba = core.Editor.CreateTextCode("Toshiba"); PropTemplRuleActionValueToSet action = new PropTemplRuleActionValueToSet(); action.SetRule(rule); action.SetValueTextCodeId(tcNameValToshiba.Id); //====Instantiate the template, create an entity, under the root folder EntityTemplToInst templToInst = core.ProcessTempl.CreateEntity(templComputer); Assert.AreEqual(TemplToInstState.InProgress, templToInst.State, "the state should be InProgress"); Assert.AreEqual(TemplToInstStep.NeedAction, templToInst.NextStep, "the next step should be NeedAction"); // 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 Starts"); // 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, get the property: Name=Toshiba PropertyBase propBase = core.Searcher.FindPropertyByKey(templToInst.Entity, templToInst.Entity.PropertyRoot, "Name", false); Assert.IsNotNull(propBase, "the propBase Type=Computer should exists"); Property prop = propBase as Property; Assert.IsNotNull(prop, "the prop Type=Computer should exists"); //----check the prop key PropertyKeyTextCode propKeyTextCode = prop.Key as PropertyKeyTextCode; Assert.IsNotNull(propKeyTextCode, "the prop key string Type should exists"); Assert.AreEqual(tcKeyName.Id, propKeyTextCode.TextCodeId, "the prop value should be the textCode id of the text Name"); //----check the prop value //PropertyValueTextCode propValueTextCode = prop.Value as PropertyValueTextCode; ValTextCodeId propValueTextCode = prop.Value as ValTextCodeId; Assert.IsNotNull(propValueTextCode, "the prop key string Typeshould exists"); Assert.AreEqual(tcNameValToshiba.Id, propValueTextCode.TextCodeId, "the prop value should be the textCode id of text Toshiba"); }