Beispiel #1
0
        public GenieConfig(GenieLamp lamp, XmlNode node)
        {
            this.lamp = lamp;
            macro     = new MacroExpander(lamp.Macro);

            name         = Utils.Xml.GetAttrValue(node, "name");
            assemblyName = Utils.Xml.GetAttrValue(node, "assembly");
            typeName     = Utils.Xml.GetAttrValue(node, "type");
            active       = Utils.Xml.GetAttrValue(node, "active", true);

            targetVersion = Environment.ExpandEnvironmentVariables(Utils.Xml.GetAttrValue(node, "targetVersion", TargetVersionWildcard));
            macro.SetMacro("%TARGET_VERSION%", targetVersion);

            outDir               = macro.Subst(Lamp.ExpandFileName(Utils.Xml.GetAttrValue(node, "outDir")));
            outFileName          = macro.Subst(Lamp.Macro.Subst(Utils.Xml.GetAttrValue(node, "outFileName")));
            this.OutFileEncoding = Encoding.GetEncoding(Utils.Xml.GetAttrValue(node, "outFileEncoding", Encoding.UTF8.BodyName));
            this.UpdateDatabase  = Utils.Xml.GetAttrValue(node, "updateDatabase", false);

            configParams = new GenieConfigParams(this, lamp.QueryNode(node, "./{0}:Param"));

            this.AssistantConfigs = new GenieAssistantConfigs(this, node);
            this.Assistants       = new List <IGenieAssistant>();

            if (!Directory.Exists(outDir))
            {
                Directory.CreateDirectory(outDir);
            }
        }
Beispiel #2
0
        public void TestCase()
        {
            string envVarName  = "GL_TEST";
            string envVar      = "%" + envVarName + "%";
            string envVarValue = "/RootTest";

            string source      = String.Format("Output to: {0}/%PROJECT_DIR%/%PROJECT_NAME%.sql", envVar);
            string projectName = "TestProject";
            string projectDir  = "TestDir/Subdir";
            string target      = String.Format("Output to: {0}/{1}/{2}.sql", envVarValue, projectDir, projectName);

            Environment.SetEnvironmentVariable(envVarName, envVarValue);
            Assert.AreEqual("%%", System.Environment.ExpandEnvironmentVariables("%%"));
            Assert.AreEqual(envVarValue, System.Environment.ExpandEnvironmentVariables(envVar));
            Assert.AreEqual("%" + envVar + "%", Utils.Sys.ExpandEnvironmentVariables("%" + envVar + "%"));

            Assert.AreEqual("%TEST123%", Utils.Sys.ExpandEnvironmentVariables("%TEST123%"));
            Assert.AreEqual("%TEST123%_%TEST456%", Utils.Sys.ExpandEnvironmentVariables("%TEST123%_%TEST456%"));
            Assert.AreEqual(envVarValue, Utils.Sys.ExpandEnvironmentVariables(envVar));
            Assert.AreEqual(String.Format("{0}_{0}", envVarValue),
                            String.Format("{0}_{0}", Utils.Sys.ExpandEnvironmentVariables(envVar)));


            MacroExpander m = new MacroExpander();

            m.SetMacro("%PROJECT_NAME%", projectName);
            m.SetMacro("%PROJECT_DIR%", projectDir);
            Assert.AreEqual(2, m.Count);

            Assert.AreEqual(target, m.Subst(source));
            m.Clear();
            Assert.AreEqual(0, m.Count);

            string unchanged = "IX%COUNTER%_%TABLE%_%COLUMNS%";

            Assert.AreEqual(unchanged, m.Subst(unchanged));
        }
Beispiel #3
0
        public string ExpandFileName(string fileName, string currentDirectory)
        {
            string newName = macro.Subst(fileName);
            string currDir = System.Environment.CurrentDirectory;

            try
            {
                System.Environment.CurrentDirectory = currentDirectory;
                newName = Path.GetFullPath(newName);                 // Relative to current directory
            }
            finally
            {
                System.Environment.CurrentDirectory = currDir;
            }
            return(newName);
        }