/// <summary> /// Останавлиает загрузку файла. /// </summary> /// <param name="file">Описание файла.</param> /// <param name="leaveLoadedPart">Если значение истино недогруженный файл не будет удалятся.</param> public void CancelDownloading(FileDescription file, bool leaveLoadedPart = true) { if (file == null) { throw new ArgumentNullException("file"); } using (var client = ClientModel.Get()) { DownloadingFile downloadingFile = client.DownloadingFiles.FirstOrDefault(current => current.File.Equals(file)); if (downloadingFile == null) { return; } string filePath = downloadingFile.FullName; downloadingFile.Dispose(); client.DownloadingFiles.Remove(downloadingFile); if (File.Exists(filePath) && !leaveLoadedPart) { File.Delete(filePath); } } }
public static IDownloadingFile ToDownloadingFile(this string jsonText, Action <IDownloaderBuilder> configure, INetDiskUser owner) { var data = jsonText.ToObject <SerializedData>(); var file = data.File; var builder = FileTransferService.GetDownloaderBuilder(); configure(builder); var downloader = builder.Build(data.DownloadInfo.ToString()); return(DownloadingFile.Create(owner, file, downloader)); }
public override IDownloadingFile Download(INetDiskFile from, FileLocator to) { var downloader = FileTransferService .GetDownloaderBuilder() .UseSixCloudConfigure() .Configure(localPath => localPath.GetUniqueLocalPath(path => File.Exists(path) || File.Exists($"{path}{ArddFileExtension}"))) .From(new RemotePathProvider(this, from.Path)) .To(Path.Combine(to, from.Path.FileName)) .Build(); var result = DownloadingFile.Create(this, from, downloader); SaveDownloadingFile(result); return(result); }
public FileData LoadServerFile(DownloadingFile fileDescr) { var systemName = string.IsNullOrEmpty(fileDescr.SystemNameString) ? fileDescr.SystemName.ToString() : fileDescr.SystemNameString; if (!folderBySystem.ContainsKey(systemName)) { if (verboseLogging) { Logger.DebugFormat("Не найдена директория для {0}", systemName); } return(null); } var sysFolder = ownFolder + folderBySystem[systemName]; var fullPath = sysFolder + "\\" + fileDescr.FilePath; var data = new FileData(fullPath); // попытка получить содержимое файла try { if (!File.Exists(fullPath)) { if (verboseLogging) { Logger.DebugFormat("Ошибка получения файла {0}, system name: {1}", fullPath, systemName); } return(null); } var fs = new FileStream(fullPath, FileMode.Open); data.FileByteStream = fs; } catch (Exception ex) { Logger.Info("LoadServerFile() - file loading error", ex); } return(data); }
protected virtual void OnDownloadingFile(object sender, Fetching.EventHandlers.DownloadingFileEventArgs e) { DownloadingFile?.Invoke(this, e); }
public void AddFileDownload(DownloadingFile file) { _downloadingFiles.Add(file.File.Id, file); }
public CommandMessage(ControlMessageType messageType, DownloadingFile targetFile, PeerConnection targetConnection) { base.targetConnection = targetConnection; base.targetFile = targetFile; }