Exemplo n.º 1
0
        public void StartApplication(string applicationName  = null, string commandName = null,
                                     List <string> arguments = null, string pipeline    = null)
        {
            applicationName = applicationName ?? Application.Default;
            commandName     = commandName ?? Command.Default;
            arguments       = (arguments ?? Enumerable.Empty <string>()).Select(a => $"\"{a}\"").ToList();
            pipeline        = !string.IsNullOrEmpty(pipeline) ? $"\"{pipeline ?? string.Empty}\"" : string.Empty;

            var application      = _applicationRepository.GetApplication(applicationName);
            var command          = _applicationRepository.GetCommand(applicationName, commandName);
            var commandArguments = (command?.Arguments ?? new List <string>())
                                   .Select(a => _templateProcessor.Transform(a, TemplateModel.PipelineAndArgs(pipeline, arguments)))
                                   .Where(a => !string.IsNullOrEmpty(a))
                                   .ToList();

            if (application == null)
            {
                throw new ArgumentException($"Application '{applicationName}' is not configured");
            }
            if (command == null)
            {
                throw new ArgumentException($"Command '{commandName}' in application '{applicationName}' is not configured");
            }

            var processInfo = GetProcessInfo(application, command, commandArguments);

            _processLauncher.Launch(processInfo, command.WaitForExit);
        }
Exemplo n.º 2
0
        private void TortoiseProc(string command, Dictionary <string, string> arguments = null, bool waitForExit = false)
        {
            arguments = arguments ?? new Dictionary <string, string>();
            var argumentsString  = $"/command:{command} {string.Join(" ", arguments.Select(kv => $"/{kv.Key}:{kv.Value}"))}";
            var processStartInfo = new ProcessStartInfo("TortoiseProc.exe", argumentsString);

            ProcessLauncher.Launch(processStartInfo, waitForExit);
        }
Exemplo n.º 3
0
    static IEnumerable <ToolStripItem> BuildTrackingMenuItems(Tracker tracker)
    {
        if (!tracker.TrackingAny)
        {
            yield break;
        }

        yield return(new MenuButton("Clear", tracker.Clear, Images.Clear));

        var deletes = tracker.Deletes
                      .OrderBy(x => x.File)
                      .ToList();

        if (deletes.Any())
        {
            yield return(new ToolStripSeparator());

            yield return(new MenuButton("Pending Deletes:", tracker.AcceptAllDeletes, Images.Delete));

            foreach (var delete in deletes)
            {
                var menu = new SplitButton($"{delete.Name}", () => tracker.Accept(delete));
                menu.AddRange(
                    new MenuButton("Accept change", () => tracker.Accept(delete)),
                    new MenuButton("Open directory", () => ExplorerLauncher.ShowFileInExplorer(delete.File)));
                yield return(menu);
            }
        }

        var moves = tracker.Moves
                    .OrderBy(x => x.Temp)
                    .ToList();

        if (moves.Any())
        {
            yield return(new ToolStripSeparator());

            yield return(new MenuButton("Pending Moves:", tracker.AcceptAllMoves, Images.Accept));

            foreach (var move in moves)
            {
                var menu = new SplitButton($"{move.Name} ({move.Extension})", () => tracker.Accept(move));
                menu.AddRange(
                    new MenuButton("Accept change", () => tracker.Accept(move)),
                    new MenuButton("Launch diff tool", () => ProcessLauncher.Launch(move)),
                    new MenuButton("Open directory", () => ExplorerLauncher.ShowFileInExplorer(move.Temp)));
                yield return(menu);
            }
        }

        yield return(new ToolStripSeparator());

        yield return(new MenuButton("Accept all", tracker.AcceptAll, Images.AcceptAll));
    }
Exemplo n.º 4
0
        public static bool TryGet(SecureCopySettings settings, string remoteHost, string userName, string remoteFile, string localFile, out Exception ex)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }
            if (string.IsNullOrEmpty(remoteHost))
            {
                throw new ArgumentNullException("remoteHost");
            }
            if (string.IsNullOrEmpty(remoteFile))
            {
                throw new ArgumentNullException("remoteFile");
            }
            if (string.IsNullOrEmpty(localFile))
            {
                throw new ArgumentNullException("localFile");
            }
            //
            if (File.Exists(localFile))
            {
                File.Delete(localFile);
            }
            if (!string.IsNullOrEmpty(userName))
            {
                remoteHost = userName + "@" + remoteHost;
            }
            string executablePath;
            var    arguments = string.Format(GetArgumentsXABC, Get(settings, out executablePath), remoteHost, remoteFile, localFile);

            try
            {
                var launcher = new ProcessLauncher();
                launcher.Launch(settings.ProcessTimeoutInMilliseconds, executablePath, arguments, (w) =>
                {
                    // Respond N
                    w.WriteLine("n");
                    w.Flush();
                });
                ex = null;
                return(true);
            }
            catch (SecureCopyException e) { ex = e; return(false); }
        }
Exemplo n.º 5
0
        //public static bool TryList<TItem>(SecureCopySettings settings, string remoteHost, string userId, string fileSpecification, out IEnumerable<TItem> items, out Exception ex)
        //{
        //    string itemsAsText;
        //    if (TryList(settings, remoteHost, userId, fileSpecification, out itemsAsText, out ex))
        //    {
        //        items = null;
        //        return true;
        //    };
        //    items = null;
        //    return false;
        //}
        public static bool TryList(SecureCopySettings settings, string remoteHost, string userName, string fileSpecification, out string items, out Exception ex)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }
            if (string.IsNullOrEmpty(remoteHost))
            {
                throw new ArgumentNullException("remoteHost");
            }
            if (string.IsNullOrEmpty(fileSpecification))
            {
                throw new ArgumentNullException("fileSpecification");
            }
            //
            if (!string.IsNullOrEmpty(userName))
            {
                remoteHost = userName + "@" + remoteHost;
            }
            string executablePath;
            var    arguments = string.Format(ListArgumentsXAB, Get(settings, out executablePath), remoteHost, fileSpecification);

            try
            {
                var launcher = new ProcessLauncher();
                launcher.Launch(settings.ProcessTimeoutInMilliseconds, executablePath, arguments, (w) =>
                {
                    // Respond N
                    w.WriteLine("n");
                    w.Flush();
                });
                items = launcher.OutputString;
                ex    = null;
                return(true);
            }
            catch (SecureCopyException e) { items = null; ex = e; return(false); }
        }
Exemplo n.º 6
0
 //public static bool TryList<TItem>(SecureCopySettings settings, string remoteHost, string userId, string fileSpecification, out IEnumerable<TItem> items, out Exception ex)
 //{
 //    string itemsAsText;
 //    if (TryList(settings, remoteHost, userId, fileSpecification, out itemsAsText, out ex))
 //    {
 //        items = null;
 //        return true;
 //    };
 //    items = null;
 //    return false;
 //}
 /// <summary>
 /// Tries the list.
 /// </summary>
 /// <param name="settings">The settings.</param>
 /// <param name="remoteHost">The remote host.</param>
 /// <param name="userName">Name of the user.</param>
 /// <param name="fileSpecification">The file specification.</param>
 /// <param name="items">The items.</param>
 /// <param name="ex">The ex.</param>
 /// <returns></returns>
 public static bool TryList(SecureCopySettings settings, string remoteHost, string userName, string fileSpecification, out string items, out Exception ex)
 {
     if (settings == null)
         throw new ArgumentNullException("settings");
     if (string.IsNullOrEmpty(remoteHost))
         throw new ArgumentNullException("remoteHost");
     if (string.IsNullOrEmpty(fileSpecification))
         throw new ArgumentNullException("fileSpecification");
     //
     if (!string.IsNullOrEmpty(userName))
         remoteHost = userName + "@" + remoteHost;
     string executablePath;
     var arguments = string.Format(ListArgumentsXAB, Get(settings, out executablePath), remoteHost, fileSpecification);
     try
     {
         var launcher = new ProcessLauncher();
         launcher.Launch(settings.ProcessTimeoutInMilliseconds, executablePath, arguments, (w) =>
         {
             // Respond N
             w.WriteLine("n");
             w.Flush();
         });
         items = launcher.OutputString;
         ex = null;
         return true;
     }
     catch (SecureCopyException e) { items = null; ex = e; return false; }
 }
Exemplo n.º 7
0
 /// <summary>
 /// Tries the put.
 /// </summary>
 /// <param name="settings">The settings.</param>
 /// <param name="remoteHost">The remote host.</param>
 /// <param name="userName">Name of the user.</param>
 /// <param name="localFiles">The local files.</param>
 /// <param name="remoteFile">The remote file.</param>
 /// <param name="ex">The ex.</param>
 /// <returns></returns>
 public static bool TryPut(SecureCopySettings settings, string remoteHost, string userName, string[] localFiles, string remoteFile, out Exception ex)
 {
     if (settings == null)
         throw new ArgumentNullException("settings");
     if (string.IsNullOrEmpty(remoteHost))
         throw new ArgumentNullException("remoteHost");
     if ((localFiles == null) || (localFiles.Length == 0))
         throw new ArgumentNullException("localFiles");
     if (string.IsNullOrEmpty(remoteFile))
         throw new ArgumentNullException("remoteFile");
     //
     if (!string.IsNullOrEmpty(userName))
         remoteHost = userName + "@" + remoteHost;
     string executablePath;
     var arguments = string.Format(PutArgumentsXABC, Get(settings, out executablePath), string.Join(" ", localFiles), remoteHost, remoteFile);
     try
     {
         var launcher = new ProcessLauncher();
         launcher.Launch(settings.ProcessPutTimeoutInMilliseconds, executablePath, arguments, (w) =>
         {
             // Respond N
             w.WriteLine("n");
             w.Flush();
         });
         ex = null;
         return true;
     }
     catch (SecureCopyException e) { ex = e; return false; }
 }