Exemple #1
0
        private static void LaunchRobot(string robotsDirectoryName, Process processInfo)
        {
            var latestVersion =
                RobotDirectory
                .GetVersions(RobotPath.Combine(robotsDirectoryName, processInfo.FileName))
                .GetLatestVersion();

            var robotFileName =
                new RobotFileNameBuilder()
                .RobotDirectoryName(robotsDirectoryName)
                .Version(latestVersion)
                .FileName(processInfo.FileName)
                .Build();

            if (string.IsNullOrEmpty(robotFileName))
            {
                throw new FileNotFoundException($"Robot not found '{robotFileName}'.");
            }

            if (IsRunning(processInfo.FileName, processInfo.Arguments))
            {
                throw new InvalidOperationException($"Robot already running '{robotFileName}'.");
            }

            using (var process = System.Diagnostics.Process.Start(new ProcessStartInfo
            {
                FileName = robotFileName,
                Arguments = processInfo.Arguments,
                WindowStyle = processInfo.WindowStyle,
                //UseShellExecute = false,
            }))
            {
                if (process == null)
                {
                    throw new ProcessNotStartedException(robotFileName);
                }

                LogEntry.New().Info().Message($"Started '{robotFileName}'").Log(Logger);

                using (var logEntry = LogEntry.New().Info().Stopwatch(sw => sw.Start()).AsAutoLog(Logger))
                {
                    process.WaitForExit();
                    if (process.ExitCode != 0)
                    {
                        logEntry.Error().Message($"'{robotFileName}' exited with error code {process.ExitCode}.");
                        throw new ProcessTerminatedException($"'{robotFileName}' exited with error code {process.ExitCode}.");
                    }
                    logEntry.Info().Message($"'{robotFileName}' exited with error code {process.ExitCode}.");
                }
            }
        }
Exemple #2
0
 public void CreateMainDirectoryName_DirectoryAndFileName_Name()
 {
     Assert.AreEqual(
         @"c:\foo\bar\baz",
         RobotPath.Combine(@"c:\foo\bar", @"baz.exe"));
 }