-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from HicServices/develop
Develop
- Loading branch information
Showing
21 changed files
with
318 additions
and
94 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
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,80 @@ | ||
using MapsDirectlyToDatabaseTable; | ||
using NUnit.Framework; | ||
using Rdmp.Core.Caching.Requests; | ||
using Rdmp.Core.Caching.Requests.FetchRequestProvider; | ||
using Rdmp.Core.Curation; | ||
using Rdmp.Core.Curation.Data; | ||
using Rdmp.Core.Curation.Data.Cache; | ||
using Rdmp.Core.DataFlowPipeline; | ||
using Rdmp.Core.Startup; | ||
using Rdmp.Dicom.Cache.Pipeline; | ||
using ReusableLibraryCode.Checks; | ||
using ReusableLibraryCode.Progress; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using Tests.Common; | ||
|
||
namespace Rdmp.Dicom.Tests | ||
{ | ||
class TestProcessBasedCacheSource : UnitTests | ||
{ | ||
[Test] | ||
public void TestWithEcho() | ||
{ | ||
var source = new ProcessBasedCacheSource(); | ||
|
||
if(IsLinux) | ||
{ | ||
source.Command = "/bin/echo"; | ||
source.Args = "Hey Thomas go get %s and store in %d"; | ||
} | ||
else | ||
{ | ||
source.Command = "cmd.exe"; | ||
source.Args = "/c echo Hey Thomas go get %s and store in %d"; | ||
} | ||
source.TimeFormat = "dd/MM/yy"; | ||
source.ThrowOnNonZeroExitCode = true; | ||
|
||
// What dates to load | ||
var cp = WhenIHaveA<CacheProgress>(); | ||
cp.CacheFillProgress = new DateTime(2001,12,24); | ||
cp.SaveToDatabase(); | ||
|
||
// Where to put files | ||
var lmd = cp.LoadProgress.LoadMetadata; | ||
|
||
var dir = new DirectoryInfo(TestContext.CurrentContext.WorkDirectory); | ||
var loadDir = LoadDirectory.CreateDirectoryStructure(dir,"blah",true); | ||
|
||
lmd.LocationOfFlatFiles = loadDir.RootPath.FullName; | ||
lmd.SaveToDatabase(); | ||
|
||
source.PreInitialize(new CacheFetchRequestProvider(cp), new ThrowImmediatelyDataLoadEventListener()); | ||
source.PreInitialize(cp.CatalogueRepository,new ThrowImmediatelyDataLoadEventListener()); | ||
source.PreInitialize(new PermissionWindow(cp.CatalogueRepository),new ThrowImmediatelyDataLoadEventListener()); | ||
|
||
var toMem = new ToMemoryDataLoadEventListener(true); | ||
var fork = new ForkDataLoadEventListener(toMem,new ThrowImmediatelyDataLoadEventListener(){WriteToConsole = true}); | ||
|
||
source.GetChunk(fork,new GracefulCancellationToken()); | ||
|
||
Assert.Contains($"Hey Thomas go get 24/12/01 and store in {Path.Combine(loadDir.Cache.FullName,"ALL")}",toMem.GetAllMessagesByProgressEventType()[ProgressEventType.Information].Select(v=>v.Message).ToArray()); | ||
|
||
|
||
|
||
} | ||
|
||
public static bool IsLinux | ||
{ | ||
get | ||
{ | ||
int p = (int) Environment.OSVersion.Platform; | ||
return (p == 4) || (p == 6) || (p == 128); | ||
} | ||
} | ||
} | ||
} |
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
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,106 @@ | ||
using Rdmp.Core.Caching.Pipeline.Sources; | ||
using Rdmp.Core.Caching.Requests; | ||
using Rdmp.Core.Curation; | ||
using Rdmp.Core.Curation.Data; | ||
using Rdmp.Core.DataFlowPipeline; | ||
using ReusableLibraryCode.Checks; | ||
using ReusableLibraryCode.Progress; | ||
using System; | ||
using System.Diagnostics; | ||
|
||
namespace Rdmp.Dicom.Cache.Pipeline | ||
{ | ||
public class ProcessBasedCacheSource : CacheSource<SMIDataChunk> | ||
{ | ||
[DemandsInitialization(@"Process to start (path only)",Mandatory = true)] | ||
public string Command {get;set;} | ||
|
||
[DemandsInitialization(@"Arguments to provide to the Process. Template with | ||
%s start time | ||
%e end time time to fetch | ||
%d directory to put files fetched | ||
Example:. './GetImages.exe ""%s"" ""%e%""'")] | ||
public string Args {get;set;} | ||
|
||
[DemandsInitialization("The datetime format for %s and %e.",Mandatory = true,DefaultValue = "yyyy-MM-dd HH:mm:ss")] | ||
public string TimeFormat {get;set;} | ||
|
||
[DemandsInitialization("True to throw an Exception if the process run returns a nonzero exit code", DefaultValue = true)] | ||
public bool ThrowOnNonZeroExitCode {get;set;} | ||
|
||
public override void Abort(IDataLoadEventListener listener) | ||
{ | ||
|
||
} | ||
|
||
public override void Check(ICheckNotifier notifier) | ||
{ | ||
|
||
} | ||
|
||
public override void Dispose(IDataLoadEventListener listener, Exception pipelineFailureExceptionIfAny) | ||
{ | ||
|
||
} | ||
|
||
public override SMIDataChunk DoGetChunk(ICacheFetchRequest request, IDataLoadEventListener listener, GracefulCancellationToken cancellationToken) | ||
{ | ||
listener.OnNotify(this,new NotifyEventArgs(ProgressEventType.Information,$"ProcessBasedCacheSource version is {typeof(ProcessBasedCacheSource).Assembly.GetName().Version}. Assembly is {typeof(ProcessBasedCacheSource).Assembly} " )); | ||
|
||
// Where we are putting the files | ||
var cacheDir = new LoadDirectory(Request.CacheProgress.LoadProgress.LoadMetadata.LocationOfFlatFiles).Cache; | ||
var cacheLayout = new SMICacheLayout(cacheDir, new SMICachePathResolver("ALL")); | ||
|
||
Chunk = new SMIDataChunk(Request) | ||
{ | ||
FetchDate = Request.Start, | ||
Modality = "ALL", | ||
Layout = cacheLayout | ||
}; | ||
|
||
var workingDirectory = cacheLayout.GetLoadCacheDirectory(listener); | ||
|
||
listener.OnNotify(this,new NotifyEventArgs(ProgressEventType.Information,"Working directory is:" + workingDirectory)); | ||
listener.OnNotify(this,new NotifyEventArgs(ProgressEventType.Information,"Fetch Start is:" + request.Start)); | ||
listener.OnNotify(this,new NotifyEventArgs(ProgressEventType.Information,"Fetch End is:" + request.End)); | ||
|
||
listener.OnNotify(this,new NotifyEventArgs(ProgressEventType.Information,"Command is:" + Command)); | ||
listener.OnNotify(this,new NotifyEventArgs(ProgressEventType.Information,"Args template is:" + Args)); | ||
listener.OnNotify(this,new NotifyEventArgs(ProgressEventType.Information,"Datetime format is:" + TimeFormat)); | ||
|
||
|
||
string args = Args | ||
.Replace("%s",request.Start.ToString(TimeFormat)) | ||
.Replace("%e",request.End.ToString(TimeFormat)) | ||
.Replace("%d",workingDirectory.FullName); | ||
|
||
listener.OnNotify(this,new NotifyEventArgs(ProgressEventType.Information,"Args resolved is:" + args)); | ||
|
||
using(var p = new Process()) | ||
{ | ||
p.StartInfo.FileName = Command; | ||
p.StartInfo.Arguments = args; | ||
p.StartInfo.UseShellExecute = false; | ||
p.StartInfo.RedirectStandardOutput = true; | ||
p.OutputDataReceived += (sender, a) => listener.OnNotify(this,new NotifyEventArgs(ProgressEventType.Information,a.Data)); | ||
|
||
p.Start(); | ||
p.BeginOutputReadLine(); | ||
|
||
p.WaitForExit(); | ||
|
||
listener.OnNotify(this,new NotifyEventArgs( p.ExitCode == 0 ? ProgressEventType.Information : ProgressEventType.Warning , "Process exited with code " + p.ExitCode)); | ||
|
||
if(p.ExitCode != 0 && ThrowOnNonZeroExitCode) | ||
throw new Exception("Process exited with code " + p.ExitCode); | ||
} | ||
|
||
return Chunk; | ||
} | ||
|
||
public override SMIDataChunk TryGetPreview() | ||
{ | ||
return null; | ||
} | ||
} | ||
} |
Oops, something went wrong.