Exemple #1
0
        public async Task <List <YoutubeDataItem> > GetRandomFromHistory(string grouping, int howMany = 5)
        {
            List <YoutubeDataItem> ret = new List <YoutubeDataItem>();

            try
            {
                LoggingService.LogInformation("RandomUserFavourites5'", "YouTubeService.RandomUserFavourites5");

                var found = AppDatabase.Current.RetrieveYoutubeHistoryItemByGrouping(grouping);
                if (found != null && found.Count > 0)
                {
                    Random rnd            = new Random();
                    var    randomizedList = from item in found.ToList()
                                            orderby rnd.Next()
                                            select item;

                    foreach (var item in randomizedList.Take(howMany))
                    {
                        var ytdi = new YoutubeDataItem(item.Uid, item.Title, item.Subtitle, item.ImagePath, item.Description, item.VideoId, null, localID: item.Id.ToString());
                        ytdi._Grouping = grouping;
                        ret.Add(ytdi);
                    }
                }
            }
            catch (Exception ex)
            {
                AlertService.LogAlertMessage("Error retrieving History from Cache", ex.Message);
            }

            return(ret);
        }
Exemple #2
0
        public async Task <YoutubeDataItem> GetFromHistory(string id)
        {
            YoutubeDataItem ret = null;

            try
            {
                LoggingService.LogInformation("GetFromHistory'", "YouTubeService.GetFromHistory");

                var found = AppDatabase.Current.RetrieveYoutubeHistoryItemByID(id);
                if (found != null && found.Count > 0)
                {
                    var item = found.First();

                    var ytdi = new YoutubeDataItem(item.Uid, item.Title, item.Subtitle, item.ImagePath, item.Description, item.VideoId, null);
                    ret = ytdi;
                }
            }
            catch (Exception ex)
            {
                AlertService.LogAlertMessage("Error retrieving History from Cache", ex.Message);
            }

            return(ret);
        }
Exemple #3
0
        public async Task RefreshHistoryDataFromCache(string grouping)
        {
            try
            {
                //await Task.Run(() =>
                //{
                //await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
                //{

                LoggingService.LogInformation("RefreshDataFromCache'", "YouTubeService.RefreshDataFromCache");

                var foundPlaying = StandardFeedResults.Where(x => !string.IsNullOrEmpty(x.UIStateFull));


                if (foundPlaying != null & foundPlaying.Count() > 0)
                {
                    //StandardFeedResults.ToList().RemoveAll(x => x != foundPlaying.First());
                    var    tempUIDs = StandardFeedResults.Where(x => string.IsNullOrEmpty(x.UIStateFull)).Select(x => x.Uid).ToArray();
                    string foundUID = foundPlaying.First().Uid;
                    for (int i = 0; i < tempUIDs.Count(); i++)
                    {
                        //if (tempUIDs[i] != foundUID)
                        StandardFeedResults.Remove(StandardFeedResults.Where(x => x.Uid == tempUIDs[i] && string.IsNullOrEmpty(x.UIStateFull)).First());
                    }
                }
                else
                {
                    StandardFeedResults.Clear();
                }


                var found = AppDatabase.Current.RetrieveYoutubeHistoryItemByGrouping(grouping);
                if (found != null && found.Count > 0)
                {
                    //StandardFeedResults.ToList().RemoveAll(x => x._Grouping == grouping);
                    found.Reverse();

                    foreach (var item in found)
                    {
                        var ytdi = new YoutubeDataItem(item.Uid, item.Title, item.Subtitle, item.ImagePath, item.Description, item.VideoId, null);

                        ytdi._Grouping = grouping;

                        //if (StandardFeedResults.Count() == 0)
                        StandardFeedResults.Add(ytdi);
                        //else
                        //    StandardFeedResults.Insert(0, ytdi);
                    }

                    return;
                }

                //});

                //});
            }
            catch (Exception ex) {
                AlertService.LogAlertMessage("Error retrieving History from Cache", ex.Message);
            }

            return;
        }