Exemple #1
0
        //
        //	Private methods
        //

        private void DirToZipStream(
            IStorageService storage,
            string dir,
            string filter,
            QueryBlobsFilterDelegate queryFilter,
            ZipStorer zipStorer)
        {
            IEnumerable <string> storageNames = storage.QueryStorage(dir, filter);

            if (queryFilter != null)
            {
                storageNames = storageNames.
                               Where(name => {
                    bool passed = true;
                    queryFilter(name, ref passed);
                    return(passed);
                });
            }

            try
            {
                foreach (string fileName in storageNames.Select(storageName => Path.Combine(dir, storageName)))
                {
                    using (Stream readStream = new MemoryStream(storage.ReadStorage(fileName)))
                    {
                        zipStorer.AddStream(m_compression, fileName, readStream, DateTime.Now);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteException(ex);
            }
        }
Exemple #2
0
        public void ToStream(
            Stream targetStream,
            IStorageService storage,
            string path,
            string filter,
            QueryBlobsFilterDelegate queryFilter,
            bool includeSubDirs,
            DirectoryView directoryView)
        {
            // Root is always included
            var directories = new List <string> {
                path
            };

            if (includeSubDirs)
            {
                directories.AddRange(storage.QuerySubDirs(
                                         path,
                                         true, // Include subdirs
                                         directoryView));
            }

            using (var zipStorer = ZipStorer.Create(targetStream))
            {
                // Handle all subdirs
                foreach (string subDir in directories)
                {
                    // Stream directory
                    DirToZipStream(
                        storage,
                        subDir,
                        filter,
                        queryFilter,
                        zipStorer);
                }
            }
        }