示例#1
0
        /// <summary>
        /// Displays entities and folder, then go inside folders to displays childs.
        /// </summary>
        private void DisplayAllObjects(EtagairEngine engine, Folder folderParent, int depth)
        {
            string indent = new string(' ', depth * 2);

            foreach (var obj in folderParent.ListChildId)
            {
                // the object is an entity
                if (obj.Value == ObjectType.Entity)
                {
                    Entity entity = engine.Searcher.FindEntityById(obj.Key);
                    // load the entity
                    Console.WriteLine(indent + "-Ent, id: " + obj.Key);
                    Console.WriteLine(indent + "   prop count: " + entity.PropertyRoot.ListProperty.Count);
                }

                // the object is an entity
                if (obj.Value == ObjectType.Folder)
                {
                    Folder folder = engine.Searcher.FindFolderById(obj.Key);
                    // load the entity
                    Console.WriteLine(indent + "-Fold, id: " + obj.Key + ", Name: " + folder.Name + ", Child count: " + folder.ListChildId.Count);

                    // displays childs objects of this folder
                    DisplayAllObjects(engine, folder, depth + 1);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Displays the propertyGroup.
        /// (yes or not if its the root propertyGroup of the entity).
        /// </summary>
        /// <param name="engine"></param>
        /// <param name="entity"></param>
        /// <param name="propertyGroupParent"></param>
        /// <param name="depth"></param>
        /// <param name="displayRootProperty"></param>
        public void DisplayPropertyGroup(EtagairEngine engine, Entity entity, PropertyGroup propertyGroupParent, int depth, bool displayRootProperty)
        {
            string indent = new string(' ', depth * 2);

            // display the proerty group itself
            if (displayRootProperty)
            {
                depth++;
                Console.WriteLine(indent + "PG: K=" + GetPropKeyText(engine, propertyGroupParent.Key) + "\\  (child(s) count= " + propertyGroupParent.ListProperty.Count + ")");
            }

            foreach (PropertyBase prop in propertyGroupParent.ListProperty)
            {
                // final property?
                Property propChild = prop as Property;
                if (propChild != null)
                {
                    DisplayProperty(engine, propChild, depth);
                    continue;
                }

                PropertyGroup propertyGroupChild = prop as PropertyGroup;
                if (propertyGroupChild != null)
                {
                    DisplayPropertyGroup(engine, entity, propertyGroupChild, depth, true);
                }
            }
        }
示例#3
0
        /// <summary>
        /// Create an entity with a property group.
        ///
        /// Ent:
        ///   P: tc:tcName= tc:tcNameToshiba
        ///   P: "RAM"= "8"
        ///   PG: "Processor"\
        ///         P: "Constructor"= "Intel"
        ///         P: "Model"= "i7"
        /// </summary>
        public void CreateEntityWithPropGroup()
        {
            EtagairEngine engine = CreateEngine();


            //----set defined (activate) language codes in the application
            engine.Editor.DefineLanguage(LanguageCode.en);
            engine.Editor.DefineLanguage(LanguageCode.fr);

            // create localized text for main languages managed in the application
            TextCode tcName = engine.Editor.CreateTextCode("Name");

            engine.Editor.CreateTextLocalModel(LanguageCode.en, tcName, "Name");
            engine.Editor.CreateTextLocalModel(LanguageCode.fr, tcName, "Nom");

            TextCode tcValueToshiba = engine.Editor.CreateTextCode("ValueToshiba");

            engine.Editor.CreateTextLocalModel(LanguageCode.en, tcValueToshiba, "Laptop Toshiba Core i7 RAM 8Go HD 1To Win10");
            engine.Editor.CreateTextLocalModel(LanguageCode.fr, tcValueToshiba, "Ordinateur portable Toshiba Core i7 RAM 8Go DD 1To Win10");

            // create an entity with one property: key and value are TextCode
            Entity toshibaCoreI7 = engine.Editor.CreateEntity();

            // Add a property to an object: key - value, both are textCode (will be displayed translated depending on the language)
            engine.Editor.CreateProperty(toshibaCoreI7, tcName, tcValueToshiba);

            // create property: RAM: 8 Go(Gb)
            engine.Editor.CreateProperty(toshibaCoreI7, "RAM", "8");

            // add a properties group (folder inside object) in the object
            PropertyGroup propGrpProc = engine.Editor.CreatePropertyGroup(toshibaCoreI7, "Processor");

            engine.Editor.CreateProperty(toshibaCoreI7, propGrpProc, "Constructor", "Intel");
            engine.Editor.CreateProperty(toshibaCoreI7, propGrpProc, "Model", "i7");
        }
示例#4
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);
        }
示例#5
0
        /// <summary>
        /// Displays the content of an entity (properties childs).
        /// </summary>
        /// <param name="engine"></param>
        /// <param name="entity"></param>
        /// <param name="depth"></param>
        public void DisplayEntity(EtagairEngine engine, Entity entity, int depth, bool displayRootProperty)
        {
            string indent = new string(' ', depth * 2);

            Console.WriteLine(indent + "Entity id: " + entity.Id);

            DisplayPropertyGroup(engine, entity, entity.PropertyRoot, depth + 1, displayRootProperty);
        }
示例#6
0
        public void DisplayProperty(EtagairEngine engine, Property property, int depth)
        {
            string indent = new string(' ', depth * 2);

            // displays the key and the value
            string keyText = indent + "P: K=" + GetPropKeyText(engine, property.Key);
            string valText = " V=" + GetPropValueText(engine, property.Value);

            Console.WriteLine(keyText + valText);
        }
示例#7
0
        /// <summary>
        ///  Search entities by the key property.
        ///  Create 3 entities, select entities having a property key equals to 'Name'.
        ///
        ///     computers\
        ///         Ent: Name=Toshiba   Ok, selected
        ///         Ent: Name=Dell      Ok, selected
        ///         Ent: Company=HP     --NOT selected
        ///
        /// -------output:
        /// Db initialized with success.
        /// -Search result: nb= 2
        /// Ent, id: 5c6822abdd125603e885d8d4
        /// Ent, id: 5c6822c1dd125603e885d8d6
        /// </summary>
        public void CreateThreeEntitiesSearchPropKeyName()
        {
            EtagairEngine engine = CreateEngine();

            //---- create a folder, under the root
            Folder foldComputers = engine.Editor.CreateFolder(null, "computers");

            //==== creates entities, with prop

            //----create entity
            Entity toshibaCoreI7 = engine.Editor.CreateEntity(foldComputers);

            engine.Editor.CreateProperty(toshibaCoreI7, "Name", "Toshiba Satellite Core I7");
            engine.Editor.CreateProperty(toshibaCoreI7, "TradeMark", "Toshiba");

            //----create entity
            Entity dellCoreI7 = engine.Editor.CreateEntity(foldComputers);

            engine.Editor.CreateProperty(dellCoreI7, "Name", "Dell Inspiron 15-5570-sku6");
            engine.Editor.CreateProperty(dellCoreI7, "TradeMark", "Dell");

            //----create entity
            Entity HPCoreI7 = engine.Editor.CreateEntity(foldComputers);

            engine.Editor.CreateProperty(HPCoreI7, "Company", "HP Core i7");
            engine.Editor.CreateProperty(HPCoreI7, "TradeMark", "HP");

            //==== define the search: from the root folder, select all entities having a key prop called 'Name'
            SearchEntity searchEntities = engine.Searcher.CreateSearchEntity("EntitiesHavingPropName", SearchFolderScope.Defined);

            //--Add sources folders, set option: go inside folders childs
            // (only one for now is managed!!)
            engine.Searcher.AddSourceFolder(searchEntities, foldComputers, true);

            //--Add criteria: (a boolean expression)
            SearchPropCriterionKeyText criterion = engine.Searcher.AddCritPropKeyText(searchEntities, "Name");

            criterion.TextMatch       = CritOptionTextMatch.TextMatchExact;
            criterion.PropKeyTextType = CritOptionPropKeyTextType.AllKeyType;

            //==== execute the search, get the result: list of found entities
            SearchEntityResult result = engine.Searcher.ExecSearchEntity(searchEntities);

            // displays found entities
            Console.WriteLine("-Search result: nb=" + result.ListEntityId.Count);
            foreach (string entityId in result.ListEntityId)
            {
                // displays the id of the entity
                Console.WriteLine("Ent, id: " + entityId);

                // load the entity and display it
                Entity entity = engine.Searcher.FindEntityById(entityId);
                // display the properties of the entity....
            }
        }
示例#8
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);
        }
示例#9
0
        private void SampleCreateThreeEntitiesSearchPropKeyName()
        {
            EtagairEngine engine = new EtagairEngine();

            // the path must exists
            string dbPath = @".\Data\";

            if (!engine.Init(dbPath))
            {
                Console.WriteLine("Db initialization Failed.");
                return;
            }
        }
示例#10
0
        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);
        }
示例#11
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);
        }
示例#12
0
        private void CreateEngine()
        {
            EtagairEngine engine = new EtagairEngine();

            // the path must exists, location where to put the database file
            string dbPath = @".\Data\";

            // create the database or reuse the existing one
            if (!engine.Init(dbPath))
            {
                Console.WriteLine("Db initialization Failed.");
                return;
            }

            // the database is created or reused and opened, ready to the execution
            Console.WriteLine("Db initialized with success.");
        }
示例#13
0
        /// <summary>
        /// Dev the language and text data model.
        /// E:
        ///   P: key=TC:tcName= Value=TC:tcNameToshiba
        /// </summary>
        public void ManageLanguagesAndLocalizedText()
        {
            EtagairEngine engine = CreateEngine();

            Console.WriteLine("Create TextCode, TextLocalModel, and then TextLocal.");

            //----set defined (activate) language codes in the application
            engine.Editor.DefineLanguage(LanguageCode.en);
            engine.Editor.DefineLanguage(LanguageCode.fr);

            // create localized text for main languages managed in the application
            TextCode tcName = engine.Editor.CreateTextCode("Name");

            engine.Editor.CreateTextLocalModel(LanguageCode.en, tcName, "Name");
            engine.Editor.CreateTextLocalModel(LanguageCode.fr, tcName, "Nom");

            TextCode tcValueToshiba = engine.Editor.CreateTextCode("ValueToshiba");

            engine.Editor.CreateTextLocalModel(LanguageCode.en, tcValueToshiba, "Laptop Toshiba Core i7 RAM 8Go HD 1To Win10");
            engine.Editor.CreateTextLocalModel(LanguageCode.fr, tcValueToshiba, "Ordinateur portable Toshiba Core i7 RAM 8Go DD 1To Win10");

            // create an entity with one property: key and value are TextCode
            Entity toshibaCoreI7 = engine.Editor.CreateEntity();

            // Add a property to an object: key - value, both are textCode (will be displayed translated depending on the language)
            engine.Editor.CreateProperty(toshibaCoreI7, tcName, tcValueToshiba);

            // set the current language, get the localized/translated text
            engine.Searcher.SetCurrentLanguage(LanguageCode.en);

            // create/generate the localized/translated text of a textCode in the current language
            TextLocal tlName = engine.Editor.GenerateTextLocal(tcName);

            // Output: Name in current language (en): Name
            Console.WriteLine("Name in current language (en): " + tlName.Text);

            // create/generate the localized/translated text of a textCode in the specified language
            TextLocal tlNameFr = engine.Editor.GenerateTextLocal(tcName, LanguageCode.fr);

            // Output: Name in fr language: Nom
            Console.WriteLine("Name in fr language: " + tlNameFr.Text);
        }
示例#14
0
        /// <summary>
        /// Very basic sample: create a folder and an entity with properties (key-value).
        ///
        ///  F:computers\
        ///    E:
        ///     "Name"= "Toshiba Satellite Core I7"
        ///     "Trademark"= "Toshiba"
        ///
        /// </summary>
        public void CreateFolderWithinEntity()
        {
            EtagairEngine engine = CreateEngine();

            Console.WriteLine("Create a folder within an entity.");
            Console.WriteLine("F: computers\\");
            Console.WriteLine("  E: ");
            Console.WriteLine("  \"Name\"= \"Toshiba Satellite Core I7\"");
            Console.WriteLine("  \"Trademark\" = \"Toshiba\"");
            Console.WriteLine("  \"Year\" = 2019");

            // create a folder, under the root
            Folder foldComputers = engine.Editor.CreateFolder(null, "computers");

            // create an entity, under the computers folder
            Entity toshibaCoreI7 = engine.Editor.CreateEntity(foldComputers);

            // Add 2 properties to the entity (key - value)
            engine.Editor.CreateProperty(toshibaCoreI7, "Name", "Toshiba Satellite Core I7");
            engine.Editor.CreateProperty(toshibaCoreI7, "Trademark", "Toshiba");
            engine.Editor.CreateProperty(toshibaCoreI7, "Year", 2019);
        }
示例#15
0
        /// <summary>
        /// Very basic sample: create a folder and an entity with properties (key-value).
        ///
        ///  F:computers\
        ///    E:
        ///     "Name"= "Toshiba Satellite Core I7"
        ///     "Trademark"= "Toshiba"
        ///
        /// </summary>
        private void SampleBasicCreateEntity()
        {
            EtagairEngine engine = new EtagairEngine();

            // the path must exists
            string dbPath = @".\Data\";

            if (!engine.Init(dbPath))
            {
                Console.WriteLine("Db initialization Failed.");
                return;
            }

            // create a folder, under the root
            Folder foldComputers = engine.Editor.CreateFolder(null, "computers");

            // create an entity, under the computers folder
            Entity toshibaCoreI7 = engine.Editor.CreateEntity(foldComputers);

            // Add 2 properties to the entity (key - value)
            engine.Editor.CreateProperty(toshibaCoreI7, "Name", "Toshiba Satellite Core I7");
            engine.Editor.CreateProperty(toshibaCoreI7, "Trademark", "Toshiba");
        }
示例#16
0
        /// <summary>
        /// Create an engine.
        /// Removes previous database files.
        /// </summary>
        /// <returns></returns>
        public EtagairEngine CreateEngine()
        {
            Console.WriteLine("Starts the Engine...");
            EtagairEngine engine = new EtagairEngine();


            // delete the previous instance of the db
            Console.WriteLine("Remove the previous data files.");
            if (File.Exists(_dbPath + "etagair.db"))
            {
                File.Delete(_dbPath + "etagair.db");
            }

            // create the database or reuse the existing one
            if (!engine.Init(_dbPath))
            {
                Console.WriteLine("Db initialization Failed.\n");
                return(null);
            }

            // the database is created or reused and opened, ready to the execution
            Console.WriteLine("Db initialized with success.\n");
            return(engine);
        }
示例#17
0
 public void DisplayAllObjects(EtagairEngine engine, Folder folderParent)
 {
     Console.WriteLine("\n----Displays Data:");
     DisplayAllObjects(engine, folderParent, 0);
 }