Exemplo n.º 1
0
        public List <AreaImpModel> ImportFile(ImportInfoDTO importInfo)
        {
            if (importInfo.requiredFields == null || importInfo.requiredFields.Count != 1)
            {
                throw new ImportException("Error on Importation: Received information is not compatible with required by the importer");
            }
            string path = importInfo.requiredFields[0].FieldValue;

            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ImportException("Error on Importation: Path to file was missing or corrupted");
            }
            List <AreaImpModel> importedArea = new List <AreaImpModel>();

            ValidatePath(path);
            try
            {
                string       json   = "";
                StreamReader reader = new StreamReader(path);
                json         = reader.ReadToEnd();
                importedArea = JsonConvert.DeserializeObject <List <AreaImpModel> >(json);
            }
            catch (Exception)
            {
                throw new ImportException("Error on Import: JSON file was corrupt or invalid");
            }
            return(importedArea);
        }
 public IActionResult Import([FromBody] ImportInfoDTO impInfo)
 {
     try
     {
         importationLogic.GetImportationsMethods(@"Importers");
         IImporter           importer         = importationLogic.GetImporter(impInfo.importationMethod);
         List <AreaImpModel> importedElements = importer.ImportFile(impInfo);
         List <Area>         realElemnts      = impElementParser.ParseElements(importedElements);
         importProcessing.ProcessImportedElements(realElemnts);
         return(Ok());
     }
     catch (Exception e)
         when(e is ImportException || e is BusinessLogicException || e is DataAccessException)
         {
             return(BadRequest(e.Message));
         }
 }
Exemplo n.º 3
0
 public List <AreaImpModel> ImportFile(IImporter importerSelected, ImportInfoDTO impInfo)
 {
     return(importerSelected.ImportFile(impInfo));
 }