public async void addHistory(string liveId) { //番組情報取得API var nicoLiveProgramInfo = new NicoLiveProgramInfo(); var result = await nicoLiveProgramInfo.getProgramInfo(liveId); //履歴機能 if (Properties.Settings.Default.program_history != "") { //追加 var historyList = Properties.Settings.Default.program_history; var historyJSONArray = JsonConvert.DeserializeObject <List <ProgramHistoryListViewData> >(historyList); historyJSONArray.Insert(0, new ProgramHistoryListViewData { Content = result.data.title, LiveId = liveId, BeginAt = result.data.beginAt, webSiteName = "ニコニコ生放送" }); //JSON配列に変換 Properties.Settings.Default.program_history = JsonConvert.SerializeObject(historyJSONArray); } else { //初めての履歴/// var historyJSONArray = JsonConvert.DeserializeObject <List <ProgramHistoryListViewData> >("[]"); historyJSONArray.Insert(0, new ProgramHistoryListViewData { Content = result.data.title, LiveId = liveId, BeginAt = result.data.beginAt, webSiteName = "ニコニコ生放送" }); //JSON配列に変換 Properties.Settings.Default.program_history = JsonConvert.SerializeObject(historyJSONArray); } Properties.Settings.Default.Save(); loadHisotry(); }
private async void AutoAdmissionAddButton_Click(object sender, RoutedEventArgs e) { //予約枠自動入場追加ボタン var autoAdmissionDialog = new AutoAdmissionDialog(); var nicoProgramInfo = new NicoLiveProgramInfo(); var nicoHtmlProgram = new NicoLiveHTMLProgram(); if (autoAdmissionDialog.ShowDialog() == true) { //HTMLからJSON取る //programinfoのAPIだと公式番組(アニメ一挙、朝鮮中央テレビ)などの番組は取得できないのでHTMLの中にあるJSONを取ることにした。 var htmlJson = await nicoHtmlProgram.getProgramJSONData(autoAdmissionDialog.ProgramID); if (htmlJson.pageContents.watch.watchInformation.program.liveCycle == "BeforeOpen") { //UnixTime var unixTime = htmlJson.pageContents.watch.watchInformation.program.openAt / 1000L; var title = htmlJson.pageContents.watch.watchInformation.program.title; var id = autoAdmissionDialog.ProgramID; //追加 autoAdmissionList.addAdmission(title, id, unixTime, true); } else { MessageBox.Show("予約枠のみが追加可能です。", "予約枠追加", MessageBoxButton.OK, MessageBoxImage.Error); } } }
private async void AddAdmissionDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) { var id = AddAdmissionDialogProgramID.Text; //予約枠自動入場 手動追加 APIで自動取得 押したとき //APIを叩く(https://live2.nicovideo.jp/watch/{LiveID}/programinfo) var nicoProgramInfo = new NicoLiveProgramInfo(); var json = await nicoProgramInfo.getProgramInfo(id); if (json != null) { //予約枠? if (json.data.status == "reserved") { AddAdmissionDialogProgramTitle.Text = json.data.title; //UnixTime->DateTime var dateTime = DateTimeOffset.FromUnixTimeSeconds(json.data.beginAt).LocalDateTime; //TimeSpan作ってTimePickerに反映させる var timeSpan = new TimeSpan(dateTime.Hour, dateTime.Minute, 0); //適用 AddAdmissionDialogDatePicker.Date = dateTime; AddAdmissionDialogTimePicker.Time = timeSpan; //何故か消えるので再表示 await AddAdmissionDialog.ShowAsync(); } else { //予約枠以外は追加できないようにする ContentDialog errorDiaog = new ContentDialog { Title = "予約枠以外は利用できません。", CloseButtonText = "閉じる" }; await errorDiaog.ShowAsync(); } } }