예제 #1
0
        public void EachItem()
        {
            Client listClient = new ClientMock(MockResponse.VideosList);

            foreach (Video item in VideosList.EachItem(listClient))
            {
                Assert.That(listClient, Is.SameAs(item.record.RecordClient));
                Assert.AreEqual(item.record.RecordEndpoint, "videos");
            }

            var per_page = "1";
            var query    = new Dictionary <string, string>()
            {
                { "per_page", per_page }
            };

            int countItem = 0;

            foreach (Video item in VideosList.EachItem(query, listClient))
            {
                countItem++;
            }

            Assert.AreEqual(countItem.ToString(), per_page);
        }
예제 #2
0
        public void NewVideosList()
        {
            var list = new VideosList();

            Assert.AreEqual(list.records.RecordEndpoint, "videos");
            Assert.IsInstanceOf <List <Record> > (list.records.List);
            Assert.IsInstanceOf <List <Video> > (list.Page);

            var client = new ClientMock(MockResponse.VideosList);

            list = new VideosList(client);

            Assert.AreEqual(list.records.RecordEndpoint, "videos");
            Assert.IsInstanceOf <List <Record> > (list.records.List);
            Assert.IsInstanceOf <List <Video> > (list.Page);

            Assert.IsInstanceOf <Client> (list.records.RecordClient);
        }
예제 #3
0
        public void Paginate()
        {
            var list = VideosList.Paginate(new ClientMock(MockResponse.VideosList));

            var listClient = list.records.RecordClient;

            Assert.AreEqual(list.records.RecordEndpoint, "videos");

            foreach (var item in list.Page)
            {
                Assert.AreEqual(item.record.RecordEndpoint, "videos");
            }

            var per_page = "1";
            var query    = new Dictionary <string, string>()
            {
                { "per_page", per_page }
            };

            var list2 = VideosList.Paginate(query, new ClientMock(MockResponse.VideosList));

            var countItem = 0;

            foreach (var item in list2.Page)
            {
                countItem++;
            }

            Assert.AreEqual(countItem.ToString(), per_page);

            list = VideosList.Paginate(new ClientMock(MockResponse.RecordPaginate));

            Assert.IsTrue(list.Next());
            Assert.IsTrue(list.Prevous());
            Assert.IsTrue(list.First());
            Assert.IsTrue(list.Last());

            list = VideosList.Paginate(new ClientMock(MockResponse.RecordPaginateEmpty));

            Assert.IsFalse(list.Next());
            Assert.IsFalse(list.Prevous());
            Assert.IsFalse(list.First());
            Assert.IsFalse(list.Last());
        }
예제 #4
0
        public static void ReadingVideosList(string id, string token)
        {
            try {
                Console.WriteLine("--EachItem()--");
                foreach (Video item in VideosList.EachItem())
                {
                    Console.WriteLine("Id: " + item["id"] + " Title: " + item["title"]);
                }

                Console.WriteLine("--EachItem(query)--");

                Dictionary <string, string> query = new Dictionary <string, string>()
                {
                    { "sort", "id" },
                    { "order", "desc" },
                    { "per_page", "2" }
                };

                Client client = new Client()
                {
                    CfgClientId = id, CfgAuthToken = token
                };
                foreach (var item in VideosList.EachItem(query, client))
                {
                    Console.WriteLine("Id: " + item["id"] + " Title: " + item["title"]);
                }

                Console.WriteLine("--Paginate--");

                var items1 = VideosList.Paginate();
                foreach (var item in items1.Page)
                {
                    Console.WriteLine("Id: " + item["id"] + " Title: " + item["title"]);
                }

                Console.WriteLine("--Paginate(query)--");

                var items2 = VideosList.Paginate(query, new Client());

                Console.WriteLine("--Paginate(query)--Initial-First--");
                foreach (var item in items2.Page)
                {
                    Console.WriteLine("Id: " + item["id"] + " Title: " + item["title"]);
                }

                while (items2.Next())
                {
                    Console.WriteLine("--Paginate(query)--Next--");

                    foreach (var item in items2.Page)
                    {
                        Console.WriteLine("Id: " + item["id"] + " Title: " + item["title"]);
                    }
                }

                Console.WriteLine("--Paginate(query)--Previous--");
                items2.Prevous();
                foreach (var item in items2.Page)
                {
                    Console.WriteLine("Id: " + item["id"] + " Title: " + item["title"]);
                }

                Console.WriteLine("--Paginate(query)--Last--");
                items2.Last();
                foreach (var item in items2.Page)
                {
                    Console.WriteLine("Id: " + item["id"] + " Title: " + item["title"]);
                }

                Console.WriteLine("--Paginate(query)--First--");
                items2.First();
                foreach (var item in items2.Page)
                {
                    Console.WriteLine("Id: " + item["id"] + " Title: " + item["title"]);
                }
            } catch (VzaarApiException ve) {
                Console.Write("!!!!!!!!! EXCEPTION !!!!!!!!!");
                Console.WriteLine(ve.Message);
            } catch (Exception e) {
                Console.Write("!!!!!!!!! EXCEPTION !!!!!!!!!");
                Console.WriteLine(e.Message);

                if (e is AggregateException)
                {
                    AggregateException ae = (AggregateException)e;

                    var flatten = ae.Flatten();

                    foreach (var fe in flatten.InnerExceptions)
                    {
                        if (fe is VzaarApiException)
                        {
                            Console.WriteLine(fe.Message);
                        }
                    }
                }
            }
        }
 public void SelectVideo(VideoViewModel videoModel)
 {
     if (BackgroundTask.Instance.IsExecuting)
     {
         return;
     }
     if (videoModel.VideoInfo == null)
     {
         // discover and append next page videos
         BackgroundTask.Instance.Start <List <VideoInfo> >(
             () =>
         {
             return(SelectedSite.Site.GetNextPageVideos());
         },
             (success, nextPageVideos) =>
         {
             if (success)
             {
                 VideosList.Remove(videoModel);
                 int selectNr = VideosList.Count;
                 nextPageVideos.ForEach(r => { r.CleanDescriptionAndTitle(); VideosList.Add(new VideoViewModel(r, SelectedCategory != null ? SelectedCategory.Category : null, SelectedSite.Site.Settings, false)
                     {
                         Selected = VideosList.Count == selectNr
                     }); });
                 if (SelectedSite.Site.HasNextPage)
                 {
                     VideosList.Add(new VideoViewModel(Translation.Instance.NextPage, "NextPage.png"));
                 }
                 VideosList.FireChange();
                 ImageDownloader.GetImages <VideoInfo>(nextPageVideos);
             }
         },
             Translation.Instance.GettingNextPageVideos);
     }
     else
     {
         if (SelectedSite.Site is Sites.IChoice && videoModel.VideoInfo.HasDetails)
         {
             // get details videos and show details view
             BackgroundTask.Instance.Start <List <DetailVideoInfo> >(
                 () =>
             {
                 return(((Sites.IChoice)SelectedSite.Site).GetVideoChoices(videoModel.VideoInfo));
             },
                 (success, choices) =>
             {
                 if (success)
                 {
                     SelectedVideo = videoModel;
                     ShowDetails(choices);
                 }
             },
                 Translation.Instance.GettingVideoDetails);
         }
         else
         {
             // get playback urls and play or show dialog to select playback options
             BackgroundTask.Instance.Start <List <string> >(
                 () =>
             {
                 return(SelectedSite.Site.GetMultipleVideoUrls(videoModel.VideoInfo));
             },
                 (success, urls) =>
             {
                 if (success)
                 {
                     if (SelectedSite.Site.Settings.Player != PlayerType.Browser)
                     {
                         Helpers.UriUtils.RemoveInvalidUrls(urls);
                     }
                     // if no valid urls were returned show error msg
                     if (urls == null || urls.Count == 0)
                     {
                         ServiceRegistration.Get <IDialogManager>().ShowDialog("[OnlineVideos.Error]", "[OnlineVideos.UnableToPlayVideo]", DialogType.OkDialog, false, DialogButtonType.Ok);
                     }
                     else
                     {
                         SelectedVideo = videoModel;
                         SelectedVideo.ChoosePlaybackOptions(urls[0], (url) => { urls[0] = url; SelectedVideo.Play(urls); });
                     }
                 }
             },
                 Translation.Instance.GettingPlaybackUrlsForVideo);
         }
     }
 }