public FhirSpecificationDefinitionLoader(ILog ILog,
                                          IUnitOfWork IUnitOfWork,
                                          IRequestMetaFactory IRequestMetaFactory,
                                          IResourceTriggerService IResourceTriggerService,
                                          IBundleTransactionOperationFactory IBundleTransactionOperationFactory,
                                          IFhirSpecificationDefinitionLoaderParameters IFhirSpecificationDefinitionLoaderParameters,
                                          IFhirTaskTool IFhirTaskTool,
                                          Common.PyroHealthFhirResource.CodeSystems.IPyroFhirServer IPyroFhirServerCodeSystem)
 {
     this.ILog                                         = ILog;
     this.IUnitOfWork                                  = IUnitOfWork;
     this.IRequestMetaFactory                          = IRequestMetaFactory;
     this.IResourceTriggerService                      = IResourceTriggerService;
     this.IBundleTransactionOperationFactory           = IBundleTransactionOperationFactory;
     this.IFhirSpecificationDefinitionLoaderParameters = IFhirSpecificationDefinitionLoaderParameters;
     this.IFhirTaskTool                                = IFhirTaskTool;
     this.IPyroFhirServerCodeSystem                    = IPyroFhirServerCodeSystem;
 }
        private bool LoadFromZip(IFhirSpecificationDefinitionLoaderParameters Parameters)
        {
            bool   OneFileCompleted = false;
            Stream FileStream       = new MemoryStream(Common.CommonResource.definitions_xml);

            try
            {
                using (ZipArchive Archive = new ZipArchive(FileStream))
                {
                    foreach (ZipArchiveEntry Entry in Archive.Entries)
                    {
                        if (Entry.FullName.EndsWith(".xml", StringComparison.OrdinalIgnoreCase))
                        {
                            //Skip loading the search-parameters as they are always loaded by a separate task, see : SearchParameterResourceLoader
                            if (!Entry.FullName.Equals("search-parameters.xml", StringComparison.OrdinalIgnoreCase))
                            {
                                //Pick processing from where it was last left off
                                if (!Parameters.FileCompletedList.Contains(Entry.FullName) || Parameters.FileCompletedList.Count == 0)
                                {
                                    Parameters.FileInProgress = Entry.FullName;
                                    if (OneFileCompleted)
                                    {
                                        //We only want to do one file in the ZIP package at a time but we want the name of the next file to process
                                        //This is why this is here.
                                        //Yes I know we are unzipping the file many times but this is better that staring all over again each time we don not get to finish the entire set.
                                        Parameters.FileInProgress = Entry.FullName;
                                        return(true);
                                    }

                                    Stream StreamItem = Entry.Open();
                                    using (StreamItem)
                                    {
                                        try
                                        {
                                            var buffer = new MemoryStream();
                                            StreamItem.CopyTo(buffer);
                                            buffer.Seek(0, SeekOrigin.Begin);
                                            System.Xml.XmlReader XmlReader = SerializationUtil.XmlReaderFromStream(buffer);
                                            Resource             Resource  = Common.Tools.FhirResourceSerializationSupport.DeSerializeFromXml(XmlReader);
                                            if (Resource is Bundle Bundle)
                                            {
                                                if (ConvertToTransactionBundle(Bundle, Entry.FullName))
                                                {
                                                    if (CommitTransactionBundle(Bundle, Entry.FullName))
                                                    {
                                                        Parameters.FileCompletedList.Add(Entry.FullName);
                                                        Parameters.TaskStatus = Hl7.Fhir.Model.Task.TaskStatus.InProgress;
                                                        OneFileCompleted      = true;;
                                                    }
                                                    else
                                                    {
                                                        string ErrorMessage = $"Internal Server Error: FHIR specification resource bundle named {Entry.FullName} from the FHIR specification zip file named: {_ZipFileName} was unable to be committed as a transaction bundle. See server logs for more info.";
                                                        ILog.Error(ErrorMessage);
                                                        Parameters.FileInError  = Entry.FullName;
                                                        Parameters.ErrorMessage = ErrorMessage;
                                                        return(false);
                                                    }
                                                }
                                                else
                                                {
                                                    string ErrorMessage = $"Internal Server Error: Unable to convert the FHIR specification resource bundle named {Entry.FullName} from the FHIR specification zip file named: {_ZipFileName}. See server logs for more info.";
                                                    ILog.Error(ErrorMessage);
                                                    Parameters.FileInError  = Entry.FullName;
                                                    Parameters.ErrorMessage = ErrorMessage;
                                                    return(false);
                                                }
                                            }
                                        }
                                        catch (PyroException PyroExec)
                                        {
                                            string ErrorMessage = $"Internal Server Error: Exception thrown when DeSerializing FHIR resources from the FHIR specification zip file named: {_ZipFileName}. See server logs for more info.";
                                            ILog.Error(PyroExec, ErrorMessage);
                                            Parameters.FileInError  = Entry.FullName;
                                            Parameters.ErrorMessage = ErrorMessage;
                                            return(false);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception Exec)
            {
                string ErrorMessage = $"Internal Server Error: Exception thrown when unzipping FHIR specification zip file named: {_ZipFileName}.";
                Parameters.ErrorMessage = ErrorMessage;
                Parameters.TaskStatus   = Hl7.Fhir.Model.Task.TaskStatus.Failed;
                ILog.Error(Exec, ErrorMessage);
                return(false);
            }
            //no errors after all processed so return true.
            //Completed to end so reset all parameters for return.
            Parameters.FileInProgress = string.Empty;
            Parameters.TaskStatus     = Hl7.Fhir.Model.Task.TaskStatus.Completed;
            Parameters.ErrorMessage   = string.Empty;
            Parameters.FileInError    = string.Empty;
            return(true);
        }