Exemple #1
0
        protected static GeneratorEditor PopulateGenSettings()
        {
            var f     = GenDataBase.DataLoader.LoadData("data/GeneratorEditor").AsDef();
            var d     = new GenDataBase(f);
            var model = new GeneratorEditor(d)
            {
                GenObject = d.Root
            };

            model.SaveFields();
            var settings = new GenSettings(d)
            {
                GenObject = CreateGenObject(d.Root, "GenSettings"), HomeDir = "."
            };

            model.GenSettingsList.Add(settings);
            settings.AddBaseFile("Minimal", "Minimal.dcb", "Data", "The simplest definition required by the generator",
                                 ".dcb");
            settings.AddBaseFile("Definition", "Definition.dcb", "Data", "The definition required by the editor", ".dcb");
            var baseFile = settings.AddBaseFile("ProgramDefinition", "ProgramDefinition.dcb", "Data",
                                                "Defines generator editor data models", ".dcb");

            baseFile.AddProfile("GenProfileModel", "GenProfileModel.prf", "Data");
            settings.AddBaseFile("GeneratorEditor", "GeneratorEditor.dcb", "Data",
                                 "Defines generator editor settings data", ".dcb");
            settings.AddFileGroup("Minimal", "Minimal.dcb", "Data", "Definition");
            settings.AddFileGroup("Basic", "Basic.dcb", "Data", "Definition");
            settings.AddFileGroup("Definition", "Definition.dcb", "Data", "Definition");
            settings.AddFileGroup("ProgramDefinition", "ProgramDefinition.dcb", "Data", "Definition");
            settings.AddFileGroup("GeneratorEditor", "GeneratorEditor.dcb", "Data", "Definition");
            settings.AddFileGroup("GeneratorDefinitionModel", "GeneratorDefinitionModel.dcb", "Data",
                                  "ProgramDefinition", "GenProfileModel");
            return(model);
        }
Exemple #2
0
        /// <summary>
        /// Create a new file and save the file group.
        /// </summary>
        /// <param name="fileGroup">The file group defining the new file.</param>
        public void CreateFile(FileGroup fileGroup)
        {
            fileGroup.SaveFields();
            if (!File.Exists(BuildFilePath(fileGroup.FilePath, fileGroup.FileName).Replace('/', '\\')))
            {
                var dataDef  = Settings.FindBaseFile(fileGroup.BaseFileName);
                var f        = GenDataBase.DataLoader.LoadData(BuildFilePath(dataDef.FilePath, dataDef.FileName)).AsDef();
                var d        = new GenDataBase(f);
                var fileName = BuildFilePath(fileGroup.FilePath, fileGroup.FileName);
                GenParameters.SaveToFile(d, fileName);
            }
            if (Settings.FindFileGroup(fileGroup.Name) == null)
            {
                Settings.Model.GenSettingsList[0].AddFileGroup(fileGroup.Name, fileGroup.FileName, fileGroup.FilePath,
                                                               fileGroup.BaseFileName, fileGroup.Profile, fileGroup.GeneratedFile);
            }

            if (fileGroup.BaseFileName == "Definition")
            {
                AddBaseFile(fileGroup);
            }

            SetFileGroup(fileGroup.Name);
            SaveSettings();
        }
Exemple #3
0
        protected static void VerifyFragment(GenDataBase genData, GenFragment genFragment, string expectedClass, FragmentType expectedType, string profileLabel, string profileText, string expected, bool isText, string parentClassName, GenDataDef profileDataDef)
        {
            Assert.AreEqual(expectedClass, genFragment.GetType().Name, "Fragment Class");
            Assert.AreEqual(expectedType, genFragment.Fragment.FragmentType, "Fragment Fragment Type");
            Assert.AreEqual(expectedType, genFragment.FragmentType, "Fragment Type");
            Assert.AreEqual(isText, genFragment.IsTextFragment, "Is text fragment?");
            if (genFragment.GenObject == null)
            {
                genFragment.GenObject = GetFirstObjectOfSubClass(GetFirstObject(genData), "Property");
            }
            var fragment = genFragment.Fragment;

            Assert.AreEqual(expected, GenFragmentExpander.Expand(genData.GenDataDef, genFragment.GenObject, fragment), "Expanded fragment");
            var genFragmentLabel = new GenFragmentLabel(fragment);

            Assert.AreEqual(profileLabel, genFragmentLabel.ProfileLabel(), "Profile label");
            Assert.AreEqual(profileText, genFragment.ProfileText(ProfileFragmentSyntaxDictionary.ActiveProfileFragmentSyntaxDictionary), "Profile text");
            if (parentClassName != null)
            {
                Assert.AreEqual(parentClassName, genFragment.Fragment.ClassName(), "Parent Class ID");
            }
            var str = GenerateFragment(genData, genFragment);

            Assert.AreEqual(expected, str);
            var genDataDef = genData.GenDataDef;

            ValidateFragmentData(genDataDef, parentClassName, genFragment, profileDataDef);
        }
        private static GenDataBase SetUpData(GenDataDef f)
        {
            var d = new GenDataBase(f);

            SetUpData(d);
            return(d);
        }
Exemple #5
0
        protected static void TestComparison(GenDataBase genData, string comparison, bool expectedLt, bool expectedEq,
                                             bool expectedGt)
        {
            var condIn = "Property.Name" + comparison;

            TestComparisonConditions(genData, expectedLt, expectedEq, expectedGt, condIn, "Nama", "Name", "Namz");
        }
Exemple #6
0
 private static void TestComparisonConditions(GenDataBase genData, bool expectedLt, bool expectedEq, bool expectedGt,
                                              string condIn, string valueLt, string valueEq, string valueGt, bool identifier = false)
 {
     TestCondition(genData, new TestConditionParams(condIn + valueLt, "", "", expectedLt, "", identifier: identifier)); // Property.Name?Nama
     TestCondition(genData, new TestConditionParams(condIn + valueEq, "", "", expectedEq, "", identifier: identifier)); // Property.Name?Name
     TestCondition(genData, new TestConditionParams(condIn + valueGt, "", "", expectedGt, "", identifier: identifier)); // Property.Name?Namz
 }
        public void RefreshProfile(GenDataBase genDataBase, GenObject genObject)
        {
            var selectedItem = ProfileNavigatorTreeView.SelectedNode;
            var dataProfile  = GenDataEditorViewModel.Data.Profile;

            dataProfile.Fragment = ProfileEditorTreeViewBuilder.GetNodeData(selectedItem);
            var text = dataProfile.GetNodeProfileText();

            // Don't change to prevent unnecessary rendering and side effects
            if (text != ProfileTextBox.Text)
            {
                var start = ProfileTextBox.SelectionStart;
                ProfileTextBox.Clear();
                ProfileTextBox.Text           = text;
                ProfileTextBox.SelectionStart = start;
            }


            text = dataProfile.GetNodeExpansionText(genDataBase, genObject);

            // Don't change to prevent unnecessary rendering and side effects
            if (text != ProfileExpansionTextBox.Text)
            {
                var start = ProfileExpansionTextBox.SelectionStart;
                ProfileExpansionTextBox.Clear();
                ProfileExpansionTextBox.Text           = text;
                ProfileExpansionTextBox.SelectionStart = start;
            }
        }
Exemple #8
0
        protected static void TestNumericComparison(GenDataBase genData, string comparison, bool expectedLt, bool expectedEq,
                                                    bool expectedGt)
        {
            var condIn = "Property.Number" + comparison;

            TestComparisonConditions(genData, expectedLt, expectedEq, expectedGt, condIn, "1", "15", "1500");
        }
Exemple #9
0
        protected static void TestCondition(GenDataBase genData, TestConditionParams testConditionParams)
        {
            var genDataDef = genData.GenDataDef;

            if (testConditionParams.CondOut == "")
            {
                testConditionParams.CondOut = testConditionParams.CondIn;
            }
            if (testConditionParams.ProfileLabel == "")
            {
                testConditionParams.ProfileLabel = testConditionParams.CondIn;
            }

            var          root = new GenProfileFragment(new GenProfileParams(genDataDef));
            const string r    = "Condition holds";
            var          exp  = testConditionParams.Expected ? r : "";

            var c = ProfileFragmentSyntaxDictionary.ActiveProfileFragmentSyntaxDictionary.ParseCondition(genDataDef, testConditionParams.CondIn);
            var g = new GenCondition(new GenConditionParams(genDataDef, root, c));

            g.GenObject = GetFirstObjectOfSubClass(GetLastObjectInSubClass(GetFirstObject(genData)), "Property");
            var t = new GenTextFragment(new GenTextFragmentParams(genDataDef, g, r));

            g.Body.Add(t);
            VerifyFragment(genData, g, "GenCondition", FragmentType.Condition, testConditionParams.ProfileLabel,
                           String.Format("`?{0}:{1}`]", testConditionParams.CondOut, r), exp, false, null, g.Fragment.GenDataBase.GenDataDef);
        }
Exemple #10
0
        protected static void TestIdentifierComparison(GenDataBase genData, string comparison, bool expectedLt, bool expectedEq,
                                                       bool expectedGt)
        {
            var condIn = "Property.Name" + comparison + "Property.Name";

            TestComparisonConditions(genData, expectedLt, expectedEq, expectedGt, condIn, "LT", "EQ", "GT", true);
        }
Exemple #11
0
        protected static GenObject CreateClass(GenDataBase d, string name)
        {
            var c = CreateGenObject(d.Root, "Class", name);

            CreateProperty("Name", c);
            return(c);
        }
Exemple #12
0
        protected static GenDataBase SetUpLookupContextData()
        {
            var f        = new GenDataDef();
            var parentId = f.AddClass("", "Parent");

            f.AddClassInstanceProperty(parentId, "Name");
            var childId = f.AddClass("Parent", "Child");

            f.AddClassInstanceProperty(childId, "Name");
            f.AddClassInstanceProperty(childId, "Lookup");
            var lookupId = f.AddClass("Parent", "Lookup");

            f.AddClassInstanceProperty(lookupId, "Name");

            var a = new GenAttributes(f, 1);
            var d = new GenDataBase(f);
            var p = CreateGenObject(d.Root, "Parent", "Parent");

            a.GenObject = CreateGenObject(p, "Child", "Child1");
            a.SetString("Lookup", "Valid");
            a.SaveFields();

            a.GenObject = CreateGenObject(p, "Child", "Child2");
            a.SetString("Lookup", "Invalid");
            a.SaveFields();

            a.GenObject = CreateGenObject(p, "Lookup", "Valid");

            return(d);
        }
Exemple #13
0
 private static void SetUpParentReference(string childDefName, string childClassName,
                                          string childName, GenDataBase dataParent, GenDataBase dataChild, GenObject parent)
 {
     dataParent.CheckReference(childDefName, dataChild.GenDataDef.AsGenDataBase());
     dataParent.CheckReference(childName, dataChild);
     SetSubClassReference(parent, childClassName, childName);
 }
Exemple #14
0
        public void GenDataReorderTests()
        {
            var f = GenDataDef.CreateMinimal();
            var d = new GenDataBase(f);

            var c = CreateGenObject(d.Root, "Class", "Class");

            CreateGenObject(c, "SubClass", "SubClass1");
            CreateGenObject(c, "SubClass", "SubClass2");
            CreateGenObject(c, "SubClass", "SubClass3");

            // Verify initial subclass order - Index is last added item
            CheckOrder(d, "123", "Verify initial subclass order");
            // Make and verify moves
            MoveItem(d, ListMove.Up, 2, "132", "Move last subclass up one place");
            MoveItem(d, ListMove.ToTop, 2, "213", "Move last subclass to top");
            MoveItem(d, ListMove.ToTop, 1, "123", "Move second subclass to top");
            MoveItem(d, ListMove.ToBottom, 0, "231", "Move first subclass to bottom");
            MoveItem(d, ListMove.ToTop, 0, "231", "Move first subclass to top (should have no effect)");
            MoveItem(d, ListMove.ToBottom, 2, "231", "Move last subclass to bottom (should have no effect)");
            MoveItem(d, ListMove.Up, 0, "231", "Move first subclass up (should have no effect)");
            MoveItem(d, ListMove.Down, 2, "231", "Move last subclass down (should have no effect)");
            MoveItem(d, ListMove.Down, 0, "321", "Move first subclass down");
            MoveItem(d, ListMove.Down, 1, "312", "Move second subclass down");
            MoveItem(d, ListMove.Up, 1, "132", "Move second subclass up");
            MoveItem(d, ListMove.ToBottom, 1, "123", "Move second subclass to bottom");
        }
Exemple #15
0
        private static GenDataBase SetUpSegmentSeparatorData(string display)
        {
            var fm = GenDataDef.CreateMinimal();
            var dm = new GenDataBase(fm);
            var td = CreateClass(dm, "TestData");

            CreateProperty("Name", td);
            CreateProperty("Display", td);
            var f = dm.AsDef();
            var a = new GenAttributes(f, 1);
            var d = new GenDataBase(f);

            a.GenObject = CreateGenObject(d.Root, "TestData", "One");
            a.SetString("Name", "One");
            a.SetString("Display", display[0] == '1' ? "True" : "");
            a.SaveFields();
            a.GenObject = CreateGenObject(d.Root, "TestData", "Two");
            a.SetString("Name", "Two");
            a.SetString("Display", display[1] == '1' ? "True" : "");
            a.SaveFields();
            a.GenObject = CreateGenObject(d.Root, "TestData", "Three");
            a.SetString("Name", "Three");
            a.SetString("Display", display[2] == '1' ? "True" : "");
            a.SaveFields();
            return(d);
        }
Exemple #16
0
 private static string SetFunctionParameters(GenDataBase genData, GenFunction genFunction, string[] values)
 {
     foreach (var value in values)
     {
         SetFunctionParameter(genData, genFunction, value);
     }
     return(string.Join(" ", values));
 }
Exemple #17
0
        protected static void MoveItem(GenDataBase d, ListMove move, int itemIndex, string order, string action)
        {
            var c  = GetFirstObject(d);
            var sc = c.GetSubClass("SubClass");

            sc.Move(move, itemIndex);
            CheckOrder(d, order, action);
        }
Exemple #18
0
        private static void SetUpParentOtherChildReferenceData(string parentClassName, string childClassName,
                                                               string childDataName, GenDataBase dataParent, GenDataBase dataChild)
        {
            var parent = CreateGenObject(dataParent.Root, parentClassName, parentClassName);

            SetUpParentReference(childClassName + "Def", childClassName, childDataName, dataParent,
                                 dataChild, parent);
        }
 public CodesDefinition(GenDataBase genDataBase)
 {
     GenDataBase = genDataBase;
     Classes.Add("CodesTable");
     Classes.Add("Code");
     SubClasses.Add("CodesTable");
     base.GenObject = genDataBase.Root;
 }
Exemple #20
0
        private static GenSegment SetUpSegmentSeparatorFragment(GenDataBase d, GenCardinality cardinality)
        {
            var profile = "`[TestData" + (cardinality == GenCardinality.AllDlm ? "/" : "\\") + ":`?TestData.Display:`TestData.Name``]`;, `]";
            var p       = new GenCompactProfileParser(d.GenDataDef, "", profile);
            var g       = (GenSegment)p.Body.Fragment[0];

            return(g);
        }
Exemple #21
0
 public Definition(GenDataBase genDataBase)
 {
     GenDataBase = genDataBase;
     Classes.Add("Class");
     Classes.Add("SubClass");
     Classes.Add("Property");
     SubClasses.Add("Class");
     base.GenObject = genDataBase.Root;
 }
Exemple #22
0
        public void GenAttributeTests()
        {
            var f = GenDataDef.CreateMinimal();
            var d = new GenDataBase(f);
            var o = CreateGenObject(d.Root, "Class", "Class");

            CreateGenObject(o, "SubClass", "SubClass");

            VerifyDataCreation(d);
        }
        public static GenDataBase CreateEmpty()
        {
            var d = new GenDataBase((GenDataDef)null)
            {
                DataName = "Definition"
            };

            d.Root.SubClass.Add(new GenSubClass(d, d.Root, 1, null));
            return(d);
        }
 public GeneratorEditor(GenDataBase genDataBase)
 {
     GenDataBase = genDataBase;
     Classes.Add("GenSettings");
     Classes.Add("FileGroup");
     Classes.Add("BaseFile");
     Classes.Add("Profile");
     SubClasses.Add("GenSettings");
     base.GenObject = genDataBase.Root;
 }
Exemple #25
0
        public IGenDataSettings LoadSettingsFromData(GenDataBase data)
        {
            var model = new GeneratorEditor(data)
            {
                GenObject = data.Root
            };

            SaveToDisk = false;
            return(new GeSettings(model));
        }
        public void EmptyGenDataAsDefTest()
        {
            var f  = GenDataDef.CreateMinimal();
            var d  = new GenDataBase(f);
            var f0 = d.AsDef();

            Assert.AreEqual(1, f0.Classes.Count); // Root class only
            Assert.AreEqual("", f0.GetClassName(0));
            Assert.AreEqual(0, f0.GetClassProperties(0).Count);
            Assert.AreEqual(0, f0.GetClassSubClasses(0).Count);
        }
        public void ContextNoReferencePropertyExistsNoReferenceTest()
        {
            var f = GenDataDef.CreateMinimal();
            var d = new GenDataBase(f);

            SetUpData(d);
            var genObject = GenObject.GetContext(d.Root, "Class");
            var id        = f.GetId("Class.Reference");

            Assert.AreEqual("", genObject.GetValue(id));
        }
Exemple #28
0
        protected static GenDataBase SetUpData()
        {
            var f = GenDataDef.CreateMinimal();
            var d = new GenDataBase(f);
            var c = CreateGenObject(d.Root, "Class", "Class");

            CreateGenObject(c, "SubClass", "SubClass");
            CreateGenObject(c, "Property", "Property");
            CreateGenObject(c, "Property", "Property2");
            return(d);
        }
Exemple #29
0
        protected static void ExecuteFunction(GenDataBase genData, string functionName, string expected, string[] values)
        {
            var r = new GenProfileFragment(new GenProfileParams(genData.GenDataDef));
            var g = new GenFunction(new GenFunctionParams(genData.GenDataDef, r, functionName));

            r.Body.Add(g);
            var b = SetFunctionParameters(genData, g, values);

            VerifyFragment(genData, g, "GenFunction", FragmentType.Function, functionName,
                           "`@" + functionName + ':' + b + "`]", expected, false, null, r.Profile.GenDataBase.GenDataDef);
        }
Exemple #30
0
        protected static void CheckOrder(GenDataBase d1, string order, string action)
        {
            var d  = d1;
            var id = d.GenDataDef.GetId("SubClass.Name");
            var s0 = GenObject.GetContext(d.Root, "SubClass");
            var s1 = GetNextObjectInSubClass(s0);
            var s2 = GetNextObjectInSubClass(s1);

            Assert.AreEqual("SubClass" + order[0], s0.GetValue(id), action + " first item");
            Assert.AreEqual("SubClass" + order[1], s1.GetValue(id), action + " second item");
            Assert.AreEqual("SubClass" + order[2], s2.GetValue(id), action + " third item");
        }