Inheritance: MediaViewModel
Example #1
0
        private async Task<List<ViewedVideoViewModel>> GetRecentMedia()
        {
            var viewedVideos = new List<ViewedVideoViewModel>();
            var badTokens = new List<string>();
            var max = 4;
            for (int i = 0; i < max; i++)
            {
                if (!_historyService.IsAudioAtPosition(i))
                {
                    try
                    {
                        var token = _historyService.GetTokenAtPosition(i);
                        if (string.IsNullOrEmpty(token))
                            continue;

                        StorageFile file = null;
                        var fileException = false;
                        if (!string.IsNullOrEmpty(token))
                        {
                            try
                            {
                                file = await _historyService.RetrieveFile(token);
                            }
                            catch (System.IO.FileNotFoundException)
                            {
                                fileException = true;
                            }
                        }

                        if (file == null || fileException)
                        {
                            badTokens.Add(token);
                            max++;
                            continue;
                        }

                        var video = new ViewedVideoViewModel(token, file);
                        await video.Initialize();
                        viewedVideos.Add(video);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("Couldn't load file from history, we may no longer have acces to it.");
                        Debug.WriteLine(ex.ToString());
                    }
                }
            }

            if (badTokens.Any())
            {
                foreach (var token in badTokens)
                    await _historyService.RemoveToken(token);
            }

            return viewedVideos;
        }
Example #2
0
        private async Task <List <ViewedVideoViewModel> > GetRecentMedia()
        {
            var viewedVideos = new List <ViewedVideoViewModel>();
            var badTokens    = new List <string>();
            var max          = 4;

            for (int i = 0; i < max; i++)
            {
                if (!_historyService.IsAudioAtPosition(i))
                {
                    try
                    {
                        var token = _historyService.GetTokenAtPosition(i);
                        if (string.IsNullOrEmpty(token))
                        {
                            continue;
                        }

                        StorageFile file          = null;
                        var         fileException = false;
                        if (!string.IsNullOrEmpty(token))
                        {
                            try
                            {
                                file = await _historyService.RetrieveFile(token);
                            }
                            catch (System.IO.FileNotFoundException)
                            {
                                fileException = true;
                            }
                        }

                        if (file == null || fileException)
                        {
                            badTokens.Add(token);
                            max++;
                            continue;
                        }

                        var video = new ViewedVideoViewModel(token, file);
                        await video.Initialize();

                        viewedVideos.Add(video);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("Couldn't load file from history, we may no longer have acces to it.");
                        Debug.WriteLine(ex.ToString());
                    }
                }
            }

            if (badTokens.Any())
            {
                foreach (var token in badTokens)
                {
                    await _historyService.RemoveToken(token);
                }
            }

            return(viewedVideos);
        }