diff --git a/src/Hl7.Fhir.STU3/Specification/Source/SnapshotSource.cs b/src/Hl7.Fhir.STU3/Specification/Source/SnapshotSource.cs deleted file mode 100644 index 8700f8db37..0000000000 --- a/src/Hl7.Fhir.STU3/Specification/Source/SnapshotSource.cs +++ /dev/null @@ -1,106 +0,0 @@ -using Hl7.Fhir.Model; -using Hl7.Fhir.Specification.Snapshot; -using Hl7.Fhir.Utility; -using System; -using System.Diagnostics; -using T=System.Threading.Tasks; - -namespace Hl7.Fhir.Specification.Source -{ - // Design: - // - SnapshotSource depends on SnapshotGenerator; NOT the other way around (!) - // - Ownership/composition: SnapshotSource => SnapshotGenerator => InternalSource - // - SnapshotGenerator rejects SnapshotSource as input argument (throw), to prevent recursion - // - SnapshotGenerator still supports stand-alone usage (w/o SnapshotSource), i.e. backwards-compatible - // - SnapshotGenerator class remains responsible for: - // - detecting and handling recursion - // - caching expanded root elements - // - annotating snapshots - - /// - /// Resolves resources from an internal instance. - /// Ensures that resolved resources have a snapshot component (re-generate on demand). - /// - [DebuggerDisplay(@"\{{DebuggerDisplay,nq}}")] - public class SnapshotSource : IResourceResolver, IAsyncResourceResolver - { - /// Creates a new instance of the for the specified snapshot generator instance. - /// A instance. - public SnapshotSource(SnapshotGenerator generator) - { - Generator = generator ?? throw Error.ArgumentNull(nameof(generator)); - } - - /// Creates a new instance of the for the specified internal resolver. - /// An internal instance. The implementation should be idempotent (i.e. cached), so the generated snapshots are persisted in memory. - /// Configuration settings for the snapshot generator. - public SnapshotSource(IResourceResolver source, SnapshotGeneratorSettings settings) - { - // SnapshotGenerator ctor will throw if source or settings are null - Generator = new SnapshotGenerator(source, settings); - } - - /// Creates a new instance of the for the specified internal resolver. - /// An internal instance. The implementation should be idempotent (i.e. cached), so the generated snapshots are persisted in memory. - /// Determines if the source should always discard any existing snapshot components provided by the internal source and force re-generation. - public SnapshotSource(IResourceResolver source, bool regenerate) - : this(source, createSettings(regenerate)) { } - - // Create default SnapshotGeneratorSettings, apply the specified regenerate flag - static SnapshotGeneratorSettings createSettings(bool regenerate) - { - var settings = SnapshotGeneratorSettings.CreateDefault(); - settings.ForceRegenerateSnapshots = regenerate; - return settings; - } - - /// Creates a new instance of the for the specified internal resolver. - /// An internal instance. The implementation should be idempotent (i.e. cached), so the generated snapshots are persisted in memory. - public SnapshotSource(IResourceResolver source) - : this(source, SnapshotGeneratorSettings.CreateDefault()) { } - - /// Returns the internal instance used by the source. - public SnapshotGenerator Generator { get; } - - #region IResourceResolver - - private IAsyncResourceResolver _resolver => Generator.AsyncResolver; - - /// Find a resource based on its relative or absolute uri. - /// The source ensures that resolved instances have a snapshot component. - public async T.Task ResolveByUriAsync(string uri) => await ensureSnapshot(await _resolver.ResolveByUriAsync(uri).ConfigureAwait(false)).ConfigureAwait(false); - - /// - [Obsolete("SnapshotSource now works best with asynchronous resolvers. Use ResolveByUriAsync() instead.")] - public Resource ResolveByUri(string uri) => TaskHelper.Await(() => ResolveByUriAsync(uri)); - - /// Find a (conformance) resource based on its canonical uri. - /// The source ensures that resolved instances have a snapshot component. - public async T.Task ResolveByCanonicalUriAsync(string uri) => await ensureSnapshot(await _resolver.ResolveByCanonicalUriAsync(uri).ConfigureAwait(false)).ConfigureAwait(false); - - /// - [Obsolete("SnapshotSource now works best with asynchronous resolvers. Use ResolveByCanonicalUriAsync() instead.")] - public Resource ResolveByCanonicalUri(string uri) => TaskHelper.Await(() => ResolveByCanonicalUriAsync(uri)); - - #endregion - - // If the specified resource is a StructureDefinition, - // then ensure snapshot component is available, (re-)generate on demand - private async T.Task ensureSnapshot(Resource res) - { - if (res is StructureDefinition sd) - { - if (!sd.HasSnapshot || Generator.Settings.ForceRegenerateSnapshots || !sd.Snapshot.IsCreatedBySnapshotGenerator()) - { - await Generator.UpdateAsync(sd).ConfigureAwait(false); - } - } - return res; - } - - // Allow derived classes to override - // http://blogs.msdn.com/b/jaredpar/archive/2011/03/18/debuggerdisplay-attribute-best-practices.aspx - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - internal protected virtual string DebuggerDisplay => $"{GetType().Name} for {_resolver.DebuggerDisplayString()}"; - } -} diff --git a/src/Hl7.Fhir.Shims.Base/Hl7.Fhir.Shims.Base.projitems b/src/Hl7.Fhir.Shims.Base/Hl7.Fhir.Shims.Base.projitems index 3f434107e1..33224d0137 100644 --- a/src/Hl7.Fhir.Shims.Base/Hl7.Fhir.Shims.Base.projitems +++ b/src/Hl7.Fhir.Shims.Base/Hl7.Fhir.Shims.Base.projitems @@ -9,6 +9,7 @@ Hl7.Fhir.Shims.Base + diff --git a/src/Hl7.Fhir.Shims.Base/Hl7.Fhir.Shims.Conformance.shproj b/src/Hl7.Fhir.Shims.Base/Hl7.Fhir.Shims.Base.shproj similarity index 100% rename from src/Hl7.Fhir.Shims.Base/Hl7.Fhir.Shims.Conformance.shproj rename to src/Hl7.Fhir.Shims.Base/Hl7.Fhir.Shims.Base.shproj diff --git a/src/Hl7.Fhir.Conformance/Specification/Source/SnapshotSource.cs b/src/Hl7.Fhir.Shims.Base/Specification/Source/SnapshotSource.cs similarity index 100% rename from src/Hl7.Fhir.Conformance/Specification/Source/SnapshotSource.cs rename to src/Hl7.Fhir.Shims.Base/Specification/Source/SnapshotSource.cs