Beispiel #1
0
        public static void SaveImagenes(IDictionary <string, KeyValuePair <string, bool> > data, IList <string> carpetasBorradas)
        {
            string root            = ConfigurationHelper.DirectorioImagenesRoot;
            var    nuevos          = data.Where(m => m.Value.Value).ToList();
            var    actualizaciones = data.Where(m => !m.Value.Value).ToList();
            var    imagenes        = ListImagesInFolder(root);

            foreach (var item in nuevos)
            {
                string directorio = item.Value.Key.Replace("_", "/");

                string    keyImagenMiniatura = item.Key + ConfigurationHelper.ImagenMiniatura;
                CacheItem imagen             = GetFileFromCache(Ticket.Create(item.Key));
                byte[]    imagenMiniatura    = GetFileContentFromCache(keyImagenMiniatura);
                byte[]    imagenNormalizada  = ImageHelper.NormalizeImage(imagen.Content, ConfigurationHelper.ImagenAnchoMax);

                if (!item.Value.Key.Equals("Papelera"))
                {
                    SaveFile(item.Key, imagenNormalizada, imagen.ContentType, directorio, imagen.Extension);
                    SaveFile(keyImagenMiniatura, imagenMiniatura, imagen.ContentType, directorio, imagen.Extension);
                }
            }

            foreach (var item in actualizaciones)
            {
                string keyImagenMiniatura = item.Key;
                string directoryOrigen    = imagenes.FirstOrDefault(m => m.Contains(keyImagenMiniatura));
                directoryOrigen = HostingEnvironment.MapPath("~/" + directoryOrigen);
                FileStream file = File.Open(directoryOrigen, FileMode.Open);

                string extension = string.Empty;
                directoryOrigen = GetFileWithoutExtension(file.Name, out extension).Replace(keyImagenMiniatura, string.Empty);
                string fileNameMinuatura = keyImagenMiniatura + "." + extension;
                string fileName          = fileNameMinuatura.Replace(ConfigurationHelper.ImagenMiniatura, string.Empty);
                file.Close();

                if (item.Value.Key.Equals("Papelera"))
                {
                    File.Delete(directoryOrigen + fileName);
                    File.Delete(directoryOrigen + fileNameMinuatura);
                }
                else
                {
                    string directorio = IOHelper.GetDiskLocation("~/" + item.Value.Key.Replace("_", "/"));

                    File.Move(directoryOrigen + fileName, IOHelper.ConbinePath(directorio, fileName));
                    File.Move(directoryOrigen + fileNameMinuatura, IOHelper.ConbinePath(directorio, fileNameMinuatura));
                }
            }

            foreach (var carpeta in carpetasBorradas)
            {
                Directory.Delete(IOHelper.GetDiskLocation(carpeta), true);
            }
        }
Beispiel #2
0
        public static string SaveFile(string name, byte[] fileContent, string contentType, string directorio, string extension)
        {
            string folder = IOHelper.GetDiskLocation(directorio);

            IOHelper.CheckAndCreateFolder(folder);

            string path = IOHelper.ConbinePath(folder, name + "." + extension);

            FileSystemFile.Save(new Archivo(name, name, fileContent, contentType, extension), path);

            return(path);
        }
Beispiel #3
0
        public static string SaveFile(Ticket ticket, byte[] fileContent, string directorio)
        {
            string folder = IOHelper.GetDiskLocation(directorio);

            IOHelper.CheckAndCreateFolder(folder);

            var    item      = GetFileFromCache(ticket);
            var    aux       = item.Name.Split('.');
            string extension = aux[aux.Length - 1];
            string path      = IOHelper.ConbinePath(folder, ticket.Value + "." + extension);

            string fullPath = directorio + "/" + ticket.Value + "." + extension;

            FileSystemFile.Save(new Archivo(item.Name, item.Description, fileContent, item.ContentType, extension), path);

            return(fullPath);
        }
Beispiel #4
0
        public static void ImportarBiblia(CacheItem cacheItem)
        {
            string tempFolder = IOHelper.GetDiskLocation(ConfigurationHelper.DirectorioBiblias);

            IOHelper.CheckAndCreateFolder(tempFolder);

            MemoryStream stream = new MemoryStream(cacheItem.Content);

            ZipFile file = ZipFile.Read(stream);

            string fileName = IOHelper.ConbinePath(tempFolder, file.Entries.First().FileName);

            LoggingComponent.LogInfo("Extrayendo biblia en directorio " + tempFolder);
            file.Extract(file.Entries.First().FileName, tempFolder, true);

            LoggingComponent.LogInfo("Comenzando importacion a la base");
            BibliaMapper.ImportarBiblia(fileName);
        }