Example #1
0
        /// <summary>
        /// Página de inicio.
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            // Borrar archivos temporales viejos.
            string rutaTemp = HttpContext.Server.MapPath("/Temp/");

            Utilerias.BorrarTemporales(rutaTemp);

            var pc = new PerConfiguracion();

            if (pc.Existe())
            {
                Debug.WriteLine("Existe");
                string rutaCopiaTrabajo = UtilSVN.ObtenerRutaCopiaTrabajo();
                rutaTemp  = Path.GetFullPath(Path.Combine(rutaCopiaTrabajo, @"..\"));
                rutaTemp += "Temp";
                Utilerias.BorrarTemporales(rutaTemp);
            }

            // Crear carpeta Temp
            string rutaCarpetaTemp = HttpContext.Server.MapPath("/Temp");

            Utilerias.CrearRuta(rutaCarpetaTemp);

            // Crear carpata App_Data
            string rutaCarpetaAppData = HttpContext.Server.MapPath("/App_Data");

            Utilerias.CrearRuta(rutaCarpetaAppData);

            // Crear archivo log.
            //string rutaLog = HttpContext.Server.MapPath("/App_Data/Log.txt");
            //Utilerias.CrearArchivoLog(rutaLog);

            return(View());
        }
Example #2
0
        public ActionResult VerRevision(int id, long rev)
        {
            string rutaLog = HttpContext.Server.MapPath("/App_Data/Log.txt");

            Documento doc       = new PerDocumento().Obtener(id);
            var       extension = Path.GetExtension(doc.Nombre);

            // Checar que sea un PDF.
            if (extension.ToLower() != ".pdf")
            {
                ViewBag.msj    = "Sólo se pueden visualizar archivos PDF.";
                ViewBag.metodo = "Versiones";
                ViewBag.id     = id;
                return(View("Ver"));
            }

            if (Request.Browser.Type.ToUpper().Contains("IE"))
            {
                if (Request.Browser.MajorVersion < 9)
                {
                    ViewBag.msj    = "El visor de PDFs no soporta Internet Explorer 8 o inferior.";
                    ViewBag.metodo = "Versiones";
                    ViewBag.id     = id;
                    return(View("Ver"));
                }
            }

            var rutaEnCopiaTrabajo = (doc.RevisionEliminacion.GetValueOrDefault() > 0) ? ((rev < doc.RevisionEliminacion.GetValueOrDefault()) ? doc.Ruta : doc.RutaEliminado) : doc.Ruta;

            string rutaTemp = HttpContext.Server.MapPath("/Temp/" + rev + doc.Nombre);
            string rutaUrl  = HttpUtility.UrlEncode("/Temp/" + rev + HttpUtility.UrlPathEncode(doc.Nombre));

            string msj = UtilSVN.ObtenerRevision(rev, rutaTemp, rutaEnCopiaTrabajo);

            if (msj == "Exito")
            {
                // Mandar a la página del viewer con el documento seleccionado.
                return(Redirect("~/Content/PDF.js/web/viewer.html?file=" + rutaUrl));
            }
            else
            {
                ViewBag.msj = msj;
                return(View());
            }
        }
Example #3
0
        public ActionResult DescargarRevision(int id, long rev)
        {
            string rutaLog = HttpContext.Server.MapPath("/App_Data/Log.txt");

            //Utilerias.EscribirLog(rutaLog, "Usuario: " + Sesion.Current.Usuario.Nombre + " quiere descargar archivo con id: " + id + " en su revisión: " + rev + ".");

            ViewBag.msj = null;

            Documento doc = new PerDocumento().Obtener(id);
            var       rutaEnCopiaTrabajo = (doc.RevisionEliminacion.GetValueOrDefault() > 0) ? ((rev < doc.RevisionEliminacion.GetValueOrDefault()) ? doc.Ruta : doc.RutaEliminado) : doc.Ruta;

            string rutaCopiaTrabajo = UtilSVN.ObtenerRutaCopiaTrabajo();

            string rutaTemp = Path.GetFullPath(Path.Combine(rutaCopiaTrabajo, @"..\"));

            rutaTemp += "Temp";
            Utilerias.CrearRuta(rutaTemp);

            var rutaArchivoTemp = rutaTemp + @"\" + doc.Nombre;

            Debug.WriteLine("rutaArchivoTemp: " + rutaArchivoTemp);

            string msj = UtilSVN.ObtenerRevision(rev, rutaArchivoTemp, rutaEnCopiaTrabajo);

            Debug.WriteLine("msj: " + msj);

            if (msj == "Exito")
            {
                if (System.IO.File.Exists(rutaArchivoTemp))
                {
                    return(File(rutaArchivoTemp, "application/octet-stream", Server.UrlEncode(doc.Nombre)));
                }
                else
                {
                    ViewBag.msj = "No se encontró el archivo.";
                    return(View("Versiones"));
                }
            }
            else
            {
                ViewBag.msj = msj;
                return(View("Versiones"));
            }
        }
Example #4
0
        public ActionResult Versiones(int id)
        {
            string rutaLog = HttpContext.Server.MapPath("/App_Data/Log.txt");
            //Utilerias.EscribirLog(rutaLog, "Usuario: " + Sesion.Current.Usuario.Nombre + " quiere ver las versiones del archivo con id: " + id + ".");

            Documento doc = new PerDocumento().Obtener(id);

            ViewBag.documento = doc;
            ActionResult ar = View(doc);

            ViewBag.colVersiones = null;
            ViewBag.msj          = null;

            string msj;

            // Obtener lista de versiones anteriores.
            System.Collections.ObjectModel.Collection <SharpSvn.SvnFileVersionEventArgs> colFileVersionEventArgs = UtilSVN.ObtenerLstVersionesAnteriores(doc, out msj);

            Debug.WriteLine(msj);

            if (String.IsNullOrEmpty(msj))
            {
                ViewBag.colVersiones = colFileVersionEventArgs;
            }
            else
            {
                ViewBag.msj = msj;
            }

            return(ar);
        }
Example #5
0
        public ActionResult Eliminar(int id)
        {
            string rutaLog = HttpContext.Server.MapPath("/App_Data/Log.txt");
            //Utilerias.EscribirLog(rutaLog, "Usuario: " + Sesion.Current.Usuario.Nombre + " quiere eliminar archivo con id: " + id + ".");

            var str   = new StringBuilder();
            var error = "";

            str.Append("{");
            str.Append("\"Eliminado\":");

            try
            {
                // Crear carpeta eliminados si no existe.
                string rutaEliminados = UtilSVN.ObtenerRutaCopiaTrabajo() + @"\Eliminados";
                bool   creado         = Utilerias.CrearRuta(rutaEliminados);

                // Obtener el usuario logueado
                var usr = Sesion.Current.Usuario;

                // Si se acaba de crear hacer un commit indicándolo.
                if (creado)
                {
                    UtilSVN.AgregarArchivo(@"\Eliminados", usr.Nombre);
                }

                if (id > 0)
                {
                    var       pd            = new PerDocumento();
                    Documento doc           = pd.Obtener(id);
                    string    rutaCarpetas  = @"\" + doc.Departamento.Nombre + @"\" + doc.Area.Nombre;
                    string    rutaEliminado = rutaEliminados + rutaCarpetas;

                    // Crear carpetas de departamento y area dentro de eliminados, y agregarlas al SVN.
                    Utilerias.CrearRuta(rutaEliminado);
                    UtilSVN.AgregarArchivo(@"\Eliminados" + rutaCarpetas, usr.Nombre);

                    rutaEliminado = rutaEliminado + @"\" + doc.Nombre;

                    // Commit eliminación.
                    string msjEliminarArchivo = UtilSVN.EliminarArchivo(doc.Ruta, rutaEliminado, rutaCarpetas + @"\" + doc.Nombre, usr.Nombre);

                    if (msjEliminarArchivo == "Exito")
                    {
                        long revEliminado = UtilSVN.ObtenerUltimaRevision();
                        Debug.WriteLine("revEliminado: " + revEliminado);

                        // Desactivar el registro de la base.
                        pd.Eliminar(id, rutaEliminado, revEliminado);

                        str.Append("1");
                    }
                    else
                    {
                        str.Append("0");
                        error += msjEliminarArchivo;
                    }
                }
                else
                {
                    str.Append("0");
                    error += "Error al eliminar el archivo: Id = 0";
                }
            }
            catch (Exception ex)
            {
                error += "Error al eliminar el archivo: " + ex.Message;
                Debug.WriteLine(ex.ToString());
                //Utilerias.EscribirLog(rutaLog, ex.ToString());

                str.Append("0");
            }

            str.Append(",");
            str.Append("\"Error\":");
            str.Append("\"" + error + "\"");
            str.Append("}");

            Debug.WriteLine("str: " + str.ToString());

            return(Json(str.ToString(), JsonRequestBehavior.AllowGet));
        }
Example #6
0
        public ActionResult Editar(Documento doc, HttpPostedFileBase archivo)
        {
            string rutaLog = HttpContext.Server.MapPath("/App_Data/Log.txt");

            //Utilerias.EscribirLog(rutaLog, "Usuario: " + Sesion.Current.Usuario.Nombre + " quiere editar archivo con id: " + doc.IdDocumento + ".");

            ViewBag.Departamento = new PerDepartamento().ObtenerActivos();
            ViewBag.Area         = new PerArea().ObtenerActivasDepartamento(0, doc.IdDepartamento.GetValueOrDefault());

            ActionResult ar = RedirectToAction("Index");

            var job = new JObject();

            job["Error"]   = true;
            job["Clase"]   = this.GetType().Name;
            job["Metodo"]  = System.Reflection.MethodBase.GetCurrentMethod().Name;
            job["Mensaje"] = "";

            if (archivo == null || archivo.ContentLength == 0)
            {
                job["Mensaje"]    += "Error al subir el archivo: El archivo esta vacío";
                ViewBag.validacion = job;
                ar = View(doc);

                return(ar);
            }

            if (doc != null)
            {
                // Insertar físicamente el archivo en la carpeta correspondiente y hacer commit.
                try
                {
                    // Se supone que las carpetas ya están creadas.
                    Departamento depa = new PerDepartamento().Obtener(doc.IdDepartamento.GetValueOrDefault());
                    Area         area = new PerArea().Obtener(doc.IdArea.GetValueOrDefault());

                    string depaArea = @"\" + depa.Nombre + @"\" + area.Nombre;
                    string ruta     = UtilSVN.ObtenerRutaCopiaTrabajo() + depaArea;

                    string nombreArchivo = Path.GetFileName(archivo.FileName);
                    ruta = Path.Combine(ruta, nombreArchivo);

                    // Obtener el usuario logueado.
                    var usr = Sesion.Current.Usuario;

                    // Borrar el archivo para poder poner el reemplazo.
                    System.IO.File.Delete(ruta);

                    // Guardar en el servidor.
                    archivo.SaveAs(ruta);

                    string msjActualizarArchivo = UtilSVN.ActualizarArchivo(depaArea + nombreArchivo, usr.Nombre);

                    if (msjActualizarArchivo == "Exito")
                    {
                        doc.Nombre = nombreArchivo;
                        doc.Ruta   = ruta;

                        // Editar registro en la BD.
                        new PerDocumento().Editar(doc);

                        job["Error"] = false;
                    }
                    else
                    {
                        job["Mensaje"] += msjActualizarArchivo;
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.ToString());
                    //Utilerias.EscribirLog(rutaLog, ex.ToString());

                    job["Mensaje"] += "Error al subir el archivo: " + ex.Message;

                    if (ex.InnerException != null)
                    {
                        job["Mensaje"] += " " + ex.InnerException.Message;
                    }

                    ViewBag.validacion = job;
                    ar = View(doc);
                }
            }

            return(ar);
        }
Example #7
0
        public ActionResult Nuevo(Documento doc, HttpPostedFileBase archivo)
        {
            string rutaLog = HttpContext.Server.MapPath("/App_Data/Log.txt");

            //Utilerias.EscribirLog(rutaLog, "Usuario: " + Sesion.Current.Usuario.Nombre + " quiere crear un nuevo archivo.");

            ViewBag.Departamento = new PerDepartamento().ObtenerActivos();
            ViewBag.Area         = null;

            ActionResult ar = RedirectToAction("Index");

            var job = new JObject();

            job["Error"]   = true;
            job["Clase"]   = this.GetType().Name;
            job["Metodo"]  = System.Reflection.MethodBase.GetCurrentMethod().Name;
            job["Mensaje"] = "";

            if (archivo == null || archivo.ContentLength == 0)
            {
                job["Mensaje"]    += "Error al subir el archivo: El archivo esta vacío";
                ViewBag.validacion = job;
                ar = View(doc);

                return(ar);
            }

            string nombreArchivo = Path.GetFileName(archivo.FileName);

            if (doc != null)
            {
                var error = false;

                // Checar si no existe un documento con el mismo nombre en esta area y departamento.
                var lst = new PerDocumento().ObtenerTodosArea(doc.IdArea.GetValueOrDefault());

                foreach (var documento in lst)
                {
                    if (documento.Nombre == nombreArchivo)
                    {
                        error = true;
                        break;
                    }
                }

                if (error)
                {
                    job["Mensaje"]    += "El nombre de archivo ya existe en esta área.";
                    ViewBag.validacion = job;
                    ar = View(doc);

                    return(ar);
                }

                try
                {
                    // Crear carpetas si no existen.
                    Departamento depa = new PerDepartamento().Obtener(doc.IdDepartamento.GetValueOrDefault());
                    Area         area = new PerArea().Obtener(doc.IdArea.GetValueOrDefault());

                    string depaArea = @"\" + depa.Nombre + @"\" + area.Nombre;
                    string ruta     = UtilSVN.ObtenerRutaCopiaTrabajo() + depaArea;
                    Utilerias.CrearRuta(ruta);

                    // Guardar en el servidor.
                    ruta = Path.Combine(ruta, nombreArchivo);
                    Debug.WriteLine("ruta al guardar archivo: " + ruta);
                    archivo.SaveAs(ruta);

                    // Obtener el usuario logueado
                    var usr = Sesion.Current.Usuario;

                    // Agregar archivo en el SVN.
                    string msjAgregarArchivo = UtilSVN.AgregarArchivo(depaArea + nombreArchivo, usr.Nombre);

                    if (msjAgregarArchivo == "Exito")
                    {
                        doc.Nombre = nombreArchivo;
                        doc.Ruta   = ruta;

                        // Crear UID.
                        int    conta;
                        string uid = Utilerias.CrearUID(doc.IdDepartamento.GetValueOrDefault(), doc.IdArea.GetValueOrDefault(), out conta);

                        doc.UID         = uid;
                        doc.ContadorUID = conta;

                        // Agregar registro a la BD.
                        new PerDocumento().Insertar(doc);

                        job["Error"] = false;
                    }
                    else
                    {
                        job["Mensaje"] += msjAgregarArchivo;
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.ToString());
                    //Utilerias.EscribirLog(rutaLog, ex.ToString());

                    job["Mensaje"] += "Error al subir el archivo: " + ex.Message;

                    if (ex.InnerException != null)
                    {
                        job["Mensaje"] += " " + ex.InnerException.Message;
                    }

                    ViewBag.validacion = job;
                    ar = View(doc);
                }
            }

            return(ar);
        }
Example #8
0
        public ActionResult Index(Configuracion conf)
        {
            ActionResult ar = RedirectToAction("Index");

            var job = new JObject();

            job["Error"]   = true;
            job["Clase"]   = this.GetType().Name;
            job["Metodo"]  = System.Reflection.MethodBase.GetCurrentMethod().Name;
            job["Mensaje"] = "";

            var rutaRepositorio  = conf.RutaRaiz + @"\Repositorio";
            var rutaCopiaTrabajo = conf.RutaRaiz + @"\CopiaTrabajo";

            conf.RutaRepositorio  = rutaRepositorio;
            conf.RutaCopiaTrabajo = rutaCopiaTrabajo;

            var pc = new PerConfiguracion();

            // Ya había una configuración.
            if (pc.Existe())
            {
                try
                {
                    // Obtener las rutas antiguas.
                    Configuracion config           = pc.Obtener();
                    var           rutaRepoAntigua  = config.RutaRepositorio;
                    var           rutaCopiaAntigua = config.RutaCopiaTrabajo;

                    string msjRepositorio  = UtilSVN.ActualizarRepositorio(rutaRepositorio, rutaRepoAntigua);
                    string msjCopiaTrabajo = UtilSVN.ActualizarCopiaTrabajo(rutaRepositorio, rutaCopiaTrabajo, rutaRepoAntigua, rutaCopiaAntigua);

                    if (msjRepositorio == "Exito" && msjCopiaTrabajo == "Exito")
                    {
                        pc.Editar(conf);

                        // Borrar todos los documentos que existan, para que no se mezclen los del anterior repositorio con los del nuevo en la base.
                        new PerDocumento().EliminarTodos();

                        job["Error"] = false;
                    }
                    else
                    {
                        if (msjRepositorio != "Exito")
                        {
                            job["Mensaje"] += msjRepositorio;
                        }

                        if (msjCopiaTrabajo != "Exito")
                        {
                            job["Mensaje"] += msjCopiaTrabajo;
                        }

                        ViewBag.validacion = job;
                        ar = View(conf);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.ToString());
                    job["Mensaje"] += "Error al guardar el registro: " + ex.Message;

                    if (ex.InnerException != null)
                    {
                        job["Mensaje"] += " " + ex.InnerException.Message;
                    }

                    ViewBag.validacion = job;
                    ar = View(conf);
                }
            }
            else // Se creará la configuración por primera vez.
            {
                try
                {
                    string msjRepositorio  = UtilSVN.CrearRepositorio(rutaRepositorio);
                    string msjCopiaTrabajo = UtilSVN.CrearCopiaTrabajo(rutaRepositorio, rutaCopiaTrabajo);

                    if (msjRepositorio == "Exito" && msjCopiaTrabajo == "Exito")
                    {
                        pc.Insertar(conf);
                        job["Error"] = false;
                    }
                    else
                    {
                        if (msjRepositorio != "Exito")
                        {
                            job["Mensaje"] += msjRepositorio;
                        }

                        if (msjCopiaTrabajo != "Exito")
                        {
                            job["Mensaje"] += msjCopiaTrabajo;
                        }

                        ViewBag.validacion = job;
                        ar = View(conf);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.ToString());
                    job["Mensaje"] += "Error al guardar el registro: " + ex.Message;

                    if (ex.InnerException != null)
                    {
                        job["Mensaje"] += " " + ex.InnerException.Message;
                    }

                    ViewBag.validacion = job;
                    ar = View(conf);
                }
            }

            return(ar);
        }