コード例 #1
0
        public void ShouldCorrectlyChangeDirectories()
        {
            var appExeDir = TestDirectories.GetTestExeDir();

            var target = TestDirectories.GetMainLibLoadTestDir();

            var dirMgr = new WorkingDirectoryMgr();
            dirMgr.SetTargetDirectory(target);

            var originalDir = dirMgr.SetCurrentWorkingDirectory();

            dirMgr.ChangeToTargetWorkingDirectory();

            var dir1 = DirectoryHelper.GetCurrentEnvironmentDirectory();

            var dir2 = DirectoryHelper.GetCurrentDirectory();

            Assert.IsTrue(target==dir1);
            Assert.IsTrue(target==dir2);
            Assert.IsTrue(dir1!=originalDir);
            Assert.IsTrue(appExeDir==originalDir);

            DirectoryHelper.ChangeToNewCurrentDirectory(appExeDir);

            dir1 = DirectoryHelper.GetCurrentEnvironmentDirectory();
            dir2 = DirectoryHelper.GetCurrentDirectory();

            Assert.IsTrue(dir1==appExeDir);
            Assert.IsTrue(dir2==appExeDir);
        }
コード例 #2
0
        public void DirectoryMgrShouldChangeDirectoriesAndReturn()
        {
            var appExeDir = TestDirectories.GetTestExeDir();

            var target = TestDirectories.GetMainLibLoadTestDir();

            var dirMgr = new WorkingDirectoryMgr();
            dirMgr.SetTargetDirectory(target);

            dirMgr.ChangeToTargetWorkingDirectory();

            Assert.IsTrue(appExeDir==dirMgr.OriginalCurrentWorkingDirectory);

            var dir1 = DirectoryHelper.GetCurrentEnvironmentDirectory();

            var dir2 = DirectoryHelper.GetCurrentDirectory();

            Assert.IsTrue(dir1==target);
            Assert.IsTrue(dir2==target);

            var result = dirMgr.ChangeBackToOriginalWorkingDirectory();

            Assert.IsTrue(result);

            dir1 = DirectoryHelper.GetCurrentEnvironmentDirectory();

            dir2 = DirectoryHelper.GetCurrentDirectory();

            Assert.IsTrue(dir1==appExeDir);
            Assert.IsTrue(dir2==appExeDir);
        }
コード例 #3
0
        public ExecuteConsoleCommand(ConsoleCommandDto cmdDto,
											ConsoleCommandLogMgr logMgr,
												ConsoleCommandLogMgr errLogMgr,
													WorkingDirectoryMgr wrkDirectoryMgr)
        {
            if (cmdDto == null)
            {
                var msg = "Console Command Dto is NULL!";
                var err = new FileOpsErrorMessageDto
                {
                    DirectoryPath = string.Empty,
                    ErrId = 1,
                    ErrorMessage = msg,
                    ErrSourceMethod = "Constructor",
                    LoggerLevel = LogLevel.FATAL
                };

                ErrorMgr.LoggingStatus = ErrorLoggingStatus.On;
                ErrorMgr.WriteErrorMsg(err);

                throw new ArgumentException(msg);

            }

            _executeCommand = cmdDto;
            _logMgr = logMgr;
            _errLogMgr = errLogMgr;
            _wrkDirectoryMgr = wrkDirectoryMgr;
        }
コード例 #4
0
        public void ShouldLocateCorrectCurrentWorkingDirector()
        {
            var appExeDir = TestDirectories.GetTestExeDir();

            var target = TestDirectories.GetMainLibLoadTestDir();

            var dirMgr = new WorkingDirectoryMgr();
            dirMgr.SetTargetDirectory(target);

            var currDir = dirMgr.SetCurrentWorkingDirectory();

            Assert.IsTrue(dirMgr.OriginalCurrentWorkingDirectory == appExeDir);
            Assert.IsTrue(currDir==appExeDir);
        }
コード例 #5
0
        public CommandExecutionMgr(JobsGroupDto jobsGroup,
								ConsoleExecutorDto consoleCmdDto)
        {
            _commandJobs = jobsGroup;

            _consoleExecutor = consoleCmdDto;

            _cmdLogMgr = new ConsoleCommandLogMgr(consoleCmdDto.DefaultCommandOutputLogFilePathName,
                                                    consoleCmdDto.CmdConsoleLogFileTimeStamp,
                                                        string.Empty);

            _errLogMgr = new ConsoleCommandLogMgr(consoleCmdDto.DefaultCommandOutputLogFilePathName,
                                                        consoleCmdDto.CmdConsoleLogFileTimeStamp,
                                                            consoleCmdDto.CmdConsoleLogFileErrorSuffix);

            _wrkDirMgr = new WorkingDirectoryMgr(_consoleExecutor.DefaultCommandExeDirectoryDto);
        }
コード例 #6
0
        public bool ExecuteCommands()
        {
            bool result;
            int jobNo = 0;
            Console.WriteLine("CmdrX.exe: Starting Job Execution...");
            try
            {
                foreach (var job in _commandJobs.Jobs)
                {
                    jobNo++;
                    job.JobNumber = jobNo;
                    job.CommandStartTime = DateTime.Now;
                    LogUtil.WriteLogJobStartUpMessage(job, _consoleExecutor);
                    _cmdLogMgr.LogWriteStartJobHeader(job);
                    _errLogMgr.LogWriteStartJobHeader(job);
                    var exeCmd = new ExecuteConsoleCommand(job, _cmdLogMgr, _errLogMgr, _wrkDirMgr);
                    exeCmd.Execute();

                    _cmdLogMgr.LogWriteEndJobFooter(job);
                    _errLogMgr.LogWriteEndJobFooter(job);
                    Console.WriteLine($"Completed Job No. {jobNo,4:###0} Exit Code: {job.CommandExitCode} Job Name: {job.CommandDisplayName}" );

                    if (job.CommandExitCode > job.KillJobsRunOnExitCodeGreaterThan
                        || job.CommandExitCode < job.KillJobsRunOnExitCodeLessThan)
                    {
                        var msg = $"Job No. {job.JobNumber} Job Name: {job.CommandDisplayName}"
                            + Environment.NewLine
                            + $"Command Exit Code Is Out-Of-Bounds! Job Exit Code = {job.CommandExitCode}  "
                            + Environment.NewLine
                            + $"Maximum Exit Code = {job.KillJobsRunOnExitCodeGreaterThan}  "
                            + $"Mininimum Exit Code = {job.KillJobsRunOnExitCodeLessThan}  "
                            + Environment.NewLine
                            + "Terminating Job Group Command Execution!";

                        Environment.ExitCode = job.CommandExitCode;
                        var err = new FileOpsErrorMessageDto
                        {
                            JobName = job.CommandDisplayName,
                            DirectoryPath = string.Empty,
                            ErrId = 10,
                            ErrorMessage = msg,
                            ErrSourceMethod = "ExecuteCommands()",
                            FileName = string.Empty,
                            LoggerLevel = LogLevel.FATAL
                        };

                        _consoleExecutor.ApplicationExitStatus.OpsError =
                            ErrorMgr.FormatErrorDto(err);
                        _consoleExecutor.ApplicationExitStatus.IsFatalError = true;
                        ErrorMgr.LoggingStatus = ErrorLoggingStatus.On;
                        ErrorMgr.WriteErrorMsg(err);
                        LogUtil.WriteLogJobEndMessage(job, _consoleExecutor);
                        return false;
                    }

                    LogUtil.WriteLogJobEndMessage(job, _consoleExecutor);

                    _wrkDirMgr.ChangeBackToOriginalWorkingDirectory();
                }

                Environment.ExitCode = 0;
                _consoleExecutor.ApplicationExitStatus.IsSuccessfulCompletion = true;
                result = true;
            }
            catch (Exception ex)
            {
                var err = new FileOpsErrorMessageDto
                {
                    DirectoryPath = string.Empty,
                    ErrId = 20,
                    ErrorMessage = "Exception thrown while executing commands! ",
                    ErrSourceMethod = "ExecuteCommands()",
                    ErrException = ex,
                    FileName = string.Empty,
                    LoggerLevel = LogLevel.FATAL
                };

                ErrorMgr.LoggingStatus = ErrorLoggingStatus.On;
                ErrorMgr.WriteErrorMsg(err);
                _consoleExecutor.ApplicationExitStatus.IsExceptionThrown = true;
                _consoleExecutor.ApplicationExitStatus.OpsError = ErrorMgr.FormatErrorDto(err);

                if (Environment.ExitCode == 0)
                {
                    Environment.ExitCode = -8;
                }

                result = false;
            }
            finally
            {
                _wrkDirMgr.ChangeBackToOriginalWorkingDirectory();
                _wrkDirMgr.Dispose();
                _wrkDirMgr = null;

                _commandJobs.Dispose();
                _commandJobs = null;

                _cmdLogMgr.Dispose();
                _cmdLogMgr = null;

                _errLogMgr.Dispose();
                _errLogMgr = null;

            }

            return result;
        }