Beispiel #1
0
        public async Task RefreshDataFromYouTube(string grouping)
        {
            if (_queueOfRequests.Contains(grouping))
            {
                return;
            }

            _queueOfRequests.Add(grouping);


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

            var result = await YouTubeService.Current.GetStandardfeedAsync("favoriten", grouping);

            if (result != null)
            {
                //add new ones only
                foreach (var item in result.Items)
                {
                    var found = StandardFeedResults.Where(x => x.Uid == item.Uid);
                    if (found == null || found.Count() == 0)
                    {
                        StandardFeedResults.Add(item);
                    }
                }


                //delete cached data
                //AppDatabase.Current.DeleteYoutubePersistedItems(grouping);

                //persist to store
                var listToSave = StandardFeedResults.Select(x => new YoutubePersistedItem()
                {
                    Uid         = x.Uid,
                    Description = x.Description,
                    Grouping    = grouping,
                    ImagePath   = x.ImagePath,
                    VideoLink   = x.Link.AbsoluteUri.ToString(),
                    VideoId     = x.videoID,
                    Title       = x.Title,
                    Subtitle    = x.Subtitle,
                    Timestamp   = DateTime.UtcNow,
                    NewUID      = Guid.NewGuid().ToString()
                }).ToList();


                foreach (var item in listToSave)
                {
                    if (!AppDatabase.Current.DoesYouTubePersistedItemExist(item.Uid))
                    {
                        AppDatabase.Current.AddUpdateYoutubePersistedItem(item);
                    }
                }
            }

            _queueOfRequests.Remove(grouping);

            return;
        }
Beispiel #2
0
        public async Task RefreshDataFromCache(string grouping)
        {
            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.RetrieveYoutubePersistedItemByGrouping(grouping);

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

                foreach (var item in found)
                {
                    var ni = new YoutubeDataItem(item.Uid, item.Title, item.Subtitle, item.Image, item.Description, item.VideoId, null);
                    ni.ImagePath = item.ImagePath;
                    ni._Grouping = grouping;
                    ni.NewUID    = item.NewUID;
                    StandardFeedResults.Add(ni);
                }

                return;
            }
        }
Beispiel #3
0
        private async Task GetYoutubeDataGroupAsync(string Uid, string Keyword, int MaxResults, int Page = 0)
        {
            string text = string.Concat(new object[]
            {
                "http://gdata.youtube.com/feeds/api/videos?max-results=",
                MaxResults,
                "&v=2&q=",
                Keyword,
                "&start-index=",
                ((Page * MaxResults) + 1)
            });

            new Uri(text);
            YoutubeDataGroup result;

            try
            {
                YoutubeDataItem  item             = null;
                YoutubeDataGroup youtubeDataGroup = new YoutubeDataGroup(Uid, "Search: " + Keyword, Keyword, "ms-appx:///Assets/Darkgray.png", "");
                WebRequest       webRequest       = WebRequest.Create(text);
                webRequest.Method = "GET";
                WebResponse webResponse = await webRequest.GetResponseAsync();

                XDocument xDocument   = XDocument.Load(webResponse.GetResponseStream());
                XmlReader xmlReader   = xDocument.CreateReader();
                int       num         = 0;
                string    title       = string.Empty;
                string    str         = string.Empty;
                string    str2        = string.Empty;
                string    description = string.Empty;
                //SearchFeedResults.Clear();
                while (xmlReader.Read())
                {
                    if (xmlReader.NodeType == XmlNodeType.Element)
                    {
                        string text2    = string.Empty;
                        string expr_1BE = xmlReader.Name;
                        if (expr_1BE != null)
                        {
                            if (!(expr_1BE == "yt:videoid"))
                            {
                                if (!(expr_1BE == "title"))
                                {
                                    if (!(expr_1BE == "media:credit"))
                                    {
                                        if (!(expr_1BE == "media:description"))
                                        {
                                            if (expr_1BE == "yt:duration")
                                            {
                                                int num2 = Convert.ToInt32(xmlReader["seconds"]);
                                                if (num2 > 60)
                                                {
                                                    int num3 = num2 / 60;
                                                    int num4 = num2 % 60;
                                                    if (num4 < 10)
                                                    {
                                                        str2 = num3.ToString() + ":0" + num4.ToString();
                                                    }
                                                    else
                                                    {
                                                        str2 = num3.ToString() + ":" + num4.ToString();
                                                    }
                                                }
                                                else
                                                {
                                                    str2 = "0:" + num2.ToString();
                                                }
                                            }
                                        }
                                        else
                                        {
                                            description = xmlReader.ReadElementContentAsString();
                                        }
                                    }
                                    else
                                    {
                                        str = xmlReader["yt:display"];
                                    }
                                }
                                else
                                {
                                    title = xmlReader.ReadElementContentAsString();
                                }
                            }
                            else
                            {
                                text2 = xmlReader.ReadElementContentAsString();
                                string imagePath = "http://i.ytimg.com/vi/" + text2 + "/hqdefault.jpg";
                                item = new YoutubeDataItem(num.ToString(), title, "by " + str + " | " + str2, imagePath, description, text2, youtubeDataGroup);
                                youtubeDataGroup.Items.Add(item);
                                StandardFeedResults.Add(item);
                            }
                        }
                    }
                    num++;
                }
                result = youtubeDataGroup;
            }
            catch (Exception)
            {
                result = null;
            }
            return;
        }
Beispiel #4
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;
        }