private async Task <bool> AddReservation(string liveId, string liveTitle)
        {
            var result = await NiconicoSession.Context.Live.ReservationAsync(liveId);

            bool isAdded = false;

            if (result.IsCanOverwrite)
            {
                // 予約数が上限到達、他のタイムシフトを削除すれば予約可能
                // いずれかの予約を削除するよう選択してもらう
                if (await HohoemaDialogService.ShowMessageDialog(
                        $"『{result.Data.Overwrite.Title}』を『{liveTitle}』のタイムシフト予約で上書きすると予約できます。\r(他のタイムシフトを削除したい場合はキャンセルしてタイムシフト一覧ページから操作してください。)",
                        "予約枠に空きがありません。古いタイムシフト予約を上書きしますか?"
                        , "予約を上書きする"
                        , "キャンセル"
                        ))
                {
                    result = await NiconicoSession.Context.Live.ReservationAsync(liveId, isOverwrite : true);
                }
            }

            if (result.IsOK)
            {
                // 予約できてるはず
                // LiveInfoのタイムシフト周りの情報と共に通知
                var notificationService = (App.Current as App).Container.Resolve <Services.NotificationService>();
                notificationService.ShowInAppNotification(new InAppNotificationPayload()
                {
                    Content = $"『{liveTitle}』のタイムシフトを予約しました。",
                });

                isAdded = true;
            }
            else if (result.IsCanOverwrite)
            {
                // 一つ前のダイアログで明示的的にキャンセルしてるはずなので特に通知を表示しない
            }
            else if (result.IsReservationDeuplicated)
            {
                var notificationService = (App.Current as App).Container.Resolve <Services.NotificationService>();
                notificationService.ShowInAppNotification(new InAppNotificationPayload()
                {
                    Content = $"指定された放送は既にタイムシフト予約しています。",
                });
            }
            else if (result.IsReservationExpired)
            {
                var notificationService = (App.Current as App).Container.Resolve <Services.NotificationService>();
                notificationService.ShowInAppNotification(new InAppNotificationPayload()
                {
                    Content = $"指定された放送はタイムシフト予約の期限を過ぎているため予約できませんでした。",
                });
            }

            return(isAdded);
        }
Ejemplo n.º 2
0
        private async Task <bool> AddReservation(string liveId, string liveTitle)
        {
            var result = await NiconicoSession.Context.Live.ReservationAsync(liveId);

            bool isAdded = false;

            if (result.IsCanOverwrite)
            {
                // 予約数が上限到達、他のタイムシフトを削除すれば予約可能
                // いずれかの予約を削除するよう選択してもらう
                if (await HohoemaDialogService.ShowMessageDialog(
                        "Dialog_ConfirmTimeshiftReservationiOverwrite".Translate(result.Data.Overwrite.Title, liveTitle),
                        "DialogTitle_ConfirmTimeshiftReservationiOverwrite".Translate(),
                        "Overwrite".Translate(),
                        "Cancel".Translate()
                        ))
                {
                    result = await NiconicoSession.Context.Live.ReservationAsync(liveId, isOverwrite : true);
                }
            }

            if (result.IsOK)
            {
                // 予約できてるはず
                // LiveInfoのタイムシフト周りの情報と共に通知
                var notificationService = (App.Current as App).Container.Resolve <Services.NotificationService>();
                notificationService.ShowInAppNotification(new InAppNotificationPayload()
                {
                    Content = "InAppNotification_AddedTimeshiftWithTitle".Translate(liveTitle),
                });

                isAdded = true;
            }
            else if (result.IsCanOverwrite)
            {
                // 一つ前のダイアログで明示的的にキャンセルしてるはずなので特に通知を表示しない
            }
            else if (result.IsReservationDeuplicated)
            {
                var notificationService = (App.Current as App).Container.Resolve <Services.NotificationService>();
                notificationService.ShowInAppNotification(new InAppNotificationPayload()
                {
                    Content = "InAppNotification_ExistTimeshift".Translate(),
                });
            }
            else if (result.IsReservationExpired)
            {
                var notificationService = (App.Current as App).Container.Resolve <Services.NotificationService>();
                notificationService.ShowInAppNotification(new InAppNotificationPayload()
                {
                    Content = "InAppNotification_TimeshiftExpired".Translate(),
                });
            }

            return(isAdded);
        }
        private async Task <bool> DeleteReservation(string liveId, string liveTitle)
        {
            if (string.IsNullOrEmpty(liveId))
            {
                throw new ArgumentException(nameof(liveId));
            }

            bool isDeleted = false;

            var token = await NiconicoSession.Context.Live.GetReservationTokenAsync();

            if (token == null)
            {
                return(isDeleted);
            }

            if (await HohoemaDialogService.ShowMessageDialog(
                    $"{liveTitle}",
                    "タイムシフト予約を削除しますか?"
                    , "予約を削除"
                    , "キャンセル"
                    )
                )
            {
                await NiconicoSession.Context.Live.DeleteReservationAsync(liveId, token);

                var deleteAfterReservations = await NiconicoSession.Context.Live.GetReservationsAsync();

                isDeleted = !deleteAfterReservations.Any(x => liveId.EndsWith(x));
                if (isDeleted)
                {
                    // 削除成功
                    var notificationService = (App.Current as App).Container.Resolve <Services.NotificationService>();
                    notificationService.ShowInAppNotification(new InAppNotificationPayload()
                    {
                        Content             = $"タイムシフト予約を削除しました。\r削除後の予約数は {deleteAfterReservations.Count}件 です。",
                        IsShowDismissButton = true,
                    });
                }
                else
                {
                    // まだ存在するゾイ
                    var notificationService = (App.Current as App).Container.Resolve <Services.NotificationService>();
                    notificationService.ShowInAppNotification(new InAppNotificationPayload()
                    {
                        Content             = $"【失敗】タイムシフト予約を削除できませんでした。",
                        IsShowDismissButton = true,
                    });

                    Debug.Fail("タイムシフト削除に失敗しました: " + liveId);
                }
            }

            return(isDeleted);
        }
Ejemplo n.º 4
0
        private async Task <bool> DeleteReservation(string liveId, string liveTitle)
        {
            if (string.IsNullOrEmpty(liveId))
            {
                throw new ArgumentException(nameof(liveId));
            }

            bool isDeleted = false;

            var token = await NiconicoSession.Context.Live.GetReservationTokenAsync();

            if (token == null)
            {
                return(isDeleted);
            }

            if (await HohoemaDialogService.ShowMessageDialog(
                    $"{liveTitle}",
                    "ConfirmDeleteTimeshift".Translate()
                    , "DeleteTimeshift".Translate()
                    , "Cancel".Translate()
                    )
                )
            {
                await NiconicoSession.Context.Live.DeleteReservationAsync(liveId, token);

                var deleteAfterReservations = await NiconicoSession.Context.Live.GetReservationsAsync();

                isDeleted = !deleteAfterReservations.Any(x => liveId.EndsWith(x));
                if (isDeleted)
                {
                    // 削除成功
                    var notificationService = (App.Current as App).Container.Resolve <Services.NotificationService>();
                    notificationService.ShowInAppNotification(new InAppNotificationPayload()
                    {
                        Content             = "InAppNotification_DeletedTimeshift".Translate(),
                        IsShowDismissButton = true,
                    });
                }
                else
                {
                    // まだ存在するゾイ
                    var notificationService = App.Current.Container.Resolve <Services.NotificationService>();
                    notificationService.ShowInAppNotification(new InAppNotificationPayload()
                    {
                        Content             = "InAppNotification_FailedDeleteTimeshift".Translate(),
                        IsShowDismissButton = true,
                    });

                    Debug.Fail("タイムシフト削除に失敗しました: " + liveId);
                }
            }

            return(isDeleted);
        }
        private async Task <bool> AddReservation(string liveId, string liveTitle)
        {
            var result = await NiconicoSession.ToolkitContext.Timeshift.ReserveTimeshiftAsync(liveId, overwrite : false);

            bool isAdded = false;

            if (result.IsCanOverwrite)
            {
                // 予約数が上限到達、他のタイムシフトを削除すれば予約可能
                // いずれかの予約を削除するよう選択してもらう
                if (await HohoemaDialogService.ShowMessageDialog(
                        "DialogContent_ConfirmTimeshiftReservationiOverwrite".Translate(result.Data.Overwrite.Title, liveTitle),
                        "DialogTitle_ConfirmTimeshiftReservationiOverwrite".Translate(),
                        "Overwrite".Translate(),
                        "Cancel".Translate()
                        ))
                {
                    result = await NiconicoSession.ToolkitContext.Timeshift.ReserveTimeshiftAsync(liveId, overwrite : true);
                }
            }

            if (result.IsSuccess)
            {
                // 予約できてるはず
                // LiveInfoのタイムシフト周りの情報と共に通知
                var notificationService = Microsoft.Toolkit.Mvvm.DependencyInjection.Ioc.Default.GetService <Services.NotificationService>();
                notificationService.ShowLiteInAppNotification_Success("InAppNotification_AddedTimeshiftWithTitle".Translate(liveTitle));

                isAdded = true;
            }
            else if (result.IsCanOverwrite)
            {
                // 一つ前のダイアログで明示的的にキャンセルしてるはずなので特に通知を表示しない
            }
            else if (result.IsReservationDeuplicated)
            {
                var notificationService = Microsoft.Toolkit.Mvvm.DependencyInjection.Ioc.Default.GetService <Services.NotificationService>();
                notificationService.ShowLiteInAppNotification_Success("InAppNotification_ExistTimeshift".Translate());
            }
            else if (result.IsReservationExpired)
            {
                var notificationService = Microsoft.Toolkit.Mvvm.DependencyInjection.Ioc.Default.GetService <Services.NotificationService>();
                notificationService.ShowLiteInAppNotification_Fail("InAppNotification_TimeshiftExpired".Translate());
            }

            return(isAdded);
        }
        private async Task <bool> DeleteReservation(string liveId, string liveTitle)
        {
            if (string.IsNullOrEmpty(liveId))
            {
                throw new ArgumentException(nameof(liveId));
            }

            bool isDeleted = false;

            var token = await NiconicoSession.ToolkitContext.Timeshift.GetReservationTokenAsync();

            if (token == null)
            {
                return(isDeleted);
            }

            if (await HohoemaDialogService.ShowMessageDialog(
                    $"{liveTitle}",
                    "ConfirmDeleteTimeshift".Translate()
                    , "DeleteTimeshift".Translate()
                    , "Cancel".Translate()
                    )
                )
            {
                await NiconicoSession.ToolkitContext.Timeshift.DeleteTimeshiftReservationAsync(liveId, token);

                var deleteAfterReservations = await NiconicoSession.ToolkitContext.Timeshift.GetTimeshiftReservationsDetailAsync();

                isDeleted = !deleteAfterReservations.Data.Items.Any(x => liveId.EndsWith(x.LiveId));
                if (isDeleted)
                {
                    // 削除成功
                    var notificationService = Microsoft.Toolkit.Mvvm.DependencyInjection.Ioc.Default.GetService <Services.NotificationService>();
                    notificationService.ShowLiteInAppNotification_Success("InAppNotification_DeletedTimeshift".Translate());
                }
                else
                {
                    // まだ存在するゾイ
                    var notificationService = Microsoft.Toolkit.Mvvm.DependencyInjection.Ioc.Default.GetService <Services.NotificationService>();
                    notificationService.ShowLiteInAppNotification_Fail("InAppNotification_FailedDeleteTimeshift".Translate());

                    Debug.Fail("タイムシフト削除に失敗しました: " + liveId);
                }
            }

            return(isDeleted);
        }