Exemple #1
0
        public void TestMethod1()
        {
            DTOResponse response = new DTOResponse();

            byte[] binario = File.ReadAllBytes(@"D:\Users\Candy\Documents\Debugger SND.CAC\Pruebas_mayo\temp_prueba_tipo_datos.xlsx");
            try
            {
                byte[]        buffer = new byte[16 * 1024];
                FileProcessBP filebp = new FileProcessBP();


                var template = filebp.GetTemplate();

                foreach (var item in template)
                {
                    IOUtilities.WriteLog(item.Name, @"Pruebas_mayo", "template.txt", false);
                }

                List <DTOValidacionArchivo> lista = filebp.ValidateFile("nombre", binario);

                if (lista.Count == 0)
                {
                    response.Archivo = new DTOArchivo()
                    {
                        Nombre = "file.xls", Id = Guid.NewGuid().ToString(), IdUsuario = "f9587aba-0990-11e7-93ae-92361f002671", FechaCreacion = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), NumFilasImportadas = 534, Tamano = binario.Length.ToString(), UrlArchivo = ""
                    };
                    //Run(binario, response.Archivo);
                }
                if (lista.Count > 0)
                {
                    response.List = lista;
                }
                System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();
                var stri = js.Serialize(response);
                File.AppendAllText(@"D:\Users\Candy\Documents\Debugger SND.CAC\Pruebas_mayo\response_testing.json", stri);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public DTOResponse Validator2(Stream log)
        {
            DTOResponse response = new DTOResponse();

            byte[] binario;
            try
            {
                byte[] buffer = new byte[16 * 1024];
                using (MemoryStream ms = new MemoryStream())
                {
                    int read;
                    while ((read = log.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        ms.Write(buffer, 0, read);
                    }
                    binario = ms.ToArray();
                    if (binario.Length > 0)
                    {
                        IFileProcessBP filebp             = new FileProcessBP();
                        List <DTOValidacionArchivo> lista = filebp.ValidateFile("nombre", binario);
                        if (lista.Count == 0)
                        {
                            response.Archivo = new DTOArchivo()
                            {
                                Nombre = "file.xls", Id = Guid.NewGuid().ToString(), IdUsuario = "f9587aba-0990-11e7-93ae-92361f002671", FechaCreacion = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), NumFilasImportadas = filebp.GetTotalRow(), Tamano = binario.Length.ToString(), UrlArchivo = ""
                            };
                            int totalsaved = MySQLStorageRun(response.Archivo);
                            if (totalsaved > 0)
                            {
                                FirebaseStorageRun(binario, response.Archivo);

                                PatientPriority(binario, response.Archivo);
                            }
                            else
                            {
                                response.Archivo = null;
                                response.List    = new List <DTOValidacionArchivo>();
                                DTOValidacionArchivo validation = new DTOValidacionArchivo()
                                {
                                    Valor         = "",
                                    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);
        }
        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);
        }