コード例 #1
0
        /// <summary>
        /// Create an entity from a template (basic case).
        /// Has one property: key and value are string type.
        ///
        /// ET: "TemplComputer"
        ///     P: K=Type, V=Computer
        ///
        /// After processing the template:
        ///
        /// E:
        ///     P: K=Type, V=Computer
        ///
        /// </summary>
        public void EntityTemplate_PropKeyAndValue_TextCode()
        {
            EtagairEngine engine = CreateEngine();

            Console.WriteLine("Create an entity template.");

            //====Create an entity template
            EntityTempl templComputer = engine.EditorTempl.CreateEntityTempl("TemplComputer");

            TextCode tcKeyType   = engine.Editor.CreateTextCode("Type");
            TextCode tcValueType = engine.Editor.CreateTextCode("Computer");

            // add property to the template, Key=Type, Value=Computer
            engine.EditorTempl.CreatePropTempl(templComputer, tcKeyType, tcValueType);

            //====Instanciate the template, create an entity, under the root folder
            EntityTemplToInst templToInst = engine.ProcessTempl.CreateEntity(templComputer);

            // the state should be Success
            Console.WriteLine("Create entity:");
            Console.WriteLine("  State: " + templToInst.State.ToString());
            // the nextStep should be: Ends
            Console.WriteLine("  NextStep: " + templToInst.NextStep.ToString());

            // displays the entity id
            Console.WriteLine("\n-----Created entity id: " + templToInst.Entity.Id);
            DisplayEntity(engine, templToInst.Entity, 0, false);
        }
コード例 #2
0
        /// <summary>
        /// Add a rule to a property template.
        /// </summary>
        /// <param name="propTempl"></param>
        /// <param name="rule"></param>
        /// <returns></returns>
        public bool AddPropTemplRule(EntityTempl entityTempl, PropTempl propTempl, PropTemplRuleBase rule)
        {
            // do some checks
            // TODO:

            // the propTempl shouln't have the same rule type
            if (propTempl.ListRule.Find(r => r.Type == rule.Type) != null)
            {
                return(false);
            }

            rule.EntityTemplId = entityTempl.Id;

            rule.PropKeyTempl = propTempl.Key;

            // find the property group parent of the prop
            //PropGroupTempl propGroupTemplParent = FindPropGroupTemplParent(entityTempl, propTempl);
            //rule.PropGroupTemplId = propGroupTemplParent.Id;
            rule.PropGroupTemplId = propTempl.PropGroupTemplParentId;

            propTempl.AddRule(rule);

            // save the entity modification
            return(_reposit.Builder.UpdateEntityTempl(entityTempl));
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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");
        }
コード例 #5
0
        /// <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!");
        }
コード例 #6
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");
        }
コード例 #7
0
        public bool UpdateEntityTempl(EntityTempl entityTempl)
        {
            // check for new added inner object: missing id
            SetPropTemplAllMissingId(entityTempl.PropertyRoot);

            // nothing more to do!
            return(true);
        }
コード例 #8
0
        /// <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);
        }
コード例 #9
0
        /// <summary>
        /// Templ Entity, has a rule the property value: will be set on entity instantiation.
        ///
        /// EntTempl TemplComputer
        ///    P: K="Name", V=RULE:ToSet
        ///
        /// The creation of the entity need to provide the property value text.
        /// Ent
        ///    P: K="Name", V="Toshiba"
        ///
        /// </summary>
        public void EntityTemplate_Rule_PropValToSet()
        {
            EtagairEngine engine = CreateEngine();

            Console.WriteLine("Create an entity template with a rule.");


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

            // create a property template without the value: will be created on the instantiation
            PropTempl propTempl = engine.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;
            engine.EditorTempl.AddPropTemplRule(templComputer, propTempl, rule);

            //====Instantiate the template, create an entity, under the root folder
            EntityTemplToInst templToInst = engine.ProcessTempl.CreateEntity(templComputer);

            // the state should be InProgress/NeedAction
            Console.WriteLine("\n1. Create entity:");
            Console.WriteLine("  State: " + templToInst.State.ToString());
            Console.WriteLine("  NextStep: " + templToInst.NextStep.ToString());

            // 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");

            // adds actions to rules and create the entity
            engine.ProcessTempl.AddActionsToCreateEntity(templToInst, action);

            // the state should be InProgress/NeedAction
            Console.WriteLine("\n2. Add Action to the rule: PropValue SetTo='Toshiba'");
            Console.WriteLine("  State: " + templToInst.State.ToString());
            // the nextStep should be: Ends
            Console.WriteLine("  NextStep: " + templToInst.NextStep.ToString());

            // create the entity, use action
            engine.ProcessTempl.CompleteCreateEntity(templToInst);

            // the state should be InProgress/NeedAction
            Console.WriteLine("\n3. Complete the creation:");
            Console.WriteLine("  State: " + templToInst.State.ToString());
            // the nextStep should be: Ends
            Console.WriteLine("  NextStep: " + templToInst.NextStep.ToString());

            // displays the entity id
            Console.WriteLine("\n-----Created entity id: " + templToInst.Entity.Id);
            DisplayEntity(engine, templToInst.Entity, 0, false);
        }
コード例 #10
0
        /// <summary>
        /// Check the consistency of the template: check properties.
        /// Return the number of problems.
        /// </summary>
        /// <param name="entityTempl"></param>
        /// <returns></returns>
        public int CheckConsistencyEntityTempl(EntityTempl entityTempl, List <PropTemplRuleBase> listRuleToExec)
        {
            // check on the entity level
            // TODO:

            // todo: manage errors: entityTempl.ListError
            // List<EntityTemplError> listError = new List<EntityTemplError>();
            //
            // check the properties
            return(CheckConsistencyPropTempl(entityTempl, entityTempl.PropertyRoot, listRuleToExec));
        }
コード例 #11
0
        public void CreateEntTempl()
        {
            EtagairCore core = Common.CreateCore(RepositConfig);

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

            Assert.IsNotNull(entityTempl.Id, "the id should be set");
            Assert.AreEqual("entityTempl", entityTempl.Name, "the name is wrong");
            Assert.IsNotNull(entityTempl.ParentFolderId, "the parent folder id should exists, its the root folder)");
        }
コード例 #12
0
        public bool SaveEntityTempl(EntityTempl entityTempl)
        {
            entityTempl.Id = Guid.NewGuid().ToString();

            // set an id to the property root
            entityTempl.PropertyRoot.Id = Guid.NewGuid().ToString();

            // save it
            _sysData.ListEntityTempl.Add(entityTempl);
            return(true);
        }
コード例 #13
0
        /// <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);
        }
コード例 #14
0
        /// <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;
        }
コード例 #15
0
        /// <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));
        }
コード例 #16
0
        /// <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));
        }
コード例 #17
0
        /// <summary>
        /// Start create/instanciate an entity from a template, under a folder parent.
        /// return the list of rules. (each rule need an action).
        /// Next step is to call the AddActionsToCreateEntity method to add actions or directly CreateEntity if there is no action.
        /// </summary>
        /// <param name="entityTempl"></param>
        /// <param name="folderParent"></param>
        /// <returns></returns>
        public EntityTemplToInst CreateEntity(EntityTempl entityTempl, Folder folderParent)
        {
            // parent folder is null? its the root
            if (folderParent == null)
            {
                folderParent = _reposit.Finder.GetRootFolder();
            }

            // create the object managing the process
            EntityTemplToInst templToInst = new EntityTemplToInst();

            templToInst.EntityTempl  = entityTempl;
            templToInst.FolderParent = folderParent;

            // check the consistency and get rule to execute (need an action) of the entity template
            List <PropTemplRuleBase> listRuleToExec = new List <PropTemplRuleBase>();

            if (_processEntPropTempl.CheckConsistencyEntityTempl(entityTempl, listRuleToExec) > 0)
            {
                templToInst.SetNextStep(TemplToInstStep.Ends);
                templToInst.SetState(TemplToInstState.Failed);

                templToInst.SetNewListRule(listRuleToExec);

                // set the problem type: Consistency
                // TODO: save the number of problems! (and details?)

                return(templToInst);
            }

            // ok, template is consistent, no rule, can create the entity, doesn't need action
            if (listRuleToExec.Count == 0)
            {
                templToInst.SetNextStep(TemplToInstStep.Starts);
                templToInst.SetState(TemplToInstState.InProgress);

                // can complete the creation of the entity
                CompleteCreateEntity(templToInst);

                return(templToInst);
            }

            // ok, template is consistent, rules exists, need all actions before creates the entity
            templToInst.SetNextStep(TemplToInstStep.NeedAction);
            templToInst.SetState(TemplToInstState.InProgress);
            templToInst.SetNewListRule(listRuleToExec);
            return(templToInst);
        }
コード例 #18
0
        /// <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));
        }
コード例 #19
0
        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));
        }
コード例 #20
0
        /// <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));
        }
コード例 #21
0
        /// <summary>
        /// Create an entity template under the root folder parent.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public EntityTempl CreateEntityTempl(Folder folderParent, string name)
        {
            // parent folder is null? its the root
            if (folderParent == null)
            {
                folderParent = _reposit.Finder.GetRootFolder();
            }

            // TODO:
            if (string.IsNullOrWhiteSpace(name))
            {
                return(null);
            }

            // check the syntax
            // TODO: no special character,...

            // create an entity, attach it the parent
            EntityTempl entityTempl = new EntityTempl();

            entityTempl.ParentFolderId = folderParent.Id;
            entityTempl.Name           = name;

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

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

            // save it
            if (!_reposit.Builder.SaveEntityTempl(entityTempl))
            {
                return(null);
            }

            folderParent.AddChild(entityTempl);

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

            return(entityTempl);
        }
コード例 #22
0
        //====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);
        }
コード例 #23
0
        /// <summary>
        /// Check the consistency of the property template: key and value.
        /// </summary>
        /// <param name="entityTempl"></param>
        /// <param name="propTempl"></param>
        /// <param name="listRuleToExec"></param>
        /// <returns></returns>
        private int CheckConsistencyPropTempl(EntityTempl entityTempl, PropTempl propTempl, List <PropTemplRuleBase> listRuleToExec)
        {
            int pbCount = 0;

            // check the key
            if (propTempl.Key == null)
            {
                // the key must exists!
                pbCount++;
            }

            // analyze all rules of the property template
            foreach (PropTemplRuleBase rule in propTempl.ListRule)
            {
                // save the rule to execute
                listRuleToExec.Add(rule);

                // the propTempl contains the rule PropValueToSet?
                if (rule.Type == PropTemplRuleType.PropValueToSet)
                {
                    // the property template value must be null!
                    if (!(propTempl.PropValueTempl.Value == null))
                    {
                        // TODO: prendre le membre inner (string, ...)
                        // + créer une liste d'erreurs.
                        //ici();

                        // TODO: voir selon le type!
                        pbCount++;
                    }
                }
            }

            // check: no rule to execute and the prop value is null-> error!
            if (listRuleToExec.Count == 0 && propTempl.PropValueTempl == null)
            {
                // todo:check the type of rule for tis case?? PropValueSetOnInstance
                pbCount++;
            }

            return(pbCount);
        }
コード例 #24
0
        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");
        }
コード例 #25
0
        public void EntOneProp_KString_VString()
        {
            EtagairCore core = Common.CreateCore(RepositConfig);

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

            // add property
            PropTempl propTempl = core.EditorTempl.CreatePropTempl(templComputer, "Type", "Computer");

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

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

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

            Assert.IsNotNull(propValueString, "the value should be a string");
            Assert.AreEqual("Computer", propValueString.Value, "the key should be 'Computer'");
        }
コード例 #26
0
        public bool SaveEntityTempl(EntityTempl entityTempl)
        {
            try
            {
                // must have a property root (a group)
                // TODO:

                entityTempl.Id = ObjectId.NewObjectId().ToString();

                // set an id for the group property
                entityTempl.PropertyRoot.Id = ObjectId.NewObjectId().ToString();

                // save the object
                _sysData.DBEngine.Insert <EntityTempl>(entityTempl);
                return(true);
            }
            catch
            {
                throw new Exception("Error, Can't save the EntityTempl.");
                //return false;
            }
        }
コード例 #27
0
        public bool UpdateEntityTempl(EntityTempl entityTempl)
        {
            if (entityTempl == null)
            {
                return(false);
            }
            if (entityTempl.Id == null)
            {
                return(false);
            }

            // check for new added inner object: missing id
            SetPropTemplAllMissingId(entityTempl.PropertyRoot);

            try
            {
                _sysData.DBEngine.Update <EntityTempl>(entityTempl);
                return(true);
            }
            catch
            {
                throw new Exception("Error, Can't update the EntityTempl.");
            }
        }
コード例 #28
0
 /// <summary>
 /// Start create/instanciate an entity from a template, under the root folder.
 /// </summary>
 /// <param name="entityTempl"></param>
 /// <returns></returns>
 public EntityTemplToInst CreateEntity(EntityTempl entityTempl)
 {
     return(CreateEntity(entityTempl, _reposit.Finder.GetRootFolder()));
 }
コード例 #29
0
        //====prop key is a string

        /// <summary>
        /// Create a property template.
        /// The string value is null.
        /// </summary>
        /// <param name="entityTempl"></param>
        /// <param name="tcKey"></param>
        /// <returns></returns>
        public PropTempl CreatePropTemplValueStringNull(EntityTempl entityTempl, string key)
        {
            return(CreatePropTempl(entityTempl, key, (string)null));
        }
コード例 #30
0
 /// <summary>
 /// Create a property template.
 /// The TextCode value is null.
 /// </summary>
 /// <param name="entityTempl"></param>
 /// <param name="tcKey"></param>
 /// <returns></returns>
 public PropTempl CreatePropTemplValueTextCodeNull(EntityTempl entityTempl, TextCode tcKey)
 {
     return(CreatePropTempl(entityTempl, tcKey, (TextCode)null));
 }