Esempio n. 1
0
        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("");
                }
            }
        }
Esempio n. 2
0
        private async Task <InAppNotificationPayload> SubmitLiveContentSuggestion(string liveId)
        {
            var liveDesc = await NicoLiveProvider.GetLiveInfoAsync(liveId);

            if (liveDesc == null)
            {
                return(null);
            }

            var liveTitle = liveDesc.VideoInfo.Video.Title;

            var payload = new InAppNotificationPayload()
            {
                Content             = "InAppNotification_ContentDetectedFromClipboard".Translate(liveTitle),
                ShowDuration        = DefaultNotificationShowDuration,
                SymbolIcon          = Symbol.Video,
                IsShowDismissButton = true,
                Commands            =
                {
                    new InAppNotificationCommand()
                    {
                        Label   = "WatchLiveStreaming".Translate(),
                        Command = new DelegateCommand(() =>
                        {
                            _eventAggregator.GetEvent <Services.Player.PlayerPlayLiveRequest>()
                            .Publish(new Services.Player.PlayerPlayLiveRequestEventArgs()
                            {
                                LiveId = liveId
                            });

                            NotificationService.DismissInAppNotification();
                        })
                    },
                    new InAppNotificationCommand()
                    {
                        Label   = HohoemaPageType.LiveInfomation.Translate(),
                        Command = new DelegateCommand(() =>
                        {
                            PageManager.OpenPageWithId(HohoemaPageType.LiveInfomation, liveId);

                            NotificationService.DismissInAppNotification();
                        })
                    },
                }
            };

            if (liveDesc.VideoInfo.Community != null)
            {
                payload.Commands.Add(new InAppNotificationCommand()
                {
                    Label   = HohoemaPageType.Community.Translate(),
                    Command = new DelegateCommand(() =>
                    {
                        PageManager.OpenPageWithId(HohoemaPageType.Community, liveDesc.VideoInfo.Community.GlobalId);

                        NotificationService.DismissInAppNotification();
                    })
                });
            }

            return(payload);
        }