public ActionResult Execute(IAppService app)
        {
            TempFolder.EnsureFolder();

            var tempDirectory = Path.Combine(FileUtil.MapPath(TempFolder.Folder), "Pathfinder.Exports");
            if (Directory.Exists(tempDirectory))
            {
                FileUtil.DeleteDirectory(tempDirectory, true);
            }

            Directory.CreateDirectory(tempDirectory);

            var exportFileName = Path.Combine(FileUtil.MapPath(tempDirectory), "Pathfinder.Exports.zip");
            using (var zip = new ZipWriter(exportFileName))
            {
                foreach (var index in app.Configuration.GetSubKeys("write-website-exports"))
                {
                    var entryName = app.Configuration.GetString("write-website-exports:" + index.Key + ":filename");
                    var fileKey = "write-website-exports:" + index.Key + ":";

                    var fileName = Path.Combine(tempDirectory, PathHelper.NormalizeFilePath(entryName).TrimStart('\\'));

                    Directory.CreateDirectory(Path.GetDirectoryName(fileName) ?? string.Empty);

                    WriteFile(app.Configuration, tempDirectory, fileName, fileKey);

                    zip.AddEntry(entryName, fileName);
                }
            }

            return new FilePathResult(exportFileName, "application/zip");
        }
        public void Synchronize(IConfiguration configuration, ZipWriter zip, string fileName, string configKey)
        {
            var databaseName = configuration.GetString(configKey + "database");
            var itemPath = configuration.GetString(configKey + "path");
            var fieldsToWrite = configuration.GetString(configKey + "fields").Split(Constants.Comma, StringSplitOptions.RemoveEmptyEntries).Select(f => f.Trim().ToLowerInvariant()).ToList();

            var database = Factory.GetDatabase(databaseName);

            using (new SecurityDisabler())
            {
                var item = database.GetItem(itemPath);
                if (item == null)
                {
                    return;
                }

                var writer = new StringWriter();
                var output = new XmlTextWriter(writer)
                {
                    Formatting = Formatting.Indented
                };

                WriteItem(output, item, fieldsToWrite, true);

                zip.AddEntry(fileName, Encoding.UTF8.GetBytes(writer.ToString()));
            }
        }
Esempio n. 3
0
        private static void AddFileToZip(ZipWriter zipWriter, Item image)
        {
            string      fileName    = image.Name + "." + image["extension"];
            MediaStream mediaStream = MediaManager.GetMedia(image).GetStream();

            if (mediaStream != null)
            {
                zipWriter.AddEntry(fileName, mediaStream.Stream);
            }
        }
Esempio n. 4
0
        public void AddPart(string fullName) 
        {
            if (_delegateWriter != null)
            {
                _delegateWriter.Close();
                _delegateWriter = null;
            }

            // the path separator in the package should be a forward slash
            _zipOutputStream.AddEntry(fullName.Replace('\\', '/'));
        }
Esempio n. 5
0
        public static void Add(string zipFileName, string[] entryPatterns)
        {
            string currentDirectory = Directory.GetCurrentDirectory();

            Console.WriteLine("Creating {0}", zipFileName);

            ZipWriter writer = new ZipWriter(zipFileName);

            // buffer to hold temp bytes
            byte[] buffer = new byte[4096];
            int    byteCount;

            // add files to archive
            foreach (string pattern in entryPatterns)
            {
                foreach (string path in Directory.GetFiles(currentDirectory, pattern))
                {
                    string fileName = Path.GetFileName(path);
                    Console.Write("Adding {0}", fileName);

                    ZipEntry entry = new ZipEntry(fileName);
                    entry.ModifiedTime = File.GetLastWriteTime(fileName);
                    entry.Comment      = "local file comment";

                    writer.AddEntry(entry);

                    FileStream reader = File.OpenRead(entry.Name);
                    while ((byteCount = reader.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        Console.Write(".");
                        writer.Write(buffer, 0, byteCount);
                    }
                    reader.Close();
                    Console.WriteLine();
                }
            }

            writer.Close();
        }