Exemple #1
0
        public static LiveSuggestion Make(this LiveStatusType liveStatus, NicoLiveVideo liveVideo, PageManager pageManager)
        {
            string title = liveStatus.ToString();

            List <SuggestAction> actions = new List <SuggestAction>();

            switch (liveStatus)
            {
            case LiveStatusType.NotFound:
                title = "放送が見つかりませんでした";
                break;

            case LiveStatusType.Closed:
                title = "放送は終了しました";
                break;

            case LiveStatusType.ComingSoon:
                title = "放送はもうすぐ始まります";
                break;

            case LiveStatusType.Maintenance:
                title = "現在メンテナンス中です";
                break;

            case LiveStatusType.CommunityMemberOnly:
                title = "この放送はコミュニティメンバー限定です";
                actions.Add(new SuggestAction("コミュニティページを開く", () =>
                {
                    pageManager.OpenPage(HohoemaPageType.Community, liveVideo.BroadcasterCommunityId);
                }));
                break;

            case LiveStatusType.Full:
                title = "満員です";
                break;

            case LiveStatusType.PremiumOnly:
                title = "この放送はプレミアム会員限定です";
                break;

            case LiveStatusType.NotLogin:
                title = "視聴するには「ニコニコ」にログインが必要です";
                actions.Add(new SuggestAction("ログイン", async() =>
                {
                    var dialog = new Dialogs.NiconicoLoginDialog();
                    var result = await dialog.ShowAsync();
                    if (result == Windows.UI.Xaml.Controls.ContentDialogResult.Primary)
                    {
                        await liveVideo.StartLiveWatchingSessionAsync();
                    }
                }));
                break;

            default:
                break;
            }


            return(new LiveSuggestion(title, actions.ToArray()));
        }
        private async Task StartLoginSequence()
        {
            var dialog = new Dialogs.NiconicoLoginDialog();

            var currentStatus = await NiconicoSession.CheckSignedInStatus();

            if (currentStatus == NiconicoSessionStatus.ServiceUnavailable)
            {
                dialog.WarningText = "UnavailableNiconicoService".Translate();

                NotificationService.ShowLiteInAppNotification("UnavailableNiconicoService".Translate(), DisplayDuration.MoreAttention, Windows.UI.Xaml.Controls.Symbol.Important);
            }

            var account = await AccountManager.GetPrimaryAccount();

            if (account != null)
            {
                dialog.Mail     = account.Item1;
                dialog.Password = account.Item2;

                dialog.IsRememberPassword = true;
            }

            bool isLoginSuccess = false;
            bool isCanceled     = false;

            while (!isLoginSuccess)
            {
                var result = await dialog.ShowAsync();

                if (result != Windows.UI.Xaml.Controls.ContentDialogResult.Primary)
                {
                    isCanceled = true;
                    break;
                }

                dialog.WarningText = string.Empty;

                _twoFactorAuthLoginCts = new TaskCompletionSource <long>();
                var loginResult = await NiconicoSession.SignIn(dialog.Mail, dialog.Password, true);

                if (loginResult == NiconicoSessionStatus.RequireTwoFactorAuth)
                {
                    await _twoFactorAuthLoginCts.Task;

                    loginResult = await NiconicoSession.CheckSignedInStatus();
                }

                _twoFactorAuthLoginCts = null;

                if (loginResult == NiconicoSessionStatus.ServiceUnavailable)
                {
                    // サービス障害中
                    // 何か通知を出す?
                    NotificationService.ShowLiteInAppNotification("UnavailableNiconicoService".Translate(), DisplayDuration.MoreAttention, Windows.UI.Xaml.Controls.Symbol.Important);
                    break;
                }
                else if (loginResult == NiconicoSessionStatus.Failed)
                {
                    dialog.WarningText = "LoginFailed_WrongMailOrPassword".Translate();
                }

                isLoginSuccess = loginResult == NiconicoSessionStatus.Success;
            }

            // ログインを選択していた場合にのみアカウント情報を更新する
            // (キャンセル時は影響を発生させない)
            if (!isCanceled)
            {
                if (account != null)
                {
                    AccountManager.RemoveAccount(account.Item1);
                }

                AccountManager.SetPrimaryAccountId(dialog.Mail);
                if (dialog.IsRememberPassword)
                {
                    await AccountManager.AddOrUpdateAccount(dialog.Mail, dialog.Password);
                }
            }
        }
        private async Task StartLoginSequence()
        {
            var dialog = new Dialogs.NiconicoLoginDialog();



            var currentStatus = await NiconicoSession.CheckSignedInStatus();

            if (currentStatus == Mntone.Nico2.NiconicoSignInStatus.ServiceUnavailable)
            {
                dialog.WarningText = "【ニコニコサービス利用不可】\nメンテナンス中またはサービス障害が発生しているかもしれません";

                // TODO: トースト通知で障害発生中としてブラウザで開くアクションを提示?
            }
            if (currentStatus == Mntone.Nico2.NiconicoSignInStatus.TwoFactorAuthRequired)
            {
                dialog.WarningText = "二要素認証によるログインが必要です";
            }


            var account = await AccountManager.GetPrimaryAccount();

            if (account != null)
            {
                dialog.Mail     = account.Item1;
                dialog.Password = account.Item2;

                dialog.IsRememberPassword = true;
            }

            bool isLoginSuccess = false;
            bool isCanceled     = false;

            while (!isLoginSuccess)
            {
                var result = await dialog.ShowAsync();

                if (result != Windows.UI.Xaml.Controls.ContentDialogResult.Primary)
                {
                    isCanceled = true;
                    break;
                }

                dialog.WarningText = string.Empty;

                var loginResult = await NiconicoSession.SignIn(dialog.Mail, dialog.Password, true);

                if (loginResult == Mntone.Nico2.NiconicoSignInStatus.ServiceUnavailable)
                {
                    // サービス障害中
                    // 何か通知を出す?
                    NotificationService.ShowInAppNotification(new InAppNotificationPayload()
                    {
                        Content        = "【ニコニコサービス利用不可】\nサービスがメンテナンス中、また何らかの障害が発生しているかもしれません"
                        , ShowDuration = TimeSpan.FromSeconds(10)
                    });
                    break;
                }

                if (loginResult == Mntone.Nico2.NiconicoSignInStatus.TwoFactorAuthRequired)
                {
                    break;
                }

                if (loginResult == Mntone.Nico2.NiconicoSignInStatus.Failed)
                {
                    dialog.WarningText = "メールアドレスかパスワードが違うようです";
                }

                isLoginSuccess = loginResult == Mntone.Nico2.NiconicoSignInStatus.Success;
            }

            // ログインを選択していた場合にのみアカウント情報を更新する
            // (キャンセル時は影響を発生させない)
            if (!isCanceled)
            {
                if (account != null)
                {
                    AccountManager.RemoveAccount(account.Item1);
                }

                if (dialog.IsRememberPassword)
                {
                    await AccountManager.AddOrUpdateAccount(dialog.Mail, dialog.Password);

                    AccountManager.SetPrimaryAccountId(dialog.Mail);
                }
                else
                {
                    AccountManager.SetPrimaryAccountId("");
                }
            }
        }
        private async Task StartLoginSequence()
        {
            var dialog = new Dialogs.NiconicoLoginDialog();

            var currentStatus = await NiconicoSession.CheckSignedInStatus();

            if (currentStatus == Mntone.Nico2.NiconicoSignInStatus.ServiceUnavailable)
            {
                dialog.WarningText = "UnavailableNiconicoService".Translate();

                NotificationService.ShowInAppNotification(new InAppNotificationPayload()
                {
                    Content      = "UnavailableNiconicoService".Translate(),
                    ShowDuration = TimeSpan.FromSeconds(10)
                });
            }

            var account = await AccountManager.GetPrimaryAccount();

            if (account != null)
            {
                dialog.Mail     = account.Item1;
                dialog.Password = account.Item2;

                dialog.IsRememberPassword = true;
            }

            bool isLoginSuccess = false;
            bool isCanceled     = false;

            while (!isLoginSuccess)
            {
                var result = await dialog.ShowAsync();

                if (result != Windows.UI.Xaml.Controls.ContentDialogResult.Primary)
                {
                    isCanceled = true;
                    break;
                }

                dialog.WarningText = string.Empty;

                var loginResult = await NiconicoSession.SignIn(dialog.Mail, dialog.Password, true);

                if (loginResult == Mntone.Nico2.NiconicoSignInStatus.ServiceUnavailable)
                {
                    // サービス障害中
                    // 何か通知を出す?
                    NotificationService.ShowInAppNotification(new InAppNotificationPayload()
                    {
                        Content        = "UnavailableNiconicoService".Translate()
                        , ShowDuration = TimeSpan.FromSeconds(10)
                    });
                    break;
                }

                if (loginResult == Mntone.Nico2.NiconicoSignInStatus.TwoFactorAuthRequired)
                {
                    break;
                }

                if (loginResult == Mntone.Nico2.NiconicoSignInStatus.Failed)
                {
                    dialog.WarningText = "LoginFailed_WrongMailOrPassword".Translate();
                }

                isLoginSuccess = loginResult == Mntone.Nico2.NiconicoSignInStatus.Success;
            }

            // ログインを選択していた場合にのみアカウント情報を更新する
            // (キャンセル時は影響を発生させない)
            if (!isCanceled)
            {
                if (account != null)
                {
                    AccountManager.RemoveAccount(account.Item1);
                }

                if (dialog.IsRememberPassword)
                {
                    await AccountManager.AddOrUpdateAccount(dialog.Mail, dialog.Password);

                    AccountManager.SetPrimaryAccountId(dialog.Mail);
                }
                else
                {
                    AccountManager.SetPrimaryAccountId("");
                }
            }
        }
 protected override async void Execute(object parameter)
 {
     var loginDialog = new Dialogs.NiconicoLoginDialog();
     await loginDialog.ShowAsync();
 }