Пример #1
0
        public void GenerarBackupDeBaseDeDatosEnCarpetaTemporal()
        {
            var backupDirectory  = Paths.CarpetaTemporalBackupBaseDeDatosAbsolute;
            var connectionString = new ApplicationDbContext().Database.Connection.ConnectionString;

            var startInfo = new ProcessStartInfo
            {
                CreateNoWindow  = false,
                UseShellExecute = false,
                FileName        = Paths.BackupGeneratorExeAbsolute ?? throw new InvalidOperationException(),
                                        WindowStyle = ProcessWindowStyle.Hidden,
                                        Arguments   = $@"script -c ""{connectionString}"" --dataTablesPattern "".*"" -d  ""{backupDirectory}"" -v -o"
            };

            try
            {
                using (var exeProcess = Process.Start(startInfo))
                {
                    exeProcess?.WaitForExit();
                }
            }
            catch (Exception ex)
            {
                YKNExHandler.LoguearYLanzarExcepcion(ex, "Error generando backup de base de datos.");
            }
        }
Пример #2
0
        private static void EliminarArchivos(string folderPath, string fileSearchPattern)
        {
            Log.Info($"Se van a eliminar todos los archivos de '{folderPath}' con extensión: '{fileSearchPattern}'.");
            var filePaths = Directory.GetFiles(folderPath, fileSearchPattern);

            Log.Info($"Cantidad de archivos con extensión '{fileSearchPattern}' encontrados en la carpeta: '{filePaths.Length}'.");
            foreach (var filePath in filePaths)
            {
                Log.Info($"Se intenta eliminar el archivo: '{filePath}'.");
                if (File.Exists(filePath))
                {
                    try
                    {
                        File.Delete(filePath);
                        Log.Info("Se eliminó correctamente.");
                    }
                    catch (Exception ex)
                    {
                        YKNExHandler.LoguearYLanzarExcepcion(ex, "Error al intentar eliminar el archivo.");
                    }
                }
                else
                {
                    Log.Info("El archivo no existía.");
                }
            }
        }
Пример #3
0
        protected static void SubirAlDrive(string filePath)
        {
            var fileName = Path.GetFileName(filePath);

            try
            {
                YKNDriveService.SubirArchivo(filePath, fileName, "application/octet-stream");
                Log.Info($"Se subió al Drive el archivo '{fileName}'");
            }
            catch (Exception e)
            {
                YKNExHandler.LoguearYLanzarExcepcion(e, $"Error subiendo al Drive el archivo '{fileName}'");
            }
        }
        public ActionResult EditarJugadorRechazado(JugadorAutofichadoVM vm)
        {
            try
            {
                if (vm.ArchivoDeFotoDNIFrente != null)
                {
                    ValidarExtensionFotoDNIFrente(vm);
                }

                if (!ModelState.IsValid)
                {
                    return(RedirectToAction("Edit", vm.Id));
                }

                var model = Context.JugadoresaAutofichados.Find(vm.Id);

                var dniAnterior = model.DNI;

                VMM.MapForEdit(vm, model);

                Context.SaveChanges();

                _imagenesJugadoresDiskPersistence.GuardarFotosTemporalesDeJugadorAutofichadoSiendoEditado(vm);

                if (dniAnterior != vm.DNI)
                {
                    _imagenesJugadoresDiskPersistence.RenombrarFotosTemporalesPorCambioDeDNI(dniAnterior, vm.DNI);
                }
            }
            catch (Exception e)
            {
                YKNExHandler.LoguearYLanzarExcepcion(e, "Error al editar jugador fichado por delegado y rechazado.");

                return(RedirectToAction("Rechazados", new IdDescripcionVM
                {
                    Descripcion = Context.Equipos.Find(vm.EquipoId).Nombre,
                    Id = vm.EquipoId
                }));
            }

            return(RedirectToAction("PendientesDeAprobacion", new IdDescripcionVM
            {
                Descripcion = Context.Equipos.Find(vm.EquipoId).Nombre,
                Id = vm.EquipoId
            }));
        }
Пример #5
0
        public static void GenerarYSubirADrive()
        {
            Log.Info("------------------------------------------------");

            try
            {
                new ImagenesGDriveBackupManager().GenerarYSubirAlDrive();
                new BaseDeDatosGDriveBackupManager().GenerarYSubirAlDrive();
                new BackupDiskPersistence(new AppPathsWebApp()).EliminarTodosLosArchivosDeLaCarpetaDondeEstanLosBackups();
            }
            catch (Exception e)
            {
                YKNExHandler.LoguearYLanzarExcepcion(e, "Error subiendo backup al Drive");
            }

            Log.Info("Finaliza la subida de backups al Drive");
            Log.Info("------------------------------------------------");
        }
Пример #6
0
        public virtual void GenerarYSubirAlDrive()
        {
            var nombreBackup = NombreDelBackupZipeadoSinExtensionNiFecha();

            try
            {
                Log.Info($"Comienza la generación del backup de '{nombreBackup}'.");

                var backupPath = ComprimirYPonerZipEnAppData();

                EliminarDelDriveBackupMasAntiguoSiHayMasDe3(NombreDelBackupZipeadoSinExtensionNiFecha(), ".zip");

                SubirAlDrive(backupPath);

                Log.Info($"Finaliza la generación del backup de '{nombreBackup}'.");
            }
            catch (Exception e)
            {
                YKNExHandler.LoguearYLanzarExcepcion(e, $"Error al generar el backup de '{nombreBackup}'");
            }
        }
Пример #7
0
        public string ComprimirBackupBaseDeDatosYPonerZipEnCarpetaDeBackups()
        {
            Directory.CreateDirectory(Paths.BackupAbsolute());
            var backupPath = Paths.BackupBaseDeDatos();

            try
            {
                using (var zip = new ZipFile())
                {
                    zip.AddDirectory(Paths.CarpetaTemporalBackupBaseDeDatosAbsolute);
                    Log.Info($"Se comprimió correctamente la carpeta '{Paths.CarpetaTemporalBackupBaseDeDatosAbsolute}'.");
                    zip.Save(backupPath);
                    Log.Info($"Se guardó el archivo comprimido en '{backupPath}'.");
                }
            }
            catch (Exception ex)
            {
                YKNExHandler.LoguearYLanzarExcepcion(ex, "Error comprimiendo base de datos");
            }

            return(backupPath);
        }
Пример #8
0
        public string ComprimirImagenesYPonerZipEnCarpetaDeBackups()
        {
            Directory.CreateDirectory(Paths.BackupAbsolute());
            var backupPath = Paths.BackupImagenes();

            try
            {
                using (var zip = new ZipFile())
                {
                    zip.AddDirectory(Paths.ImagenesAbsolute);
                    Log.Info($"Se comprimió correctamente la carpeta '{Paths.ImagenesAbsolute}'.");
                    zip.Save(backupPath);
                    Log.Info($"Se guardó la carpeta comprimida en '{backupPath}'.");
                }
            }
            catch (Exception ex)
            {
                YKNExHandler.LoguearYLanzarExcepcion(ex, "Error comprimiendo imágenes");
            }

            return(backupPath);
        }
Пример #9
0
        protected void EliminarDelDriveBackupMasAntiguoSiHayMasDe3(string fileNameStartWith, string fileNameEndsWith)
        {
            Log.Info($"Si en el Drive hay más de 3 backups de '{NombreDelBackupZipeadoSinExtensionNiFecha()}', se eliminará el más antiguo.");
            var files = YKNDriveService.ListAll().Where(x => x.Name.StartsWith(fileNameStartWith) && x.Name.EndsWith(fileNameEndsWith)).OrderBy(x => x.CreatedTime).ToList();

            if (files.Count >= 3)
            {
                try
                {
                    YKNDriveService.DeleteFile(files.First().Id);
                    Log.Info($"Se eliminó el backup de nombre '{files.First().Name}'.");
                }
                catch (Exception e)
                {
                    YKNExHandler.LoguearYLanzarExcepcion(e, $"Error al intentar borrar del drive el archivo '{files.First().Name}'");
                }
            }
            else
            {
                Log.Info($"No se eliminó nada porque había {files.Count} backups más antiguos.");
            }
        }
Пример #10
0
        public JsonResult Autofichaje()
        {
            try
            {
                var vm    = CastearRequestAJugadorAutofichadoVM();
                var model = new JugadorAutofichado();
                VMM.MapForCreateAndEdit(vm, model);

                SiElDNISeHabiaFichadoYEstaRechazadoEliminarElAnterior(model.DNI);

                Context.JugadoresaAutofichados.Add(model);
                Context.SaveChanges();

                _imagenesJugadoresDiskPersistence.GuardarFotosTemporalesDeJugadorAutofichado(vm);
            }
            catch (Exception e)
            {
                YKNExHandler.LoguearYLanzarExcepcion(e, "Error en autofichaje.");
                return(Json("Error", JsonRequestBehavior.AllowGet));
            }

            return(Json("OK", JsonRequestBehavior.AllowGet));
        }
        public ActionResult Aprobar(int id)
        {
            var jugadorAutofichado = _context.JugadoresaAutofichados.Single(x => x.Id == id);

            try
            {
                var jugador = new Jugador();

                var vm = new FicharNuevoJugadorVM
                {
                    DNI             = jugadorAutofichado.DNI,
                    Apellido        = jugadorAutofichado.Apellido,
                    Nombre          = jugadorAutofichado.Nombre,
                    EquipoId        = jugadorAutofichado.EquipoId,
                    FechaNacimiento = DateTimeUtils.ConvertToString(jugadorAutofichado.FechaNacimiento)
                };

                var jugadorEquipo = _jugadorVMM.MapCreate(vm, jugador);

                _context.JugadorEquipos.Add(jugadorEquipo);
                jugadorAutofichado.Estado = EstadoJugadorAutofichado.Aprobado;

                var club       = _context.Equipos.Find(vm.EquipoId).Club;
                var movimiento = _generadorDeMovimientos.GenerarMovimientoFichajeImpago(club, vm.DNI);
                club.Movimientos.Add(movimiento);

                _context.SaveChanges();

                _imagenesJugadoresDiskPersistence.FicharJugadorTemporal(jugadorAutofichado.DNI);
            }
            catch (Exception e)
            {
                YKNExHandler.LoguearYLanzarExcepcion(e, "Error al fichar jugador temporal");
            }

            return(RedirectToAction("Index", new { Estado = 1 }));
        }