Exemplo n.º 1
0
 public void UncompressDirectoryFiles(string directory, Action <string> uncompress = null)
 {
     //foreach (FileInfo fileInfo in new DirectoryInfo(directory).EnumerateFiles("*.*", SearchOption.AllDirectories))
     foreach (var fileInfo in zDirectory.CreateDirectoryInfo(directory).EnumerateFiles("*.*", SearchOption.AllDirectories))
     {
         //if (CompressManager.IsCompressFile(fileInfo.Name))
         if (_compressManager.IsCompressFile(fileInfo.Name))
         {
             if (uncompress != null)
             {
                 uncompress(fileInfo.FullName);
             }
             Uncompress(fileInfo.FullName);
         }
     }
 }
Exemplo n.º 2
0
        private void EndDownloadFile(DownloadFile_v1 <TKey> downloadFile)
        {
            try
            {
                DownloadedFile_v1 <TKey> downloadedFile = new DownloadedFile_v1 <TKey>
                {
                    key               = downloadFile.key,
                    downloadLinks     = downloadFile.downloadLinks,
                    downloadLink      = downloadFile.downloadLink,
                    file              = downloadFile.file,
                    state             = downloadFile.state,
                    requestTime       = downloadFile.requestTime,
                    startDownloadTime = downloadFile.startDownloadTime,
                    endDownloadTime   = DateTime.Now,
                    downloadDuration  = DateTime.Now - downloadFile.startDownloadTime
                };
                string downloadedPath    = _downloadClient.GetDownloadLocalFileById(downloadFile.downloadId);
                string downloadDirectory = zPath.GetDirectoryName(downloadFile.file);
                //if (_trace)
                //{
                //    pb.Trace.WriteLine("ManageEndDownloadFiles()                      : downloadFile.file : \"{0}\"", downloadFile.file);
                //    pb.Trace.WriteLine("ManageEndDownloadFiles()                      : _downloadClient.GetDownloadLocalFileById() : \"{0}\"", downloadedPath);
                //}
                downloadedFile.downloadedFile = zpath.PathSetDirectory(downloadedPath, downloadDirectory);
                downloadedFile.id             = _mongoDownloadedFileManager.GetNewId();

                _mongoDownloadedFileManager.Save(downloadedFile.id, downloadedFile);
                _mongoQueueDownloadFileManager.Remove(downloadFile.id);
                _downloadClient.RemoveDownloadById(downloadFile.downloadId);

                // _uncompressFile
                if (downloadFile.state == DownloadState.DownloadCompleted && _uncompressManager != null && CompressManager.IsCompressFile(downloadedPath))
                {
                    TaskManager.AddTask(new Task
                    {
                        name = "Uncompress download file",
                        task = () =>
                        {
                            UncompressFile(downloadedPath, downloadedFile, downloadDirectory);
                            _mongoDownloadedFileManager.Save(downloadedFile.id, downloadedFile);
                        }
                    });
                    if (_onDownloaded != null)
                    {
                        TaskManager.AddTask(new Task {
                            name = "onDownloaded", task = () => _onDownloaded(downloadedFile)
                        });
                    }
                }
                else if (_onDownloaded != null)
                {
                    _onDownloaded(downloadedFile);
                }

                DownloadFile_v1 <TKey> downloadFile2;
                if (!_downloadFiles.TryRemove(downloadFile.id, out downloadFile2))
                {
                    pb.Trace.WriteLine("error unable to remove downloadFile with id {0} from ConcurrentDictionary _downloadFiles (DownloadManager<TKey>.ManageEndDownloadFiles())", downloadFile.id);
                }
            }
            catch (Exception exception)
            {
                pb.Trace.WriteLine("error in DownloadManager_v1.EndDownloadFile() : {0}", exception.Message);
                pb.Trace.WriteLine(exception.StackTrace);
            }
        }