Beispiel #1
0
        public AddingToQueueResult EnqueueMediaItem(MediaItemsListModelItem mediaItem, bool immediate, bool forceNow = false)
        {
            if (LoggedUser.Downloads.Count(queuedDownload => queuedDownload.Id == mediaItem.Id) == 0)
            {
                QueuedDownload.DownloadState initialState =
                    App.Engine.LoggedUser.Settings.AutomaticDownloads ?
                    QueuedDownload.DownloadState.Queued :
                    (immediate ? QueuedDownload.DownloadState.Queued : QueuedDownload.DownloadState.Paused);

                QueuedDownload queuedDownload = new QueuedDownload(mediaItem)
                {
                    State = initialState
                };

                using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if (isf.FileExists(Utils.MediaFilePath(LoggedUser, queuedDownload)))
                    {
                        return(AddingToQueueResult.ItemAlreadyDownloaded);
                    }
                }

                StatisticsManager.LogDownloadAdd(queuedDownload);
                LoggedUser.Downloads.Add(queuedDownload);
                _downloadEnqueuedEvent.OnNext(queuedDownload);

                if (initialState != QueuedDownload.DownloadState.Stopped)
                {
                    DownloadManager.StartDownload(queuedDownload, false, forceNow);
                }
                return(AddingToQueueResult.ItemAddedToQueue);
            }
            else if (immediate)
            {
                QueuedDownload queuedDownload = (from download in LoggedUser.Downloads where download.Id == mediaItem.Id select download).First();
                queuedDownload.State = QueuedDownload.DownloadState.Queued;
                DownloadManager.StartDownload(queuedDownload);
                return(AddingToQueueResult.DownloadItemStarted);
            }
            else
            {
                return(AddingToQueueResult.ItemAlreadyDownloaded);
            }
        }
Beispiel #2
0
 public void StartDownload(QueuedDownload download)
 {
     DownloadManager.StartDownload(download);
 }