Ejemplo n.º 1
0
        // Loads the file data and puts it into the podcast list class
        public static void GetPodcastList()
        {
            if (File.Exists("data\\Podcast.txt"))
            {
                XDocument xdoc = XDocument.Load("data\\Podcast.txt");

                xdoc.Descendants("Podcast").Select(p => new
                {
                    Url       = p.Element("Url").Value,
                    Episodes  = Convert.ToInt32(p.Element("Episodes").Value),
                    Title     = p.Element("Title").Value,
                    Category  = p.Element("Category").Value,
                    Frequency = Convert.ToInt32(p.Element("Frequency").Value)
                }).ToList().ForEach(p =>
                {
                    Podcast pod = new Podcast(
                        p.Url,
                        p.Episodes,
                        p.Title,
                        p.Category,
                        p.Frequency
                        );

                    PodcastList.AddPodcast(pod);
                    TheTimer.SetTimer(p.Url, p.Title, p.Category, p.Frequency);
                });
            }
        }
Ejemplo n.º 2
0
        // New RSS feed
        public static void RssFeed(string url, string cat, int freq)
        {
            // Reading the feed
            XmlReader       reader = XmlReader.Create(url);
            SyndicationFeed feed   = SyndicationFeed.Load(reader);

            reader.Close();

            // Creating a Podcast object and adding it to PodcastList
            string podTitle = feed.Title.Text;
            int    nrOfEp   = feed.Items.Count();

            Podcast podcast = new Podcast(url, nrOfEp, podTitle, cat, freq);

            PodcastList.AddPodcast(podcast);

            // Creating the Episodes objects and adding them to PodcastEpList
            foreach (SyndicationItem item in feed.Items)
            {
                string title       = item.Title.Text;
                string description = item.Summary.Text;

                Episode episode = new Episode(podTitle, title, description);
                EpisodeList.AddEpisode(episode);
            }

            TheTimer.SetTimer(url, podTitle, cat, freq);
        }
Ejemplo n.º 3
0
        // Updates the data of a specific podcast
        private void btnUpdatePod_Click(object sender, EventArgs e)
        {
            try
            {
                string title = lvPods.SelectedItems[0].SubItems[1].Text;

                string url             = tbUrl.Text;
                string category        = cbCategory.Text;
                var    stringFrequency = cbFrequency.SelectedItem;

                if (Validator.StringNotEmpty(title) &&
                    Validator.StringNotEmpty(category) &&
                    Validator.ParseFrequency(stringFrequency))
                {
                    int frequency = Int32.Parse(stringFrequency.ToString());

                    PodcastList.DeletePod(title);
                    EpisodeList.DeleteEpisodes(title);

                    DataLayerAccessor.AddPodcast(url, category, frequency);
                    DataLayerAccessor.CreateFiles();

                    UpdatePodListView();
                    lvEpisodes.Items.Clear();
                    tbEpDescription.Clear();
                    MessageBox.Show("Podcasten uppdaterades!", "Wohoo!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch
            {
                MessageBox.Show("Ingen podcast är vald.", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 4
0
        public static void GetPodcastFromRss(string category, int updateFrequency, string url)
        {
            using (var reader = XmlReader.Create(url))
            {
                try
                {
                    var feed         = SyndicationFeed.Load(reader);
                    var podcastName  = feed.Title.Text;
                    int episodeCount = 0;
                    foreach (SyndicationItem s in feed.Items)
                    {
                        var episodeName = s.Title.Text;
                        var detail      = s.Summary.Text;
                        var episode     = new Episode(episodeName, podcastName, detail);
                        EpisodeList.Add(episode);
                        episodeCount++;
                    }

                    PodcastList.AddPodcast(new Podcast(podcastName, category, updateFrequency, episodeCount, url));
                    PodcastUpdate.pUpdate(podcastName, category, updateFrequency, url);
                }
                catch (Exception)
                {
                    System.Windows.Forms.MessageBox.Show("Cannot read RSS");
                }
            }
        }
Ejemplo n.º 5
0
 public ModifyPodcastForm(Podcast aPod, PodcastList aPodList)
 {
     InitializeComponent();
     podcastList = aPodList;
     podcast     = aPod;
     load();
     setFields();
 }
Ejemplo n.º 6
0
 public void SavePodcast(string podcast)
 {
     foreach (var pod in PodcastList.GetPodcasts().Where(p => p.PodcastName.Equals(podcast)))
     {
         textBoxUrl.Text = pod.Url;
         comboBoxUpdateFrequency.SelectedIndex = comboBoxUpdateFrequency.Items.IndexOf(pod.PodcastUpdateFrequency + " sekunder");
         comboBoxCategory.SelectedIndex        = comboBoxCategory.Items.IndexOf(pod.PodcastCategory);
     }
 }
Ejemplo n.º 7
0
        public void UpdatePodcasts(string podcast)
        {
            int updatefrequency = Convert.ToInt32(comboBoxUpdateFrequency.Text.Split(' ')[0]);

            PodcastList.RemovePodcast(podcast);
            EpisodeList.RemoveEpisode(podcast);
            Podcast.AddPodcast(comboBoxCategory.Text, updatefrequency, textBoxUrl.Text);

            UpdatelistViewPodcast();
            listViewEpisodes.Items.Clear();
            rTBoxEpisodeDetail.Clear();
        }
Ejemplo n.º 8
0
 public static void SavePodcasts()
 {
     if (File.Exists("podcasts.txt"))
     {
         File.Delete("podcasts.txt");
     }
     using (Stream stream = File.OpenWrite(Environment.CurrentDirectory + "\\podcasts.txt"))
     {
         new XmlSerializer(typeof(List <Podcast>)).Serialize(stream, PodcastList.GetPodcasts());
         stream.Close();
     }
 }
Ejemplo n.º 9
0
        // Updates the data in the form elements
        public void SetFormElements(string title)
        {
            List <Podcast> podList = PodcastList.GetPodList();

            for (int i = 0; i < podList.Count(); i++)
            {
                if (podList.ElementAt(i).Title == title)
                {
                    tbUrl.Text = podList.ElementAt(i).Url;
                    cbFrequency.SelectedIndex = cbFrequency.Items.IndexOf(podList.ElementAt(i).Frequency.ToString());
                    cbCategory.SelectedIndex  = cbCategory.Items.IndexOf(podList.ElementAt(i).Category);
                }
            }
        }
Ejemplo n.º 10
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         string podcast = listViewPodcast.SelectedItems[0].Text;
         PodcastList.RemovePodcast(podcast);
         EpisodeList.RemoveEpisode(podcast);
         UpdatelistViewPodcast();
     }
     catch (Exception)
     {
         MessageBox.Show("You must select the podcast you want to delete!");
     }
 }
Ejemplo n.º 11
0
 public void UpdatelistViewPodcastCategory(string category)
 {
     listViewPodcast.Items.Clear();
     foreach (var pod in PodcastList.GetPodcasts().Where(p => p.PodcastCategory == category))
     {
         var list = new ListViewItem(new[]
         {
             pod.PodcastName,
             pod.PodcastCategory,
             pod.EpisodeCount.ToString(),
             pod.PodcastUpdateFrequency.ToString() + " sekunder"
         });
         listViewPodcast.Items.Add(list);
     }
 }
Ejemplo n.º 12
0
        // Creates the podcast file and puts data into it
        public static void CreatePodcastFile()
        {
            // Deleted the file if found to not leave old data in it and cause errors
            if (File.Exists(currentDirectory + "\\data\\Podcast.txt"))
            {
                File.Delete(currentDirectory + "\\data\\Podcast.txt");
            }

            //Creating the file
            Stream stream = File.OpenWrite(currentDirectory + "\\data\\Podcast.txt");

            // Writing to the file
            XmlSerializer serializer = new XmlSerializer(typeof(List <Podcast>));

            serializer.Serialize(stream, PodcastList.GetPodList());
            stream.Close();
        }
Ejemplo n.º 13
0
        public IActionResult PodcastsShow(string name)
        {
            ViewData["Title"] = name;
            List <Author>        author   = db.Authors.Where(p => p.Name == name).ToList();
            IQueryable <Podcast> podcasts = db.Podcasts.Include(p => p.Author).Where(p => p.Author.Name == name);

            PodcastList podcastList = new PodcastList
            {
                AuthorId    = author[0].Id,
                Name        = author[0].Name,
                Description = author[0].Description,
                Image       = author[0].Image,
                Podcasts    = podcasts,
                Audio       = "~/music/Disgusting men/pod.mp3"
            };

            return(View(podcastList));
        }
Ejemplo n.º 14
0
        public void UpdatelistViewPodcast()
        {
            listViewPodcast.Items.Clear();
            List <Podcast> podcastlist = PodcastList.GetPodcasts();

            for (int i = 0; i < podcastlist.Count; i++)
            {
                Podcast pod  = podcastlist[i];
                var     list = new ListViewItem(new[]
                {
                    pod.PodcastName,
                    pod.PodcastCategory,
                    pod.EpisodeCount.ToString(),
                    pod.PodcastUpdateFrequency.ToString() + " sekunder"
                });
                listViewPodcast.Items.Add(list);
            }
        }
Ejemplo n.º 15
0
        // Updates the list view of the Podcasts
        private void UpdatePodListView()
        {
            lvPods.Items.Clear();

            List <Podcast> podList = PodcastList.GetPodList();

            foreach (var pod in podList)
            {
                var list = new ListViewItem(new[]
                {
                    pod.Episodes.ToString(),
                    pod.Title,
                    pod.Category,
                    pod.Frequency.ToString()
                });

                lvPods.Items.Add(list);
            }
        }
Ejemplo n.º 16
0
        // The timer, NOT DONE!!!
        private static async void TimerElapsed(object sender, System.Timers.ElapsedEventArgs e, string url, string title, string category, int frequency)
        {
            List <Podcast> list                = PodcastList.GetPodList();
            bool           PodExists           = false;
            int            NumberOfEpisodes    = 0;
            int            OldNumberOfEpisodes = await RssReader.GetNumberOfEpisodes(url);

            foreach (Podcast pod in list)
            {
                if (pod.Title == title)
                {
                    NumberOfEpisodes = pod.Episodes;
                    PodExists        = true;
                }
            }

            if (!PodExists)
            {
                timer.Enabled = false;
            }

            if (NumberOfEpisodes > OldNumberOfEpisodes)
            {
                PodcastList.DeletePod(title);
                EpisodeList.DeleteEpisodes(title);
                DataLayerAccessor.AddPodcast(url, category, frequency);
                CreateFile.CreatePodcastFile();
                CreateFile.CreateEpisodeFile();

                timer.Enabled = false;

                MessageBox.Show("Nytt avsnitt har hittats!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                MessageBox.Show("Inga nya avsnitt hittades!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            PodExists = false;
        }
Ejemplo n.º 17
0
        // Button to delete a podcast
        private void btnDeletePod_Click(object sender, EventArgs e)
        {
            try
            {
                string title = lvPods.SelectedItems[0].SubItems[1].Text;

                if (Validator.StringNotEmpty(title))
                {
                    PodcastList.DeletePod(title);
                    EpisodeList.DeleteEpisodes(title);
                    DataLayerAccessor.CreateFiles();

                    UpdatePodListView();
                    lvEpisodes.Items.Clear();
                    tbEpDescription.Clear();
                }
            }
            catch
            {
                MessageBox.Show("Ingen podcast är vald.", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 18
0
        public CustomerDemo()
        {
            Customer customer;

            Console.WriteLine("***************Customer  demo- Inheritance,Polymorphism,Interface*********");
            OTTCustomer oTT = new OTTCustomer();

            customer = oTT;   //runtime polymorphism
            oTT.display("Welcome to OTT subscription services");
            oTT.AddSubscription();
            customer.display();
            oTT.display("Thank you!!");

            PodcastList podcastList = new PodcastList();

            customer = podcastList;
            podcastList.AddSubscription();
            customer.display();     //runtime polymorphism
            podcastList.RemoveSubscription();
            customer.display();
            podcastList.display("Thank you!!");
        }