Пример #1
0
        /// <summary>Searches for the first or download.</summary>
        /// <exception cref="DirectoryNotFoundException">Thrown when the requested directory is not
        ///  present.</exception>
        /// <exception cref="Exception">                 Thrown when an exception error condition occurs.</exception>
        /// <param name="releaseName">The release name (e.g., R4, DSTU2).</param>
        /// <param name="packageName">Name of the package.</param>
        /// <param name="version">    The version string (e.g., 4.0.1).</param>
        /// <param name="offlineMode">True to allow, false to suppress the download.</param>
        /// <param name="isOptional"> (Optional) True if is optional, false if not.</param>
        private void FindOrDownload(
            string releaseName,
            string packageName,
            string version,
            bool offlineMode,
            bool isOptional = false)
        {
            if (string.IsNullOrEmpty(packageName))
            {
                if (isOptional)
                {
                    return;
                }

                throw new ArgumentNullException(nameof(packageName));
            }

            if (!Loader.TryFindPackage(
                    releaseName,
                    packageName,
                    version,
                    _fhirSpecDirectory,
                    out _))
            {
                if (offlineMode)
                {
                    if (isOptional)
                    {
                        Console.WriteLine(
                            $"Failed to find OPTIONAL {packageName}-{version}" +
                            $" in {_fhirSpecDirectory}");
                        return;
                    }

                    throw new DirectoryNotFoundException(
                              $"Failed to find FHIR {packageName}" +
                              $" ({releaseName})" +
                              $" in {_fhirSpecDirectory}");
                }

                Console.WriteLine($" <<< downloading {packageName}-{version}...");

                if (!FhirPackageDownloader.Download(
                        releaseName,
                        packageName,
                        version,
                        _fhirSpecDirectory))
                {
                    if (isOptional)
                    {
                        Console.WriteLine(
                            $"Failed to download OPTIONAL {packageName}-{version}");
                        return;
                    }

                    throw new Exception($"Could not download: {packageName}-{version}");
                }
            }
        }
Пример #2
0
        /// <summary>Downloads either a Package or Published version of the requested type.</summary>
        /// <param name="releaseName">      The release name (e.g., R4, DSTU2).</param>
        /// <param name="packageName">      Name of the package.</param>
        /// <param name="version">          The version string (e.g., 4.0.1).</param>
        /// <param name="fhirSpecDirectory">Pathname of the FHIR spec directory.</param>
        /// <returns>True if it succeeds, false if it fails.</returns>
        public static bool Download(
            string releaseName,
            string packageName,
            string version,
            string fhirSpecDirectory)
        {
            bool loaded = false;

            try
            {
                Console.WriteLine($" <<< downloading PACKAGE {packageName}:{version}");

                // download from the package manager
                loaded = FhirPackageDownloader.DownloadPackage(
                    releaseName,
                    packageName,
                    version,
                    fhirSpecDirectory);

                if (loaded)
                {
                    return(true);
                }
            }
            catch (HttpRequestException)
            {
                Console.WriteLine($"Failed to download Package: {packageName}:{version}");
            }
            catch (AggregateException)
            {
                Console.WriteLine($"Failed to download Published: {packageName}:{version}");
            }
            catch (System.Threading.Tasks.TaskCanceledException)
            {
                Console.WriteLine($"Failed to download Published: {packageName}:{version}");
            }

            try
            {
                Console.WriteLine($" <<< downloading PUBLISHED {packageName}:{version}");

                // download from publish URL
                loaded = FhirPackageDownloader.DownloadPublished(
                    releaseName,
                    packageName,
                    version,
                    fhirSpecDirectory);
            }
            catch (HttpRequestException)
            {
                Console.WriteLine($"Failed to download Published: {packageName}:{version}");
            }
            catch (AggregateException)
            {
                Console.WriteLine($"Failed to download Published: {packageName}:{version}");
            }
            catch (System.Threading.Tasks.TaskCanceledException)
            {
                Console.WriteLine($"Failed to download Published: {packageName}:{version}");
            }

            return(loaded);
        }
Пример #3
0
        /// <summary>Loads a package.</summary>
        /// <exception cref="ArgumentNullException">Thrown when one or more required arguments are null.</exception>
        /// <param name="localPublishDirectory"> Local FHIR Publish directory.</param>
        /// <param name="fhirSpecDirectory">     Pathname of the FHIR spec directory.</param>
        /// <param name="fhirVersionInfo">       [in,out] Information describing the FHIR version.</param>
        /// <param name="localLoadType">         Type of the local load.</param>
        /// <param name="officialExpansionsOnly">True to official expansions only.</param>
        public static void LoadLocalBuild(
            string localPublishDirectory,
            string fhirSpecDirectory,
            ref FhirVersionInfo fhirVersionInfo,
            string localLoadType,
            bool officialExpansionsOnly)
        {
            // sanity checks
            if (fhirVersionInfo == null)
            {
                Console.WriteLine($"LoadLocalBuild <<< invalid version info is NULL, cannot load {localPublishDirectory}");
                throw new ArgumentNullException(nameof(fhirVersionInfo));
            }

            // tell the user what's going on
            Console.WriteLine(
                $"LoadLocalBuild <<<" +
                $" Found: {fhirVersionInfo.PackageName}" +
                $" version: {fhirVersionInfo.VersionString}" +
                $" build: {fhirVersionInfo.ReleaseName}");

            string expansionDir;
            string packageDir;

            if (localLoadType == "latest")
            {
                FhirPackageDownloader.CopyAndExtract(
                    localPublishDirectory,
                    fhirVersionInfo.ExpansionsPackageName,
                    fhirVersionInfo.VersionString,
                    fhirSpecDirectory,
                    out expansionDir);

                expansionDir = Path.Combine(expansionDir, "package");
            }
            else
            {
                expansionDir = Path.Combine(
                    fhirSpecDirectory,
                    $"local-{fhirVersionInfo.ExpansionsPackageName}-{fhirVersionInfo.VersionString}",
                    "package");
            }

            // load package info
            FhirPackageInfo expansionPackageInfo = FhirPackageInfo.Load(expansionDir);

            // tell the user what's going on
            Console.WriteLine($"LoadPackage <<< Found: {expansionPackageInfo.Name} version: {expansionPackageInfo.Version}");

            if (localLoadType == "latest")
            {
                FhirPackageDownloader.CopyAndExtract(
                    localPublishDirectory,
                    fhirVersionInfo.PackageName,
                    fhirVersionInfo.VersionString,
                    fhirSpecDirectory,
                    out packageDir);

                packageDir = Path.Combine(packageDir, "package");
            }
            else
            {
                packageDir = Path.Combine(
                    fhirSpecDirectory,
                    $"local-{fhirVersionInfo.PackageName}-{fhirVersionInfo.VersionString}",
                    "package");
            }

            // load package info
            FhirPackageInfo packageInfo = FhirPackageInfo.Load(packageDir);

            // tell the user what's going on
            Console.WriteLine($"LoadPackage <<< Found: {packageInfo.Name} version: {packageInfo.Version}");

            // update our structure
            fhirVersionInfo.VersionString = packageInfo.Version;

            // process Code Systems
            ProcessFileGroup(packageDir, "CodeSystem", ref fhirVersionInfo);

            // process Value Set expansions
            if (officialExpansionsOnly)
            {
                ProcessFileGroup(expansionDir, "ValueSet", ref fhirVersionInfo);
            }
            else
            {
                ProcessFileGroup(packageDir, "ValueSet", ref fhirVersionInfo);
            }

            // process structure definitions
            ProcessFileGroup(packageDir, "StructureDefinition", ref fhirVersionInfo);

            // process search parameters (adds to resources)
            ProcessFileGroup(packageDir, "SearchParameter", ref fhirVersionInfo);

            // process operations (adds to resources and version info (server level))
            ProcessFileGroup(packageDir, "OperationDefinition", ref fhirVersionInfo);

            // add version-specific "MAGIC" items
            AddSearchMagicParameters(ref fhirVersionInfo);

            // make sure we cleared the last line
            Console.WriteLine($"LoadPackage <<< Loaded and Parsed FHIR {fhirVersionInfo.ReleaseName}{new string(' ', 100)}");
        }