示例#1
0
        void CaptureOutput(ICommandOutput value, string[] captures, List <ITaskItem> captureResult)
        {
            var outputType       = value.GetType();
            var matchingCaptures = GetCaptureProperties(captures, outputType.Name).Concat(GetCaptureProperties(captures, outputType.FullName));

            foreach (var propertiesPath in matchingCaptures)
            {
                object currentValue = value;
                foreach (var segment in propertiesPath.Value)
                {
                    try
                    {
                        currentValue = currentValue.GetType().GetProperty(segment).GetValue(currentValue, BindingFlags.Instance | BindingFlags.Public, null, null, null);
                    }
                    catch
                    {
                        currentValue = null;
                        break;
                    }
                }
                if (currentValue != null)
                {
                    captureResult.Add(new TaskItem(currentValue.ToString(), new Dictionary <string, string> {
                        { "Property", propertiesPath.Key }
                    }));
                }
            }
        }
示例#2
0
        void ProcessOutput(ICommandOutput cmd)
        {
            if (string.IsNullOrEmpty(Capture) == false)
            {
                var type     = cmd.GetType();
                var captures = Capture.Split(';');
            }
            switch (cmd.Type)
            {
            case CommandResultType.Error:
                Log.LogError(cmd.ToString());
                _success = false;
                break;

            case CommandResultType.Warning:
                Log.LogWarning(cmd.ToString());
                break;

            case CommandResultType.Data:
            case CommandResultType.Info:
                Log.LogMessage(cmd.ToString());
                break;

            case CommandResultType.Verbose:
                Log.LogMessage(MessageImportance.Low, cmd.ToString());
                break;
            }
        }
 public RePackArchiveConvention(
     ICalamariFileSystem fileSystem,
     ICommandOutput commandOutput,
     ICommandLineRunner commandLineRunner)
 {
     this.fileSystem = fileSystem;
     this.jarTool    = new JarTool(commandLineRunner, commandOutput, fileSystem);
 }
示例#4
0
 public static void WriteLine(this ICommandOutput output, string pattern, params object[] args)
 {
     if (output == null)
     {
         throw new ArgumentNullException(nameof(output));
     }
     output.WriteLine(string.Format(CultureInfo.CurrentCulture, pattern, args));
 }
示例#5
0
        /// <inheritdoc />
        public void Execute(object contextObject, ICommandOutput output, object runtimeModel)
        {
            DirectoryInfo dir = new DirectoryInfo(Environment.CurrentDirectory);

            if (dir.FullName != dir.Root.FullName)
            {
                Environment.CurrentDirectory = dir.Parent.FullName;
                //(contextObject as ConsoleContext).
            }
        }
        IDisposable ColorFromOutput(ICommandOutput output)
        {
            switch(output.Type)
            {
                case CommandResultType.Error: return ColoredText.Red;
                case CommandResultType.Warning: return ColoredText.Yellow;
                case CommandResultType.Verbose: return ColoredText.Gray;

            }
            return new ActionOnDispose(()=>{});
        }
示例#7
0
        internal PastJob(ICommandOutput output)
        {
            this.Command = output.Command;
            this.Id      = output.Id;
            this.Started = output.Started.Value;
            this.Status  = output.Status;

            if (output is ICommandResult cr)
            {
                this.Ended = cr.Ended.GetValueOrDefault();
            }
        }
        IDisposable ColorFromOutput(ICommandOutput output)
        {
            switch (output.Type)
            {
            case CommandResultType.Error: return(ColoredText.Red);

            case CommandResultType.Warning: return(ColoredText.Yellow);

            case CommandResultType.Verbose: return(ColoredText.Gray);
            }
            return(new ActionOnDispose(() => {}));
        }
        public void Render(ICommandOutput commandOutput)
        {
            DteGuard.BeginInvoke(dte =>
            {
                if (_outputWindow == null)
                {
                    var output = (OutputWindow)dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput).Object;

                    _outputWindow = output.OutputWindowPanes.Cast<OutputWindowPane>().FirstOrDefault(x => x.Name == "OpenWrap")
                                    ?? output.OutputWindowPanes.Add("OpenWrap");
                }

                _outputWindow.OutputString(commandOutput + "\r\n");
            });
        }
        public void Render(ICommandOutput commandOutput)
        {
            DteGuard.BeginInvoke(dte =>
            {
                if (_outputWindow == null)
                {
                    var output = (OutputWindow)dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput).Object;

                    _outputWindow = output.OutputWindowPanes.Cast <OutputWindowPane>().FirstOrDefault(x => x.Name == "OpenWrap")
                                    ?? output.OutputWindowPanes.Add("OpenWrap");
                }

                _outputWindow.OutputString(commandOutput + "\r\n");
            });
        }
示例#11
0
        /// <inheritdoc />
        public void Execute(object contextObject, ICommandOutput output, object runtimeModel)
        {
            ChangeDirCommandModel model = runtimeModel as ChangeDirCommandModel;

            switch (model?.Target?.Trim())
            {
            case null:
            case "":
            case ".":
            {
                break;         // remain;
            }

            case "..":
            {
                DirectoryInfo dir = new DirectoryInfo(Environment.CurrentDirectory);
                if (dir.FullName != dir.Root.FullName)
                {
                    Environment.CurrentDirectory = dir.Parent?.FullName ?? dir.FullName;         // stay
                }
                break;
            }

            case "\\":
            {
                DirectoryInfo dir = new DirectoryInfo(Environment.CurrentDirectory);
                Environment.CurrentDirectory = dir.Root.FullName;
                break;
            }

            default:
            {
                string path = model.Target.Trim();
                if (!Path.IsPathRooted(path))
                {
                    Environment.CurrentDirectory = new DirectoryInfo(path).FullName;
                }
                else
                {
                    path = Path.Combine(Environment.CurrentDirectory, path);
                    Environment.CurrentDirectory = new DirectoryInfo(path).FullName;
                }
                break;
            }

                //(contextObject as ConsoleContext).
            }
        }
示例#12
0
        public JarTool(ICommandLineRunner commandLineRunner, ICommandOutput commandOutput, ICalamariFileSystem fileSystem)
        {
            this.commandLineRunner = commandLineRunner;
            this.fileSystem        = fileSystem;
            this.commandOutput     = commandOutput;

            /*
             *  The precondition script will also set the location of the java libray files
             */
            toolsPath = Path.Combine(
                Environment.GetEnvironmentVariable(SpecialVariables.Action.Java.JavaLibraryEnvVar) ?? "",
                "contentFiles",
                "any",
                "any",
                "tools.jar");
        }
示例#13
0
        public JarTool(ICommandLineRunner commandLineRunner, ICommandOutput commandOutput, VariableDictionary variables)
        {
            this.commandLineRunner = commandLineRunner;
            this.commandOutput     = commandOutput;

            /*
             *  The precondition script will also set the location of the java libray files
             */

            toolsPath = Path.Combine(
                variables?.Get(SpecialVariables.Action.Java.JavaLibraryEnvVar, "") ?? "",
                "contentFiles",
                "any",
                "any",
                "tools.jar");
        }
示例#14
0
        private void ListCurrentFolder(object contextObject, ICommandOutput output, DirCommandModel parameters)
        {
            string filter   = string.IsNullOrWhiteSpace(parameters.Filter) ? "*.*" : parameters.Filter;
            string basePath = Environment.CurrentDirectory;

            DataTable <string> filesTable = new DataTable <string>(
                new ColumnInfo("Name", ColumnAlignment.Left),
                new ColumnInfo("Size", ColumnAlignment.Right),
                new ColumnInfo("Modified", ColumnAlignment.Right));

            var baseDir = new DirectoryInfo(basePath);

            if (parameters.IncludeFolders)
            {
                var dirs = baseDir.GetDirectories(filter, SearchOption.TopDirectoryOnly);
                foreach (var dirInfo in dirs)
                {
                    filesTable.AddRow(
                        dirInfo.FullName,
                        new[]
                    {
                        dirInfo.Name,
                        "<DIR>",
                        Directory.GetLastWriteTime(dirInfo.FullName).ToString(output.UiCulture.DateTimeFormat.ShortDatePattern)
                    });
                }
            }

            var files = baseDir.GetFiles(filter, SearchOption.TopDirectoryOnly);

            foreach (var fileInfo in files)
            {
                filesTable.AddRow(
                    fileInfo.FullName,
                    new[]
                {
                    fileInfo.Name,
                    fileInfo.Length.ToFriendlyXBytesText(output.UiCulture),
                    File.GetLastWriteTime(fileInfo.FullName).ToString(output.UiCulture.DateTimeFormat.ShortDatePattern)
                });
            }

            output.PrintSimpleTable(filesTable);
        }
示例#15
0
 internal LCollection(DataContext context, object owner, QueryExpression query, string[] fieldPaths)
 {
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     if (owner == null)
     {
         throw new ArgumentNullException(nameof(owner));
     }
     if (query == null)
     {
         throw new ArgumentNullException(nameof(query));
     }
     options         = context.Options;
     output          = context.Output;
     this.owner      = owner;
     this.query      = query;
     this.fieldPaths = fieldPaths;
 }
示例#16
0
        public void Flush(ICommandOutput output)
        {
            using (var strReader = new StringReader(StdOut))
            {
                string line = strReader.ReadLine();
                while (line != null)
                {
                    output.WriteInfo(line);
                    line = strReader.ReadLine();
                }
            }

            using (var strReader = new StringReader(StdErr))
            {
                string line = strReader.ReadLine();
                while (line != null)
                {
                    output.WriteError(line);
                    line = strReader.ReadLine();
                }
            }
        }
示例#17
0
        void ProcessOutput(ICommandOutput cmd)
        {
            switch (cmd.Type)
            {
            case CommandResultType.Error:
                Log.LogError(cmd.ToString());
                _success = false;
                break;

            case CommandResultType.Warning:
                Log.LogWarning(cmd.ToString());
                break;

            case CommandResultType.Data:
            case CommandResultType.Info:
                Log.LogMessage(cmd.ToString());
                break;

            case CommandResultType.Verbose:
                Log.LogMessage(MessageImportance.Low, cmd.ToString());
                break;
            }
        }
示例#18
0
        CommandResult ExecuteCommandInternal(string arguments, out string result, ICommandOutput output = null)
        {
            var environmentVar = defaultEnvironmentVariables;

            if (environmentVariables != null)
            {
                environmentVar.MergeDictionaries(environmentVariables);
            }

            var commandLineInvocation = new CommandLineInvocation(TerraformExecutable,
                                                                  arguments, TemplateDirectory, environmentVar);

            var commandOutput = new CaptureOutput(output ?? new ConsoleCommandOutput());
            var cmd           = new CommandLineRunner(commandOutput);

            Log.Info(commandLineInvocation.ToString());

            var commandResult = cmd.Execute(commandLineInvocation);

            result = String.Join("\n", commandOutput.Infos);

            return(commandResult);
        }
示例#19
0
        void CaptureOutput(ICommandOutput value, string[] captures, List<ITaskItem> captureResult)
        {
            var outputType = value.GetType();
            var matchingCaptures = GetCaptureProperties(captures, outputType.Name).Concat(GetCaptureProperties(captures, outputType.FullName));

            foreach(var propertiesPath in matchingCaptures)
            {
                object currentValue = value;
                foreach(var segment in propertiesPath.Value)
                {
                    try
                    {
                        currentValue = currentValue.GetType().GetProperty(segment).GetValue(currentValue, BindingFlags.Instance | BindingFlags.Public, null, null, null);
                    }
                    catch
                    {
                        currentValue = null;
                        break;
                    }
                }
                if (currentValue != null)
                    captureResult.Add(new TaskItem(currentValue.ToString(), new Dictionary<string, string> { { "Property", propertiesPath.Key } }));
            }
        }
示例#20
0
        public void Execute(object contextObject, ICommandOutput output, object runtimeModel)
        {
            var model = runtimeModel as DirCommandModel; // necessary to avoid Generic-inheritance troubles...

            // TODO: custom filters normalization?

            switch (model.Mode)
            {
            case DirectoryListMode.CurrentDir:
            {
                this.ListCurrentFolder(contextObject, output, model);
                break;
            }

            case DirectoryListMode.CurrentLocalState:
                break;

            case DirectoryListMode.CurrentRemoteHead:
                break;

            default:
                break;
            }
        }
示例#21
0
 static bool HiddenVerboseOutput(IEnumerable<string> args, ICommandOutput commandOutput)
 {
     return commandOutput.Type == CommandResultType.Verbose && !HasFlag(args, "verbose");
 }
示例#22
0
 static void RenderOutput(ICommandOutput commandOutput)
 {
     if (commandOutput is IProgressOutput)
     {
         var progress = (IProgressOutput)commandOutput;
         var progressFinished = new ManualResetEvent(false);
         int writtenDots = 0;
         bool progressOpened = false;
         Console.WriteLine(commandOutput);
         progress.StatusChanged += (s, e) => Console.WriteLine(e.Message);
         progress.ProgressChanged += (s, e) =>
         {
             if (!progressOpened)
             {
                 Console.Write("[");
                 progressOpened = true;
             }
             var currentDots = e.Progress / 10;
             if (currentDots > writtenDots)
             {
                 var dotsToWrite = currentDots - writtenDots;
                 Console.Write(new string('.', dotsToWrite));
                 writtenDots = currentDots;
             }
             if (e.Progress >= 100)
             {
                 Console.WriteLine("]");
             }
         };
         progress.Complete += (s, e) => progressFinished.Set();
         progressFinished.WaitOne();
     }
     else
         Console.WriteLine(commandOutput);
 }
示例#23
0
 public void Render(ICommandOutput output)
 {
     using (ColorFromOutput(output))
         Console.WriteLine(output.ToString());
 }
示例#24
0
 public static bool Success(this ICommandOutput output)
 {
     return(output.Type != CommandResultType.Error);
 }
示例#25
0
 GenericMessage PackageNotFoundInRemote(ICommandOutput m)
 {
     return new GenericMessage("Package '{0}' doesn't exist in any remote repository.", ((DependencyResolutionFailedResult)m).Result.Dependencies.First().Dependency.Name)
     {
             Type = CommandResultType.Warning
     };
 }
 /// <inheritdoc />
 public void Execute(object contextObject, ICommandOutput output, object runtimeModel)
 {
     output.PrintWarning("Temrinating application...");
     (contextObject as ConsoleContext).ShallTerminate = true; // let it throw on null
 }
示例#27
0
 public CommandLineRunner(ICommandOutput commandOutput)
 {
     this.commandOutput = commandOutput;
 }
示例#28
0
 protected object BuildModelForCommand(CommandInfo cmdInfo, IEnumerable <string> arguments, ICommandParserOptions options, ICommandOutput outputManager)
 {
     return(cmdInfo.CommandModelBuilder.BuildModel(arguments, options, outputManager));
 }
示例#29
0
 public CommandLineRunner(ICommandOutput commandOutput)
 {
     this.commandOutput = commandOutput;
 }
示例#30
0
        public CommandModel BuildModel(IEnumerable <string> arguments, ICommandParserOptions options, ICommandOutput output)
        {
            var model = Activator.CreateInstance(this._modelType) as CommandModel;

            string[] args         = arguments.ToArray();
            int      argIndex     = 0;
            int      unnamedIndex = 0;

            string[]         flagSwitchPrefixes = options.SwitchCharacters.Concat(options.FlagCharacters).Distinct().ToArray();
            HashSet <string> usedProperties     = new HashSet <string>();

            this.ApplyDefaults(model);

            while (argIndex < args.Length)
            {
                string         arg = args[argIndex].Trim();
                IParsingResult result;

                // need to skip unnamed parameters there are just exactly like one of prefixes (i.e. - single slash or backslash)
                if (flagSwitchPrefixes.All(p => p != arg) && flagSwitchPrefixes.Any(p => arg.StartsWith(p)))
                {
                    var propertyParser = this.FindProperty(options, arg);
                    if (propertyParser == null)
                    {
                        output.PrintWarning($"Command's argument is not valid => \"{arg}\".");
                        return(null);
                    }

                    if (usedProperties.Contains(propertyParser.TargetProperty.Name))
                    {
                        output.PrintWarning($"Similar argument has been already specified => \"{arg}\".");
                        return(null);
                    }

                    usedProperties.Add(propertyParser.TargetProperty.Name);
                    result = propertyParser.Apply(options, model, args, ref argIndex);
                }
                else
                {
                    var propertyParser = this._switchlessParsers.SingleOrDefault(p => p.ArgumentIndex == unnamedIndex++);
                    if (propertyParser == null)
                    {
                        output.PrintWarning($"This command does not expect so many standalone arguments => \"{arg}\".");
                        return(null);
                    }

                    usedProperties.Add(propertyParser.TargetProperty.Name);
                    result = propertyParser.Apply(options, model, args, ref argIndex);
                }

                if (!result.IsFine)
                {
                    output.PrintWarning($"Parsing error => {result.Message}");
                    return(null);
                }

                //argIndex++; not needed, all parsers move index forward accordingly to parsing settings and expected number of arguments
            }

            foreach (var syntaxInfo in this._syntax)
            {
                if (syntaxInfo.IsMandatory && !usedProperties.Contains(syntaxInfo.TargetPropertyName))
                {
                    output.PrintWarning($"Expected mandatory argument has not been provided => \"{syntaxInfo.OptionName}\".");
                    return(null);
                }
            }
            // TODO: validate that all mandatory options were provided and switch-less arguments too
            // TODO: validate mixed / non mixed mode for switch-less parameters

            return(model);
        }
示例#31
0
 /// <inheritdoc />
 public void Execute(object contextObject, ICommandOutput output, object runtimeModel)
 {
     output.Clear();
 }
示例#32
0
 public static void SendCommandOutput(ICommandOutput commandOutput)
 {
     SendCommandOutput(new List<ICommandOutput> { commandOutput });
 }
示例#33
0
 public JarExtractor(ICommandLineRunner commandLineRunner, ICommandOutput commandOutput,
                     ICalamariFileSystem fileSystem)
 {
     jarTool = new JarTool(commandLineRunner, commandOutput, fileSystem);
 }
示例#34
0
 void ProcessOutput(ICommandOutput cmd)
 {
     switch (cmd.Type)
     {
         case CommandResultType.Error:
             Log.LogError(cmd.ToString());
             _success = false;
             break;
         case CommandResultType.Warning:
             Log.LogWarning(cmd.ToString());
             break;
         case CommandResultType.Data:
         case CommandResultType.Info:
             Log.LogMessage(cmd.ToString());
             break;
         case CommandResultType.Verbose:
             Log.LogMessage(MessageImportance.Low, cmd.ToString());
             break;
     }
 }
示例#35
0
 public CaptureOutput(ICommandOutput decorated)
 {
     this.decorated = decorated;
 }
示例#36
0
 public void Execute(object contextObject, ICommandOutput output, object runtimeModel)
 {
     throw new NotImplementedException();
 }
示例#37
0
        public CommandResult ExecuteCommand(out string result, ICommandOutput output, params string[] arguments)
        {
            var commandResult = ExecuteCommandInternal(ToSpaceSeparated(arguments), out result, output);

            return(commandResult);
        }
 /// <summary>
 /// Sets the command output.
 /// </summary>
 /// <param name="output">Output.</param>
 public void SetCommandOutput(ICommandOutput output)
 {
     _commandOutput = output;
 }
示例#39
0
 public JavaPackageExtractor(ICommandLineRunner commandLineRunner, ICommandOutput commandOutput, ICalamariFileSystem fileSystem)
 {
     this.commandLineRunner = commandLineRunner;
     this.fileSystem        = fileSystem;
     this.commandOutput     = commandOutput;
 }
 public void Render(ICommandOutput output)
 {
     using (ColorFromOutput(output))
         Console.WriteLine(output.ToString());
 }
示例#41
0
        void ProcessOutput(ICommandOutput cmd)
        {
            if (string.IsNullOrEmpty(Capture) == false)
            {
                var type = cmd.GetType();
                var captures = Capture.Split(';');

            }
            switch (cmd.Type)
            {
                case CommandResultType.Error:
                    Log.LogError(cmd.ToString());
                    _success = false;
                    break;
                case CommandResultType.Warning:
                    Log.LogWarning(cmd.ToString());
                    break;
                case CommandResultType.Data:
                case CommandResultType.Info:
                    Log.LogMessage(cmd.ToString());
                    break;
                case CommandResultType.Verbose:
                    Log.LogMessage(MessageImportance.Low, cmd.ToString());
                    break;
            }
        }