From 795fe6937f8b7b9d8403a2b6d755881207082fae Mon Sep 17 00:00:00 2001 From: Marco Visser Date: Wed, 6 Jul 2022 11:45:57 +0200 Subject: [PATCH] Remove unused #if NET40 --- common | 2 +- .../Hl7.Fhir.Core.Tests.csproj | 4 - src/Hl7.Fhir.Core.Tests/TestDataHelper.cs | 70 +-------- .../Validation/SearchDataExtraction.cs | 82 +++++----- .../Validation/ValidationTests.cs | 12 -- src/Hl7.Fhir.Core/Rest/FhirClientSearch.cs | 21 +-- .../RoundtripTest.cs | 144 ++++-------------- .../StreamXmlResources.cs | 13 -- .../Summary/ArtifactSummaryExtensions.cs | 111 +------------- .../Summary/ArtifactSummaryPropertyBag.cs | 5 - .../Specification/Source/ZipCacher.cs | 53 +------ .../StructureDefinitionSummaryProvider.cs | 14 -- 12 files changed, 80 insertions(+), 451 deletions(-) diff --git a/common b/common index c138bceb52..54bc885745 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit c138bceb529358577f904fd303d5a02f1f5fcfa9 +Subproject commit 54bc88574586e8640b59153227a31a30ef354e4e diff --git a/src/Hl7.Fhir.Core.Tests/Hl7.Fhir.Core.Tests.csproj b/src/Hl7.Fhir.Core.Tests/Hl7.Fhir.Core.Tests.csproj index ef91c54426..6a257e6787 100644 --- a/src/Hl7.Fhir.Core.Tests/Hl7.Fhir.Core.Tests.csproj +++ b/src/Hl7.Fhir.Core.Tests/Hl7.Fhir.Core.Tests.csproj @@ -19,10 +19,6 @@ - - - - PreserveNewest diff --git a/src/Hl7.Fhir.Core.Tests/TestDataHelper.cs b/src/Hl7.Fhir.Core.Tests/TestDataHelper.cs index f910964dd1..2ec5f553b4 100644 --- a/src/Hl7.Fhir.Core.Tests/TestDataHelper.cs +++ b/src/Hl7.Fhir.Core.Tests/TestDataHelper.cs @@ -1,13 +1,5 @@ -using System; -using System.Collections.Generic; -using System.IO; +using System.IO; using System.IO.Compression; -using System.Reflection; -using System.Text; -#if NET40 -using System.Linq; -using ICSharpCode.SharpZipLib.Zip; -#endif namespace Hl7.Fhir.Tests { @@ -18,7 +10,7 @@ public static string GetFullPathForExample(string filename) //string location = typeof(TestDataHelper).GetTypeInfo().Assembly.Location; //var path = Path.GetDirectoryName(location); //return Path.Combine(path, "TestData", filename); - return Path.Combine("TestData",filename); + return Path.Combine("TestData", filename); } public static string ReadTestData(string filename) @@ -27,68 +19,10 @@ public static string ReadTestData(string filename) return File.ReadAllText(file); } -#if NET40 - public static ZipArchive ReadTestZip(string filename) - { - string file = GetFullPathForExample(filename); - return new ZipArchive(new ZipFile(file)); - } -#else public static ZipArchive ReadTestZip(string filename) { string file = GetFullPathForExample(filename); return ZipFile.OpenRead(file); } -#endif - } - -#if NET40 - internal class ZipArchiveEntry - { - private ZipFile _zip; - private ZipEntry _zipEntry; - - public ZipArchiveEntry(ZipEntry zipEntry, ZipFile zipFile) - { - _zipEntry = zipEntry; - _zip = zipFile; - } - - public string Name - { - get - { - return _zipEntry.Name; - } - } - - public Stream Open() - { - return _zip.GetInputStream(_zipEntry); - } - } - - internal class ZipArchive : IDisposable - { - private ZipFile _zip; - - public ZipArchive(ZipFile zip) - { - _zip = zip; - } - - public IEnumerable Entries - { - get - { - return _zip.Cast().Select(e => new ZipArchiveEntry(e, _zip)); - } - } - - public void Dispose() - { - ((IDisposable)_zip).Dispose(); - } } -#endif } diff --git a/src/Hl7.Fhir.Core.Tests/Validation/SearchDataExtraction.cs b/src/Hl7.Fhir.Core.Tests/Validation/SearchDataExtraction.cs index f6fd55338c..ab467b962d 100644 --- a/src/Hl7.Fhir.Core.Tests/Validation/SearchDataExtraction.cs +++ b/src/Hl7.Fhir.Core.Tests/Validation/SearchDataExtraction.cs @@ -6,24 +6,20 @@ * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE */ +using Hl7.Fhir.ElementModel; +using Hl7.Fhir.FhirPath; +using Hl7.Fhir.Model; +using Hl7.Fhir.Serialization; +using Hl7.Fhir.Utility; +using Hl7.FhirPath; +using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Collections.Generic; -using System.Linq; -using System.IO; -using System.Xml; -using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Diagnostics; -using Hl7.Fhir.Model; -using Hl7.Fhir.Serialization; +using System.IO; using System.IO.Compression; -using Hl7.Fhir.FhirPath; -using Hl7.FhirPath; -using Hl7.Fhir.Utility; -using Hl7.Fhir.ElementModel; -#if NET40 -using ICSharpCode.SharpZipLib.Zip; -#endif -using Hl7.Fhir.Tests; +using System.Linq; +using System.Xml; namespace Hl7.Fhir.Test.Validation { @@ -46,50 +42,44 @@ public void SearchExtractionAllExamples() int testFileCount = 0; Dictionary exampleSearchValues = new Dictionary(); Dictionary failedInvariantCodes = new Dictionary(); -#if NET40 - var zip = new ZipArchive(new ZipFile(examplesZip)); -#else - var zip = ZipFile.OpenRead(examplesZip); -#endif - using (zip) + + using var zip = ZipFile.OpenRead(examplesZip); + foreach (var entry in zip.Entries) { - foreach (var entry in zip.Entries) + Stream file = entry.Open(); + using (file) { - Stream file = entry.Open(); - using (file) - { - // Verified examples that fail validations + // Verified examples that fail validations - //// vsd-3, vsd-8 - //if (file.EndsWith("valueset-ucum-common(ucum-common).xml")) - // continue; + //// vsd-3, vsd-8 + //if (file.EndsWith("valueset-ucum-common(ucum-common).xml")) + // continue; - testFileCount++; + testFileCount++; - try - { - // Debug.WriteLine(String.Format("Validating {0}", file)); - var reader = SerializationUtil.WrapXmlReader(XmlReader.Create(file)); - var resource = parser.Parse(reader); + try + { + // Debug.WriteLine(String.Format("Validating {0}", file)); + var reader = SerializationUtil.WrapXmlReader(XmlReader.Create(file)); + var resource = parser.Parse(reader); - ExtractValuesForSearchParameterFromFile(exampleSearchValues, resource); + ExtractValuesForSearchParameterFromFile(exampleSearchValues, resource); - if (resource is Bundle) + if (resource is Bundle) + { + foreach (var item in (resource as Bundle).Entry) { - foreach (var item in (resource as Bundle).Entry) + if (item.Resource != null) { - if (item.Resource != null) - { - ExtractValuesForSearchParameterFromFile(exampleSearchValues, item.Resource); - } + ExtractValuesForSearchParameterFromFile(exampleSearchValues, item.Resource); } } } - catch (Exception ex) - { - System.Diagnostics.Trace.WriteLine("Error processing file " + entry.Name + ": " + ex.Message); - parserErrorCount++; - } + } + catch (Exception ex) + { + System.Diagnostics.Trace.WriteLine("Error processing file " + entry.Name + ": " + ex.Message); + parserErrorCount++; } } } diff --git a/src/Hl7.Fhir.Core.Tests/Validation/ValidationTests.cs b/src/Hl7.Fhir.Core.Tests/Validation/ValidationTests.cs index 4280accc4a..7df43df3ca 100644 --- a/src/Hl7.Fhir.Core.Tests/Validation/ValidationTests.cs +++ b/src/Hl7.Fhir.Core.Tests/Validation/ValidationTests.cs @@ -86,31 +86,19 @@ public void OIDandUUIDUrls() var oidWithZero = "urn:oid:1.2.0.3.4"; FhirUri uri = new(oidUrl); -#if NET40 - Validator.ValidateObject(uri, new ValidationContext(uri, null, null), true); -#else Validator.ValidateObject(uri, new ValidationContext(uri), true); -#endif uri = new FhirUri(illOidUrl); validateErrorOrFail(uri); uri = new FhirUri(uuidUrl); -#if NET40 - Validator.ValidateObject(uri, new ValidationContext(uri, null, null), true); -#else Validator.ValidateObject(uri, new ValidationContext(uri), true); -#endif uri = new FhirUri(illUuidUrl); validateErrorOrFail(uri); uri = new FhirUri(oidWithZero); -#if NET40 - Validator.ValidateObject(uri, new ValidationContext(uri, null, null), true); -#else Validator.ValidateObject(uri, new ValidationContext(uri), true); -#endif Assert.IsTrue(Uri.Equals(new Uri("http://nu.nl"), new Uri("http://nu.nl"))); } diff --git a/src/Hl7.Fhir.Core/Rest/FhirClientSearch.cs b/src/Hl7.Fhir.Core/Rest/FhirClientSearch.cs index 0b16151056..eb85a479ee 100644 --- a/src/Hl7.Fhir.Core/Rest/FhirClientSearch.cs +++ b/src/Hl7.Fhir.Core/Rest/FhirClientSearch.cs @@ -9,7 +9,6 @@ using Hl7.Fhir.Model; using Hl7.Fhir.Utility; using System; -using System.Collections.Generic; using System.Linq; using System.Net; using System.Threading.Tasks; @@ -18,8 +17,8 @@ namespace Hl7.Fhir.Rest { public abstract partial class BaseFhirClient { - #pragma warning disable CS1584 // XML comment has syntactically incorrect cref attribute - #pragma warning disable CS1658 // Warning is overriding an error +#pragma warning disable CS1584 // XML comment has syntactically incorrect cref attribute +#pragma warning disable CS1658 // Warning is overriding an error #region Search Execution @@ -509,7 +508,7 @@ public Task SearchByIdUsingPostAsync(string id, (string path, return SearchByIdUsingPostAsync(ModelInfo.GetFhirTypeNameForType(typeof(TResource)), id, includes, pageSize, revIncludes); } - + public Task SearchByIdUsingPostAsync(string id, string[] includes = null, int? pageSize = null, string[] revIncludes = null) where TResource : Resource, new() { @@ -688,16 +687,10 @@ public Task ContinueAsync(Bundle current, PageDirection direction = Page { // Return a null bundle, can not return simply null because this is a task Bundle nullValue = null; -#if NET40 - TaskCompletionSource completionSource = new TaskCompletionSource(); - completionSource.SetResult(nullValue); - - return completionSource.Task; -#else return System.Threading.Tasks.Task.FromResult(nullValue); -#endif } } + /// /// Uses the FHIR paging mechanism to go navigate around a series of paged result Bundles /// @@ -748,13 +741,13 @@ private SearchParams toQuery(string[] criteria, (string path, IncludeModifier mo private (string path, IncludeModifier modifier)[] stringToIncludeTuple(string[] includes) { - if(includes != null && includes.Any()) + if (includes != null && includes.Any()) return includes.Select(i => (i, IncludeModifier.None)).ToArray(); else return new (string path, IncludeModifier modifier)[] { }; } } - #endregion + #endregion public enum PageDirection { First, @@ -762,5 +755,5 @@ public enum PageDirection Next, Last } - + } diff --git a/src/Hl7.Fhir.Serialization.Tests/RoundtripTest.cs b/src/Hl7.Fhir.Serialization.Tests/RoundtripTest.cs index c964b504e6..cfa4929cb9 100644 --- a/src/Hl7.Fhir.Serialization.Tests/RoundtripTest.cs +++ b/src/Hl7.Fhir.Serialization.Tests/RoundtripTest.cs @@ -6,42 +6,38 @@ * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE */ -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Diagnostics; using Hl7.Fhir.Model; -using System.IO.Compression; using Hl7.Fhir.Specification; using Hl7.Fhir.Specification.Source; -using System.Collections.Generic; -using System; using Hl7.Fhir.Tests; -using Tasks = System.Threading.Tasks; -using System.Linq; -#if NET40 -using ICSharpCode.SharpZipLib.Zip; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.IO.Compression; using System.Linq; -#endif +using Tasks = System.Threading.Tasks; namespace Hl7.Fhir.Serialization.Tests { [TestClass] public class RoundtripTest - { + { [TestMethod] [TestCategory("LongRunner")] public void FullRoundtripOfAllExamplesXmlPoco() { - FullRoundtripOfAllExamples("examples.zip", "FHIRRoundTripTestXml", - "Roundtripping xml->json->xml", usingPoco: true, provider:null); + FullRoundtripOfAllExamples("examples.zip", "FHIRRoundTripTestXml", + "Roundtripping xml->json->xml", usingPoco: true, provider: null); } - + [TestMethod] [TestCategory("LongRunner")] public async Tasks.Task FullRoundtripOfAllExamplesXmlPocoAsync() { - await FullRoundtripOfAllExamplesAsync("examples.zip", "FHIRRoundTripTestXml", - "Roundtripping xml->json->xml", usingPoco: true, provider:null); + await FullRoundtripOfAllExamplesAsync("examples.zip", "FHIRRoundTripTestXml", + "Roundtripping xml->json->xml", usingPoco: true, provider: null); } [TestMethod] @@ -51,7 +47,7 @@ public void FullRoundtripOfAllExamplesJsonPoco() FullRoundtripOfAllExamples("examples-json.zip", "FHIRRoundTripTestJson", "Roundtripping json->xml->json", usingPoco: true, provider: null); } - + [TestMethod] [TestCategory("LongRunner")] public async Tasks.Task FullRoundtripOfAllExamplesJsonPocoAsync() @@ -67,7 +63,7 @@ public void FullRoundtripOfAllExamplesXmlNavPocoProvider() FullRoundtripOfAllExamples("examples.zip", "FHIRRoundTripTestXml", "Roundtripping xml->json->xml", usingPoco: false, provider: new PocoStructureDefinitionSummaryProvider()); } - + [TestMethod] [TestCategory("LongRunner")] public async Tasks.Task FullRoundtripOfAllExamplesXmlNavPocoProviderAsync() @@ -83,7 +79,7 @@ public void FullRoundtripOfAllExamplesJsonNavPocoProvider() FullRoundtripOfAllExamples("examples-json.zip", "FHIRRoundTripTestJson", "Roundtripping json->xml->json", usingPoco: false, provider: new PocoStructureDefinitionSummaryProvider()); } - + [TestMethod] [TestCategory("LongRunner")] public async Tasks.Task FullRoundtripOfAllExamplesJsonNavPocoProviderAsync() @@ -100,7 +96,7 @@ public void FullRoundtripOfAllExamplesXmlNavSdProvider() FullRoundtripOfAllExamples("examples.zip", "FHIRRoundTripTestXml", "Roundtripping xml->json->xml", usingPoco: false, provider: new StructureDefinitionSummaryProvider(source)); } - + [TestMethod] [TestCategory("LongRunner")] public async Tasks.Task FullRoundtripOfAllExamplesXmlNavSdProviderAsync() @@ -118,7 +114,7 @@ public void FullRoundtripOfAllExamplesJsonNavSdProvider() FullRoundtripOfAllExamples("examples-json.zip", "FHIRRoundTripTestJson", "Roundtripping json->xml->json", usingPoco: false, provider: new StructureDefinitionSummaryProvider(source)); } - + [TestMethod] [TestCategory("LongRunner")] public async Tasks.Task FullRoundtripOfAllExamplesJsonNavSdProviderAsync() @@ -130,97 +126,11 @@ await FullRoundtripOfAllExamplesAsync("examples-json.zip", "FHIRRoundTripTestJso private static string GetFullPathForExample(string filename) => Path.Combine("TestData", filename); -#if NET40 - public static ZipArchive ReadTestZip(string filename) - { - string file = GetFullPathForExample(filename); - return new ZipArchive(new ZipFile(file)); - } - - public class ZipArchiveEntry - { - private ZipFile _zip; - private ZipEntry _zipEntry; - - public ZipArchiveEntry(ZipEntry zipEntry, ZipFile zipFile) - { - _zipEntry = zipEntry; - _zip = zipFile; - } - - public string Name - { - get - { - return _zipEntry.Name; - } - } - - public Stream Open() - { - return _zip.GetInputStream(_zipEntry); - } - } - - public class ZipArchive : IDisposable - { - private ZipFile _zip; - - public ZipArchive(ZipFile zip) - { - _zip = zip; - } - - public IEnumerable Entries - { - get - { - return _zip.Cast().Select(e => new ZipArchiveEntry(e, _zip)); - } - } - - public void Dispose() - { - ((IDisposable)_zip).Dispose(); - } - - public void ExtractToDirectory(string directory) - { - byte[] buffer = new byte[4096]; - - foreach (ZipEntry entry in _zip) - { - using (Stream entryStream = _zip.GetInputStream(entry)) - { - string fullPath = Path.Combine(directory, entry.Name.Replace('/', Path.DirectorySeparatorChar).Replace('\\', Path.DirectorySeparatorChar)); - FileInfo entryFileInfo = new FileInfo(fullPath); - - if (!Directory.Exists(entryFileInfo.DirectoryName)) - { - Directory.CreateDirectory(entryFileInfo.DirectoryName); - } - - using (FileStream entryOutputStream = File.Create(fullPath)) - { - int bytesRead = entryStream.Read(buffer, 0, 4096); - - while (bytesRead > 0) - { - entryOutputStream.Write(buffer, 0, bytesRead); - bytesRead = entryStream.Read(buffer, 0, 4096); - } - } - } - } - } - } -#else public static ZipArchive ReadTestZip(string filename) { string file = GetFullPathForExample(filename); return ZipFile.OpenRead(file); } -#endif public static void FullRoundtripOfAllExamples(string zipname, string dirname, string label, bool usingPoco, IStructureDefinitionSummaryProvider provider) { @@ -234,7 +144,7 @@ public static void FullRoundtripOfAllExamples(string zipname, string dirname, st createEmptyDir(baseTestPath); doRoundTrip(examples, baseTestPath, usingPoco, provider); } - + public static async Tasks.Task FullRoundtripOfAllExamplesAsync(string zipname, string dirname, string label, bool usingPoco, IStructureDefinitionSummaryProvider provider) { ZipArchive examples = ReadTestZip(zipname); @@ -274,7 +184,7 @@ private static void createEmptyDir(string baseTestPath) if (Directory.Exists(baseTestPath)) Directory.Delete(baseTestPath, true); Directory.CreateDirectory(baseTestPath); } - + private static void doRoundTrip(ZipArchive examplesZip, string baseTestPath, bool usingPoco, IStructureDefinitionSummaryProvider provider) { var examplePath = Path.Combine(baseTestPath, "input"); @@ -409,7 +319,7 @@ private static int convertFiles(string inputPath, string outputPath, bool usingP else convertResourceNav(file, outputFile, provider); } - catch(Exception ex) + catch (Exception ex) { errors.Add($"{exampleName}{ext}: " + ex.Message); } @@ -447,7 +357,7 @@ private static async Tasks.Task convertFilesAsync(string inputPath, string else await convertResourceNavAsync(file, outputFile, provider); } - catch(Exception ex) + catch (Exception ex) { errors.Add($"{exampleName}{ext}: " + ex.Message); } @@ -549,7 +459,7 @@ private static async Tasks.Task convertResourcePocoAsync(string inputFile, strin await File.WriteAllTextAsync(outputFile, xml); } } - + private static void convertResourceNav(string inputFile, string outputFile, IStructureDefinitionSummaryProvider provider) { if (inputFile.EndsWith(".xml")) @@ -562,8 +472,8 @@ private static void convertResourceNav(string inputFile, string outputFile, IStr else { var json = File.ReadAllText(inputFile); - var nav = JsonParsingHelpers.ParseToTypedElement(json, provider, - settings: new FhirJsonParsingSettings { AllowJsonComments = true, PermissiveParsing = true } ); + var nav = JsonParsingHelpers.ParseToTypedElement(json, provider, + settings: new FhirJsonParsingSettings { AllowJsonComments = true, PermissiveParsing = true }); var xml = nav.ToXml(); File.WriteAllText(outputFile, xml); } @@ -581,8 +491,8 @@ private static async Tasks.Task convertResourceNavAsync(string inputFile, string else { var json = await File.ReadAllTextAsync(inputFile); - var nav = await JsonParsingHelpers.ParseToTypedElementAsync(json, provider, - settings: new FhirJsonParsingSettings { AllowJsonComments = true, PermissiveParsing = true } ); + var nav = await JsonParsingHelpers.ParseToTypedElementAsync(json, provider, + settings: new FhirJsonParsingSettings { AllowJsonComments = true, PermissiveParsing = true }); var xml = await nav.ToXmlAsync(); await File.WriteAllTextAsync(outputFile, xml); } diff --git a/src/Hl7.Fhir.Serialization.Tests/StreamXmlResources.cs b/src/Hl7.Fhir.Serialization.Tests/StreamXmlResources.cs index 5bc9ba5bcb..8601d4b9bc 100644 --- a/src/Hl7.Fhir.Serialization.Tests/StreamXmlResources.cs +++ b/src/Hl7.Fhir.Serialization.Tests/StreamXmlResources.cs @@ -7,9 +7,6 @@ using System.IO; using System.IO.Compression; using System.Linq; -#if NET40 -using ICSharpCode.SharpZipLib.Zip; -#endif namespace Hl7.Fhir.Support.Tests.Serialization { @@ -123,15 +120,6 @@ public void NavigateZipStream() // ZipDeflateStream does not support seeking (forward-only stream) // Therefore this only works for the XmlNavigatorStream, as the ctor does NOT (need to) call Reset() // JsonNavigatorStream cannot support zip streams; ctor needs to call Reset after scanning resourceType -#if NET40 - using (var archive = new ZipFile(ZipSource.SpecificationZipFileName)) - { - var entry = archive.Cast().FirstOrDefault(e => e.Name == "profiles-resources.xml"); - Assert.IsNotNull(entry); - - using (var entryStream = archive.GetInputStream(entry)) - { -#else using var archive = ZipFile.Open(ZipSource.SpecificationZipFileName, ZipArchiveMode.Read); var entry = archive.Entries.FirstOrDefault(e => e.Name == "profiles-resources.xml"); Assert.IsNotNull(entry); @@ -144,7 +132,6 @@ public void NavigateZipStream() Assert.IsTrue(navStream.IsBundle); Assert.AreEqual(ResourceType.Bundle.GetLiteral(), navStream.ResourceType); }; -#endif } } } diff --git a/src/Hl7.Fhir.Specification/Specification/Source/Summary/ArtifactSummaryExtensions.cs b/src/Hl7.Fhir.Specification/Specification/Source/Summary/ArtifactSummaryExtensions.cs index c3f9834279..7daf7f4cc0 100644 --- a/src/Hl7.Fhir.Specification/Specification/Source/Summary/ArtifactSummaryExtensions.cs +++ b/src/Hl7.Fhir.Specification/Specification/Source/Summary/ArtifactSummaryExtensions.cs @@ -10,9 +10,7 @@ using Hl7.Fhir.Support; using Hl7.Fhir.Utility; using System; -using System.Collections; using System.Collections.Generic; -using System.IO; using System.Linq; namespace Hl7.Fhir.Specification.Source @@ -58,7 +56,7 @@ public static IEnumerable FindConformanceResources(this IEnumer var version = values.Length == 2 ? values[1] : string.Empty; - return summaries.ConformanceResources().Where(r => r.GetConformanceCanonicalUrl() == values[0] && + return summaries.ConformanceResources().Where(r => r.GetConformanceCanonicalUrl() == values[0] && (string.IsNullOrEmpty(version) || r.GetConformanceVersion() == version)); } @@ -104,10 +102,10 @@ public static ArtifactSummary ResolveByCanonicalUri(this IEnumerable summaries, string uniqueId) => summaries.FindNamingSystems(uniqueId).SingleOrDefault(NamingSystemUrlConflictExceptionFactory); -/// Resolve the for the resource with the specified ValueSet uri. + /// Resolve the for the resource with the specified ValueSet uri. public static ArtifactSummary ResolveCodeSystem(this IEnumerable summaries, string uri) => summaries.FindCodeSystems(uri).SingleOrDefault(CodeSystemConflictExceptionFactory); - + /// Resolve the for the resource with the specified source and/or target uri(s). public static ArtifactSummary ResolveConceptMap(this IEnumerable summaries, string sourceUri = null, string targetUri = null) => summaries.FindConceptMaps(sourceUri, targetUri).SingleOrDefault(ConceptMapUrlConflictExceptionFactory); @@ -252,107 +250,4 @@ static TSource SingleOrDefault(this IEnumerable source, Func : IReadOnlyCollection>, IEnumerable>, IEnumerable - { - // - // Summary: - // Gets the element that has the specified key in the read-only dictionary. - // - // Parameters: - // key: - // The key to locate. - // - // Returns: - // The element that has the specified key in the read-only dictionary. - // - // Exceptions: - // T:System.ArgumentNullException: - // key is null. - // - // T:System.Collections.Generic.KeyNotFoundException: - // The property is retrieved and key is not found. - TValue this[TKey key] { get; } - - // - // Summary: - // Gets an enumerable collection that contains the keys in the read-only dictionary. - // - // Returns: - // An enumerable collection that contains the keys in the read-only dictionary. - IEnumerable Keys { get; } - // - // Summary: - // Gets an enumerable collection that contains the values in the read-only dictionary. - // - // Returns: - // An enumerable collection that contains the values in the read-only dictionary. - IEnumerable Values { get; } - - // - // Summary: - // Determines whether the read-only dictionary contains an element that has the - // specified key. - // - // Parameters: - // key: - // The key to locate. - // - // Returns: - // true if the read-only dictionary contains an element that has the specified key; - // otherwise, false. - // - // Exceptions: - // T:System.ArgumentNullException: - // key is null. - bool ContainsKey(TKey key); - // - // Summary: - // Gets the value that is associated with the specified key. - // - // Parameters: - // key: - // The key to locate. - // - // value: - // When this method returns, the value associated with the specified key, if the - // key is found; otherwise, the default value for the type of the value parameter. - // This parameter is passed uninitialized. - // - // Returns: - // true if the object that implements the System.Collections.Generic.IReadOnlyDictionary`2 - // interface contains an element that has the specified key; otherwise, false. - // - // Exceptions: - // T:System.ArgumentNullException: - // key is null. - bool TryGetValue(TKey key, out TValue value); - } - - // - // Summary: - // Represents a read-only collection of elements that can be accessed by index. - // - // Type parameters: - // T: - // The type of elements in the read-only list. This type parameter is covariant. - // That is, you can use either the type you specified or any type that is more derived. - // For more information about covariance and contravariance, see Covariance and - // Contravariance in Generics. - public interface IReadOnlyList : IReadOnlyCollection, IEnumerable, IEnumerable - { - // - // Summary: - // Gets the element at the specified index in the read-only list. - // - // Parameters: - // index: - // The zero-based index of the element to get. - // - // Returns: - // The element at the specified index in the read-only list. - T this[int index] { get; } - } -#endif } \ No newline at end of file diff --git a/src/Hl7.Fhir.Specification/Specification/Source/Summary/ArtifactSummaryPropertyBag.cs b/src/Hl7.Fhir.Specification/Specification/Source/Summary/ArtifactSummaryPropertyBag.cs index 9ebae7c4c2..7ac322ded6 100644 --- a/src/Hl7.Fhir.Specification/Specification/Source/Summary/ArtifactSummaryPropertyBag.cs +++ b/src/Hl7.Fhir.Specification/Specification/Source/Summary/ArtifactSummaryPropertyBag.cs @@ -38,11 +38,6 @@ public class ArtifactSummaryPropertyBag : Dictionary, IArtifactS /// Returns an empty instance. public static ArtifactSummaryPropertyBag Empty => new ArtifactSummaryPropertyBag(); -#if NET40 - IEnumerable IReadOnlyDictionary.Keys => this.Keys; - - IEnumerable IReadOnlyDictionary.Values => this.Values; -#endif /// Default initial capacity. public const int DefaultCapacity = 8; diff --git a/src/Hl7.Fhir.Specification/Specification/Source/ZipCacher.cs b/src/Hl7.Fhir.Specification/Specification/Source/ZipCacher.cs index 23da506dff..51b700c146 100644 --- a/src/Hl7.Fhir.Specification/Specification/Source/ZipCacher.cs +++ b/src/Hl7.Fhir.Specification/Specification/Source/ZipCacher.cs @@ -9,12 +9,8 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; -#if NET40 -using ICSharpCode.SharpZipLib.Zip; -#else using System.IO.Compression; -#endif +using System.Linq; namespace Hl7.Fhir.Specification.Source { @@ -32,9 +28,9 @@ internal class ZipCacher private string _cachePath; private string _zipPath; - public ZipCacher(string zipPath, string cacheKey=null) + public ZipCacher(string zipPath, string cacheKey = null) { - if(cacheKey == null) cacheKey = Guid.NewGuid().ToString(); + if (cacheKey == null) cacheKey = Guid.NewGuid().ToString(); _cachePath = Path.Combine(Path.GetTempPath(), cacheKey); _zipPath = zipPath; } @@ -82,18 +78,12 @@ public void Refresh() dir.Create(); -#if NET40 - ExtractToDirectory(_zipPath, dir.FullName); - if (File.Exists(Path.Combine(dir.FullName, "fhir-all-xsd.zip"))) - ExtractToDirectory(Path.Combine(dir.FullName, "fhir-all-xsd.zip"), dir.FullName); -#else ZipFile.ExtractToDirectory(_zipPath, dir.FullName); // and also extract the contained zip in there too with all the xsds in there if (File.Exists(Path.Combine(dir.FullName, "fhir-all-xsd.zip"))) ZipFile.ExtractToDirectory(Path.Combine(dir.FullName, "fhir-all-xsd.zip"), dir.FullName); -#endif // Set the last write time to be equal to the write time of the zip file, // this way, we can compare this time to the write times of newer zips and @@ -128,43 +118,8 @@ private DirectoryInfo getCachedZipDirectory() var zipCachePath = Path.Combine(cache.FullName, cacheName); var zipCacheDir = new DirectoryInfo(zipCachePath); - - return zipCacheDir; - } -#if NET40 - private void ExtractToDirectory(string zipFilePath, string directory) - { - byte[] buffer = new byte[4096]; - - using (ZipFile zipFile = new ZipFile(zipFilePath)) - { - foreach (ZipEntry entry in zipFile) - { - using (Stream entryStream = zipFile.GetInputStream(entry)) - { - string fullPath = Path.Combine(directory, entry.Name.Replace('/', Path.DirectorySeparatorChar).Replace('\\', Path.DirectorySeparatorChar)); - FileInfo entryFileInfo = new FileInfo(fullPath); - - if (!Directory.Exists(entryFileInfo.DirectoryName)) - { - Directory.CreateDirectory(entryFileInfo.DirectoryName); - } - - using (FileStream entryOutputStream = File.Create(fullPath)) - { - int bytesRead = entryStream.Read(buffer, 0, 4096); - - while (bytesRead > 0) - { - entryOutputStream.Write(buffer, 0, bytesRead); - bytesRead = entryStream.Read(buffer, 0, 4096); - } - } - } - } - } + return zipCacheDir; } -#endif } } diff --git a/src/Hl7.Fhir.Specification/Specification/StructureDefinitionSummaryProvider.cs b/src/Hl7.Fhir.Specification/Specification/StructureDefinitionSummaryProvider.cs index ed837b9430..bb6cc5d038 100644 --- a/src/Hl7.Fhir.Specification/Specification/StructureDefinitionSummaryProvider.cs +++ b/src/Hl7.Fhir.Specification/Specification/StructureDefinitionSummaryProvider.cs @@ -79,11 +79,7 @@ public BackboneElementComplexTypeSerializationInfo(ElementDefinitionNavigator na public bool IsResource => false; public IReadOnlyCollection GetElements() => -#if NET40 - StructureDefinitionComplexTypeSerializationInfo.getElements(_nav).ToReadOnlyCollection(); -#else StructureDefinitionComplexTypeSerializationInfo.getElements(_nav).ToList(); -#endif } internal struct StructureDefinitionComplexTypeSerializationInfo : IStructureDefinitionSummary @@ -101,15 +97,6 @@ public StructureDefinitionComplexTypeSerializationInfo(ElementDefinitionNavigato public bool IsResource => _nav.StructureDefinition.Kind == StructureDefinition.StructureDefinitionKind.Resource; -#if NET40 - public IReadOnlyCollection GetElements() - { - if (_nav.Current == null && !_nav.MoveToFirstChild()) - return new ReadOnlyList(); - - return getElements(_nav).ToReadOnlyCollection(); - } -#else public IReadOnlyCollection GetElements() { if (_nav.Current == null && !_nav.MoveToFirstChild()) @@ -117,7 +104,6 @@ public IReadOnlyCollection GetElements() return getElements(_nav).ToList(); } -#endif private static bool isPrimitiveValueConstraint(ElementDefinition ed) => ed.Path.EndsWith(".value") && ed.Type.All(t => t.Code == null);