Skip to content

Commit

Permalink
Merge pull request #149 from Genometric/export_dir
Browse files Browse the repository at this point in the history
Report the export path on console
  • Loading branch information
VJalili committed Mar 15, 2021
2 parents b43a5d1 + 017c693 commit db3f1a8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 9 deletions.
43 changes: 41 additions & 2 deletions CLI.Tests/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Security;
using System.Text.RegularExpressions;
using Xunit;

Expand Down Expand Up @@ -169,7 +170,7 @@ public void CorrectAndSuccessfulAnalysis()
// Arrange
string outputPath = "session_" + DateTime.Now.ToString("yyyyMMdd_HHmmssfff_", CultureInfo.InvariantCulture) + new Random().Next(100000, 999999).ToString();
WriteSampleFiles(out string rep1Filename, out string rep2Filename, out string culture);

ParserConfig cols = new ParserConfig() { Culture = culture };
var configFilename = Path.GetTempPath() + Guid.NewGuid().ToString() + ".json";
using (StreamWriter w = new StreamWriter(configFilename))
Expand Down Expand Up @@ -679,7 +680,7 @@ public void WriteTablesHeaderInLogFile()
}

[Theory]
[InlineData("300%", "2")]
[InlineData("300%", "2")]
[InlineData("-300%", "1")]
public void WarningDisplayedForInvalidC(string c, string expected)
{
Expand Down Expand Up @@ -723,5 +724,43 @@ public void ExportPathIsReportedInLogs()
var loggedOutputPath = rx.Match(outputPathLogMessage[0]).Groups[1].Value;
Assert.True(Path.IsPathRooted(loggedOutputPath));
}

[Fact]
public void ExportPathIsReportedInConsole()
{
// Arrange
string msg;

// Act
using (var tmpMspc = new TmpMspc())
msg = tmpMspc.Run();

// Assert
var rx = new Regex(".*Export Directory: (.*)\r\n.*");
var loggedOutputPath = rx.Match(msg).Groups[1].Value.Trim();

var isAValidPath = TryGetFullPath(loggedOutputPath, out _);
Assert.True(isAValidPath);
}

private static bool TryGetFullPath(string path, out string result)
{
result = string.Empty;
if (string.IsNullOrWhiteSpace(path))
return false;

try
{
result = Path.GetFullPath(path);
return true;
}
catch (Exception e) when (e is ArgumentException or
SecurityException or
NotSupportedException or
PathTooLongException)
{
return false;
}
}
}
}
12 changes: 6 additions & 6 deletions CLI/Logging/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,13 @@ private void Setup(string logFilePath, string repository, string name, string ex
log = LogManager.GetLogger(_repository, _name);

log.Info("NOTE THAT THE LOG PATTERN IS: <Date> <#Thread> <Level> <Message>");
log.Info($"Export Directory: {exportPath}");
Log($"Export Directory: {exportPath}", ConsoleColor.DarkGray);
}

public void LogStartOfASection(string header)
{
string msg = ".::." + header.PadLeft(((_sectionHeaderLenght - header.Length) / 2) + header.Length, '.').PadRight(_sectionHeaderLenght, '.') + ".::.";
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(Environment.NewLine + msg);
Console.ResetColor();
log.Info(msg);
Log(Environment.NewLine + msg, ConsoleColor.Yellow);
}

public void LogException(Exception e)
Expand Down Expand Up @@ -170,9 +167,12 @@ public void LogMSPCStatus(object sender, ValueEventArgs e)
}
}

public void Log(string message)
public void Log(string message, ConsoleColor color = ConsoleColor.Black)
{
if (color != ConsoleColor.Black)
Console.ForegroundColor = color;
Console.WriteLine(message);
Console.ResetColor();
log.Info(message);
}

Expand Down
2 changes: 1 addition & 1 deletion CLI/Orchestrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private void AssertDegreeOfParallelism(int dp)
if (dp > 0)
_degreeOfParallelism = dp;

_logger.Log(string.Format("Degree of parallelism is set to {0}.", _degreeOfParallelism));
_logger.Log(string.Format("Degree of parallelism is set to {0}.", _degreeOfParallelism), ConsoleColor.DarkGray);
}

private bool LoadParserConfig(CommandLineOptions options, out ParserConfig config)
Expand Down

0 comments on commit db3f1a8

Please sign in to comment.