Ejemplo n.º 1
0
        /// <summary>
        /// filter according to the key type: string, TextCode or All
        /// </summary>
        /// <param name=""></param>
        /// <param name=""></param>
        /// <returns></returns>
        private bool FilterOnKeyType(PropertyKeyBase propertyKeyBase, SearchPropCriterionKeyTextWork propCritKeyTextWork)
        {
            // match all key type: string and TextCode
            if (propCritKeyTextWork.PropKeyTextType == CritOptionPropKeyTextType.AllKeyType)
            {
                return(true);
            }

            // get the type of the prop key
            PropertyKeyString propKeyString = propertyKeyBase as PropertyKeyString;

            if (propKeyString != null)
            {
                if (propCritKeyTextWork.PropKeyTextType == CritOptionPropKeyTextType.KeyStringOnly)
                {
                    return(true);
                }

                return(false);
            }

            // the prop key type is TextCode
            if (propCritKeyTextWork.PropKeyTextType == CritOptionPropKeyTextType.KeyTextCodeOnly)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create an entity, under a folder parent.
        /// </summary>
        /// <param name="folderParent"></param>
        /// <returns></returns>
        public Entity CreateEntity(Folder folderParent)
        {
            // parent folder is null? its the root
            if (folderParent == null)
            {
                folderParent = _reposit.Finder.GetRootFolder();
            }

            // create an entity, attach it under the parent
            Entity entity = new Entity();

            entity.ParentFolderId = folderParent.Id;

            // set a key to the property root
            PropertyKeyString key = new PropertyKeyString();

            key.Key = CoreDef.DefaultPropertyRootName;
            entity.PropertyRoot.Key = key;

            // save it
            if (!_reposit.Builder.SaveEntity(entity))
            {
                return(null);
            }

            folderParent.AddChild(entity);

            // update the parent foder, has a new child
            if (!_reposit.Builder.UpdateFolder(folderParent))
            {
                return(null);
            }

            return(entity);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// low-level 2.
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="propertyParent"></param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public Property CreateProperty(Entity entity, PropertyGroup propertyParent, string key, IValue value)
        {
            // check the entity parent
            if (entity == null)
            {
                return(null);
            }

            if (propertyParent == null)
            {
                propertyParent = entity.PropertyRoot;
            }

            if (string.IsNullOrWhiteSpace(key))
            {
                return(null);
            }

            // check the key, not used by an existing property
            if (_searcher.FindPropertyByKey(entity, propertyParent, key, false) != null)
            {
                return(null);
            }

            PropertyKeyString propertyKey = new PropertyKeyString();

            propertyKey.Key = key;

            return(CreateProperty(entity, propertyParent, propertyKey, value));
        }
        public void EntOneProp_KString_VBool()
        {
            EtagairCore core = Common.CreateCore(RepositConfig);

            // create an entity template to instantiate
            EntityTempl templComputer = core.EditorTempl.CreateEntityTempl("TemplComputer");

            // add property
            core.EditorTempl.CreatePropTempl(templComputer, "Count", true);

            //====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 key property: Count
            PropertyBase propBase = core.Searcher.FindPropertyByKey(templToInst.Entity, templToInst.Entity.PropertyRoot, "Count", false);
            Property     prop     = propBase as Property;

            //----check the prop key, is: Count
            PropertyKeyString propKeyString = prop.Key as PropertyKeyString;

            Assert.IsNotNull(propKeyString, "the prop key string Type should exists");
            Assert.AreEqual("Count", propKeyString.Key, "the key should be Count");

            // check the prop value
            ValBool propValueBool = prop.Value as ValBool;

            Assert.IsNotNull(propValueBool, "the prop key bool Count should exists");
            Assert.AreEqual(true, propValueBool.Value, "the value should be 12.0");
        }
        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>
        /// Set the prop root to an entity, from a template.
        /// the key is a string (like the root key from the template).
        /// </summary>
        /// <param name="entityTempl"></param>
        /// <param name="entity"></param>
        public void SetEntPropertyRootFromTempl(EntityTempl entityTempl, Entity entity)
        {
            // TODO: always a string?
            PropKeyTemplString propKeyTemplString = entityTempl.PropertyRoot.Key as PropKeyTemplString;

            // set a key to the property root
            PropertyKeyString key = new PropertyKeyString();

            key.Key = propKeyTemplString.Key; // CoreDef.DefaultPropertyRootName;
            entity.PropertyRoot.Key = key;
            entity.PropertyRoot.PropGroupTemplId = entityTempl.PropertyRoot.Id;
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        /// <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);
        }
Ejemplo n.º 10
0
        public PropertyGroup CreatePropertyGroup(Entity entity, PropertyGroup propertyParent, string key)
        {
            // check the entity parent
            if (entity == null)
            {
                return(null);
            }

            if (propertyParent == null)
            {
                propertyParent = entity.PropertyRoot;
            }

            if (string.IsNullOrWhiteSpace(key))
            {
                return(null);
            }

            // check the key, not used by an existing property
            if (_searcher.FindPropertyByKey(entity, propertyParent, key, false) != null)
            {
                return(null);
            }

            PropertyKeyString propertyKey = new PropertyKeyString();

            propertyKey.Key = key;
            // create the property, set the key and the value
            PropertyGroup property = new PropertyGroup();

            property.Key = propertyKey;
            property.PropGroupParentId = propertyParent.Id;

            // add the property under the root properties
            entity.AddProperty(propertyParent, property);

            // save the entity modification
            if (!_reposit.Builder.UpdateEntity(entity))
            {
                return(null);
            }

            return(property);
        }
Ejemplo n.º 11
0
        // 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);
        }
Ejemplo n.º 12
0
        public void CreateEntity_Prop_KeyString_ValInt()
        {
            EtagairCore core = Common.CreateCore(RepositConfig);

            // create an ent
            Entity toshibaCoreI7 = core.Editor.CreateEntity();

            // Add a property to an object: key - value
            Property propName = core.Editor.CreateProperty(toshibaCoreI7, "Year", 2019);

            // check the property key (type and value)
            PropertyKeyString propKeyString = propName.Key as PropertyKeyString;

            Assert.IsNotNull(propKeyString, "the key should be a string");
            Assert.AreEqual("Year", propKeyString.Key, "the key should be 'Year'");

            // check the property value (type and value)
            ValInt propValueInt = propName.Value as ValInt;

            Assert.IsNotNull(propValueInt, "the value should be an int");
            Assert.AreEqual(2019, propValueInt.Value, "the key should be an int");
        }
Ejemplo n.º 13
0
        public void CreateEntity_Prop_KeyString_ValDouble()
        {
            EtagairCore core = Common.CreateCore(RepositConfig);

            // create an ent
            Entity toshibaCoreI7 = core.Editor.CreateEntity();

            // Add a property to an object: key - value
            Property propName = core.Editor.CreateProperty(toshibaCoreI7, "Value", 12.5);

            // check the property key (type and value)
            PropertyKeyString propKeyString = propName.Key as PropertyKeyString;

            Assert.IsNotNull(propKeyString, "the key should be a string");
            Assert.AreEqual("Value", propKeyString.Key, "the key should be 'Value'");

            // check the property value (type and value)
            ValDouble propValueDouble = propName.Value as ValDouble;

            Assert.IsNotNull(propValueDouble, "the value should be a  double");
            Assert.AreEqual(12.5, propValueDouble.Value, "the key should be 12.5");
        }
Ejemplo n.º 14
0
        public void CreateEntity_Prop_KeyString_ValBool()
        {
            EtagairCore core = Common.CreateCore(RepositConfig);

            // create an ent
            Entity toshibaCoreI7 = core.Editor.CreateEntity();

            // Add a property to an object: key - value
            Property propName = core.Editor.CreateProperty(toshibaCoreI7, "Done", true);

            // check the property key (type and value)
            PropertyKeyString propKeyString = propName.Key as PropertyKeyString;

            Assert.IsNotNull(propKeyString, "the key should be a string");
            Assert.AreEqual("Done", propKeyString.Key, "the key should be 'Value'");

            // check the property value (type and value)
            ValBool propValueBool = propName.Value as ValBool;

            Assert.IsNotNull(propValueBool, "the value should be a bool");
            Assert.AreEqual(true, propValueBool.Value, "the key should be true");
        }
        /// <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!");
        }
Ejemplo n.º 16
0
        public void CreateEntity_Prop_KeyString_ValString()
        {
            EtagairCore core = Common.CreateCore(RepositConfig);

            // create an ent
            Entity toshibaCoreI7 = core.Editor.CreateEntity();

            // Add a property to an object: key - value
            Property propName = core.Editor.CreateProperty(toshibaCoreI7, "Name", "Toshiba");

            // check the property key (type and value)
            PropertyKeyString propKeyString = propName.Key as PropertyKeyString;

            Assert.IsNotNull(propKeyString, "the key should be a string");
            Assert.AreEqual("Name", propKeyString.Key, "the key should be 'Name'");

            // check the property value (type and value)
            //PropertyValueString propValueString = propName.Value as PropertyValueString;
            ValString propValueString = propName.Value as ValString;

            Assert.IsNotNull(propValueString, "the value should be a string");
            Assert.AreEqual("Toshiba", propValueString.Value, "the key should be 'Toshiba'");
        }
Ejemplo n.º 17
0
        public void EntOneProp_KeyString_ValString_RULToSet()
        {
            EtagairCore core = Common.CreateCoreInMemory();

            // 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.CreatePropTemplValueStringNull(templComputer, "Name");

            // Add Rule: add property, V=RULE:Toset, type= TextCode: to be set on instanciation
            PropTemplRuleValueToSet rule = new PropTemplRuleValueToSet();

            rule.ValueType = PropValueType.String;
            core.EditorTempl.AddPropTemplRule(templComputer, propTempl, rule);

            // provide an action to the rule (to execute it automatically): Property value set on instantiation
            PropTemplRuleActionValueToSet action = new PropTemplRuleActionValueToSet();

            action.SetRule(rule);
            action.SetValueString("Toshiba");

            //====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
            PropertyKeyString propKeyString = prop.Key as PropertyKeyString;

            Assert.IsNotNull(propKeyString, "the prop key string Type should exists");
            Assert.AreEqual("Name", propKeyString.Key, "the prop value should be Name");

            //----check the prop value
            //PropertyValueString propValueValue = prop.Value as PropertyValueString;
            ValString propValueString = prop.Value as ValString;

            Assert.IsNotNull(propValueString, "the prop key string Typeshould exists");
            Assert.AreEqual("Toshiba", propValueString.Value, "the prop value should be Toshiba");
        }
Ejemplo n.º 18
0
        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");
        }