Exemple #1
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);
                }
            }
        }
        // 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();
        }
Exemple #3
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);
            }
        }
Exemple #4
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;
        }