Beispiel #1
0
        public void TestLogFileWithRelativePathWithMessageIf()
        {
            string logFile = "logfile2.log";

            Core.Miscellaneous.Utilities.EnsureFileDoesNotExist(logFile);
            try
            {
                using GRYLog logObject = GRYLog.Create(logFile);
                logObject.Configuration.SetFormat(GRYLogLogFormat.GRYLogFormat);
                string file = logFile;
                Assert.IsFalse(File.Exists(file));
                string fileWithRelativePath = logFile;
                logObject.Configuration.SetLogFile(fileWithRelativePath);
                Assert.AreEqual(fileWithRelativePath, logObject.Configuration.GetLogFile());
                Assert.IsFalse(File.Exists(fileWithRelativePath));
                string testContent = "test";
                logObject.Log(testContent, LogLevel.Warning, "MyMessageId");
                Assert.IsTrue(File.Exists(fileWithRelativePath));
                Assert.IsTrue(Regex.IsMatch(File.ReadAllText(logFile), "^\\[\\d\\d\\d\\d-\\d\\d-\\d\\d \\d\\d:\\d\\d:\\d\\d\\] \\[MyMessageId\\] \\[Warning\\] test$"));
            }
            finally
            {
                Core.Miscellaneous.Utilities.EnsureFileDoesNotExist(logFile);
            }
        }
Beispiel #2
0
        public void TestLogFileWithRelativePath()
        {
            string logFile = "logfile.log";

            Core.Miscellaneous.Utilities.EnsureFileDoesNotExist(logFile);
            try
            {
                using GRYLog logObject = GRYLog.Create(logFile);
                logObject.Configuration.SetFormat(GRYLogLogFormat.OnlyMessage);
                string file = logFile;
                Assert.IsFalse(File.Exists(file));
                string fileWithRelativePath = logFile;
                logObject.Configuration.SetLogFile(fileWithRelativePath);
                Assert.AreEqual(fileWithRelativePath, logObject.Configuration.GetLogFile());
                Assert.IsFalse(File.Exists(fileWithRelativePath));
                string testContent = "test";
                logObject.Log(testContent);
                Assert.IsTrue(File.Exists(fileWithRelativePath));
                Assert.AreEqual(testContent, File.ReadAllText(logFile));
            }
            finally
            {
                Core.Miscellaneous.Utilities.EnsureFileDoesNotExist(logFile);
            }
        }
Beispiel #3
0
        public int Main(string[] arguments)
        {
            int result = ExitCodeNoProgramExecuted;

            try
            {
                Version          = GetVersion();
                LicenseLink      = $"https://raw.githubusercontent.com/anionDev/Epew/v{Version}/License.txt";
                _SentenceBuilder = SentenceBuilder.Create();
                if (arguments == null)
                {
                    throw Utilities.CreateNullReferenceExceptionDueToParameter(nameof(arguments));
                }
                string argumentsAsString = String.Join(' ', arguments);
                _Log = GRYLog.Create();
                string workingDirectory = Directory.GetCurrentDirectory();
                try
                {
                    if (arguments.Length == 0)
                    {
                        _Log.Log($"{ProgramName} v{Version}");
                        _Log.Log($"Run '{ProgramName} --help' to get help about the usage.");
                    }
                    else
                    {
                        ParserResult <EpewOptions> parserResult = new Parser(settings => settings.CaseInsensitiveEnumValues = true).ParseArguments <EpewOptions>(arguments);
                        if (IsHelpCommand(arguments))
                        {
                            WriteHelp(parserResult);
                        }
                        else
                        {
                            parserResult.WithParsed(options =>
                            {
                                result = HandleSuccessfullyParsedArguments(options);
                            })
                            .WithNotParsed(errors =>
                            {
                                HandleParsingErrors(argumentsAsString, errors);
                            });
                            return(result);
                        }
                    }
                }
                catch (Exception exception)
                {
                    _Log.Log($"Fatal error occurred while processing argument '{workingDirectory}> epew {argumentsAsString}", exception);
                }
            }
            catch (Exception exception)
            {
                System.Console.Error.WriteLine($"Fatal error occurred", exception.ToString());
                result = ExitCodeFatalErroroccurred;
            }
            return(result);
        }
Beispiel #4
0
        public void TestLogProgress()
        {
            GRYLog logObject = GRYLog.Create();

            logObject.Configuration.StoreProcessedLogItemsInternally = true;
            logObject.LogProgress(0, 4);
            logObject.LogProgress(3, 122);
            logObject.LogProgress(73, 73);
            Assert.AreEqual(3, logObject.ProcessedLogItems.Count);
            Assert.AreEqual("Processed 0/4 items (0%)", logObject.ProcessedLogItems[0].PlainMessage);
            Assert.AreEqual("Processed 003/122 items (2,46%)", logObject.ProcessedLogItems[1].PlainMessage);
            Assert.AreEqual("Processed 73/73 items (100%)", logObject.ProcessedLogItems[2].PlainMessage);
        }
Beispiel #5
0
 public static GitCommandResult ExecuteGitCommand(string repositoryFolder, string argument, bool throwErrorIfExitCodeIsNotZero = false, int?timeoutInMilliseconds = null, bool printErrorsAsInformation = false, bool writeOutputToConsole = false)
 {
     using GRYLog log          = GRYLog.Create();
     log.Configuration.Enabled = true;
     log.Configuration.SetEnabledOfAllLogTargets(writeOutputToConsole);
     using ExternalProgramExecutor externalProgramExecutor = new("git", argument, repositoryFolder)
           {
               LogObject                     = log,
               TimeoutInMilliseconds         = timeoutInMilliseconds,
               PrintErrorsAsInformation      = printErrorsAsInformation,
               ThrowErrorIfExitCodeIsNotZero = throwErrorIfExitCodeIsNotZero
           };
     externalProgramExecutor.StartSynchronously();
     return(new GitCommandResult(argument, repositoryFolder, externalProgramExecutor.AllStdOutLines, externalProgramExecutor.AllStdErrLines, externalProgramExecutor.ExitCode));
 }
Beispiel #6
0
        public void TestLogFileWithRelativePathWithSubFolder()
        {
            string folder  = "folder";
            string logFile = folder + "/logFile.log";

            Core.Miscellaneous.Utilities.EnsureFileDoesNotExist(logFile);
            try
            {
                using GRYLog logObject = GRYLog.Create(logFile);
                logObject.Configuration.SetFormat(GRYLogLogFormat.OnlyMessage);
                Assert.IsFalse(File.Exists(logFile));
                string testContent = "x";
                logObject.Log(testContent);
                Assert.IsTrue(File.Exists(logFile));
                Assert.AreEqual(testContent, File.ReadAllText(logFile));
            }
            finally
            {
                Core.Miscellaneous.Utilities.EnsureDirectoryDoesNotExist(folder);
            }
        }
Beispiel #7
0
 public static SupervisedThread CreateByLogFile(Action action, string logFile, string name = "", string informationAboutInvoker = "")
 {
     return(CreateByGRYLog(action, GRYLog.Create(logFile), name, informationAboutInvoker));
 }