-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e1b7c1e
commit ce247d3
Showing
17 changed files
with
257 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
|
||
using WitsmlExplorer.Api.Jobs; | ||
|
||
namespace WitsmlExplorer.Api.Services | ||
{ | ||
public interface IJobProgressService | ||
{ | ||
void Setup(JobInfo jobInfo, double start = 0, double end = double.MaxValue); | ||
void SetCurrent(double current); | ||
} | ||
|
||
public class JobProgressService : IJobProgressService | ||
{ | ||
private JobInfo _jobInfo; | ||
private double _start; | ||
private double _end; | ||
private double _current; | ||
|
||
public void Setup(JobInfo jobInfo, double start = 0.0, double end = double.MaxValue) | ||
{ | ||
if (jobInfo == null) | ||
{ | ||
throw new InvalidOperationException("_jobInfo not set!"); | ||
} | ||
|
||
_jobInfo = jobInfo; | ||
_start = start < end ? start : end; | ||
_end = end; | ||
_current = _start; | ||
|
||
UpdateJobProgress(); | ||
} | ||
|
||
public void SetCurrent(double current) | ||
{ | ||
if (_jobInfo != null) | ||
{ | ||
if (current > _end) | ||
{ | ||
_current = _end; | ||
UpdateJobProgress(); | ||
} | ||
else if (current > _current) | ||
{ | ||
_current = current; | ||
UpdateJobProgress(); | ||
} | ||
} | ||
} | ||
|
||
private void UpdateJobProgress() | ||
{ | ||
if (_jobInfo != null) | ||
{ | ||
if (_start >= _end) | ||
{ | ||
_jobInfo.Progress = 100; | ||
} | ||
else | ||
{ | ||
_jobInfo.Progress = (int)Math.Floor((_current - _start) / (_end - _start) * 100.0); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.