示例#1
0
 private void AccessButton_Click(object sender, System.EventArgs e)
 {
     try
     {
         if (channel.GetWebsiteUrl() != null)
         {
             PodcasCoUtility.AccessWebsite(channel.GetWebsiteUrl());
         }
     }
     catch (FileNotFoundException)
     {
         MessageBox.Show("ブラウザが見つかりません", "警告");
     }
 }
示例#2
0
        /// <summary>
        /// ヘッドラインをネットから取得する
        /// </summary>
        public virtual void FetchHeadline()
        {
            // ローカルヘッドラインで、RSSが見あたらない場合は何もしない
            if (setting.RssUrl.IsFile == true && File.Exists(setting.RssUrl.LocalPath) == false)
            {
                return;
            }

            // 時刻をセットする
            lastCheckTime = DateTime.Now;

            WebStream     st     = null;
            FileStream    fs     = null;
            XmlTextReader reader = null;

            try
            {
                // 番組のリスト
                ArrayList alChannels = new ArrayList();

                // チャンネル
                Channel channel = null;
                // itemタグの中にいるか
                bool inItemFlag = false;

                // Enclosureの一時リスト
                ArrayList alTempEnclosure = new ArrayList();

                if (setting.RssUrl.IsFile == true)
                {
                    fs     = new FileStream(setting.RssUrl.LocalPath, FileMode.Open, FileAccess.Read);
                    reader = new XmlTextReader(fs);
                }
                else
                {
                    st     = PodcasCoUtility.GetWebStream(setting.RssUrl);
                    reader = new XmlTextReader(st);
                }

                // 解析したヘッドラインの個数
                int analyzedCount = 0;

                OnHeadlineAnalyze(new HeadlineAnalyzeEventArgs(0, HeadlineAnalyzeEventArgs.UNKNOWN_WHOLE_COUNT));

                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        if (reader.LocalName.Equals("item"))
                        {
                            inItemFlag = true;
                            channel    = new Channel(this);
                        } // End of item
                        // itemタグの中にいる場合
                        else if (inItemFlag == true)
                        {
                            if (reader.LocalName == "title")
                            {
                                channel.Title = reader.ReadString();
                            } // End of title
                            else if (reader.LocalName == "description")
                            {
                                channel.Description = reader.ReadString();
                            } // End of description
                            else if (reader.LocalName == "link")
                            {
                                try
                                {
                                    channel.Link = new Uri(reader.ReadString());
                                }
                                catch (UriFormatException)
                                {
                                    ;
                                }
                            } // End of link
                            else if (reader.LocalName == "pubDate")
                            {
                                channel.SetDate(reader.ReadString());
                            } // End of pubDate
                            else if (reader.LocalName == "category")
                            {
                                channel.Category = reader.ReadString();
                            } // End of category
                            else if (reader.LocalName == "author")
                            {
                                channel.Author = reader.ReadString();
                            } // End of author
                            else if (reader.LocalName == "guid")
                            {
                                try
                                {
                                    channel.Link = new Uri(reader.ReadString());
                                }
                                catch (UriFormatException)
                                {
                                    ;
                                }
                            } // End of guid
                            else if (reader.LocalName == "enclosure")
                            {
                                Uri    enclosureUrl    = null;
                                string enclosureLength = "";
                                string enclosureType   = "";

                                try
                                {
                                    if (reader.MoveToFirstAttribute())
                                    {
                                        enclosureUrl    = new Uri(reader.GetAttribute("url"));
                                        enclosureLength = reader.GetAttribute("length");
                                        enclosureType   = reader.GetAttribute("type");
                                    }

                                    if (enclosureLength == null)
                                    {
                                        enclosureLength = string.Empty;
                                    }
                                    if (enclosureType == null)
                                    {
                                        enclosureType = string.Empty;
                                    }

                                    // Enclosureタグの数だけ、 Enclosure一時リストにEnclosureの内容を追加していく
                                    Enclosure enclosure = new Enclosure(enclosureUrl, enclosureLength, enclosureType);
                                    if (enclosure.IsPodcast() == true)
                                    {
                                        alTempEnclosure.Add(enclosure);
                                    }
                                }
                                catch (UriFormatException)
                                {
                                    ;
                                }
                            } // End of enclosure
                        }     // End of itemタグの中にいる場合
                    }
                    else if (reader.NodeType == XmlNodeType.EndElement)
                    {
                        if (reader.LocalName == "item")
                        {
                            inItemFlag = false;

                            // Enclosureの要素の数だけ、Channelの複製を作る
                            if (alTempEnclosure.Count != 0)
                            {
                                foreach (Enclosure enclosure in alTempEnclosure)
                                {
                                    Channel clonedChannel = (Channel)channel.Clone(this);
                                    clonedChannel.Url    = enclosure.Url;
                                    clonedChannel.Length = enclosure.Length;
                                    clonedChannel.Type   = enclosure.Type;
                                    alChannels.Add(clonedChannel);
                                    OnHeadlineAnalyzing(new HeadlineAnalyzeEventArgs(++analyzedCount, HeadlineAnalyzeEventArgs.UNKNOWN_WHOLE_COUNT));
                                }
                            }

                            // Enclosure一時リストをクリア
                            alTempEnclosure.Clear();
                        }
                    }
                }

                OnHeadlineAnalyzed(new HeadlineAnalyzeEventArgs(analyzedCount, analyzedCount));

                channels = (Channel[])alChannels.ToArray(typeof(Channel));
            }
            catch (XmlException)
            {
                // ローカルヘッドラインの解析に失敗した場合は、そのファイルを削除する
                if (setting.RssUrl.IsFile == true)
                {
                    File.Delete(setting.RssUrl.LocalPath);
                }
                throw;
            }
            finally
            {
                if (st != null)
                {
                    st.Close();
                }
                if (fs != null)
                {
                    fs.Close();
                }
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
示例#3
0
        /// <summary>
        /// 放送局名をネットから取得して返す
        /// </summary>
        /// <returns>ネットから取得した放送局名</returns>
        public virtual string FetchStationName()
        {
            WebStream st     = null;
            XmlReader reader = null;

            try
            {
                string title = null;

                // itemタグの中にいるか
                bool inItemFlag = false;
                // channelタグの中にいるか
                bool inChannelFlag = false;

                st     = PodcasCoUtility.GetWebStream(setting.RssUrl);
                reader = new XmlTextReader(st);

                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        if (reader.LocalName == "channel")
                        {
                            inChannelFlag = true;
                        }
                        // トップ下のtitleの内容を返す
                        if (reader.LocalName == "title" && inChannelFlag == true && inItemFlag == false)
                        {
                            title = reader.ReadString();
                            return(title);
                        } // End of title
                        else if (reader.LocalName == "item")
                        {
                            inItemFlag = true;
                        } // End of item
                    }
                    else if (reader.NodeType == XmlNodeType.EndElement)
                    {
                        if (reader.LocalName == "channel")
                        {
                            inChannelFlag = false;
                        }
                        else if (reader.LocalName == "item")
                        {
                            inItemFlag = false;
                        }
                    }
                }

                // トップ下のtitleが見あたらないために、とりあえずUrlを返しておく
                return((title != null) ? title : setting.RssUrl.ToString());
            }
            finally
            {
                if (st != null)
                {
                    st.Close();
                }
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }