public async void Extract(ZipItem item)
    {
        if (!string.IsNullOrEmpty(_token))
        {
            StorageFile file = await _access.GetFileAsync(_token);

            if (file != null)
            {
                using (Stream stream = await file.OpenStreamForReadAsync())
                {
                    using (ZipArchive archive = new ZipArchive(stream, ZipArchiveMode.Read))
                    {
                        ZipArchiveEntry entry = archive.GetEntry(item.Name);
                        if (entry != null)
                        {
                            StorageFile source = await SaveFileAsync(entry.Name, Path.GetExtension(entry.Name), desc_file);

                            if (source != null)
                            {
                                using (Stream output = await source.OpenStreamForWriteAsync())
                                {
                                    await entry.Open().CopyToAsync(output);

                                    await output.FlushAsync();
                                }
                            }
                        }
                    }
                }
            }
        }
    }
        private async Task <MessageResult> Extract(ZipItem zipItem, MessageResult skip = MessageResult.No)
        {
            if (skip != MessageResult.No)
            {
                return(skip);
            }

            if (zipItem.EncryptionType != EncryptionType.None)
            {
                zipItem.Password = Password;
            }

            try
            {
                await Task.Run(() => zipItem.Extract(FilePath));

                Progress += zipItem.UncompressedSize;
            }
            catch (WrongPasswordException)
            {
                skip = MessageBoxService.ShowMessage(String.Format("{0}\r\n\r\n{1}", Properties.Resources.WrongPasswordMessage, zipItem.Name),
                                                     Properties.Resources.WrongPassword, MessageButton.YesNoCancel, MessageIcon.Error);

                if (skip == MessageResult.No)
                {
                    MessageResult result = DialogService.ShowDialog(MessageButton.OKCancel, Properties.Resources.WrongPassword, this);
                    skip = result == MessageResult.OK ? MessageResult.No : MessageResult.Cancel;
                }

                await Extract(zipItem, skip);
            }

            return(skip);
        }
示例#3
0
        private void SearchFiles(string dirOrFile, List <ZipItem> items)
        {
            if (File.Exists(dirOrFile))
            {
                var item = new ZipItem
                {
                    Filename = dirOrFile
                };
                items.Add(item);
            }
            else if (Directory.Exists(dirOrFile))
            {
                var files = Directory.GetFiles(dirOrFile);
                for (var i = 0; i < files.Length; i++)
                {
                    var file = files[i];
                    var item = new ZipItem
                    {
                        Filename = file
                    };
                    items.Add(item);
                }

                var dirs = Directory.GetDirectories(dirOrFile);
                SearchFiles(dirs, items);
            }
        }
示例#4
0
        private static void ZipFolder(List <ZipItem> items, string sourceFolderPath, string currentFolderPath)
        {
            var files   = Directory.GetFiles(currentFolderPath);
            var folders = Directory.GetDirectories(currentFolderPath);

            foreach (var folderPath in folders)
            {
                var folderName = folderPath.Replace(sourceFolderPath + "\\", string.Empty);

                var newEntity = new ZipItem
                {
                    Name = folderName
                };

                items.Add(newEntity);

                ZipFolder(items, sourceFolderPath, folderPath);
            }

            foreach (var filePath in files)
            {
                var fileName = filePath.Replace(sourceFolderPath + "\\", string.Empty);

                var newEntity = new ZipItem
                {
                    Name    = fileName,
                    Content = File.ReadAllBytes(filePath)
                };

                items.Add(newEntity);
            }
        }
        public IActionResult GenerateDocument([Bind("DocId, InputText, OutputType")] SvgDocumentForm svgDocument)
        {
            Dictionary <string, string[]> jsonInput;
            int documentId = svgDocument.DocId;

            try
            {
                jsonInput = DataExtractor.GetJsonData(svgDocument.InputText);
            }
            catch (Exception e)
            {
                var error = e.Message;
                return(Content(error));
            }

            var document = _context.SvgDocuments.Find(documentId);

            string path = _hostingEnvironment.WebRootPath + document.DocumentPath;

            int            max         = jsonInput.First().Value.Length;
            int            index       = 0;
            List <ZipItem> outputFiles = new List <ZipItem>();


            foreach (var item in jsonInput)
            {
                int currentLength = item.Value.Length;
                if (currentLength != max)
                {
                    var error = "Value array error in column: " + item.Key + ". Expected length: " + max
                                + ", current length: " + currentLength;
                    return(Content(error));
                }
            }

            for (int i = 0; i < max; i++)
            {
                SvgDocumentEditModel model = new SvgDocumentEditModel()
                {
                    TemplateDocumentPath    = path,
                    ElementName             = "text",
                    Attribute               = "id",
                    ValueIndex              = index,
                    ElementsForSubstitution = jsonInput
                };
                index++;

                MemoryStream readySvgDocument = SvgEditor.GenerateSvgDocument(model);
                //MemoryStream jpegDocument = SvgEditor.SvgToJpeg(readySvgDocument);
                ZipItem zipItem = new ZipItem("Document" + index + ".svg", readySvgDocument);
                outputFiles.Add(zipItem);
                //jpegDocument.Close();
                //readySvgDocument.Close();
            }

            var resultZip = Zipper.Zip(outputFiles);

            return(File(resultZip, "application/octet-stream", "Documents.zip"));
        }
        public async Task <IActionResult> Descargar(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            Solicitud solicitud = await _context.Solicitud
                                  .FirstOrDefaultAsync(m => m.SolicitudId == id);

            var matricula = await _context.PDF
                            .FirstOrDefaultAsync(m => m.ID_PDF == solicitud.InformeDeMatricula);

            var expediente = await _context.PDF
                             .FirstOrDefaultAsync(m => m.ID_PDF == solicitud.ExpedienteAcademico);

            var fotocopia = await _context.PDF
                            .FirstOrDefaultAsync(m => m.ID_PDF == solicitud.FotocopiaCedula);

            List <ZipItem> archivos         = new List <ZipItem>();
            ZipItem        archivoMatricula = new ZipItem(solicitud.Carne + " matricula.pdf", matricula.PDF_File);

            archivos.Add(archivoMatricula);
            archivos.Add(new ZipItem(solicitud.Carne + " expediente.pdf", expediente.PDF_File));
            archivos.Add(new ZipItem(solicitud.Carne + " fotocopia.pdf", fotocopia.PDF_File));

            string csv = "Carné, Nombre, Primer Apellido, Segundo Apellido, Promedio, Cédula, Teléfono 1, Teléfono 2, Correo, Carrera, Nivel, Número " +
                         "de créditos, Promedia, Cuenta Bancaria, Banco, Número de Cuenta, Asistenca, Tiene Horas Asistente en otra unidad, Cantidad de Horas Asistente, " +
                         "Tiene Horas Estudiantes en otra unidad, Cantidad de Horas Estudiante\n";

            csv += solicitud.Carne + " ," + solicitud.Nombre + " ," + solicitud.Apellido1 + " ," + solicitud.Apellido2 + " ," + solicitud.Promedio + " ," +
                   solicitud.Cedula + " ," + solicitud.Telefono1 + " ," + solicitud.Telefono2 + " ," + solicitud.CorreoSolicitante + " ," + solicitud.CarreraQueCursa + " ," +
                   solicitud.Nivel + " ," + solicitud.NumeroDeCreditos + " ," + solicitud.Promedio + " ," + solicitud.CuentaBancaria + " ," + solicitud.Banco + " ," + solicitud.NumeroDeCuenta +
                   " ," + solicitud.Asistencia + " ," + solicitud.TieneHA + " ," + solicitud.CantidadHA + " ," + solicitud.TieneHE + " ," + solicitud.CantidadHE + "\n";

            Encoding encoding = Encoding.ASCII;

            archivos.Add(new ZipItem(solicitud.Carne + ".csv", csv, encoding));

            var zipStream = new MemoryStream();

            using (var zip = new ZipArchive(zipStream, ZipArchiveMode.Create, true))
            {
                foreach (var zipItem in archivos)
                {
                    var entry = zip.CreateEntry(zipItem.Name);
                    using (var entryStream = entry.Open())
                    {
                        zipItem.Content.CopyTo(entryStream);
                    }
                }
            }
            zipStream.Position = 0;
            FileStreamResult file = File(zipStream, "application/octet-stream");

            file.FileDownloadName = solicitud.Carne + ".zip";
            return(file);
        }
示例#7
0
        public ZipItemModel(ZipItem zipItem)
        {
            ZipItem = zipItem;
            Icon    = zipItem.Attributes.HasFlag(FileAttributes.Directory) ? Folder : FileSystemImageHelper.GetImage(zipItem.Name, IconSize.Small);

            string[] items = zipItem.Name.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

            Name   = items.Last();
            Path   = String.Join("/", items);
            Parent = String.Join("/", items.Take(items.Length - 1));
        }
示例#8
0
 public static System.Device.Location.GeoCoordinate GetLatLong(int zip)
 {
     foreach (string s in System.IO.File.ReadLines("zipcode.csv"))
     {
         ZipItem z = new ZipItem(s);
         if (z.HasValue && z.ZipCode == zip)
         {
             return(new System.Device.Location.GeoCoordinate(z.Latitude, z.Longitude));
         }
         ;
     }
     return(new System.Device.Location.GeoCoordinate());
 }
    public async Task <List <ZipItem> > RemoveAsync(ZipItem item)
    {
        if (!string.IsNullOrEmpty(_token))
        {
            StorageFile file = await _access.GetFileAsync(_token);

            if (file != null)
            {
                using (Stream stream = await file.OpenStreamForWriteAsync())
                {
                    using (ZipArchive zipArchive = new ZipArchive(stream, ZipArchiveMode.Update))
                    {
                        ZipArchiveEntry entry = zipArchive.GetEntry(item.Name);
                        if (entry != null)
                        {
                            entry.Delete();
                        }
                    }
                }
                return(await List());
            }
        }
        return(null);
    }
示例#10
0
 public ZipItem FetchDetails(ZipItem item)
 {
     return item;
 }
示例#11
0
 public void DoAction(ZipItem item)
 {
 }
        private async void Remove_Click(object sender, RoutedEventArgs e)
        {
            ZipItem item = (ZipItem)((AppBarButton)sender).Tag;

            Display.ItemsSource = await library.RemoveAsync(item);
        }
        private void Extract_Click(object sender, RoutedEventArgs e)
        {
            ZipItem item = (ZipItem)((AppBarButton)sender).Tag;

            library.Extract(item);
        }