public async Task <FileInfoList> GenerateAsync() { List <string> itemsLegacy = new List <string>(); List <FileSendInfo> items = new List <FileSendInfo>(); foreach (var item in files) { var key = item.UniqueKey; var stats = await item.File.GetFileStats(); itemsLegacy.Add(GetQueueFileInfoLegacy(key, item.SlicesCount, item.FileName, stats, item.RelativePath)); items.Add(item); } var infoList = new QueueInfo { Files = items, }; return(new FileInfoList { FileInfoListJsonLegacy = JsonConvert.SerializeObject(itemsLegacy), FileInfoListJson = JsonConvert.SerializeObject(infoList), }); }
public FileReceiveProgressCalculator(QueueInfo queueInfo, ulong sliceMaxSize, string senderName, Guid guid) : base(sliceMaxSize, senderName, guid) { foreach (var item in queueInfo.Files) { TransferStatus.Add(item.UniqueKey, new FileTransferStatus { LastSliceSize = item.LastSliceSize, NextSlice = 0, SliceMaxSize = item.SliceMaxLength, SlicesCount = item.SlicesCount, }); } }
private async Task StartDownload(QueueInfo queueInfo, string senderName, string ip, Guid sessionKey, bool isResume, CancellationToken cancellationToken) { IFolder downloadRootFolder; if (isResume) { await DataStorageProviders.HistoryManager.OpenAsync(); downloadRootFolder = await folderResolver((DataStorageProviders.HistoryManager.GetItem(sessionKey).Data as ReceivedFileCollection).StoreRootPath); DataStorageProviders.HistoryManager.Close(); } else { downloadRootFolder = await downloadFolderDecider.DecideAsync(queueInfo.Files.Select(x => Path.GetExtension(x.FileName)).ToArray()); await AddToHistory(queueInfo, sessionKey, senderName, downloadRootFolder); } progressCalculator = new FileReceiveProgressCalculator(queueInfo, queueInfo.Files.First().SliceMaxLength, senderName, sessionKey); progressCalculator.FileTransferProgress += ProgressCalculator_FileTransferProgress; await queueInfo.Files.ParallelForEachAsync(numberOfParallelDownloads, async item => { await DownloadFile(item, downloadRootFolder, ip, sessionKey, cancellationToken); }); await DataStorageProviders.HistoryManager.OpenAsync(); DataStorageProviders.HistoryManager.ChangeCompletedStatus(sessionKey, true); DataStorageProviders.HistoryManager.Close(); await SendFinishGetRequestAsync(ip, sessionKey); FileTransferProgress?.Invoke(new FileTransfer2ProgressEventArgs { State = FileTransferState.Finished, Guid = sessionKey, TotalFiles = queueInfo.Files.Count, SenderName = senderName, }); ReceiveFinishTcs.SetResult(true); }
private static async Task AddToHistory(QueueInfo queueInfo, Guid sessionKey, string senderName, IFolder downloadRootFolder) { await DataStorageProviders.HistoryManager.OpenAsync(); DataStorageProviders.HistoryManager.Add(sessionKey, DateTime.Now, senderName, new ReceivedFileCollection { Files = queueInfo.Files.Select(x => new ReceivedFile { Name = x.FileName, OriginalName = x.FileName, Size = (long)x.FileSize, StorePath = Path.Combine(downloadRootFolder.Path, NormalizePathForCombine(x.RelativePath)), Completed = false, DownloadStarted = false, }).ToList(), StoreRootPath = downloadRootFolder.Path, }, false); DataStorageProviders.HistoryManager.Close(); }