예제 #1
0
 private IEnumerable <ConformanceInformation> readInformationFromFile(string path)
 {
     using (var bundleStream = File.OpenRead(path))
     {
         if (bundleStream != null)
         {
             var scanner = new ConformanceArtifactScanner(bundleStream, path);
             return(scanner.ListConformanceResourceInformation().ToList());
         }
         else
         {
             return(Enumerable.Empty <ConformanceInformation>());
         }
     }
 }
예제 #2
0
        /// <summary>
        /// Locates the file belonging to the given artifactId on a filesystem (within the store directory given in the constructor)
        /// and reads an artifact with the given id from it.
        /// </summary>
        /// <param name="url">identifying uri of the conformance resource to find</param>
        /// <returns>An artifact (Profile, ValueSet, etc) or null if an artifact with the given uri could not be located. If both an
        /// xml and a json version is available, the xml version is returned</returns>
        public Resource LoadConformanceResourceByUrl(string url)
        {
            if (url == null)
            {
                throw Error.ArgumentNull("identifier");
            }
            prepareResources();

            var info = _resourceInformation.SingleOrDefault(ci => ci.Url == url);

            if (info == null)
            {
                return(null);
            }

            var    path = info.Origin;
            string artifactXml;

            // Note: no exception handling. If the expected bundled file cannot be
            // read, throw the original exception.
            using (var content = File.OpenRead(path))
            {
                if (content == null)
                {
                    throw new FileNotFoundException("Cannot find file " + path);
                }

                var scanner = new ConformanceArtifactScanner(content, path);
                var entry   = scanner.FindConformanceResourceByUrl(url);

                artifactXml = entry != null?entry.ToString() : null;
            }

            if (artifactXml != null)
            {
                return(new FhirXmlParser().Parse <Resource>(artifactXml));
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// Locates the file belonging to the given artifactId on a filesystem (within the store directory given in the constructor)
        /// and reads an artifact with the given id from it.
        /// </summary>
        /// <param name="url">identifying uri of the conformance resource to find</param>
        /// <returns>An artifact (Profile, ValueSet, etc) or null if an artifact with the given uri could not be located. If both an
        /// xml and a json version is available, the xml version is returned</returns>
        public Resource LoadConformanceResourceByUrl(string url)
        {
            if (url == null) throw Error.ArgumentNull("identifier");
            prepareResources();

            var info = _resourceInformation.SingleOrDefault(ci => ci.Url == url);
            
            if(info == null) return null;

            var path = info.Origin;
            string artifactXml;

            // Note: no exception handling. If the expected bundled file cannot be
            // read, throw the original exception.
            using (var content = File.OpenRead(path))
            {
                if (content == null) throw new FileNotFoundException("Cannot find file " + path);

                var scanner = new ConformanceArtifactScanner(content, path);
                var entry = scanner.FindConformanceResourceByUrl(url);

                artifactXml = entry != null ? entry.ToString() : null;
            }

            if (artifactXml != null)
                return FhirParser.ParseResourceFromXml(artifactXml);
            else
                return null;
        }
 private IEnumerable<ConformanceInformation> readInformationFromFile(string path)
 {
     using (var bundleStream = File.OpenRead(path))
     {
         if (bundleStream != null)
         {
             var scanner = new ConformanceArtifactScanner(bundleStream, path);
             return scanner.ListConformanceResourceInformation().ToList();
         }
         else
             return Enumerable.Empty<ConformanceInformation>();
     }
 }