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");
        }
        /// <summary>
        /// Add list of actions matching rules to create the entity from the template.
        /// </summary>
        /// <param name="templToInst"></param>
        /// <param name="listAction"></param>
        /// <returns></returns>
        public bool AddActionsToCreateEntity(EntityTemplToInst templToInst, List <PropTemplRuleActionBase> listAction)
        {
            // match actions to rules to execute
            List <PropTemplRuleBase>       listRuleToExecWithoutAction;
            List <PropTemplRuleActionBase> listActionMatches;
            bool res = MatchActionsToRules(templToInst.ListRule, listAction, out listRuleToExecWithoutAction, out listActionMatches);

            // save the actions match the rules and rules without action
            templToInst.AddActions(listActionMatches);
            templToInst.AddRulesWithoutAction(listRuleToExecWithoutAction);

            // actions don't match rules? or rules don't have actions?
            if (!res)
            {
                // one or several rules don't have an action!
                templToInst.SetNextStep(TemplToInstStep.NeedAction);
                templToInst.SetState(TemplToInstState.InProgress);
                return(false);
            }

            // ok, each rule have an action, can continue create the entity
            templToInst.SetNextStep(TemplToInstStep.Starts);
            templToInst.SetState(TemplToInstState.InProgress);
            return(true);
        }
Exemplo n.º 3
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);
        }
        public bool AddActionsToCreateEntity(EntityTemplToInst templToInst, PropTemplRuleActionBase action)
        {
            List <PropTemplRuleActionBase> listAction = new List <PropTemplRuleActionBase>();

            listAction.Add(action);
            return(AddActionsToCreateEntity(templToInst, listAction));
        }
        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");
        }
Exemplo n.º 6
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);
        }
        /// <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);
        }
        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>
        /// Complete the creation of an entity from a template.
        /// Need to be called to process rules.
        /// </summary>
        /// <param name="templToInst"></param>
        /// <returns></returns>
        public bool CompleteCreateEntity(EntityTemplToInst templToInst)
        {
            // check
            if (templToInst.NextStep != TemplToInstStep.Starts)
            {
                return(false);
            }

            if (templToInst.State != TemplToInstState.InProgress)
            {
                return(false);
            }

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

            entity.ParentFolderId = templToInst.FolderParent.Id;
            entity.SetCreatedFromTempl(templToInst.EntityTempl);
            templToInst.Entity = entity;

            // set a key to the property root, from the template
            _processEntPropTempl.SetEntPropertyRootFromTempl(templToInst.EntityTempl, entity);

            if (!_reposit.Builder.SaveEntity(entity))
            {
                return(false);
            }

            // build properties of the entity, step by step, from the property root
            List <PropTemplRuleBase> listRuleWithoutAction;

            if (!_processEntPropTempl.CreateAllPropGroupChildsFromTempl(templToInst.EntityTempl, templToInst.EntityTempl.PropertyRoot, entity, entity.PropertyRoot, templToInst.ListActionMatches, out listRuleWithoutAction))
            {
                templToInst.SetNextStep(TemplToInstStep.Ends);
                templToInst.SetState(TemplToInstState.Failed);

                // set the problem type: error occurs on instantiating properties
                // TODO:
                return(false);
            }

            // no rule to execute, the creation of the entity is incomplete
            if (listRuleWithoutAction.Count > 0)
            {
                // TODO: can't be possible!! after the refactoring; detected at the start
                // the creation of the entity needs some actions on rules
                templToInst.SetNextStep(TemplToInstStep.Ends);
                templToInst.SetState(TemplToInstState.Failed);
                // save rules
                //templToInst.SetNewListRule(listRuleWithoutAction);
                return(false);
            }

            // no rule to execute, the creation of the entity is complete
            templToInst.Entity.BuildFinished = true;
            templToInst.SetNextStep(TemplToInstStep.Ends);
            templToInst.SetState(TemplToInstState.Success);

            // save it
            if (!_reposit.Builder.UpdateEntity(entity))
            {
                return(false);
            }

            templToInst.FolderParent.AddChild(entity);

            // update the parent folder, has a new child
            if (!_reposit.Builder.UpdateFolder(templToInst.FolderParent))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 10
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");
        }
Exemplo n.º 11
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");
        }