public virtual Task RemoveAllTransfers() { DownloadDataContext.Clear(); foreach (var transfer in BackgroundTransferService.Requests) { RemoveTransfer(transfer); } return(UpdateTransfersList()); }
/// <summary> /// Initializes failsafe parts of the app. /// /// Safe to call from App.xaml.cs constructor. /// </summary> public static void Start() { ProviderService.Instance.Register(new PhoneProvider()); Application.Current.Host.Settings.EnableFrameRateCounter = false; FileUtils.CreateDirIfNotExists(PhoneLocalLibrary.Instance.BaseMusicPath); FileUtils.CreateDirIfNotExists(PhoneCoverService.CoverFolder); // initializes the database if it doesn't exist MusicDataContext.CreateIfNotExists(); DownloadDataContext.CreateIfNotExists(); UiService.Instance.SetUiUtils(PhoneUtil.Instance); }
/// <summary> /// Downloads the song in the background if it's not already available offline. /// </summary> /// <param name="track"></param> public async Task SubmitDownload(MusicItem track) { await BeforeDownload(track); try { var maybeLocalUri = await PhoneLocalLibrary.Instance.LocalUriIfExists(track); if (maybeLocalUri == null) { // For Subsonic, the response may be transcoded audio, in which case the // path to the track, which has the original file extension as stored on // the server, may be incorrect (example: response is transcoded to .mp3, // path is .flac). // TODO: Ensure that the file is stored locally with the correct extension, // that is, find out whether the response is transcoded. var destination = LocalLibrary.AbsolutePathTo(track); var downloadUri = MusicProvider.DownloadUriFor(track); // Only downloads tracks that are stored as MP3s, because this app does not support other local file formats. if (destination.EndsWith("mp3")) { var downloadable = new Downloadable(downloadUri, destination); if (LoadTransfersCount() < 3) { AddTransfer(downloadUri, destination); } else { // add the download to persistent storage from which it will be taken // later when there are fewer concurrent downloads DownloadDataContext.Add(downloadable); } } } } catch (PathTooLongException) { // Thrown if track.Path is about over 190 characters long, but I'm not sure what // the limit is and I don't want to be too defensive with this so I catch and // suppress the exception when it occurs. // The exception says "The specified path, file name, or both are too long. // The fully qualified file name must be less than 260 characters, and the // directory name must be less than 248 characters.", however, I don't know // the length of the fully qualified path name, so 190 chars is an estimate. AddMessage("Download of " + track.Name + " failed. The path is too long: " + track.Path); } }
protected void LoadTransfersFromPersistentStorage() { // Initializing downloads eats a lot of CPU, so I only add 3 at a time if (LoadTransfersCount() < 3) { var downloadables = DownloadDataContext.Pop(3); //Debug.WriteLine("Downloading " + downloadables.Count + " more files..."); foreach (var item in downloadables) { AddTransfer(item.Source, item.Destination); } } // downloading 25 files concurrently is very expensive it seems... //var canTake = Math.Max(25 - LoadTransfersCount(), 0); //var downloadables = DownloadDataContext.Pop(canTake); //Debug.WriteLine("Downloading " + downloadables.Count + " more files..."); //foreach (var item in downloadables) { // AddTransfer(item.Source, item.Destination); //} }
public async Task SubmitDownloads(IEnumerable <MusicItem> tracks) { await BeforeDownload(tracks); try { var remoteTracks = await tracks.FilterAsync(async track => await PhoneLocalLibrary.Instance.LocalUriIfExists(track) == null); var downloadables = remoteTracks .Select(track => new Downloadable(MusicProvider.DownloadUriFor(track), LocalLibrary.AbsolutePathTo(track))) .Where(d => d.Destination.EndsWith("mp3")) .ToList(); var transfers = LoadTransfersCount(); var queueables = (transfers < 3 ? downloadables.Skip(3) : downloadables).ToList(); if (transfers < 3) { foreach (var dl in downloadables.Take(3).ToList()) { AddTransfer(dl.Source, dl.Destination); } } if (queueables.Count > 0) { // add the download to persistent storage from which it will be taken // later when there are fewer concurrent downloads DownloadDataContext.AddAll(queueables); } } catch (PathTooLongException) { // Thrown if track.Path is about over 190 characters long, but I'm not sure what // the limit is and I don't want to be too defensive with this so I catch and // suppress the exception when it occurs. // The exception says "The specified path, file name, or both are too long. // The fully qualified file name must be less than 260 characters, and the // directory name must be less than 248 characters.", however, I don't know // the length of the fully qualified path name, so 190 chars is an estimate. AddMessage("Unable to submit all tracks for download. A file path was too long."); } }