Ejemplo n.º 1
0
        /// <summary>
        /// Try to deserialize the full resource represented by the specified <see cref="ArtifactSummary"/>.
        /// </summary>
        /// <param name="info">An <see cref="ArtifactSummary"/> instance.</param>
        /// <typeparam name="T">The expected resource type.</typeparam>
        /// <returns>A new instance of type <typeparamref name="T"/>, or <c>null</c>.</returns>
        private static T getResourceFromScannedSource <T>(ArtifactSummary info)
            where T : Resource
        {
            // File path of the containing resource file (could be a Bundle)
            var path = info.Origin;

            using (var navStream = DefaultNavigatorStreamFactory.Create(path))
            {
                // TODO: Handle exceptions & null return values
                // e.g. file may have been deleted/renamed since last scan

                // Advance stream to the target resource (e.g. specific Bundle entry)
                if (navStream != null && navStream.Seek(info.Position))
                {
                    // Create navigator for the target resource
                    var nav = navStream.Current;
                    if (nav != null)
                    {
                        // Parse target resource from navigator
                        var parser = new BaseFhirParser();
                        var result = parser.Parse <T>(nav);
                        if (result != null)
                        {
                            // Add origin annotation
                            result.SetOrigin(info.Origin);
                            return(result);
                        }
                    }
                }

                return(null);
            }
        }
Ejemplo n.º 2
0
        /// <summary>Returns <c>null</c> if the specified <paramref name="summary"/> equals <c>null</c>.</summary>
        T loadResourceInternal <T>(ArtifactSummary summary) where T : Resource
        {
            if (summary == null)
            {
                return(null);
            }

            // File path of the containing resource file (could be a Bundle)
            var origin = summary.Origin;

            if (string.IsNullOrEmpty(origin))
            {
                throw Error.Argument($"Unable to load resource from summary. The '{nameof(ArtifactSummary.Origin)}' information is unavailable.");
            }

            var pos = summary.Position;

            if (string.IsNullOrEmpty(pos))
            {
                throw Error.Argument($"Unable to load resource from summary. The '{nameof(ArtifactSummary.Position)}' information is unavailable.");
            }

            // Always use the current Xml/Json parser settings
            var settings = _settings;
            var factory  = _navigatorFactory;

            settings.XmlParserSettings.CopyTo(factory.XmlParsingSettings);
            settings.JsonParserSettings.CopyTo(factory.JsonParsingSettings);

            // Also use the current PoCo parser settings
            var pocoSettings = PocoBuilderSettings.CreateDefault();

            settings.ParserSettings?.CopyTo(pocoSettings);

            T result = null;

            using (var navStream = factory.Create(origin))
            {
                // Handle exceptions & null return values?
                // e.g. file may have been deleted/renamed since last scan

                // Advance stream to the target resource (e.g. specific Bundle entry)
                if (navStream != null && navStream.Seek(pos))
                {
                    // Create navigator for the target resource
                    // Current property uses the specified Xml/JsonParsingSettings for parsing
                    var nav = navStream.Current;
                    if (nav != null)
                    {
                        // Parse target resource from navigator
                        result = nav.ToPoco <T>(pocoSettings);

                        // Add origin annotation
                        result?.SetOrigin(origin);
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Load the resource from which the specified summary was generated.
 /// <para>
 /// This implementation annotates returned resource instances with an <seealso cref="OriginAnnotation"/>
 /// that captures the value of the <see cref="ArtifactSummary.Origin"/> property.
 /// The <seealso cref="OriginAnnotationExtensions.GetOrigin(Resource)"/> extension method
 /// provides access to the annotated location.
 /// </para>
 /// </summary>
 /// <param name="summary">An <see cref="ArtifactSummary"/> instance generated by this source.</param>
 /// <returns>A new <see cref="Resource"/> instance, or <c>null</c>.</returns>
 /// <remarks>
 /// The <see cref="ArtifactSummary.Origin"/> and <see cref="ArtifactSummary.Position"/>
 /// summary properties allow the source to identify and resolve the artifact.
 /// </remarks>
 public Resource LoadBySummary(ArtifactSummary summary)
 {
     if (summary == null)
     {
         throw Error.ArgumentNull(nameof(summary));
     }
     return(loadResourceInternal <Resource>(summary));
 }
Ejemplo n.º 4
0
        static IEnumerable <string> GetConceptMapUrls(ArtifactSummary conceptMapSummary)
        {
            var source = conceptMapSummary.GetConceptMapSource();

            if (source != null)
            {
                yield return(source);
            }
            var target = conceptMapSummary.GetConceptMapTarget();

            if (target != null)
            {
                yield return(target);
            }
        }
Ejemplo n.º 5
0
        /// <summary>Returns <c>null</c> if the specified <paramref name="summary"/> equals <c>null</c>.</summary>
        T loadResourceInternal <T>(ArtifactSummary summary) where T : Resource
        {
            if (summary == null)
            {
                return(null);
            }

            // File path of the containing resource file (could be a Bundle)
            var origin = summary.Origin;

            if (string.IsNullOrEmpty(origin))
            {
                throw Error.Argument($"Cannot load resource from summary. The {nameof(ArtifactSummary.Origin)} information is empty or missing.");
            }

            var pos = summary.Position;

            if (string.IsNullOrEmpty(pos))
            {
                throw Error.Argument($"Cannot load resource from summary. The {nameof(ArtifactSummary.Position)} information is empty or missing.");
            }

            T result = null;

            using (var navStream = DefaultNavigatorStreamFactory.Create(origin))
            {
                // Handle exceptions & null return values?
                // e.g. file may have been deleted/renamed since last scan

                // Advance stream to the target resource (e.g. specific Bundle entry)
                if (navStream != null && navStream.Seek(pos))
                {
                    // Create navigator for the target resource
                    var nav = navStream.Current;
                    if (nav != null)
                    {
                        // Parse target resource from navigator
                        var parser = new BaseFhirParser();
                        result = parser.Parse <T>(nav);
                        // Add origin annotation
                        result?.SetOrigin(origin);
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Load the resource from which the specified summary was generated.
 /// <para>
 /// The internal <see cref="DirectorySource"/> instance annotates returned resource instances
 /// with an <seealso cref="OriginAnnotation"/> that captures the value of the
 /// <see cref="ArtifactSummary.Origin"/> property.
 /// The <seealso cref="OriginAnnotationExtensions.GetOrigin(Resource)"/> extension method
 /// provides access to the annotated location.
 /// </para>
 /// </summary>
 /// <param name="summary">An <see cref="ArtifactSummary"/> instance generated by this source.</param>
 /// <returns>A new <see cref="Resource"/> instance, or <c>null</c>.</returns>
 /// <remarks>
 /// The <see cref="ArtifactSummary.Origin"/> and <see cref="ArtifactSummary.Position"/>
 /// summary properties allow the source to identify and resolve the artifact.
 /// </remarks>
 public Resource LoadBySummary(ArtifactSummary summary) => FileSource.LoadBySummary(summary);
 /// <summary>Load the resource from which the specified summary was generated.</summary>
 /// <param name="source">A <see cref="ISummarySource"/> instance.</param>
 /// <param name="summary">An <see cref="ArtifactSummary"/> instance generated by this source.</param>
 /// <typeparam name="T">The resource type to return.</typeparam>
 /// <returns>A new resource instance of type <typeparamref name="T"/>, or <c>null</c>.</returns>
 public static T LoadBySummary <T>(this ISummarySource source, ArtifactSummary summary) where T : Resource
 => source.LoadBySummary(summary) as T;