Ejemplo n.º 1
0
 /// <summary>
 ///  Helper to generate Test Data for Gui Testing
 /// Fires OnVideosFetched in case of success (amount more than 0)
 /// Fires OnVideosFetchErrorOccured in case of an error (amount less or equal to 0)
 /// </summary>
 /// <param name="videoUrl"></param>
 /// <param name="amount"></param>
 public void GenerateTestData(String videoUrl, int amount)
 {
     if (amount <= 0)
     {
         if (OnVideosFetchErrorOccured != null)
         {
             OnVideosFetchErrorOccured.Invoke(this, null);
         }
         return;
     }
     _videoInfos = new List <VideoInfo>();
     for (int i = 0; i < amount; i++)
     {
         _videoInfos.Add(new VideoInfo
         {
             Description =
                 "A tutorial is a method of transferring knowledge and may be used as a part of a " +
                 "learning process. More interactive and specific than a book or a lecture; a " +
                 "tutorial seeks to teach by example and supply the information to complete a " +
                 "certain task.",
             Id        = i.ToString(CultureInfo.InvariantCulture),
             Timestamp = DateTime.Now,
             Title     = "Tutorial - From Wikipedia, the free encyclopedia",
             Url       = videoUrl
         });
     }
     if (OnVideosFetched != null)
     {
         OnVideosFetched.Invoke(this, new VideosFetchedEventArgs(_videoInfos));
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Retrieve Video Informations from Server asynchronously
        /// Fires OnVideosFetched in case of success
        /// Fires OnVideosFetchErrorOccured in case of an error
        /// </summary>
        public void GetVideoInformationFromServer()
        {
            try
            {
                _catInfos = new List <Category>();
                XElement xraw  = XElement.Load(_catUrl);
                XElement xroot = XElement.Parse(xraw.ToString());
                _catInfos =
                    (from item in xroot.Elements("category")
                     let id = item.Element("id")
                              let name = item.Element("name")
                                         let subcat = item.Element("subcategories")
                                                      select new Category
                {
                    Id = int.Parse(id.Value),
                    Name = name.Value,
                    Children = parseSubCat(subcat.ToString()),
                }).ToList();

                foreach (var element in _catInfos)
                {
                    evalParents(element.Children, element);
                }

                if (OnCategoriesFetched != null)
                {
                    OnCategoriesFetched.Invoke(this, new CategoriesFetchedEventArgs(_catInfos));
                }

                ////////////////////////////////////////////////////////////////
                _videoInfos = new List <VideoInfo>();
                xraw        = XElement.Load(_url);
                xroot       = XElement.Parse(xraw.ToString());
                List <VideoInfo> links =
                    (from item in xroot.Descendants("video")
                     let id = item.Element("id")
                              let title = item.Element("title")
                                          let description = item.Element("description")
                                                            let icon = item.Element("icon")
                                                                       let url = item.Element("url")
                                                                                 let timestamp = item.Element("timestamp")
                                                                                                 let cat = item.Element("category")
                                                                                                           select new VideoInfo
                {
                    Id = id.Value,
                    Title = title.Value,
                    Description = description.Value,
                    Icon = icon.Value,
                    Url = url.Value,
                    Timestamp = DateTimeFromUnixTimestampSeconds(timestamp.Value),
                    Category = int.Parse(cat.Value)
                }).ToList();

                _videoInfos = links;
                if (OnVideosFetched != null)
                {
                    OnVideosFetched.Invoke(this, new VideosFetchedEventArgs(links));
                }
            }
            catch (Exception exception)
            {
                if (OnVideosFetchErrorOccured != null)
                {
                    OnVideosFetchErrorOccured.Invoke(this, new ErrorEventArgs(exception));
                }
            }
        }