private async void FirebaseStorageRun(byte[] binario, DTOArchivo dto)
        {
            try
            {
                int total = -1;
                if (dto != null)
                {
                    var re = await FirebaseController.WriteOnFirebaseStorage(binario, dto);

                    dto.UrlArchivo = re;
                    Archivo_Factory factory = new Archivo_Factory();
                    tbl_archivo_cac modelo  = factory.transformModel(dto);

                    var temp_modelo = db.tbl_archivo_cac.Where(m => m.id == modelo.id).FirstOrDefault();

                    if (temp_modelo != null)
                    {
                        temp_modelo.urlArchivo = re;
                        db.tbl_archivo_cac.Attach(temp_modelo);
                        db.Entry(temp_modelo).State = System.Data.EntityState.Modified;
                        total = db.SaveChanges();
                    }
                    //IOUtilities.WriteLog(string.Format("{0}\t{1}\tFirebaseStorageRun\t{2}", IOUtilities.GetLocalTime(), Configuration.GetClassName<FileService>(), total), Configuration.GetClassName<IOUtilities>(), Configuration.GetValueConf(Constants.LogFile));
                }
            }
            catch (Exception ex)
            {
                IOUtilities.WriteExceptionLog(ex, Configuration.GetClassName <FileService>());
            }
        }
Beispiel #2
0
        public static async Task <string> WriteOnFirebaseStorage(byte[] file, DTOArchivo archivo)
        {
            var stream = new MemoryStream(file);
            var auth   = new FirebaseAuthProvider(new FirebaseConfig(ApiKey));
            var a      = await auth.SignInWithEmailAndPasswordAsync(AuthEmail, AuthPassword);

            var    cancellation = new CancellationTokenSource();
            string url          = "";
            var    task         = new FirebaseStorage(
                Bucket,
                new FirebaseStorageOptions
            {
                AuthTokenAsyncFactory = () => Task.FromResult(a.FirebaseToken),
                ThrowOnCancel         = true
            })
                                  .Child(archivo.IdUsuario)
                                  .Child(archivo.Id)
                                  .Child(archivo.Nombre)
                                  .PutAsync(stream, cancellation.Token);

            task.Progress.ProgressChanged += (s, e) => Progress = e.Percentage;
            try
            {
                url = await task;
            }
            catch (Exception ex)
            {
                IOUtilities.WriteExceptionLog(ex, Configuration.GetClassName <FirebaseController>());
            }
            return(url);
        }
        private void PatientPriority(byte[] decompress, DTOArchivo dtoArchivo)
        {
            IPriorityPatient priorityPatient = new PriorityPatient();

            priorityPatient.Build(decompress, dtoArchivo.Id, dtoArchivo.Nombre);
            ICACBP cacBP = new CACBP();

            cacBP.saveData(decompress, dtoArchivo.Id, dtoArchivo.Nombre, dtoArchivo.IdUsuario);
        }
Beispiel #4
0
        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 DTOArchivo GetFileById(string id)
        {
            DTOArchivo response = null;

            try
            {
                Archivo_Factory factory = new Archivo_Factory();
                Guid            idparse = Guid.Parse(id);
                tbl_archivo_cac modelo  = db.tbl_archivo_cac.Where(m => m.id == idparse).FirstOrDefault();
                if (modelo != null)
                {
                    response = factory.transformDTO(modelo);
                }
            }
            catch (Exception ex)
            {
                IOUtilities.WriteExceptionLog(ex, Configuration.GetClassName <CACService>());
            }

            return(response);
        }
        private int MySQLStorageRun(DTOArchivo archivo)
        {
            int total = -1;

            try
            {
                Archivo_Factory factory     = new Archivo_Factory();
                tbl_archivo_cac modelo      = factory.transformModel(archivo);
                var             temp_modelo = db.tbl_archivo_cac.Where(m => m.id == modelo.id).FirstOrDefault();
                if (temp_modelo == null)
                {
                    db.tbl_archivo_cac.Add(modelo);
                    total = db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                IOUtilities.WriteExceptionLog(ex, Configuration.GetClassName <FileService>());
            }
            return(total);
        }
        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);
        }