public void CanExpandInputWithNoOccurences()
        {
            const string input  = "text with no occurences";
            string       result = ExpandableVars.ReplaceOccurences("VAR", "EXP", input);

            Assert.Equal(input, result);
        }
        public void CannotExpandInputWithEscapedOccurence()
        {
            const string input  = "text with escaped \\$(VAR) occurence";
            string       result = ExpandableVars.ReplaceOccurences("VAR", "EXP", input);

            Assert.DoesNotContain("EXP", result);
        }
        public void CanExpandInputWithManyOccurences()
        {
            const string input  = "text with $(VAR) - ${VAR) occurences";
            string       result = ExpandableVars.ReplaceOccurences("VAR", "EXP", input);

            Assert.Equal(input.Replace("$(VAR)", "EXP"), result);
        }
Exemplo n.º 4
0
        private static void ExecuteCommand(string command, string commandType)
        {
            command = ExpandableVars.Instance.ExpandAllInString(command);
            command = ExpandableVars.ExpandToEmptyInString(command);
            Log.Info("Executing '{0}' process: {1}", commandType, command);

            string process   = command;
            string args      = "";
            int    argsIndex = command.IndexOf(' ') + 1;

            if (argsIndex > 1)
            {
                process = command.Substring(0, argsIndex - 1);
                args    = command.Substring(argsIndex);
            }

            var psi = new ProcessStartInfo(process, args)
            {
                WorkingDirectory = Directory.GetCurrentDirectory()
            };

            try
            {
                using (new Log.ScopedIndent())
                {
                    ShellUtil.StartProcess(psi, ConsoleOutputHandler, ConsoleErrorHandler, true, true);
                }
            }
            catch (Exception ex)
            {
                Log.Error("Failed to execute build command. See Exception below.");
                Log.Error(ex.ToString());
                throw;
            }
        }
Exemplo n.º 5
0
        private void ExpandVariables(IDictionary <string, object> expandableProperties)
        {
            var modifiedProperties = new Dictionary <string, object>();

            if (variableExpansions != null && variableExpansions.Count > 0)
            {
                Log.Debug("Expanding variables. {0} properties to check for {1} defined variables.",
                          expandableProperties.Count, variableExpansions.Count);

                foreach (KeyValuePair <string, object> kvp in expandableProperties)
                {
                    object expanded = ExpandableVars.ExpandAllForProperty(kvp.Key, kvp.Value, variableExpansions,
                                                                          GetPropertyDefinition);

                    modifiedProperties[kvp.Key] = expanded;
                }

                foreach (KeyValuePair <string, object> kvp in modifiedProperties)
                {
                    expandableProperties[kvp.Key] = kvp.Value;
                }
            }
            else
            {
                Log.Debug("No expandable variables set... skipping expansion of {0} read properties.",
                          expandableProperties.Count);
            }
        }
        public void CanStripEscapedVariables()
        {
            const string input    = "text with escaped \\$(VAR) occurence";
            bool         didStrip = ExpandableVars.StripEscapedVariablesInCopy(input, out object result);

            Assert.True(didStrip);
            Assert.DoesNotContain("\\$", result.ToString());
        }
Exemplo n.º 7
0
        public Settings ExpandVariablesInCopy()
        {
            var copy = new Dictionary <string, object>(properties);

            foreach (string propertyName in properties.Keys)
            {
                copy[propertyName] = ExpandableVars.ExpandAllForProperty(propertyName, copy[propertyName],
                                                                         ExpandableVars.Instance.Variables, PropertyDefinitionGetter);
            }

            return(new Settings(copy, PropertyDefinitionGetter));
        }
Exemplo n.º 8
0
        private Task <ModuleReader.Result> ReadModuleAsync(ObjectElement moduleElement)
        {
            var reader      = new ModuleReader(Solution, Templates, templateReader);
            var baseVars    = new Dictionary <string, string>(ExpandableVars.Instance.Variables);
            int indentLevel = Log.Instance.IndentLevel;

            return(Task.Run(() =>
            {
                using (new Log.BufferedTaskOutput("RM-" + moduleElement.Heading.Name, indentLevel))
                {
                    ExpandableVars.Init(baseVars);
                    ModuleReader.Result moduleResult = reader.Read(moduleElement);
                    return moduleResult;
                }
            }));
        }