private string prepareExampleDirectory(out int numFiles) { var zipFile = Path.Combine(Directory.GetCurrentDirectory(), "specification.zip"); var zip = new ZipCacher(zipFile); var zipPath = zip.GetContentDirectory(); var testPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(testPath); copy(zipPath, "extension-definitions.xml", testPath); copy(zipPath, "flag.xsd", testPath); copy(zipPath, "patient.sch", testPath); copy(@"TestData", "TestPatient.xml", testPath); File.WriteAllText(Path.Combine(testPath, "bla.dll"), "This is text, acting as a dll"); File.WriteAllText(Path.Combine(testPath, "nonfhir.xml"), "<root>this is not a valid FHIR xml resource.</root>"); File.WriteAllText(Path.Combine(testPath, "invalid.xml"), "<root>this is invalid xml"); Directory.CreateDirectory(Path.Combine(testPath, "sub")); copy(@"TestData", "TestPatient.json", testPath); // If you add or remove files, please correct the numFiles here below numFiles = 8 - 1; // 8 files - 1 binary (which should be ignored) return(testPath); }
public void ZipCacherShouldCache() { var cacheKey = Guid.NewGuid().ToString(); var zipFile = Path.Combine(Directory.GetCurrentDirectory(), "specification.zip"); var fa = new ZipCacher(zipFile, cacheKey); Assert.IsFalse(fa.IsActual()); var sw = new Stopwatch(); sw.Start(); fa.GetContents(); sw.Stop(); var firstRun = sw.ElapsedMilliseconds; Assert.IsTrue(fa.IsActual()); sw.Restart(); fa.GetContents(); sw.Stop(); var secondRun = sw.ElapsedMilliseconds; Assert.IsTrue(firstRun > secondRun); fa = new ZipCacher(zipFile, cacheKey); Assert.IsTrue(fa.IsActual()); sw.Start(); fa.GetContents(); sw.Stop(); var thirdRun = sw.ElapsedMilliseconds; Assert.IsTrue(thirdRun < firstRun); fa.Clear(); Assert.IsFalse(fa.IsActual()); sw.Restart(); fa.GetContents(); sw.Stop(); var fourthRun = sw.ElapsedMilliseconds; Assert.IsTrue(fourthRun > secondRun); // Something fishy going on here. // if I do not wait before the statement File.SetLastWriteTimeUtc fa.IsActual returns true Thread.Sleep(500); File.SetLastWriteTimeUtc(zipFile, DateTimeOffset.UtcNow.DateTime); Assert.IsFalse(fa.IsActual()); }
/// <summary> /// Unpacks the zip-file and constructs a new FileArtifactSource on the unzipped directory /// </summary> /// <remarks>This is an expensive operations and should be run once. As well, it unpacks files on the /// file system and is not thread-safe.</remarks> private void prepare() { if (_prepared) return; if (!File.Exists(_zipPath)) throw new FileNotFoundException(String.Format("Cannot prepare ZipArtifactSource: file '{0}' was not found", _zipPath )); var zc = new ZipCacher(_zipPath, CACHE_KEY); _filesSource = new FileDirectoryArtifactSource(zc.GetContentDirectory(), includeSubdirectories: false); _prepared = true; }
public void ZipCacherShouldCache() { var cacheKey = Guid.NewGuid().ToString(); var zipFile = Path.Combine(Directory.GetCurrentDirectory(), "specification.zip"); var fa = new ZipCacher(zipFile, cacheKey); Assert.IsFalse(fa.IsActual()); var sw = new Stopwatch(); sw.Start(); fa.GetContents(); sw.Stop(); var firstRun = sw.ElapsedMilliseconds; Assert.IsTrue(fa.IsActual()); sw.Restart(); fa.GetContents(); sw.Stop(); var secondRun = sw.ElapsedMilliseconds; Assert.IsTrue(firstRun > secondRun); fa = new ZipCacher(zipFile, cacheKey); Assert.IsTrue(fa.IsActual()); sw.Start(); fa.GetContents(); sw.Stop(); var thirdRun = sw.ElapsedMilliseconds; Assert.IsTrue(thirdRun < firstRun); fa.Clear(); Assert.IsFalse(fa.IsActual()); sw.Restart(); fa.GetContents(); sw.Stop(); var fourthRun = sw.ElapsedMilliseconds; Assert.IsTrue(fourthRun > secondRun); File.SetLastWriteTime(zipFile, DateTime.Now); Assert.IsFalse(fa.IsActual()); }
public void ZipCacherShouldCache() { var cacheKey = Guid.NewGuid().ToString(); var zipFile = Path.Combine(Directory.GetCurrentDirectory(),"validation.xml.zip"); var fa = new ZipCacher(zipFile,cacheKey); Assert.IsFalse(fa.IsActual()); var sw = new Stopwatch(); sw.Start(); fa.GetContents(); sw.Stop(); var firstRun = sw.ElapsedMilliseconds; Assert.IsTrue(fa.IsActual()); sw.Restart(); fa.GetContents(); sw.Stop(); var secondRun = sw.ElapsedMilliseconds; Assert.IsTrue(firstRun > secondRun); fa = new ZipCacher(zipFile,cacheKey); Assert.IsTrue(fa.IsActual()); sw.Start(); fa.GetContents(); sw.Stop(); var thirdRun = sw.ElapsedMilliseconds; Assert.IsTrue(thirdRun < firstRun); fa.Clear(); Assert.IsFalse(fa.IsActual()); sw.Restart(); fa.GetContents(); sw.Stop(); var fourthRun = sw.ElapsedMilliseconds; Assert.IsTrue(fourthRun > secondRun); File.SetLastWriteTime(zipFile, DateTime.Now); Assert.IsFalse(fa.IsActual()); }
/// <summary> /// Unpacks zip-files containing the artifact files, and enumerates all (zipped/nonzipped) files. /// </summary> /// <remarks>This is an expensive operations and should be run once. As well, it unpacks files on the /// file system and is not thread-safe.</remarks> public void Prepare() { #if !PORTABLE45 _artifactFiles = new List <string>(); var zips = Directory.GetFiles(_contentDirectory, "*.zip"); // Get the files in each *.zip files present in the content directory // The ZipCacher will avoid re-extracting these files. foreach (string zipPath in zips) { ZipCacher zc = new ZipCacher(zipPath, CACHE_KEY); _artifactFiles.AddRange(zc.GetContents()); } _isPrepared = true; #else throw Error.NotImplemented("File based Core artifact source is not supported on the portable runtime"); #endif }
private string prepareExampleDirectory() { var zipFile = Path.Combine(Directory.GetCurrentDirectory(), "validation.xml.zip"); var zip = new ZipCacher(zipFile); var zipPath = zip.GetContentDirectory(); var testPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(testPath); copy(zipPath, "extension-definitions.xml", testPath); copy(zipPath, "flag.xsd", testPath); copy(zipPath, "patient.sch", testPath); copy(@"TestData", "TestPatient.xml", testPath); File.WriteAllText(Path.Combine(testPath, "bla.dll"), "This is text, acting as a dll"); Directory.CreateDirectory(Path.Combine(testPath, "sub")); copy(@"TestData", "TestPatient.json", testPath); return(testPath); }
private string prepareExampleDirectory() { var zipFile = Path.Combine(Directory.GetCurrentDirectory(), "validation.xml.zip"); var zip = new ZipCacher(zipFile); var zipPath = zip.GetContentDirectory(); var testPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(testPath); copy(zipPath, "extension-definitions.xml", testPath); copy(zipPath, "flag.xsd", testPath); copy(zipPath, "patient.sch", testPath); copy(@"TestData", "TestPatient.xml", testPath); File.WriteAllText(Path.Combine(testPath, "bla.dll"), "This is text, acting as a dll"); Directory.CreateDirectory(Path.Combine(testPath, "sub")); copy(@"TestData", "TestPatient.json", testPath); return testPath; }