Esempio n. 1
0
        public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
        {
            var id         = intent.GetIntExtra("id", 0);
            var url        = intent.GetStringExtra("url");
            var filePath   = intent.GetStringExtra("filePath");
            var iQueueType = intent.GetIntExtra("queueType", 0);

            QueueType queueType = ConvertIntToQueueType(iQueueType);

            Task.Run(() => {
                var imageHelper = new DownloadHelper();
                imageHelper.DownloadFileAsync(url, filePath)
                .ContinueWith(fp => {
                    var message = new DownloadFinishedMessage
                    {
                        Id        = id,
                        Url       = url,
                        FilePath  = fp.Result,
                        QueueType = queueType
                    };
                    MessagingCenter.Send(message, "DownloadFinishedMessage");
                });
            });

            return(StartCommandResult.Sticky);
        }
Esempio n. 2
0
        private async Task PodcastFileCompletedAsync(DownloadFinishedMessage message)
        {
            try
            {
                //refetch rssEpisode in case it's different from the currently viewed one
                var episode = await DataStore.GetEpisodeItemByIdAsync(message.Id);

                if (episode != null)
                {
                    episode.IsPlaying             = IsPlayingEnum.NotStarted;
                    episode.IsDownloaded          = IsDownloadedEnum.Downloaded;
                    episode.PlayPauseDownloadIcon = IconFont.PlayArrow;
                    RssEpisodeManager.UpdateRssEpisodeWithFileInfo(ref episode);
                    //save download status to the database
                    var resultSave = await DataStore.SaveEpisodeItemAsync(episode, true); //returns the number of items changed

                    if (resultSave != 1)
                    {
                        Debug.WriteLine("DownloadService.PodcastFileCompletedAsync Could not Update episode");
                    }
                }
                else
                {
                    Debug.WriteLine("DownloadService.PodcastFileCompletedAsync episode was null from GetEpisodeItemByIdAsync");
                }
                _downloadStatus = DownloadStatus.NotStarted;
                await StartDownloadAsync(); //start next download
            }
            catch (Exception ex)
            {
                Debug.WriteLine("DownloadService.PodcastFileCompletedAsync Error " + ex.Message);
            }
        }
Esempio n. 3
0
        private async Task DownloadFinishedAsync(DownloadFinishedMessage message)
        {
            _downloadStatus = DownloadStatus.DownloadFinished;
            var stopMessage = new StopLongRunningTaskMessage();

            MessagingCenter.Send(stopMessage, "StopLongRunningTaskMessage"); //stop downloads

            var isSuccessful = System.IO.File.Exists(message.FilePath);

            if (message.Id > 0 && isSuccessful)
            {
                switch (message.QueueType)
                {
                case QueueType.PodcastFile:
                    await PodcastFileCompletedAsync(message);

                    break;

                case QueueType.ImageFile:
                    await ImageFileCompletedAsync(message);

                    break;

                case QueueType.RssFeed:
                    await RssFeedFileCompletedAsync(message);

                    break;
                }
            }
            else
            {
                Debug.WriteLine("DownloadService.DownloadFinishedAsync message.Id <= 0 or !isSuccessful");
            }
        }
        public override void DidFinishDownloading(NSUrlSession session, NSUrlSessionDownloadTask downloadTask, NSUrl location)
        {
            CopyDownloadedImage(location);

            var message = new DownloadFinishedMessage()
            {
                FilePath = targetFileName,
                Url      = downloadTask.OriginalRequest.Url.AbsoluteString
            };

            MessagingCenter.Send <DownloadFinishedMessage> (message, "DownloadFinishedMessage");
        }
Esempio n. 5
0
 private async Task RssFeedFileCompletedAsync(DownloadFinishedMessage message)
 {
     try
     {
         //nothing in particular to do
         _downloadStatus = DownloadStatus.NotStarted;
         await StartDownloadAsync(); //start next download
     }
     catch (Exception ex)
     {
         Debug.WriteLine("DownloadService.RssFeedFileCompletedAsync Error " + ex.Message);
     }
 }
        public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
        {
            var url = intent.GetStringExtra("url");

            Task.Run(() => {
                var imageHelper = new ImageHelper();
                imageHelper.DownloadImageAsync(url)
                .ContinueWith(filePath => {
                    var message = new DownloadFinishedMessage {
                        FilePath = filePath.Result
                    };
                    MessagingCenter.Send(message, "DownloadFinishedMessage");
                });
            });

            return(StartCommandResult.Sticky);
        }