Skip to content

Commit

Permalink
Adds a warning when dev methods are used in RELEASE
Browse files Browse the repository at this point in the history
Closes #179

Now when some entry points are used in RELEASE builds they'll issue a warning to let users know what the problem might be.
  • Loading branch information
atruskie committed Jul 11, 2018
1 parent 0de4691 commit beae4fb
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/AnalysisPrograms/AED.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ public static Image DrawSonogram(BaseSonogram sonogram, IEnumerable<AcousticEven

public static void Execute(Arguments arguments)
{
MainEntry.WarnIfDevleoperEntryUsed();

TowseyLibrary.Log.Verbosity = 1;
string date = "# DATE AND TIME: " + DateTime.Now;
LoggedConsole.WriteLine("# Running acoustic event detection.");
Expand Down
2 changes: 2 additions & 0 deletions src/AnalysisPrograms/EPR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ public override Task<int> Execute(CommandLineApplication app)

public static void Execute(Arguments arguments)
{
MainEntry.WarnIfDevleoperEntryUsed();

string title = "# EVENT PATTERN RECOGNITION.";
string date = "# DATE AND TIME: " + DateTime.Now;
Log.WriteLine(title);
Expand Down
2 changes: 2 additions & 0 deletions src/AnalysisPrograms/GroundParrotRecogniser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ public static Tuple<BaseSonogram, List<AcousticEvent>> Detect(FileInfo wavFilePa

public static void Execute(Arguments arguments)
{
MainEntry.WarnIfDevleoperEntryUsed();

if (arguments == null)
{
throw new NoDeveloperMethodException();
Expand Down
20 changes: 16 additions & 4 deletions src/AnalysisPrograms/Production/MainEntryUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,20 +210,32 @@ internal static void BeforeExecute(MainArgs main, CommandLineApplication applica

ModifyVerbosity(main);

Log.Debug($"Metric reporting is {(ApMetricRecording ? "en" : "dis")}abled.");
Log.Debug($"Metric reporting is {(ApMetricRecording ? "en" : "dis")}abled (but not yet functional).");

LoadNativeCode();
}

internal static void Copyright()
{
LoggedConsole.WriteLine(
// ReSharper disable once UnreachableCode
$@"{Meta.Description} - version {BuildMetadata.VersionString} ({(InDEBUG ? "DEBUG" : "RELEASE")} build, {BuildMetadata.BuildDate})
LoggedConsole.WriteLine($@"{Meta.Description} - version {BuildMetadata.VersionString} ({(InDEBUG ? "DEBUG" : "RELEASE")} build, {BuildMetadata.BuildDate})
Git branch-version: {BuildMetadata.GitBranch}-{BuildMetadata.GitCommit}, DirtyBuild:{BuildMetadata.IsDirty}, CI:{BuildMetadata.CiBuild}
Copyright {Meta.NowYear} {Meta.Organization}");
}

internal static void WarnIfDevleoperEntryUsed(string message = null)
{
if (!InDEBUG)
{
message = message == null ? string.Empty : "\n! " + message;
Log.Warn($@"!
!
! The entry point called is designed for use by devleopers and debuggers.
! It is likely that this entry point does not do what you want and will fail.{message}
!
!");
}
}

/// <summary>
/// This method will stop the program from exiting if the solution was built in #DEBUG
/// and the program was started by Visual Studio.
Expand Down
7 changes: 4 additions & 3 deletions src/AnalysisPrograms/Recognizers/Base/RecognizerEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public class RecognizerEntry
{
public const string CommandName = "EventRecognizer";
private const string Description =
"The entry point for all species or event recognizers. Only to be used on short recordings (< 2 mins)." +
"This recognizer runs any IEventRecognizer. The recognizer run is based on the " +
"Identifier field and parsed from the AnalysisName field in the config file of the same name";
"The entry point for all species or event recognizers. Only to be used on short recordings (< 2 mins) that exactly match the code assumptions (e.g. correct format, channels, sample rate)." +
"This recognizer runs any IEventRecognizer. The recognizer run" +
"follows the same rules as " + AnalyseLongRecording.CommandName;

[Command(
CommandName,
Expand All @@ -61,6 +61,7 @@ public override Task<int> Execute(CommandLineApplication app)
/// </summary>
public static void Execute(Arguments arguments)
{
MainEntry.WarnIfDevleoperEntryUsed("EventRecognizer entry does not do any audio maniuplation.");
Log.Info("Running event recognizer");

var sourceAudio = arguments.Source;
Expand Down
2 changes: 2 additions & 0 deletions src/AnalysisPrograms/Segment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public override Task<int> Execute(CommandLineApplication app)

public static void Execute(Arguments arguments)
{
MainEntry.WarnIfDevleoperEntryUsed();

string date = "# DATE AND TIME: " + DateTime.Now;
Log.WriteLine("# SEGMENTING A RECORDING");
Log.WriteLine(date);
Expand Down

0 comments on commit beae4fb

Please sign in to comment.