コード例 #1
0
        public async Task GetJsonTest()
        {
            var expected = ReadJsonFile("OloPizzasTest.pizzas.json");
            var actual   = await LocalProgram.GetJson();

            Assert.AreEqual(expected, actual);
        }
コード例 #2
0
        void HandleQueueDownloaderOnStart(LocalProgram startedProgram, int queueSize)
        {
            InvokeOnMainThread(delegate {
                Console.WriteLine("{0} has started", startedProgram.Name);

                TitleLabel.Text = startedProgram.Name;
                TitleLabel.SetNeedsDisplay();
                ImageView.Image = RemoteProgramHelper.GetFullsizeImageFromFile(startedProgram.ThumbnailPath, ImageView.Bounds);
                if (queueSize == 0)
                {
                    SubLabel.Text = "Downloading. No more items in the queue";
                }
                else if (queueSize == 1)
                {
                    SubLabel.Text = String.Format("Downloading. {0} item remaining to download", queueSize);
                }
                else
                {
                    SubLabel.Text = string.Format("Downloading. {0} items remaining to download", queueSize);
                }

                SubLabel.SetNeedsDisplay();
                ProgressBar.Progress = 0;
                ProgressBar.SetNeedsDisplay();
            });
        }
コード例 #3
0
 void HandleQueueDownloaderOnProgress(LocalProgram currentProgram, float progress)
 {
     InvokeOnMainThread(delegate {
         Console.WriteLine("{0} has progressed", currentProgram.Name);
         ProgressBar.Progress = progress;
         ProgressBar.SetNeedsDisplay();
     });
 }
コード例 #4
0
        void HandleQueueDownloaderOnEnd(LocalProgram finishedProgram)
        {
            InvokeOnMainThread(delegate {
                Console.WriteLine("{0} is finished", finishedProgram.Name);

                AppDelegate.SessionDatabase.MarkProgramAsDownloaded(finishedProgram.Id);
            });
        }
コード例 #5
0
        public async Task OutputTest()
        {
            const string expected          = "1 pepperoni 5\r\n2 bacon 4\r\n3 feta cheese 3\r\n4 beef, sausage 2\r\n5 bacon, beef, mozzarella cheese, onions, pineapple 1\r\n";
            var          toppings          = JsonConvert.DeserializeObject <List <Toppings> >(ReadJsonFile("OloPizzasTest.simple.json"));
            var          groupedAndOrdered = (await LocalProgram.GroupAndOrder(toppings)).ToList();

            using (var consoleOutput = new ConsoleOutput())
            {
                LocalProgram.MyOutput(groupedAndOrdered);

                Assert.AreEqual(expected, consoleOutput.GetOuput());
            }
        }
コード例 #6
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            CloseButton.TouchUpInside += delegate {
                DismissModalViewControllerAnimated(true);
            };

            CloseButton.Hidden = true;

            queueDownloader       = new QueueDownloader();
            queueDownloader.Queue = AppDelegate.SessionDatabase.GetLocalQueuedPrograms();

            if (queueDownloader.Queue.Count > 0)
            {
                LocalProgram firstProgram = queueDownloader.Queue[0];

                TitleLabel.Text = firstProgram.Name;

                ImageView.Image = RemoteProgramHelper.GetFullsizeImageFromFile(firstProgram.ThumbnailPath, ImageView.Bounds);
                int queueSize = queueDownloader.Queue.Count;
                if (queueSize == 0)
                {
                    SubLabel.Text = "Downloading. No more items in the queue";
                }
                else if (queueSize == 1)
                {
                    SubLabel.Text = String.Format("Downloading. {0} item remaining to download", queueSize);
                }
                else
                {
                    SubLabel.Text = string.Format("Downloading. {0} items remaining to download", queueSize);
                }


                ProgressBar.Progress = 0;
            }
            queueDownloader.OnStart       += HandleQueueDownloaderOnStart;
            queueDownloader.OnProgress    += HandleQueueDownloaderOnProgress;
            queueDownloader.OnEnd         += HandleQueueDownloaderOnEnd;
            queueDownloader.OnNoMoreItems += HandleQueueDownloaderOnNoMoreItems;

            UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true;
            UIApplication.SharedApplication.IdleTimerDisabled = true;
            queueDownloader.Start();
        }
コード例 #7
0
        public async Task GroupAndOrderTest()
        {
            var toppings          = JsonConvert.DeserializeObject <List <Toppings> >(ReadJsonFile("OloPizzasTest.simple.json"));
            var groupedAndOrdered = (await LocalProgram.GroupAndOrder(toppings)).ToList();

            Assert.AreEqual(5, groupedAndOrdered.Count);
            Assert.AreEqual("pepperoni", groupedAndOrdered[0].Key);
            Assert.AreEqual("bacon", groupedAndOrdered[1].Key);
            Assert.AreEqual("feta cheese", groupedAndOrdered[2].Key);
            Assert.AreEqual("beef, sausage", groupedAndOrdered[3].Key);
            Assert.AreEqual("bacon, beef, mozzarella cheese, onions, pineapple", groupedAndOrdered[4].Key);

            Assert.AreEqual(5, groupedAndOrdered[0].Count());
            Assert.AreEqual(4, groupedAndOrdered[1].Count());
            Assert.AreEqual(3, groupedAndOrdered[2].Count());
            Assert.AreEqual(2, groupedAndOrdered[3].Count());
            Assert.AreEqual(1, groupedAndOrdered[4].Count());
        }
コード例 #8
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            //Show an edit button

            //NavigationItem.RightBarButtonItem = EditButtonItem;

            UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true;
            SelectedProgram.PopulateExtendedFields();



            this.Title              = SelectedProgram.Program.Name;
            this.TitleLabel.Text    = SelectedProgram.Program.Name;
            this.SubtitleLabel.Text = SelectedProgram.Program.Description;
            SubtitleLabel.Font      = UIFont.SystemFontOfSize(UIFont.SmallSystemFontSize);
            this.ImageView.Image    = SelectedProgram.GetFullsizeImage(ImageView.Bounds);

            UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;

            if (SelectedProgram.DownloadedFileExists)
            {
                this.DownloadButton.SetTitle("Play", UIControlState.Normal);
            }

            this.WatchButton.TouchUpInside += delegate {
                // This is for when the user wants to stream the video
                string url = SelectedProgram.StreamingUrl;
                if (string.IsNullOrEmpty(url))
                {
                    using (UIAlertView alertView = new UIAlertView("Sorry.", "Sorry, this program is not available for streaming.", null, "OK"))
                    {
                        alertView.Show();
                        this.WatchButton.SetTitle("Not available", UIControlState.Normal);
                    }
                }
                else
                {
                    moviePlayer = new MPMoviePlayerViewController(new NSUrl(SelectedProgram.StreamingUrl));
                    PresentMoviePlayerViewController(moviePlayer);
                }
            };

            this.DownloadButton.TouchUpInside += delegate {
                if (SelectedProgram.DownloadedFileExists)
                {
                    // if we have the file, we can play it! yay!
                    Console.WriteLine("playing");
                    moviePlayer = new MPMoviePlayerViewController(new NSUrl(SelectedProgram.OutputFilename, false));
                    PresentMoviePlayerViewController(moviePlayer);
                }
                else
                {
                    //If you happen to be out of the UK, but want to see how the queueing works, you may want to remove this
                    // bit, as it checks if you can download and will not queue if it can't.
                    // you still can't download, obviously, but atleast you can see the workflow.

                    if (SelectedProgram.PrepareForQueue())
                    {
                        LocalProgram localQueueProgram = LocalProgramHelper.LocalProgramFromRemoteProgram(SelectedProgram.Program);

                        localQueueProgram.State = "Q";
                        AppDelegate.SessionDatabase.AddLocalProgram(localQueueProgram);

                        this.DownloadButton.SetTitle("Queued", UIControlState.Normal);
                    }
                    else
                    {
                        // could be that you are outside of the UK, on 3G, or just that the show isn't ready yet.
                        using (UIAlertView alertView = new UIAlertView("Sorry.", "Sorry, this program is not available for download.", null, "OK"))
                        {
                            alertView.Show();
                            this.DownloadButton.SetTitle("Not available", UIControlState.Normal);
                        }
                    }
                    this.DownloadButton.Enabled = false;
                }
            };
        }