예제 #1
0
        /// <summary>
        /// 放送局を生成して返す
        /// </summary>
        /// <param name="name">放送局の名前</param>
        /// <param name="stationKind">放送局の種類</param>
        /// <returns>生成した放送局</returns>
        public static Station CreateStation(string name, StationKinds stationKind)
        {
            string id;
            bool   isExistId = false;

            do
            {
                id        = DateTime.Now.ToString("yyyyMMddHHmmssff");
                isExistId = false;
                foreach (Station station in GetStationList())
                {
                    if (station.Id == id)
                    {
                        isExistId = true;
                        break;
                    }
                }
            } while (isExistId == true);

            return(new Station(id, name, stationKind));
        }
예제 #2
0
        /// <summary>
        /// 放送局のコンストラクタ
        /// </summary>
        /// <param name="id">放送局のID</param>
        /// <param name="name">放送局の名前</param>
        /// <param name="stationKind">放送局の種類</param>
        public Station(string id, string name, StationKinds stationKind)
        {
            if (id == null)
            {
                throw new ArgumentNullException("StationのIDにNullは指定できません");
            }
            if (id == string.Empty)
            {
                throw new ArgumentException("StationのIDに空文字は指定できません");
            }

            this.id   = id;
            this.name = name;
            this.kind = stationKind;

            switch (kind)
            {
            case StationKinds.Netladio:
                headline = new PocketLadio.Stations.Netladio.Headline(id, this);
                break;

            case StationKinds.RssPodcast:
                headline = new PocketLadio.Stations.RssPodcast.Headline(id, this);
                break;

            case StationKinds.ShoutCast:
                headline = new PocketLadio.Stations.ShoutCast.Headline(id, this);
                break;

            case StationKinds.Icecast:
                headline = new PocketLadio.Stations.Icecast.Headline(id, this);
                break;

            default:
                // ここには到達しない
                Trace.Assert(false, "想定外の動作のため、終了します");
                break;
            }
        }
예제 #3
0
        /// <summary>
        /// 設定をファイルから読み込む
        /// </summary>
        public static void LoadSetting()
        {
            if (File.Exists(SettingPath))
            {
                FileStream    fs     = null;
                XmlTextReader reader = null;

                try
                {
                    fs     = new FileStream(SettingPath, FileMode.Open, FileAccess.Read);
                    reader = new XmlTextReader(fs);

                    ArrayList alStation = new ArrayList();

                    // StationListタグの中にいるか
                    bool inStationListFlag = false;

                    while (reader.Read())
                    {
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            if (reader.LocalName == "StationList")
                            {
                                inStationListFlag = true;
                            } // End of StationList
                            // StationListタグの中にいる場合
                            else if (inStationListFlag == true)
                            {
                                if (reader.LocalName == "Station")
                                {
                                    string       id          = string.Empty;
                                    string       name        = string.Empty;
                                    StationKinds stationKind = StationKinds.Netladio;

                                    if (reader.MoveToFirstAttribute())
                                    {
                                        id   = reader.GetAttribute("id");
                                        name = reader.GetAttribute("name");
                                        string kind = reader.GetAttribute("kind");
                                        if (kind == StationKinds.Netladio.ToString())
                                        {
                                            stationKind = StationKinds.Netladio;
                                        }
                                        else if (kind == StationKinds.RssPodcast.ToString())
                                        {
                                            stationKind = StationKinds.RssPodcast;
                                        }
                                        else if (kind == StationKinds.ShoutCast.ToString())
                                        {
                                            stationKind = StationKinds.ShoutCast;
                                        }
                                        else if (kind == StationKinds.Icecast.ToString())
                                        {
                                            stationKind = StationKinds.Icecast;
                                        }
                                        else
                                        {
                                            // ここに到達することはあり得ない
                                            Trace.Assert(false, "想定外の動作のため、終了します");
                                        }

                                        alStation.Add(new Station(id, name, stationKind));
                                    }
                                } // End of Station
                            }     // End of StationListタグの中にいる場合
                            else if (reader.LocalName == "FilterEnable")
                            {
                                string enable;
                                enable = reader.GetAttribute("enable");
                                if (enable == bool.TrueString)
                                {
                                    FilterEnable = true;
                                }
                                else if (enable == bool.FalseString)
                                {
                                    FilterEnable = false;
                                }
                            } // End of FilterEnable
                            else if (reader.LocalName.Equals("HeadlineTimer"))
                            {
                                if (reader.MoveToFirstAttribute())
                                {
                                    string check = reader.GetAttribute("check");
                                    if (check == bool.TrueString)
                                    {
                                        HeadlineTimerCheck = true;
                                    }
                                    else if (check == bool.FalseString)
                                    {
                                        HeadlineTimerCheck = false;
                                    }
                                    try
                                    {
                                        HeadlineTimerMillSecond = Convert.ToInt32(reader.GetAttribute("millsecond"));
                                    }
                                    catch (ArgumentException)
                                    {
                                        ;
                                    }
                                    catch (FormatException)
                                    {
                                        ;
                                    }
                                    catch (OverflowException)
                                    {
                                        ;
                                    }
                                }
                            } // End of HeadlineTimer
                            else if (reader.LocalName == "MediaPlayerPath")
                            {
                                MediaPlayerPath = reader.GetAttribute("path");
                            } // End of MediaPlayerPath
                            else if (reader.LocalName == "BrowserPath")
                            {
                                BrowserPath = reader.GetAttribute("path");
                            } // End of BrowserPath
                            else if (reader.LocalName == "PlayListSave")
                            {
                                string save;
                                save = reader.GetAttribute("save");
                                if (save == bool.TrueString)
                                {
                                    PlayListSave = true;
                                }
                                else if (save == bool.FalseString)
                                {
                                    PlayListSave = false;
                                }
                            } // End of PlayListSave
                            else if (reader.LocalName.Equals("HeadlineListBoxFont"))
                            {
                                if (reader.MoveToFirstAttribute())
                                {
                                    string check = reader.GetAttribute("change");
                                    if (check == bool.TrueString)
                                    {
                                        HeadlineListBoxFontSizeChange = true;
                                    }
                                    else if (check == bool.FalseString)
                                    {
                                        HeadlineListBoxFontSizeChange = false;
                                    }
                                    try
                                    {
                                        HeadlineListBoxFontSize = Convert.ToInt32(reader.GetAttribute("size"));
                                    }
                                    catch (ArgumentException)
                                    {
                                        ;
                                    }
                                    catch (FormatException)
                                    {
                                        ;
                                    }
                                    catch (OverflowException)
                                    {
                                        ;
                                    }
                                }
                            } // End of HeadlineListBoxFont
                            else if (reader.LocalName == "Proxy")
                            {
                                if (reader.MoveToFirstAttribute())
                                {
                                    string use = reader.GetAttribute("use");
                                    if (use == ProxyConnect.Unuse.ToString())
                                    {
                                        ProxyUse = ProxyConnect.Unuse;
                                    }
                                    else if (use == ProxyConnect.OsSetting.ToString())
                                    {
                                        ProxyUse = ProxyConnect.OsSetting;
                                    }
                                    else if (use == ProxyConnect.OriginalSetting.ToString())
                                    {
                                        ProxyUse = ProxyConnect.OriginalSetting;
                                    }

                                    ProxyServer = reader.GetAttribute("server");

                                    try
                                    {
                                        string port = reader.GetAttribute("port");
                                        ProxyPort = int.Parse(port);
                                    }
                                    catch (ArgumentException)
                                    {
                                        ;
                                    }
                                    catch (FormatException)
                                    {
                                        ;
                                    }
                                    catch (OverflowException)
                                    {
                                        ;
                                    }
                                }
                            } // End of Proxy
                        }
                        else if (reader.NodeType == XmlNodeType.EndElement)
                        {
                            if (reader.LocalName == "StationList")
                            {
                                inStationListFlag = false;
                                StationList.SetStationList((Station[])alStation.ToArray(typeof(Station)));
                            }
                        }
                    }
                }
                finally
                {
                    reader.Close();
                    fs.Close();
                }
            }
        }