private DownloadableItem GetDownloadableItem(TLInt dcId, TLInputAudioFileLocation location, TLObject owner, TLInt fileSize) { var item = new DownloadableItem { Owner = owner, DCId = dcId, InputAudioLocation = location }; item.Parts = GetItemParts(fileSize, item); return(item); }
public void DownloadFile(TLInt dcId, TLInputAudioFileLocation fileLocation, TLObject owner, TLInt fileSize) { var downloadableItem = GetDownloadableItem(dcId, fileLocation, owner, fileSize); var downloadedCount = downloadableItem.Parts.Count(x => x.Status == PartStatus.Processed); var count = downloadableItem.Parts.Count; var isComplete = downloadedCount == count; if (isComplete) { var id = downloadableItem.InputAudioLocation.Id; var accessHash = downloadableItem.InputAudioLocation.AccessHash; var fileName = string.Format("audio{0}_{1}.mp3", id, accessHash); var getPartName = new Func <DownloadablePart, string>(x => string.Format("audio{0}_{1}_{2}.dat", id, accessHash, x.Number)); FileUtils.MergePartsToFile(getPartName, downloadableItem.Parts, fileName); downloadableItem.IsoFileName = fileName; _eventAggregator.Publish(downloadableItem); } else { lock (_itemsSyncRoot) { bool addFile = true; foreach (var item in _items) { if (item.InputAudioLocation.AccessHash.Value == fileLocation.AccessHash.Value && item.InputAudioLocation.Id.Value == fileLocation.Id.Value && item.Owner == owner) { addFile = false; break; } } if (addFile) { _items.Add(downloadableItem); } } StartAwaitingWorkers(); } }