예제 #1
0
        public async Task <NiconicoSignInStatus> SignOut()
        {
            NiconicoSignInStatus result = NiconicoSignInStatus.Failed;

            try
            {
                await _SigninLock.WaitAsync();

                if (NiconicoContext == null)
                {
                    return(result);
                }

                // 全てのバックグラウンド処理をキャンセル
                BackgroundUpdater.CancelAll();


                try
                {
                    MediaManager.StopCacheDownload();
                }
                catch { }

                try
                {
                    if (Util.InternetConnection.IsInternet())
                    {
                        result = await NiconicoContext.SignOutOffAsync();
                    }
                    else
                    {
                        result = NiconicoSignInStatus.Success;
                    }

                    NiconicoContext.Dispose();
                }
                finally
                {
                    NiconicoContext = new NiconicoContext();

                    FollowManager = null;
                    LoginUserId   = uint.MaxValue;

                    OnSignout?.Invoke();
                }
            }
            finally
            {
                UpdateServiceStatus();

                _SigninLock.Release();
            }

            return(result);
        }
예제 #2
0
 internal BackgroundUpdateScheduleHandler(
     IBackgroundUpdateable target,
     BackgroundUpdater owner,
     string id,
     string groupId,
     int priority,
     string label
     )
 {
     Target   = target;
     Owner    = owner;
     Id       = id;
     GroupId  = groupId;
     Priority = priority;
     Label    = label;
 }
예제 #3
0
        private void RagistrationBackgroundUpdateHandle()
        {
            // 非同期な初期化処理の遅延実行をスケジュール
            MediaManagerUpdater = BackgroundUpdater.RegistrationBackgroundUpdateScheduleHandler(
                MediaManager,
                "NicoMediaManager",
                label: "キャッシュ"
                );


            MylistManagerUpdater = BackgroundUpdater.RegistrationBackgroundUpdateScheduleHandler(
                UserMylistManager,
                "MylistManagerManager",
                label: "マイリスト一覧"
                );

            MediaManagerUpdater.ScheduleUpdate();
        }
예제 #4
0
        private HohoemaApp(IEventAggregator ea)
        {
            EventAggregator           = ea;
            NiconicoContext           = new NiconicoContext();
            LoginUserId               = uint.MaxValue;
            LoggingChannel            = new LoggingChannel("HohoemaLog", new LoggingChannelOptions(HohoemaLoggerGroupGuid));
            UserSettings              = new HohoemaUserSettings();
            ContentFinder             = new NiconicoContentFinder(this);
            UserMylistManager         = new UserMylistManager(this);
            OtherOwneredMylistManager = new OtherOwneredMylistManager(ContentFinder);
            FeedManager               = new FeedManager(this);

            FollowManager = null;

            _SigninLock = new SemaphoreSlim(1, 1);

            BackgroundUpdater = new BackgroundUpdater("HohoemaBG", UIDispatcher);

            ApplicationData.Current.DataChanged += Current_DataChanged;


            UpdateServiceStatus();
            NetworkInformation.NetworkStatusChanged += NetworkInformation_NetworkStatusChanged;
        }
예제 #5
0
        public IAsyncOperation <NiconicoSignInStatus> SignIn(string mailOrTelephone, string password)
        {
            return(AsyncInfo.Run <NiconicoSignInStatus>(async(cancelToken) =>
            {
                if (!Util.InternetConnection.IsInternet())
                {
                    NiconicoContext?.Dispose();
                    NiconicoContext = new NiconicoContext();
                    return NiconicoSignInStatus.Failed;
                }

                if (NiconicoContext != null &&
                    NiconicoContext.AuthenticationToken?.MailOrTelephone == mailOrTelephone &&
                    NiconicoContext.AuthenticationToken?.Password == password)
                {
                    return NiconicoSignInStatus.Success;
                }

                await SignOut();

                try
                {
                    await _SigninLock.WaitAsync();



                    var context = new NiconicoContext(new NiconicoAuthenticationToken(mailOrTelephone, password));

                    context.AdditionalUserAgent = HohoemaUserAgent;

                    LoginErrorText = "";

                    Debug.WriteLine("try login");

                    NiconicoSignInStatus result = NiconicoSignInStatus.Failed;
                    try
                    {
                        result = await context.SignInAsync();
                    }
                    catch
                    {
                        LoginErrorText = "サインインに失敗、再起動をお試しください";
                    }

                    UpdateServiceStatus(result);

                    NiconicoContext = context;

                    if (result == NiconicoSignInStatus.Success)
                    {
                        Debug.WriteLine("login success");


                        using (var loginActivityLogger = LoggingChannel.StartActivity("login process"))
                        {
                            loginActivityLogger.LogEvent("begin login process.");

                            var fields = new LoggingFields();

                            await Task.Delay(500);
                            try
                            {
                                loginActivityLogger.LogEvent("getting UserInfo.");
                                var userInfo = await NiconicoContext.User.GetInfoAsync();

                                LoginUserId = userInfo.Id;
                                IsPremiumUser = userInfo.IsPremium;

                                {
                                    try
                                    {
                                        var user = await NiconicoContext.User.GetUserDetail(LoginUserId.ToString());
                                        LoginUserName = user.Nickname;
                                        UserIconUrl = user.ThumbnailUri;

                                        OnPropertyChanged(nameof(LoginUserName));
                                        OnPropertyChanged(nameof(UserIconUrl));
                                    }
                                    catch (Exception ex)
                                    {
                                        throw new Exception("ユーザー名取得のフォールバック処理に失敗 + " + LoginUserId, ex);
                                    }
                                }

                                fields.AddString("user id", LoginUserId.ToString());
                                fields.AddString("user name", LoginUserName);
                                fields.AddBoolean("is premium", IsPremiumUser);

                                loginActivityLogger.LogEvent("[Success]:get UserInfo.", fields, LoggingLevel.Information);
                            }
                            catch (Exception ex)
                            {
                                LoginErrorText = $"ユーザー情報の取得に失敗しました。再起動をお試しください。({ex.Message})";

                                fields.AddString("mail", mailOrTelephone);
                                loginActivityLogger.LogEvent(LoginErrorText, fields, LoggingLevel.Warning);

                                NiconicoContext.Dispose();
                                NiconicoContext = new NiconicoContext();

                                return NiconicoSignInStatus.Failed;
                            }

                            fields.Clear();



                            Debug.WriteLine("user id is : " + LoginUserId);


                            // 0.4.0以前のバージョンからのログインユーザー情報の移行処理
                            try
                            {
                                await MigrateLegacyUserSettings(LoginUserId.ToString());
                            }
                            catch
                            {
                                LoginErrorText = "ユーザー設定の過去バージョンとの統合処理に失敗しました。";

                                return NiconicoSignInStatus.Failed;
                            }


                            try
                            {
                                Debug.WriteLine("initilize: fav");
                                loginActivityLogger.LogEvent("initialize user favorite");
                                FollowManager = await FollowManager.Create(this, LoginUserId);
                            }
                            catch
                            {
                                LoginErrorText = "お気に入り情報の取得に失敗しました。再起動をお試しください。";
                                Debug.WriteLine(LoginErrorText);
                                loginActivityLogger.LogEvent(LoginErrorText, fields, LoggingLevel.Error);
                                NiconicoContext.Dispose();
                                NiconicoContext = new NiconicoContext();
                                return NiconicoSignInStatus.Failed;
                            }

                            FollowManagerUpdater = BackgroundUpdater.RegistrationBackgroundUpdateScheduleHandler(
                                FollowManager,
                                "FollowManager",
                                label: "フォロー"
                                );


                            Debug.WriteLine("Login done.");
                            loginActivityLogger.LogEvent("[Success]: Login done");
                        }

                        // BG更新をスケジュール
                        UpdateAllComponent();

                        // 動画のキャッシュフォルダの選択状態をチェック
                        await(App.Current as App).CheckVideoCacheFolderState();


                        // サインイン完了
                        OnSignin?.Invoke();

                        // TODO: 途中だった動画のダウンロードを再開
                        // await MediaManager.StartBackgroundDownload();



                        // ニコニコサービスの裏で取得させたいので強制的に待ちを挟む
                        await Task.Delay(1000);
                    }
                    else
                    {
                        Debug.WriteLine("login failed");
                        NiconicoContext?.Dispose();
                        NiconicoContext = null;
                    }

                    return result;
                }
                finally
                {
                    _SigninLock.Release();
                }
            }));
        }
예제 #6
0
 public void Dispose()
 {
     MediaManager?.Dispose();
     LoggingChannel?.Dispose();
     BackgroundUpdater?.Dispose();
 }