예제 #1
0
        public void Undefined_variable_should_not_have_value()
        {
            var variables = new Variables();
            var runner = new Runner(variables);

            runner.ExecScript("DummyFileName", @"
            [define]
            some_var=value
            some_var=
            ");
            variables.Get("some_var");
        }
예제 #2
0
        /// <summary>
        /// Updates value of an attribute in the given node (by xpath) or creates the attribute
        /// </summary>
        public static void UpdateNodeAttribute(
            Variables variables,
            string nodePath,
            string nodeDisplayName,
            string attributeName,
            string value,
            bool quietMode = false)
        {
            var doc = XDocument.Load(variables.Get(Variables.PATH_WEBCONFIG));
            var nodes = doc.XPathSelectElements(nodePath);
            if (nodes.Count() == 0)
                throw new Exception(String.Format("Cannot find {0}", nodeDisplayName));

            foreach (var node in nodes)
            {
                if (!quietMode) Console.WriteLine(" Set {0} {1} to {2}", nodeDisplayName, attributeName, value);
                node.SetAttributeValue(attributeName, value);
            }

            doc.Save(variables.Get(Variables.PATH_WEBCONFIG));
        }
예제 #3
0
        public void Define_variable_in_script_and_read_its_value()
        {
            var variables = new Variables();
            var runner = new Runner(variables);

            runner.ExecScript("DummyFileName", @"
            [define]
            some_var=value
            ");

            Assert.AreEqual("value", variables.Get("some_var"));
        }
예제 #4
0
        public static string GetConnectionString(Variables variables, string name)
        {
            var doc = XDocument.Load(variables.Get(Variables.PATH_WEBCONFIG));
            var node = doc.XPathSelectElement(String.Format("/configuration/connectionStrings/add[@name='{0}']", name));
            if (node == null)
                throw new Exception("Cannot find a connection string with name " + name);

            var attribute = node.Attribute("connectionString");
            if (attribute == null)
                throw new Exception("No connectionString attribute found in connection string node");

            return attribute.Value;
        }
예제 #5
0
        public void Comments_have_no_effect()
        {
            var variables = new Variables();
            var runner = new Runner(variables);

            runner.ExecScript("DummyFileName", @"
            [define]
            some_var=value1
            #some_var=value2

            ");
            Assert.AreEqual("value1", variables.Get("some_var"));
        }
예제 #6
0
        public void Variables_from_included_script_should_exist()
        {
            var variables = new Variables();
            var runner = new Runner(variables);

            Prepare.Script("common.deploy", @"
            [define]
            some_var=value
            ");

            runner.ExecScript("DummyFileName", @"
            include common.deploy
            ");

            Assert.AreEqual("value", variables.Get("some_var"));
        }
예제 #7
0
        static void Main(string[] args)
        {
            try
            {
                Arguments = Arguments.Create(args);
                if (Arguments.PrintHelp)
                {
                    PrintHelp();
                    return;
                }

                Variables = new Variables();
                if (Arguments.PrintVariables)
                {
                    PrintVariables();
                    return;
                }

                if (Arguments.Scripts.Count == 0)
                {
                    // if no command line argument, execute:
                    // _start.deploy
                    // %server%.deploy
                    // _other.deploy (if above server file not found)
                    // _finish.deploy

                    RunIfExist("_start.deploy");

                    if (!RunIfExist(Variables.Get(Variables.SERVER) + ".deploy"))
                    {
                        RunIfExist("_other.deploy");
                    }

                    RunIfExist("_finish.deploy");

                }
                else
                {
                    foreach (var script in Arguments.Scripts)
                    {
                        if (!RunIfExist(script))
                            throw new Exception("Cannot find script:" + script);
                    }
                }

            }
            catch (ScriptException err)
            {
                Console.Error.WriteLine("{0}:{1} {2}", err.ScriptName, err.LineNumber, err.Message);
            }
            catch (Exception err)
            {
                Console.Error.WriteLine(Arguments.DebugMode ? err.ToString() : err.Message);
            }

            if (!Arguments.Quiet)
            {
                Console.WriteLine("\nDone. Press any key.");
                Console.ReadKey();
            }
        }
예제 #8
0
 public static IEnumerable<string> PossibleSettingKeys(Variables variables)
 {
     var doc = XDocument.Load(variables.Get(Variables.PATH_WEBCONFIG));
     return doc.XPathSelectElements("/configuration/appSettings/add").Select(n =>
         n.Attribute("key").Value);
 }