Skip to content

Commit

Permalink
Fixes #27 add more to progress updater (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
msevestre authored Nov 28, 2019
1 parent 2cf1237 commit dc46dcb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 31 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
configuration: Debug
image: Visual Studio 2017
image: Visual Studio 2019

# hack until donet patching works with PR
init:
Expand Down
70 changes: 40 additions & 30 deletions src/OSPSuite.Utility/Events/ProgressUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ public interface IProgressUpdater : IDisposable
void Initialize(int numberOfIterations);

/// <summary>
/// Initializes a progesss with the given number of iterations and the message and throws the event
/// Initializes a progress with the given number of iterations and the message and throws the event
/// <see cref="ProgressInitEvent" />
/// </summary>
/// <param name="numberOfIterations">Number of total iterations in the process</param>
/// <param name="message">Message that will be forwared to be for instance logged or displayed</param>
/// <param name="message">Message that will be forwarded to be for instance logged or displayed</param>
void Initialize(int numberOfIterations, string message);

/// <summary>
Expand All @@ -27,7 +27,7 @@ public interface IProgressUpdater : IDisposable
/// Increments the progress of one iteration and throws the event <see cref="ProgressingEvent" /> with the given
/// <paramref name="message" />
/// </summary>
/// <param name="message">Message that will be forwared to be for instance logged or displayed</param>
/// <param name="message">Message that will be forwarded to be for instance logged or displayed</param>
void IncrementProgress(string message);

/// <summary>
Expand All @@ -37,18 +37,35 @@ public interface IProgressUpdater : IDisposable
/// <param name="iteration">Iteration indication the progress made</param>
void ReportProgress(int iteration);

/// <summary>
/// Reports the current progress for the iteration given as parameter and throws the event
/// <see cref="ProgressingEvent" />
/// </summary>
/// <param name="iteration">Iteration indication the progress made</param>
/// <param name="numberOfIterations">Number total of iterations</param>
void ReportProgress(int iteration, int numberOfIterations);

/// <summary>
/// Reports the current progress for the iteration given as parameter and throws the event
/// <see cref="ProgressingEvent" /> with the given <paramref name="message" />
/// </summary>
/// <param name="iteration">Iteration indication the progress made</param>
/// <param name="message">Message that will be forwared to be for instance logged or displayed</param>
/// <param name="message">Message that will be forwarded to be for instance logged or displayed</param>
void ReportProgress(int iteration, string message);

/// <summary>
/// Reports the current progress for the iteration given as parameter and throws the event
/// <see cref="ProgressingEvent" /> with the given <paramref name="message" />
/// </summary>
/// <param name="iteration">Iteration indication the progress made</param>
/// <param name="numberOfIterations">Number total of iterations</param>
/// <param name="message">Message that will be forwarded to be for instance logged or displayed</param>
void ReportProgress(int iteration, int numberOfIterations, string message);

/// <summary>
/// Reports a status for the given <paramref name="message" /> by throwing the event <see cref="StatusMessageEvent" />
/// </summary>
/// <param name="message">Message that will be forwared to be for instance logged or displayed</param>
/// <param name="message">Message that will be forwarded to be for instance logged or displayed</param>
void ReportStatusMessage(string message);

/// <summary>
Expand Down Expand Up @@ -76,38 +93,31 @@ public virtual void Initialize(int numberOfIterations)
public virtual void Initialize(int numberOfIterations, string message)
{
_numberOfIterations = numberOfIterations;
_currentIteration = 0;
_eventPublisher.PublishEvent(new ProgressInitEvent(numberOfIterations, message));
}

public virtual void IncrementProgress()
{
IncrementProgress(string.Empty);
}
public virtual void IncrementProgress() => IncrementProgress(string.Empty);

public virtual void IncrementProgress(string message)
{
ReportProgress(_currentIteration + 1, message);
}
public virtual void IncrementProgress(string message) => ReportProgress(_currentIteration + 1, message);

public virtual void ReportProgress(int iteration)
{
ReportProgress(iteration, string.Empty);
}
public virtual void ReportProgress(int iteration) => ReportProgress(iteration, _numberOfIterations);

public virtual void ReportProgress(int iteration, int numberOfIterations) => ReportProgress(iteration, numberOfIterations, string.Empty);

public virtual void ReportProgress(int iteration, string message) => ReportProgress(iteration, _numberOfIterations, message);

public virtual void ReportProgress(int iteration, string message)
public virtual void ReportProgress(int iteration, int numberOfIterations, string message)
{
_currentIteration = iteration;
_eventPublisher.PublishEvent(new ProgressingEvent(iteration, percentFrom(iteration), message));
_eventPublisher.PublishEvent(new ProgressingEvent(iteration, percentFrom(iteration, numberOfIterations), message));
}

public virtual void ReportStatusMessage(string message)
{
_eventPublisher.PublishEvent(new StatusMessageEvent(message));
}
public virtual void ReportStatusMessage(string message) => _eventPublisher.PublishEvent(new StatusMessageEvent(message));

private int percentFrom(int iteration)
private int percentFrom(int iteration, int numberOfIterations)
{
return (int) Math.Floor((double) iteration * 100 / _numberOfIterations);
return (int) Math.Floor((double) iteration * 100 / numberOfIterations);
}

public virtual void Terminate()
Expand All @@ -116,6 +126,11 @@ public virtual void Terminate()
_eventPublisher.PublishEvent(new StatusMessageEvent(string.Empty));
}

protected virtual void Cleanup()
{
Terminate();
}

#region Disposable properties

private bool _disposed;
Expand All @@ -134,11 +149,6 @@ public void Dispose()
Cleanup();
}

protected virtual void Cleanup()
{
Terminate();
}

#endregion
}
}

0 comments on commit dc46dcb

Please sign in to comment.