Skip to content

Commit

Permalink
Add timings to command result.
Browse files Browse the repository at this point in the history
  • Loading branch information
twitchax committed Mar 7, 2019
1 parent fb66713 commit 9ff6c14
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/Core/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ internal static Task<ICommandResult> RunCommand(
});
}
var startTime = DateTime.Now;
process.Start();
process.BeginOutputReadLine();
Expand All @@ -159,12 +161,14 @@ internal static Task<ICommandResult> RunCommand(
process.WaitForExit();
var endTime = DateTime.Now;
var succeeded = process.ExitCode == 0;
var exitCode = process.ExitCode;
var standard = standardOutput.ToString();
var error = standardError.ToString();
return new CommandResult(succeeded, exitCode, standard, error);
return new CommandResult(succeeded, exitCode, standard, error, startTime, endTime);
});
t.Start();

Expand Down
30 changes: 28 additions & 2 deletions src/Core/Implementations/CommandResult.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

using System;
using Sheller.Models;

namespace Sheller.Implementations
Expand Down Expand Up @@ -32,19 +33,42 @@ public class CommandResult : ICommandResult
/// <value>The standard error of an executable.</value>
public string StandardError { get; private set; }

/// <summary>
/// StartTime property.
/// </summary>
/// <value>The start time of an executable.</value>
public DateTime StartTime { get; private set; }

/// <summary>
/// EndTime property.
/// </summary>
/// <value>The end time of an executable.</value>
public DateTime EndTime { get; private set; }

/// <summary>
/// RunTime property.
/// </summary>
/// <value>The run time of an executable.</value>
public TimeSpan RunTime { get; private set; }

/// <summary>
/// The CommandResult constructor.
/// </summary>
/// <param name="succeeded"></param>
/// <param name="exitCode"></param>
/// <param name="standardOutput"></param>
/// <param name="standardError"></param>
public CommandResult(bool succeeded, int exitCode, string standardOutput, string standardError)
/// <param name="startTime"></param>
/// <param name="endTime"></param>
public CommandResult(bool succeeded, int exitCode, string standardOutput, string standardError, DateTime startTime, DateTime endTime)
{
Succeeded = succeeded;
ExitCode = exitCode;
StandardOutput = standardOutput;
StandardError = standardError;
StartTime = startTime;
EndTime = endTime;
RunTime = endTime - startTime;
}
}

Expand All @@ -67,8 +91,10 @@ public class CommandResult<TResult> : CommandResult, ICommandResult<TResult>
/// <param name="exitCode"></param>
/// <param name="standardOutput"></param>
/// <param name="standardError"></param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
/// <param name="result"></param>
public CommandResult(bool succeeded, int exitCode, string standardOutput, string standardError, TResult result) : base(succeeded, exitCode, standardOutput, standardError)
public CommandResult(bool succeeded, int exitCode, string standardOutput, string standardError, DateTime startTime, DateTime endTime, TResult result) : base(succeeded, exitCode, standardOutput, standardError, startTime, endTime)
{
Result = result;
}
Expand Down
20 changes: 20 additions & 0 deletions src/Core/Models/ICommandResult.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

namespace Sheller.Models
{
/// <summary>
Expand Down Expand Up @@ -28,6 +30,24 @@ public interface ICommandResult
/// </summary>
/// <value>The standard error of an executable.</value>
string StandardError { get; }

/// <summary>
/// StartTime property.
/// </summary>
/// <value>The start time of an executable.</value>
DateTime StartTime { get; }

/// <summary>
/// EndTime property.
/// </summary>
/// <value>The end time of an executable.</value>
DateTime EndTime { get; }

/// <summary>
/// RunTime property.
/// </summary>
/// <value>The run time of an executable.</value>
TimeSpan RunTime { get; }
}

/// <summary>
Expand Down

0 comments on commit 9ff6c14

Please sign in to comment.