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)); }
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'"); }
/// <summary> /// Create a property to an object: key - value, /// both are textCode (will be displayed translated depending on the language). /// </summary> /// <param name="entity"></param> /// <param name="tcKey"></param> /// <param name="tcValue"></param> /// <returns></returns> public Property CreateProperty(Entity entity, PropertyGroup propertyParent, TextCode tcKey, TextCode tcValue) { // create the property value ValTextCodeId valTextCode = new ValTextCodeId(); valTextCode.TextCodeId = tcValue.Id; return(CreateProperty(entity, propertyParent, tcKey, valTextCode)); }
private string GetPropValueText(EtagairEngine engine, IValue value) { ValString propValueString = value as ValString; if (propValueString != null) { return("\"" + propValueString.Value + "\""); } ValTextCodeId propValueTextCode = value as ValTextCodeId; string propKeyText = "\"" + "tc/" + engine.Searcher.FindTextCodeById(propValueTextCode.TextCodeId).Code + "\""; return(propKeyText); }
/// <summary> /// Return the property value content as a string. /// Can be a string, a textCodeId. /// Later: image,... /// /// </summary> /// <param name="propertyKeyBase"></param> /// <returns></returns> public static string GetPropertyValueContent(IValue value) { ValString propValueString = value as ValString; if (propValueString != null) { return(propValueString.Value); } ValTextCodeId propValueTextCode = value as ValTextCodeId; if (propValueTextCode != null) { return(propValueTextCode.TextCodeId); } // TODO: implement others types: Image, ImageCode,... return(null); }
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"); }
/// <summary> /// create the value by copy from the template. /// </summary> /// <param name="actionSetOnInst"></param> /// <param name="ruleValueSetOnInst"></param> /// <returns></returns> //private PropertyValueBase CreatePropValueFromAction(PropTemplRuleActionValueToSet actionSetOnInst, PropTemplRuleValueToSet ruleValueSetOnInst) private IValue CreatePropValueFromAction(PropTemplRuleActionValueToSet actionSetOnInst, PropTemplRuleValueToSet ruleValueSetOnInst) { if (ruleValueSetOnInst.ValueType == PropValueType.String) { //PropertyValueString propValueString = new PropertyValueString(); //propValueString.Value = actionSetOnInst.ValueString; // return propValueString; ValString valString = new ValString(); valString.Value = actionSetOnInst.ValueString; return(valString); } if (ruleValueSetOnInst.ValueType == PropValueType.TextCode) { //PropertyValueTextCode propValueTextCode = new PropertyValueTextCode(); //propValueTextCode.TextCodeId = actionSetOnInst.ValueTextCodeId; //return propValueTextCode; ValTextCodeId valTextCodeId = new ValTextCodeId(); valTextCodeId.TextCodeId = actionSetOnInst.ValueTextCodeId; return(valTextCodeId); } throw new Exception("property Value type 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"); }