コード例 #1
0
ファイル: RssItem.cs プロジェクト: raybishun/apps
        public void CreateJsonFile(string[,] rssData, string dstFile)
        {
            var items = new List <RssItem>();

            if (rssData != null)
            {
                for (int i = 0; i < rssData.GetLength(0); i++)
                {
                    if (rssData[i, 1] != null)
                    {
                        RssItem item = new RssItem
                        {
                            PubDate = UtilScrubData.RemoveZeros(rssData[i, 0]),
                            Title   = rssData[i, 1],
                            Link    = rssData[i, 3]
                        };

                        items.Add(item);
                    }
                }

                var json = JsonConvert.SerializeObject(items, Newtonsoft.Json.Formatting.Indented);

                File.WriteAllText(dstFile, json);
            }
        }
コード例 #2
0
        private void RefreshButton_Click(object sender, EventArgs e)
        {
            ReturnedItems.Text = "Returned: 0";
            TitlesComboBox.Items.Clear();

            try
            {
                RssItem rssItem = new RssItem();

                rssData = rssItem.GetRssData(ChannelTextBox.Text.Trim());

                ReturnedItems.Text = $"Returned: {rssItem.RssItemCount.ToString()}";

                if (rssData != null)
                {
                    for (int i = 0; i < rssData.GetLength(0); i++)
                    {
                        if (rssData[i, 1] != null)
                        {
                            string pubDate = UtilScrubData.RemoveZeros(rssData[i, 0]);
                            string title   = rssData[i, 1];

                            // Populate ComboBox
                            TitlesComboBox.Items.Add($"{pubDate} | {title}");
                        }
                    }

                    TitlesComboBox.SelectedIndex = 0;

                    rssItem.CreateCsvFile(rssData, @"rssItems.csv");

                    rssItem.CreateJsonFile(rssData, @"rssItems.json");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #3
0
ファイル: RssItem.cs プロジェクト: raybishun/apps
        public void CreateCsvFile(string[,] rssData, string dstFile)
        {
            if (rssData != null)
            {
                using (StreamWriter sw = new StreamWriter(dstFile, false))
                {
                    for (int i = 0; i < rssData.GetLength(0); i++)
                    {
                        if (rssData[i, 1] != null)
                        {
                            RssItem rssItem = new RssItem
                            {
                                PubDate = UtilScrubData.RemoveZeros(rssData[i, 0]),
                                Title   = rssData[i, 1],
                                Link    = rssData[i, 3]
                            };

                            sw.WriteLine(rssItem.ToString());
                        }
                    }
                }
            }
        }