public ActionResult UploadFileValidator(HttpPostedFileBase file = null) { string id_usuario = Request["user_id"]; if (file != null) { DTOTransporteArchivo dtotransporte = new DTOTransporteArchivo(); DTOArchivo archivo = new DTOArchivo(); archivo.FechaCreacion = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); archivo.Id = Guid.NewGuid().ToString(); archivo.Tamano = file.ContentLength.ToString(); archivo.Nombre = file.FileName; archivo.IdUsuario = id_usuario; try { // convert xmlstring to byte using ascii encoding byte[] binario; byte[] buffer = new byte[16 * 1024]; using (MemoryStream ms = new MemoryStream()) { int read; while ((read = file.InputStream.Read(buffer, 0, buffer.Length)) > 0) { ms.Write(buffer, 0, read); } binario = ms.ToArray(); } byte[] data = binario; dtotransporte.Binario = data; dtotransporte.Archivo = archivo; ISynchronizationManager syn = new SynchronizationManager(); Request request = new Request(); JavaScriptSerializer json_serializer = new JavaScriptSerializer(); request.Content = json_serializer.Serialize(dtotransporte); request.ContentType = "application/json"; request.Method = "POST"; request.Url = "http://192.168.160.98:10090/api/cac/v1/file/validator"; Response response = syn.PostRequest(request); return(Json(response.TextResponse)); } catch (Exception ex) { } } return(null); }
public DTOResponse Validator(DTOTransporteArchivo log) { DTOResponse response = new DTOResponse(); response.Archivo = new DTOArchivo() { Nombre = "file.xls", Id = Guid.NewGuid().ToString(), IdUsuario = "f9587aba-0990-11e7-93ae-92361f002671", FechaCreacion = DateTime.Now.ToString(Configuration.GetValueConf(Constants.DateFormat)), NumFilasImportadas = 534, Tamano = "4687", UrlArchivo = "" }; response.List = new List <DTOValidacionArchivo>() { new DTOValidacionArchivo() { Celda = "A 1", Descripcion = "Valor falso de prueba", FechaCreacion = DateTime.Now.ToString(Configuration.GetValueConf(Constants.DateFormat)), Valor = "Valor falso que no se envió con tíldes y comilla \"dobles\" y 'simples'" } }; return(response); }
public ActionResult UploadFileValidator(HttpPostedFileBase file = null) { string id_usuario = Request["user_id"]; if (file != null) { DTOTransporteArchivo dtotransporte = new DTOTransporteArchivo(); DTOArchivo archivo = new DTOArchivo(); archivo.FechaCreacion = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); archivo.Id = Guid.NewGuid().ToString(); archivo.Tamano = file.ContentLength.ToString(); archivo.Nombre = file.FileName; archivo.IdUsuario = id_usuario; try { // convert xmlstring to byte using ascii encoding byte[] binario; byte[] buffer = new byte[16 * 1024]; using (MemoryStream ms = new MemoryStream()) { int read; while ((read = file.InputStream.Read(buffer, 0, buffer.Length)) > 0) { ms.Write(buffer, 0, read); } binario = ms.ToArray(); } byte[] data = null; string directory = System.Web.Hosting.HostingEnvironment.MapPath($@"{Resources.TemporalServerFolder}"); string path_file = $@"{directory}/{file.FileName}"; if (Directory.Exists(directory) == false) { Directory.CreateDirectory(directory); } if (System.IO.File.Exists(path_file) == false) { // Create the file. using (FileStream fs = System.IO.File.Create(path_file)) { fs.Write(binario, 0, binario.Length); } } else { System.IO.File.WriteAllBytes(path_file, binario); } FileInfo fileinfo = new FileInfo(path_file); string compressfilename = ZipFile.CompressGZipStream(fileinfo); if (compressfilename != null) { FileStream fs = new FileStream(compressfilename, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); data = br.ReadBytes((int)fs.Length); br.Close(); fs.Close(); System.IO.File.Delete(compressfilename); System.IO.File.Delete(path_file); } dtotransporte.Binario = data; dtotransporte.Archivo = archivo; ISynchronizationManager syn = new SynchronizationManager(); Request request = new Request(); JavaScriptSerializer json_serializer = new JavaScriptSerializer(); json_serializer.MaxJsonLength = 2147483647; request.Content = json_serializer.Serialize(dtotransporte); request.ContentType = "application/json"; request.Method = "POST"; request.Url = $@"{url}/{Resources.FILE_VALIDATOR_POST}"; Response response = syn.PostRequest(request); return(Json(response.TextResponse)); } catch (Exception ex) { return(Json(ex.Message)); } } return(null); }
public DTOResponse Validator(DTOTransporteArchivo log) { DTOResponse response = new DTOResponse(); try { if (log.Archivo != null && log.Binario != null && log.Binario.Length > 0) { var decompress2 = ZipFile.DecompressGZipStream(log.Binario); var decompress = log.Archivo.Nombre.Contains(".zip") == true?ZipFile.DecompressZipStream(decompress2) : decompress2; //var decompress = File.ReadAllBytes(@"D:\Users\Candy\Documents\Debugger SND.CAC\Pruebas_mayo\Comprimido\EMPTY_FIELDS2.csv"); IFileProcessBP filebp = new FileProcessBP(); List <DTOValidacionArchivo> lista = filebp.ValidateFile(log.Archivo.Nombre, decompress); if (lista.Count == 0) { log.Archivo.NumFilasImportadas = filebp.GetTotalRow(); log.Archivo.Tamano = decompress.Length.ToString(); log.Archivo.UrlArchivo = "NO_URL"; int totalsaved = MySQLStorageRun(log.Archivo); if (totalsaved > 0) { FirebaseStorageRun(decompress, log.Archivo); response.Archivo = log.Archivo; System.Threading.Tasks.Task.Factory.StartNew(() => PatientPriority(decompress, log.Archivo)); } else { response.Archivo = null; response.List = new List <DTOValidacionArchivo>(); DTOValidacionArchivo validation = new DTOValidacionArchivo() { Valor = totalsaved.ToString(), FechaCreacion = DateTime.Now.ToString(Configuration.GetValueConf(Constants.DateFormat)), Descripcion = "No se pudo agregar el archivo a la base de datos. Por favor comunicarse con el servicio tecnico." }; response.List.Add(validation); } } if (lista.Count > 0) { response.List = lista; } } else { response.Archivo = null; response.List = new List <DTOValidacionArchivo>(); DTOValidacionArchivo validation = new DTOValidacionArchivo() { Valor = "", FechaCreacion = DateTime.Now.ToString(Configuration.GetValueConf(Constants.DateFormat)), Descripcion = "No fue adjuntado ningun archivo para realizar el análisis" }; response.List.Add(validation); } return(response); } catch (Exception ex) { IOUtilities.WriteExceptionLog(ex, Configuration.GetClassName <FileService>()); } return(null); }