Example #1
0
        private void DownloadFile1()
        {
            ReadOnlyControlFile controlFile = new ReadOnlyControlFile(_inputfilename);
            PodcastInfo         info        = GetPodcastInfo(controlFile, 0);

            DisplayMessage(string.Format("Reading a feed: {0}", info.Feed.Address));
            IList <ISyncItem> allEpisodes = GetAllEpisodesInFeed(controlFile, info);

            if (allEpisodes.Count < 1)
            {
                DisplayMessage("No episodes in the feed - dont forget the state.xml file is being used", DisplayLevel.Warning);
                return;
            }
            IList <ISyncItem> firstEpisode = new List <ISyncItem>(1);

            firstEpisode.Add(allEpisodes.First());

            DisplayMessage(string.Format("Downloading Eposode: {0}", firstEpisode.First().EpisodeTitle));
            ISyncItemToEpisodeDownloaderTaskConverter converter = _iocContainer.Resolve <ISyncItemToEpisodeDownloaderTaskConverter>();

            IEpisodeDownloader[] downloadTasks = converter.ConvertItemsToTasks(firstEpisode, StatusUpdate, ProgressUpdate);

            // run them in a task pool
            ITaskPool taskPool = _iocContainer.Resolve <ITaskPool>();

            taskPool.RunAllTasks(1, downloadTasks);

            DisplayMessage(string.Format("Download Complete", allEpisodes.Count));
        }
Example #2
0
        private PodcastInfo GetPodcastInfo(ReadOnlyControlFile controlFile, int index)
        {
            IEnumerable <PodcastInfo> podcasts = controlFile.GetPodcasts();
            PodcastInfo info = podcasts.ElementAt(index);

            return(info);
        }
        protected override void GivenThat()
        {
            base.GivenThat();

            _controlFile = TestControlFileFactory.CreateControlFile();
            _podcastInfo = new PodcastInfo(_controlFile);
        }
        private List <ISyncItem> ApplyDownloadStrategy(string stateKey, PodcastInfo podcastInfo, List <ISyncItem> episodesFound)
        {
            switch (podcastInfo.Feed.DownloadStrategy.Value)
            {
            case PodcastEpisodeDownloadStrategy.All:
                return(episodesFound);

            case PodcastEpisodeDownloadStrategy.HighTide:
                var state       = _stateProvider.GetState(stateKey);
                var newEpisodes =
                    (from episode in episodesFound
                     where episode.Published > state.DownloadHighTide
                     select episode);
                var filteredEpisodes = new List <ISyncItem>(1);
                filteredEpisodes.AddRange(newEpisodes);
                return(filteredEpisodes);

            case PodcastEpisodeDownloadStrategy.Latest:
                episodesFound.Sort((e1, e2) => e2.Published.CompareTo(e1.Published));
                var latestEpisodes = new List <ISyncItem>(1);
                latestEpisodes.AddRange(episodesFound.Take(1));
                return(latestEpisodes);

            default:
                throw new EnumOutOfRangeException();
            }
        }
        public void TestResumePodcastAlreadyStopped()
        {
            Dictionary <String, String> input = new Dictionary <string, string>
            {
                { "Command", "podcast" },
                { "Subcommand", "resume" },
            };
            IConfigurationManager configMan = GetConfigurationManager();

            Mock <IMediaFilePlayer> mediaPlayer = new Mock <IMediaFilePlayer>(MockBehavior.Strict);

            mediaPlayer.Setup(s => s.IsValid).Returns(true);
            mediaPlayer.Setup(s => s.CurrentState).Returns(PlayerState.Stopped);
            AddComponentToConfigurationManager(mediaPlayer.Object);

            PodcastInfo info = new PodcastInfo("Test Podcast", new Uri(Directory.GetCurrentDirectory() + "/testRssFeed.xml", UriKind.Absolute), false);

            info.Initialize(configMan);

            CurrentConversation = new PodcastConversation(configMan, new List <PodcastInfo> {
                info
            });

            Assert.AreEqual("", RunSingleConversation <PodcastConversation>(input));

            mediaPlayer.Verify(s => s.CurrentState, Times.Exactly(1));
        }
        public void TestPlayPodcastAlreadyPaused()
        {
            Dictionary <String, String> input = new Dictionary <string, string>
            {
                { "Command", "podcast" },
                { "Subcommand", "playnext" },
                { "Podcast", "Test Podcast" },
            };
            IConfigurationManager configMan = GetConfigurationManager();

            Mock <IMediaFilePlayer> mediaPlayer = new Mock <IMediaFilePlayer>(MockBehavior.Strict);

            mediaPlayer.Setup(s => s.IsValid).Returns(true);
            mediaPlayer.Setup(s => s.CurrentState).Returns(PlayerState.Paused);
            mediaPlayer.Setup(s => s.StopAudioFile());
            mediaPlayer.Setup(s => s.PlayAudioFile("http://www.podtrac.com/pts/redirect.mp3/twit.cachefly.net/audio/tnt/tnt1129/tnt1129.mp3"));
            AddComponentToConfigurationManager(mediaPlayer.Object);

            PodcastInfo info = new PodcastInfo("Test Podcast", new Uri(Directory.GetCurrentDirectory() + "/testRssFeed.xml", UriKind.Absolute), false);

            info.Initialize(configMan);

            CurrentConversation = new PodcastConversation(configMan, new List <PodcastInfo> {
                info
            });

            Assert.AreEqual("", RunSingleConversation <PodcastConversation>(input));

            mediaPlayer.Verify(s => s.CurrentState, Times.Exactly(1));
            mediaPlayer.Verify(s => s.StopAudioFile(), Times.Exactly(1));
            mediaPlayer.Verify(s => s.PlayAudioFile("http://www.podtrac.com/pts/redirect.mp3/twit.cachefly.net/audio/tnt/tnt1129/tnt1129.mp3"), Times.Exactly(1));
        }
 protected override void GivenThat()
 {
     base.GivenThat();
     _podcastInfo = new PodcastInfo(_controlFile)
     {
         Folder = "folder"
     };
 }
Example #8
0
        private void TrackCellActivity(TreeViewColumn tree_column, CellRenderer cell,
                                       TreeModel tree_model, TreeIter iter)
        {
            PodcastInfo        pi       = tree_model.GetValue(iter, 0) as PodcastInfo;
            CellRendererPixbuf renderer = cell as CellRendererPixbuf;

            renderer.Pixbuf    = null;
            renderer.StockId   = null;
            renderer.Sensitive = true;

            if (IsStreaming(pi))
            {
                renderer.StockId = Stock.MediaPlay;
            }
            else if (pi.Track != null)
            {
                if (pi.Track.PlayCount == 0)
                {
                    renderer.Pixbuf = PodcastPixbufs.NewPodcastIcon;
                }
                else if (pi.Track == PlayerEngineCore.CurrentTrack)
                {
                    renderer.StockId = Stock.MediaPlay;
                }
            }
            else if (pi.DownloadInfo != null)
            {
                switch (pi.DownloadInfo.State)
                {
                case DownloadState.Failed:
                    renderer.StockId = Stock.DialogError;
                    break;

                case DownloadState.Ready:
                case DownloadState.Paused:
                case DownloadState.Queued:
                    renderer.StockId   = Stock.GoForward;
                    renderer.Sensitive = false;
                    break;

                case DownloadState.Canceled:
                case DownloadState.CancelRequested:
                    renderer.StockId = Stock.Cancel;
                    break;

                case DownloadState.Running:
                    renderer.StockId = Stock.GoForward;
                    break;

                default:
                    break;
                }
            }
            else if (pi.DownloadFailed)
            {
                renderer.StockId = Stock.DialogError;
            }
        }
Example #9
0
        ///<summary>
        /// Create a new podcast
        ///</summary>
        ///<param name="controlFile"></param>
        ///<returns></returns>
        public IPodcastInfo CreatePodcast(IControlFileGlobalDefaults controlFile)
        {
            var podcast = new PodcastInfo(controlFile)
            {
                Feed = new FeedInfo(controlFile)
            };

            return(podcast);
        }
Example #10
0
        public void QueueAdd(PodcastInfo pi)
        {
            lock (add_queue.SyncRoot)
            {
                add_queue.Add(pi);
            }

            GLib.Idle.Add(PumpAddQueue);
        }
Example #11
0
        public void TestItemHasPropertiesSet()
        {
            IConfigurationManager configManager = GetConfigurationManager();
            PodcastInfo           info          = new PodcastInfo("Test Podcast", new Uri(Directory.GetCurrentDirectory() + "/testRssFeed.xml", UriKind.Absolute), false);

            Assert.AreEqual(false, info.IsValid);
            Assert.AreEqual("Test Podcast", info.Name);
            Assert.AreEqual(null, info.NextAudioFileLocation);
        }
Example #12
0
        public void QueueRemove(PodcastInfo pi)
        {
            lock (remove_queue.SyncRoot)
            {
                remove_queue.Add(pi);
            }

            GLib.Idle.Add(PumpRemoveQueue);
        }
Example #13
0
        private void AddPodcast(PodcastInfo pi)
        {
            if (pi == null)
            {
                return;
            }

            pi.TreeIter = AppendValues(pi);
        }
Example #14
0
        private void DownloadCellToggle(TreeViewColumn tree_column, CellRenderer cell,
                                        TreeModel tree_model, TreeIter iter)
        {
            CellRendererToggle toggle = (CellRendererToggle)cell;

            PodcastInfo pi = tree_model.GetValue(iter, 0) as PodcastInfo;

            if (pi.Track != null)
            {
                toggle.Active    = true;
                toggle.Sensitive = false;
            }
            else if (pi.DownloadInfo != null)
            {
                switch (pi.DownloadInfo.State)
                {
                case DownloadState.Failed:
                    toggle.Active    = false;
                    toggle.Sensitive = true;
                    break;

                case DownloadState.Ready:
                case DownloadState.Paused:
                case DownloadState.Queued:
                case DownloadState.Running:
                    toggle.Active    = true;
                    toggle.Sensitive = true;
                    break;

                case DownloadState.Completed:
                    toggle.Active    = true;
                    toggle.Sensitive = false;
                    break;

                case DownloadState.Canceled:
                case DownloadState.CancelRequested:
                case DownloadState.New:
                default:
                    toggle.Active    = false;
                    toggle.Sensitive = false;
                    break;
                }
            }
            else if (pi.IsDownloaded == true)
            {
                toggle.Active    = true;
                toggle.Sensitive = false;
            }
            else
            {
                toggle.Active    = pi.IsQueued;
                toggle.Sensitive = true;
            }
        }
        protected override void GivenThat()
        {
            base.GivenThat();

            var podcast1 = new PodcastInfo(ControlFile)
            {
                Folder = "pod1"
            };

            podcast1.Pattern.Value = "*.mp3";
            podcast1.MaximumNumberOfFiles.Value = 2;
            podcast1.AscendingSort.Value        = true;
            podcast1.DeleteEmptyFolder.Value    = true;
            podcast1.SortField.Value            = PodcastFileSortField.FileName;

            var podcast2 = new PodcastInfo(ControlFile)
            {
                Folder = "AnotherPodcast"
            };

            podcast2.Pattern.Value = "*.wma";
            podcast2.MaximumNumberOfFiles.Value = 3;
            podcast2.AscendingSort.Value        = false;
            podcast2.DeleteEmptyFolder.Value    = false;
            podcast2.SortField.Value            = PodcastFileSortField.CreationTime;

            PodcastFiles1 = new List <IFileInfo> {
                GenerateMock <IFileInfo>(), GenerateMock <IFileInfo>()
            };
            PodcastFiles2 = new List <IFileInfo> {
                GenerateMock <IFileInfo>(), GenerateMock <IFileInfo>(), GenerateMock <IFileInfo>()
            };

            ControlFile.Stub(c => c.GetPodcasts())
            .Return(new List <PodcastInfo> {
                podcast1, podcast2
            });

            ControlFile.Stub(c => c.GetSourceRoot())
            .Return(@"c:\media\blah");
            ControlFile.Stub(c => c.GetDestinationRoot())
            .Return(@"k:\podcasts");
            ControlFile.Stub(c => c.GetFreeSpaceToLeaveOnDestination())
            .Return(500);

            FileFinder.Stub(f => f.GetFiles(@"c:\media\blah\pod1", "*.mp3", 2, PodcastFileSortField.FileName, true))
            .Return(PodcastFiles1);
            FileFinder.Stub(f => f.GetFiles(@"c:\media\blah\AnotherPodcast", "*.wma", 3, PodcastFileSortField.CreationTime, false))
            .Return(PodcastFiles2);

            FileCopier.Stub(c => c.CopyFilesToTarget(null, null, null, 0, false))
            .IgnoreArguments()
            .WhenCalled(invocation => FilesToCopy = (List <FileSyncItem>)invocation.Arguments[0]);
        }
Example #16
0
        public TrackInfo IterTrackInfo(TreeIter iter)
        {
            PodcastInfo pi = IterPodcastInfo(iter);

            if (pi != null)
            {
                return(pi.Track);
            }

            return(null);
        }
Example #17
0
        public void TestItemIgnoresInvalidWebUri()
        {
            IConfigurationManager configManager = GetConfigurationManager();
            PodcastInfo           info          = new PodcastInfo("Test Podcast", new Uri("http://www.samiautomation.com/invalidrss.xml", UriKind.Absolute), false);

            info.Initialize(configManager);

            Assert.AreEqual(false, info.IsValid);
            Assert.AreEqual("Test Podcast", info.Name);
            Assert.AreEqual(null, info.NextAudioFileLocation);
        }
Example #18
0
        public void TestItemHasPropertiesSetAfterInitialize()
        {
            IConfigurationManager configManager = GetConfigurationManager();
            PodcastInfo           info          = new PodcastInfo("Test Podcast", new Uri(Directory.GetCurrentDirectory() + "/testRssFeed.xml", UriKind.Absolute), false);

            info.Initialize(configManager);

            Assert.AreEqual(true, info.IsValid);
            Assert.AreEqual("Test Podcast", info.Name);
            Assert.AreEqual(new Uri("http://www.podtrac.com/pts/redirect.mp3/twit.cachefly.net/audio/tnt/tnt1129/tnt1129.mp3"), info.NextAudioFileLocation);
        }
Example #19
0
        public void TestItemIgnoresInvalidLocalUri()
        {
            IConfigurationManager configManager = GetConfigurationManager();
            PodcastInfo           info          = new PodcastInfo("Test Podcast", new Uri(Directory.GetCurrentDirectory() + "/InvalidFeedFile.xml", UriKind.Absolute), false);

            info.Initialize(configManager);

            Assert.AreEqual(false, info.IsValid);
            Assert.AreEqual("Test Podcast", info.Name);
            Assert.AreEqual(null, info.NextAudioFileLocation);
        }
Example #20
0
        public void TestAppValidWhenPodcastInfoExists()
        {
            IConfigurationManager configManager = GetConfigurationManager();

            PodcastApp  app  = new PodcastApp();
            PodcastInfo info = new PodcastInfo("Test Podcast", new Uri(Directory.GetCurrentDirectory() + "/testRssFeed.xml", UriKind.Absolute), false);

            app.AddChild(info);

            Assert.AreEqual(true, app.IsValid);
        }
Example #21
0
        private bool PumpQueue(ArrayList queue,
                               SinglePodcastAction spa, MultiplePodcastAction mpa)
        {
            PodcastInfo pi       = null;
            ICollection podcasts = null;

            int range_upper = -1;

            lock (queue.SyncRoot)
            {
                if (queue.Count == 0)
                {
                    return(false);
                }

                int queue_count = queue.Count;
                // A count of 32 caused relatively skipless audio playback
                // while synchronizing large feeds (200-300 episodes).
                range_upper = (queue_count >= 32) ? 31 : queue_count;

                if (queue_count == 1)
                {
                    pi = queue [0] as PodcastInfo;
                }
                else if (queue_count > 1)
                {
                    podcasts = queue.GetRange(0, range_upper);
                }
            }

            if (pi != null)
            {
                spa(pi);
            }
            else if (podcasts != null)
            {
                mpa(podcasts);
            }

            lock (queue.SyncRoot)
            {
                queue.RemoveRange(0, range_upper);

                if (queue.Count == 0)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
        }
Example #22
0
        public PodcastPropertiesDialog(PodcastInfo pi) :
            base(pi.Title, InterfaceElements.MainWindow, DialogFlags.DestroyWithParent)
        {
            if (pi == null)
            {
                throw new ArgumentNullException("pi");
            }

            this.pi = pi;
            BuildWindow();
            IconThemeUtils.SetWindowIcon(this);
        }
Example #23
0
 /// <summary>
 /// Показать содержимое подкаста в виде html-страницы
 /// </summary>
 /// <param name="podcast">Ссылка на экземпляр класса Podcast</param>
 private void PodcastnOnHtmlPage(PodcastInfo podcast)
 {
     _dvm = new ProcessViewModel(podcast, Browsers.CurrentItem as BrowserInfo);
     _dvm.CreateHtml(Browsers.CurrentItem as BrowserInfo);
     //var sw = new StatusWindow(podcast.Url, Browsers.CurrentItem as BrowserInfo)
     //{
     //    ShowCancelButton = Visibility.Hidden
     //};
     ////IsBusy = Visibility.Collapsed;
     //sw.ShowDialog();
     ////IsBusy = Visibility.Visible;
 }
Example #24
0
        private int PodcastPubDateTreeIterCompareFunc(TreeModel model, TreeIter a,
                                                      TreeIter b)
        {
            PodcastInfo pi_a = model.GetValue(a, 0) as PodcastInfo;
            PodcastInfo pi_b = model.GetValue(b, 0) as PodcastInfo;

            if (pi_a == null || pi_b == null)
            {
                return(-1);
            }

            return(DateTime.Compare(pi_a.PubDate, pi_b.PubDate));
        }
Example #25
0
        private int PodcastTitleTreeIterCompareFunc(TreeModel model, TreeIter a,
                                                    TreeIter b)
        {
            PodcastInfo pi_a = model.GetValue(a, 0) as PodcastInfo;
            PodcastInfo pi_b = model.GetValue(b, 0) as PodcastInfo;

            if (pi_a == null || pi_b == null)
            {
                return(-1);
            }

            return(String.Compare(pi_a.Title.ToLower(), pi_b.Title.ToLower()));
        }
Example #26
0
        public void TestItemMovesToNextFileNoSql()
        {
            IConfigurationManager configManager = GetConfigurationManager();
            PodcastInfo           info          = new PodcastInfo("Test Podcast", new Uri(Directory.GetCurrentDirectory() + "/testRssFeed.xml", UriKind.Absolute), false);

            info.Initialize(configManager);
            info.NextEpisodeFinished();

            Assert.AreEqual(true, info.IsValid);
            Assert.AreEqual("Test Podcast", info.Name);
            // Not correct behavior, but required until we are able to have access to database.
            Assert.AreEqual(new Uri("http://www.podtrac.com/pts/redirect.mp3/twit.cachefly.net/audio/tnt/tnt1129/tnt1129.mp3"), info.NextAudioFileLocation);
        }
Example #27
0
        private void RemovePodcast(PodcastInfo pi)
        {
            if (pi != null)
            {
                TreeIter iter = pi.TreeIter;
                pi.TreeIter = TreeIter.Zero;

                if (IterIsValid(iter))
                {
                    Remove(ref iter);
                }
            }
        }
 protected override void GivenThat()
 {
     base.GivenThat();
     _podcastInfo = new PodcastInfo(_controlFile)
     {
         Folder = "folder"
     };
     _podcastInfo.Pattern.Value              = "pattern";
     _podcastInfo.SortField.Value            = PodcastFileSortField.CreationTime;
     _podcastInfo.AscendingSort.Value        = true;
     _podcastInfo.MaximumNumberOfFiles.Value = 123;
     _podcastInfo.DeleteEmptyFolder.Value    = true;
 }
Example #29
0
        private void TrackCellPubDate(TreeViewColumn tree_column,
                                      CellRenderer cell, TreeModel tree_model, TreeIter iter)
        {
            PodcastInfo pi = tree_model.GetValue(iter, 0) as PodcastInfo;

            if (pi == null)
            {
                return;
            }

            SetRendererAttributes(
                (CellRendererText)cell, pi.PubDate.ToString("d"), tree_model, iter
                );
        }
Example #30
0
        private void ReadFeed1()
        {
            ReadOnlyControlFile controlFile = new ReadOnlyControlFile(_inputfilename);
            PodcastInfo         info        = GetPodcastInfo(controlFile, 0);

            DisplayMessage(string.Format("Reading a feed: {0}", info.Feed.Address));

            IList <ISyncItem> allEpisodes = GetAllEpisodesInFeed(controlFile, info);

            DisplayMessage(string.Format("Eposodes in feed: {0}", allEpisodes.Count));
            foreach (ISyncItem item in allEpisodes)
            {
                DisplayMessage(string.Format("Eposode: {0}", item.EpisodeTitle));
            }
        }
        private void RemovePodcast(PodcastInfo pi)
        {
            if (pi != null)
            {
                TreeIter iter = pi.TreeIter;
                pi.TreeIter = TreeIter.Zero;

                if (IterIsValid (iter))
                {
                    Remove (ref iter);
                }
            }
        }
        private void AddPodcast(PodcastInfo pi)
        {
            if (pi == null)
            {
                return;
            }

            pi.TreeIter = AppendValues (pi);
        }
        public void QueueRemove(PodcastInfo pi)
        {
            lock (remove_queue.SyncRoot)
            {
                remove_queue.Add (pi);
            }

            GLib.Idle.Add (PumpRemoveQueue);
        }
        public void QueueAdd(PodcastInfo pi)
        {
            lock (add_queue.SyncRoot)
            {
                add_queue.Add (pi);
            }

            GLib.Idle.Add (PumpAddQueue);
        }