/// <summary> /// ヘッドラインを削除する /// </summary> /// <param name="headline">ヘッドライン</param> public static void RemoveHeadline(HeadlineBase headline) { if (headline == null) { throw new ArgumentNullException(); } if (headlines.Exists(delegate(HeadlineBase v) { return(v == headline); }) == false) { throw new ArgumentException(); } headlines.Remove(headline); // ヘッドラインの保存先のファイルを削除する if (headlineSettingFiles.ContainsKey(headline) == true) { if (File.Exists(PocketLadioDeuxInfo.HeadlineSettingDirectoryPath + @"\" + headlineSettingFiles[headline].FilePath) == true) { File.Delete(PocketLadioDeuxInfo.HeadlineSettingDirectoryPath + @"\" + headlineSettingFiles[headline].FilePath); } headlineSettingFiles.Remove(headline); } }
/// <summary> /// FetchChannelsAsyncExceptionEventHandlerの処理 /// </summary> /// <param name="headline">例外が発生したヘッドライン</param> /// <param name="exception">例外</param> private static void OnFetchChannelsAsyncExceptionEvent(HeadlineBase headline, Exception exception) { if (FetchChannelsAsyncExceptionEventHandler != null) { FetchChannelsAsyncExceptionEventHandler(null, new FetchChannelsAsyncExceptionEventArgs(headline, exception)); } }
/// <summary> /// FetchChannelsAsyncCancelEventHandlerの処理 /// </summary> /// <param name="headline">キャンセルされたヘッドライン</param> private static void OnFetchChannelsAsyncCancelEvent(HeadlineBase headline) { if (FetchChannelsAsyncCancelEventHandler != null) { FetchChannelsAsyncCancelEventHandler(null, new HeadlineEventArgs(headline)); } }
/// <summary> /// 選択されたヘッドラインを下に下げる /// </summary> private void DownHeadline() { if (headlineListView.SelectedIndices.Count == 1 && headlineListView.SelectedIndices[0] != -1 && headlineListView.SelectedIndices[0] < headlineListView.Items.Count - 1) { HeadlineBase selectedHeadline = (HeadlineBase)headlineListView.Items[headlineListView.SelectedIndices[0]].Tag; HeadlineManager.Down(selectedHeadline); headlineListView.BeginUpdate(); UpdateHeadlineListView(); // 選択を復元する for (int i = 0; i < headlineListView.Items.Count; ++i) { if ((HeadlineBase)headlineListView.Items[i].Tag == selectedHeadline) { headlineListView.Items[i].Selected = true; break; } } headlineListView.EndUpdate(); } }
/// <summary> /// 指定のヘッドラインの設定フォームを表示するためのEventHandlerを生成する /// </summary> /// <param name="headline">ヘッドライン</param> /// <returns>設定フォームを表示するためのEventHandler</returns> private EventHandler CreateShowSettingFormEventHandler(HeadlineBase headline) { return(new EventHandler( delegate { headline.ShowSettingForm(); })); }
/// <summary> /// 指定の非同期で動作している番組取得処理をキャンセルする /// </summary> /// <param name="headline"></param> public static void CancelFetchChannelsAsync(HeadlineBase headline) { lock (fetchingChannelBackgroundWorkersLock) { if (fetchingChannelBackgroundWorkers.ContainsKey(headline) == true) { fetchingChannelBackgroundWorkers[headline].CancelAsync(); } } }
private void MainForm_Load(object sender, EventArgs e) { // フォームのテキストバーを設定 this.Text = AssemblyUtility.GetTitle(Assembly.GetExecutingAssembly()); // 設定の復元 LoadFormSetting(); // 初めて起動された場合 if (UserSettingAdapter.IsSettingCreatedNew == true) { // メインフォームのスプリッターの位置を適当に設定する topPanel.Height = Convert.ToInt32(Height * 0.618); // メッセージボックスにファイルパスを設定するように表示する MessageBox.Show(messagesResource.GetString("PleaseSettingPath"), messagesResource.GetString("Infomation"), MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1); SettingForm settingForm = new SettingForm(); settingForm.ShowDialog(); settingForm.Dispose(); foreach (HeadlinePlugin plugin in HeadlinePluginManager.Plugins) { switch (plugin.ClassName) { // ねとらじプラグインが見つかった場合は、ねとらじのヘッドラインを作成する case "PocketLadioDeux.NetLadioHeadlinePlugin.Headline": { HeadlineBase headline = plugin.CreateInstance(); headline.Name = "ねとらじ"; HeadlineManager.AddHeadline(headline); } break; case "PocketLadioDeux.ShoutCastHeadlinePlugin.Headline": { HeadlineBase headline = plugin.CreateInstance(); if (headline is PocketLadioDeux.ShoutCastHeadlinePlugin.Headline) { headline.Name = "Jazz"; ((PocketLadioDeux.ShoutCastHeadlinePlugin.Headline)headline).Setting.SearchWord = "Jazz"; HeadlineManager.AddHeadline(headline); } } break; default: break; } } } }
private void addButton_Click(object sender, EventArgs e) { HeadlinePlugin plugin = ((KindCombo)kindComboBox.SelectedItem).Plugin; HeadlineBase headline = plugin.CreateInstance(); headline.Name = nameTextBox2.Text; headline.ConnectionSetting = HeadlineManager.ConnectionSetting; headline.CreatedHeadlineByManual(); HeadlineManager.AddHeadline(headline); nameTextBox2.Text = string.Empty; UpdateHeadlineListView(); }
/// <summary> /// ヘッドラインを追加する /// </summary> /// <param name="headline">ヘッドライン</param> public static void AddHeadline(HeadlineBase headline) { if (headline == null) { throw new ArgumentNullException(); } // 接続の設定 headline.ConnectionSetting = connectionSetting; headlines.Add(headline); // ヘッドラインの保存先を生成する headlineSettingFiles[headline] = new HeadlineSettingFilePathStore(); headlineSettingFiles[headline].ClassName = headline.GetType().FullName; string filePath; do { filePath = rand.Next().ToString() + ".conf"; } while (File.Exists(PocketLadioDeuxInfo.HeadlineSettingDirectoryPath + @"\" + filePath) == true || IsExistHeadlineSettingFilePath(filePath) == true); headlineSettingFiles[headline].FilePath = filePath; }
/// <summary> /// 指定のヘッドラインの順番を下げる /// </summary> /// <param name="headline">ヘッドライン</param> public static void Down(HeadlineBase headline) { if (headline == null) { throw new ArgumentNullException(); } if (headlines.Exists(delegate(HeadlineBase v) { return(v == headline); }) == false) { throw new ArgumentException(); } int index = headlines.FindIndex(delegate(HeadlineBase v) { return(v == headline); }); if (index != -1 && index < headlines.Count - 1) { Swap(headlines, index, index + 1); } }
/// <summary> /// ヘッドライン情報を読み込む /// </summary> public static void Load() { if (File.Exists(PocketLadioDeuxInfo.HeadlineSettingFilePath) == true) { #region ヘッドライン情報ファイルの読み込み FileStream fs = null; try { fs = new FileStream(PocketLadioDeuxInfo.HeadlineSettingFilePath, FileMode.Open, FileAccess.Read); XmlSerializer sr = new XmlSerializer(typeof(HeadlineSettingFilePathStore[])); HeadlineSettingFilePathStore[] settingStores = sr.Deserialize(fs) as HeadlineSettingFilePathStore[]; // 個別のヘッドラインの情報を復元する foreach (HeadlineSettingFilePathStore setting in settingStores) { if (File.Exists(PocketLadioDeuxInfo.HeadlineSettingDirectoryPath + @"\" + setting.FilePath)) { // ヘッドラインのインスタンスを生成 HeadlineBase headline = null; foreach (HeadlinePlugin plugin in HeadlinePluginManager.Plugins) { if (setting.ClassName == plugin.ClassName) { headline = plugin.CreateInstance(); break; } } // ヘッドラインの読み込み if (headline != null) { FileStream hfs = null; try { hfs = new FileStream(PocketLadioDeuxInfo.HeadlineSettingDirectoryPath + @"\" + setting.FilePath, FileMode.Open, FileAccess.Read); headline.Load(hfs); } #if !DEBUG catch (IOException) {; } #endif // !DEBUG finally { if (hfs != null) { hfs.Close(); } } headlineSettingFiles[headline] = setting; // 接続の設定 headline.ConnectionSetting = connectionSetting; headlines.Add(headline); } } } } #if !DEBUG catch (InvalidOperationException) {; } catch (IOException) {; } #endif // !DEBUG finally { if (fs != null) { fs.Close(); } } #endregion // ヘッドライン情報ファイルの読み込み } }
/// <summary> /// ヘッドラインから番組の情報を非同期で取得する /// </summary> /// <param name="headline">ヘッドライン</param> public static void FetchChannelsAsync(HeadlineBase headline) { // 指定のヘッドラインが取得処理中の場合は、何もせず終了 if (headline.IsFetching == true || fetchingChannelBackgroundWorkers.ContainsKey(headline) == true) { return; } BackgroundWorker bg = new BackgroundWorker(); bg.WorkerSupportsCancellation = true; EventHandler <ChannelAddedEventArgs> cancelEventHandler = null; bg.DoWork += new DoWorkEventHandler( delegate(object sender, DoWorkEventArgs e) { // 番組の取得をキャンセルするための処理 cancelEventHandler = new EventHandler <ChannelAddedEventArgs>( delegate { if (bg.CancellationPending == true) { e.Cancel = true; // 番組の取得をキャンセル headline.FetchCancel(); } }); headline.ChannelAddedEventHandler += cancelEventHandler; // 番組の取得を開始 headline.FetchHeadlineA(); }); bg.RunWorkerCompleted += new RunWorkerCompletedEventHandler( delegate(object sender, RunWorkerCompletedEventArgs e) { // ヘッドラインから番組取得キャンセルのためのイベントを削除 headline.ChannelAddedEventHandler -= cancelEventHandler; // 非同期動作中のBackgroundWorkerリストからこのBackgroundWorkerを削除 lock (fetchingChannelBackgroundWorkersLock) { if (fetchingChannelBackgroundWorkers.ContainsKey(headline) == true && fetchingChannelBackgroundWorkers[headline] == (BackgroundWorker)sender) { fetchingChannelBackgroundWorkers.Remove(headline); } } if (e.Error != null) { OnFetchChannelsAsyncExceptionEvent(headline, e.Error); } else if (e.Cancelled == true) { OnFetchChannelsAsyncCancelEvent(headline); } }); // 非同期動作中のBackgroundWorkerリストにこのBackgroundWorkerを追加 lock (fetchingChannelBackgroundWorkersLock) { fetchingChannelBackgroundWorkers.Add(headline, bg); } OnFetchChannelsAsync(headline); bg.RunWorkerAsync(); OnFetchedChannelsAsync(headline); }
/// <summary> /// コンストラクタ /// </summary> /// <param name="headline">例外が発生したヘッドライン</param> /// <param name="exception">例外</param> public FetchChannelsAsyncExceptionEventArgs(HeadlineBase headline, Exception exception) { this.headline = headline; this.exception = exception; }
/// <summary> /// ヘッドラインコンボボックスの内容を更新する /// </summary> private void UpdateHeadlineListComboBox() { #region ヘッドラインを更新する必要があるかをチェック // ヘッドラインの数がコンボボックス項目数と一致しない場合は更新の必要あり if (HeadlineManager.Headlines.Length == headlineListComboBox.Items.Count) { bool isUpdate = false; for (int i = 0; i < headlineListComboBox.Items.Count; ++i) { // コンボボックスのヘッドラインと、所持しているヘッドラインが異なる場合には更新の必要あり if (HeadlineManager.Headlines[i] != ((HeadlineCombo)headlineListComboBox.Items[i]).Headline) { isUpdate = true; break; } // コンボボックスのテキスト表示内容と、所持しているヘッドラインのテキスト表示内容が異なる場合には更新の必要あり if (((HeadlineCombo)headlineListComboBox.Items[i]).Display != headlineComboBoxTexts[i]) { isUpdate = true; break; } } // 更新の必要がない場合はここで終了 if (isUpdate == false) { return; } } #endregion // ヘッドラインを更新する必要があるかをチェック // 選択されているヘッドラインを取得 HeadlineCombo selectedHeadlineCombo = (HeadlineCombo)headlineListComboBox.SelectedItem; HeadlineBase selected = (selectedHeadlineCombo != null) ? selectedHeadlineCombo.Headline : null; headlineListComboBox.BeginUpdate(); headlineComboBoxTexts.Clear(); // コンボボックスの内容を生成 headlineListComboBox.Items.Clear(); foreach (HeadlineBase headline in HeadlineManager.Headlines) { HeadlineCombo combo = new HeadlineCombo(headline); headlineListComboBox.Items.Add(combo); headlineComboBoxTexts.Add(combo.Display); } // コンボボックスの選択を復元 if (selected != null) { for (int i = 0; i < headlineListComboBox.Items.Count; ++i) { if (((HeadlineCombo)headlineListComboBox.Items[i]).Headline == selected) { headlineListComboBox.SelectedIndex = i; break; } } } // 選択が存在しない場合 if (selected == null || headlineListComboBox.SelectedIndex == -1) { // ヘッドラインが存在したら一番最初のヘッドラインを選択 if (headlineListComboBox.Items.Count > 0) { headlineListComboBox.SelectedIndex = 0; } } headlineListComboBox.EndUpdate(); }
/// <summary> /// コンストラクタ /// </summary> /// <param name="headline">ヘッドライン</param> public HeadlineCombo(HeadlineBase headline) { this.headline = headline; }
/// <summary> /// コンストラクタ /// </summary> /// <param name="headline">ヘッドライン</param> public HeadlineEventArgs(HeadlineBase headline) { this.headline = headline; }