public void TestSourceCaching() { var src = new CachedArtifactSource(ArtifactResolver.CreateDefault()); src.Prepare(); Stopwatch sw1 = new Stopwatch(); // Ensure looking up a failed endpoint repeatedly does not cost much time sw1.Start(); src.ReadResourceArtifact(new Uri("http://some.none.existant.address.nl")); sw1.Stop(); var sw2 = new Stopwatch(); sw2.Start(); src.ReadResourceArtifact(new Uri("http://some.none.existant.address.nl")); sw2.Stop(); Assert.IsTrue(sw2.ElapsedMilliseconds < sw1.ElapsedMilliseconds && sw2.ElapsedMilliseconds < 100); // Now try an existing artifact sw1.Restart(); src.ReadResourceArtifact(new Uri("http://hl7.org/fhir/v2/vs/0292")); sw1.Stop(); sw2.Restart(); src.ReadResourceArtifact(new Uri("http://hl7.org/fhir/v2/vs/0292")); sw2.Stop(); Assert.IsTrue(sw2.ElapsedMilliseconds < sw1.ElapsedMilliseconds && sw2.ElapsedMilliseconds < 100); }
public void TestSourceCaching() { var src = new CachedArtifactSource(new MultiArtifactSource(ZipArtifactSource.CreateValidationSource(), new WebArtifactSource())); Stopwatch sw1 = new Stopwatch(); // Ensure looking up a failed endpoint repeatedly does not cost much time sw1.Start(); src.LoadConformanceResourceByUrl("http://some.none.existant.address.nl/fhir/StructureDefinition/bla"); sw1.Stop(); var sw2 = new Stopwatch(); sw2.Start(); src.LoadConformanceResourceByUrl("http://some.none.existant.address.nl/fhir/StructureDefinition/bla"); sw2.Stop(); Debug.WriteLine("sw2 {0}, sw1 {1}", sw2.ElapsedMilliseconds, sw1.ElapsedMilliseconds); Assert.IsTrue(sw2.ElapsedMilliseconds <= sw1.ElapsedMilliseconds && sw2.ElapsedMilliseconds < 100); // Now try an existing artifact sw1.Restart(); src.LoadConformanceResourceByUrl("http://hl7.org/fhir/ValueSet/v2-0292"); sw1.Stop(); sw2.Restart(); src.LoadConformanceResourceByUrl("http://hl7.org/fhir/ValueSet/v2-0292"); sw2.Stop(); Assert.IsTrue(sw2.ElapsedMilliseconds < sw1.ElapsedMilliseconds && sw2.ElapsedMilliseconds < 100); }
public static void ExpandProfileFile(string inputfile, string outputfile) { var source = new CachedArtifactSource(ArtifactResolver.CreateOffline()); var expander = new ProfileExpander(source); string xml = File.ReadAllText(inputfile); var diff = (Profile)FhirParser.ParseResourceFromXml(xml); expander.Expand(diff); xml = FhirSerializer.SerializeResourceToXml(diff); File.WriteAllText(outputfile, xml); }
public static SpecificationProvider CreateOffline(params IArtifactSource[] sources) { ArtifactResolver resolver = new ArtifactResolver(); foreach (IArtifactSource s in sources) { resolver.AddSource(s); } resolver.AddSource(new CoreZipArtifactSource()); resolver.AddSource(new FileArtifactSource()); IArtifactSource cache = new CachedArtifactSource(resolver); return(new SpecificationProvider(cache)); }