Esempio n. 1
0
 public Task Archive(string sourcePath, string destinationPath)
 {
     return(Task.Factory.StartNew(() =>
     {
         if (File.Exists(sourcePath))
         {
             var fileName = Path.GetFileName(sourcePath);
             var folderName = Path.GetFileNameWithoutExtension(sourcePath);
             var archiveSize = FolderSizeCalculator.GetFolderSize(sourcePath);
             var folderNode = new FolderNode(folderName, archiveSize);
             folderNode.ReportArchivationProgress += ReportArchivationProgress;
             folderNode.ReportDeArchivationProgress += ReportDeArchivationProgress;
             var fileNode = new FileNode(string.Format(@"{0}\{1}", folderName, fileName), archiveSize);
             fileNode.ReportArchivationProgress += ReportArchivationProgress;
             fileNode.ReportDeArchivationProgress += ReportDeArchivationProgress;
             folderNode.AddChildNode(fileNode);
             fileNode.Load(sourcePath);
             folderNode.Serialize(destinationPath);
         }
         if (Directory.Exists(sourcePath))
         {
             var folderName = Path.GetFileName(sourcePath);
             var archiveSize = FolderSizeCalculator.GetFolderSize(sourcePath);
             var folderNode = new FolderNode(folderName, archiveSize);
             folderNode.ReportArchivationProgress += ReportArchivationProgress;
             folderNode.Load(sourcePath);
             folderNode.Serialize(destinationPath);
         }
     }));
 }
Esempio n. 2
0
        public override void Load(string filePath)
        {
            if (!File.Exists(filePath))
            {
                Console.WriteLine("This File does not exist");
                return;
            }
            var fileSize = FolderSizeCalculator.GetFileSize(filePath);

            using (var binaryFile = File.OpenRead(filePath))
            {
                _fileMemoryStream = new MemoryStream();
                binaryFile.CopyTo(_fileMemoryStream);
            }
            if (ReportArchivationProgress != null)
            {
                ReportArchivationProgress(this, new ArchivationProgressEventArgs(fileSize, _archiveSize));
            }
        }