Beispiel #1
0
        private static void ReadCLPRFiles(IMappable mapper, DbContextOptionsBuilder <MedicContext> builder, string directoryPath)
        {
            string invalidCLPRFileMessage = "Invalid CLPR file.";


            string[]        files          = Directory.GetFiles(directoryPath, "*.xml");
            IMedicXmlParser medicXmlParser = new DefaultMedicXmlParser(new GetXmlParameters());

            int counter = 1;

            foreach (string file in files)
            {
                using FileStream sr = new FileStream(file, FileMode.Open, FileAccess.Read);

                CLPR.HospitalPractice clprFile = medicXmlParser.ParseXML <CLPR.HospitalPractice>(sr);

                if (clprFile != default)
                {
                    HospitalPractice hospitalPracticeEntity = mapper.Map <HospitalPractice, CLPR.HospitalPractice>(clprFile);

                    if (hospitalPracticeEntity != default)
                    {
                        using MedicContext medicContext        = new MedicContext(builder.Options);
                        using IImportMedicFile importMedicFile = new ImportMedicFile(medicContext);

                        importMedicFile.ImportHospitalPractice(hospitalPracticeEntity);

                        consoleWriter.Notify($"{file} - imported, ({counter++}/{files.Length}).");
                    }
                    else
                    {
                        consoleWriter.Notify(invalidCLPRFileMessage);
                    }
                }
                else
                {
                    consoleWriter.Notify(invalidCLPRFileMessage);
                }
            }
        }
        public async Task <IActionResult> HospitalPractice(IFormFile HopsitalPracticeFormFile)
        {
            try
            {
                string error = string.Empty;

                if (HopsitalPracticeFormFile != default)
                {
                    CLPR.HospitalPractice hospitalPracticeModel = MedicXmlParser
                                                                  .ParseXML <CLPR.HospitalPractice>(HopsitalPracticeFormFile.OpenReadStream());

                    if (hospitalPracticeModel != default)
                    {
                        HospitalPractice hospitalPracticeEntity = Mapper.Map <HospitalPractice, CLPR.HospitalPractice>(hospitalPracticeModel);

                        await Task.Run(() => ImportMedicFile.ImportHospitalPractice(hospitalPracticeEntity));

                        ClearCache();
                    }
                    else
                    {
                        error = MedicDataLocalization.Get(MedicDataLocalization.InvalidFile);
                    }
                }
                else
                {
                    error = MedicDataLocalization.Get(MedicDataLocalization.InvalidFile);
                }

                return(View(new FileUploadPageHospitalPractice()
                {
                    Title = MedicDataLocalization.Get(MedicDataLocalization.HospitalPracticeFile),
                    Description = MedicDataLocalization.Get(MedicDataLocalization.HospitalPracticeFile),
                    Keywords = MedicDataLocalization.Get(MedicDataLocalization.HospitalPracticeFileSummary),
                    Error = error
                }));
            }
            catch (XmlException xmlEx)
            {
                Task <int> _ = MedicLoggerService.SaveAsync(new Log()
                {
                    Message = xmlEx.Message,
                    InnerExceptionMessage = xmlEx?.InnerException?.Message ?? null,
                    Source     = xmlEx.Source,
                    StackTrace = xmlEx.StackTrace,
                    Date       = DateTime.Now
                });

                return(View(new FileUploadPageHospitalPractice()
                {
                    Title = MedicDataLocalization.Get(MedicDataLocalization.CPFile),
                    Description = MedicDataLocalization.Get(MedicDataLocalization.CPFile),
                    Keywords = MedicDataLocalization.Get(MedicDataLocalization.CPFileSummary),
                    Error = MedicDataLocalization.Get(MedicDataLocalization.InvalidFile)
                }));
            }
            catch (InvalidOperationException invalOpEx)
            {
                Task <int> _ = MedicLoggerService.SaveAsync(new Log()
                {
                    Message = invalOpEx.Message,
                    InnerExceptionMessage = invalOpEx?.InnerException?.Message ?? null,
                    Source     = invalOpEx.Source,
                    StackTrace = invalOpEx.StackTrace,
                    Date       = DateTime.Now
                });

                return(View(new FileUploadPageHospitalPractice()
                {
                    Title = MedicDataLocalization.Get(MedicDataLocalization.HospitalPracticeFile),
                    Description = MedicDataLocalization.Get(MedicDataLocalization.HospitalPracticeFile),
                    Keywords = MedicDataLocalization.Get(MedicDataLocalization.HospitalPracticeFileSummary),
                    Error = MedicDataLocalization.Get(MedicDataLocalization.InvalidFile)
                }));
            }
            catch (Exception ex)
            {
                Task <int> _ = MedicLoggerService.SaveAsync(new Log()
                {
                    Message = ex.Message,
                    InnerExceptionMessage = ex?.InnerException?.Message ?? null,
                    Source     = ex.Source,
                    StackTrace = ex.StackTrace,
                    Date       = DateTime.Now
                });

                throw;
            }
        }