Esempio n. 1
0
        /// <summary>
        /// インスタレーション情報をNebulaサーバから取得する
        /// </summary>
        /// <returns>NbSsePushInstallation</returns>
        /// <exception cref="InvalidOperationException">インスタレーションのパラメータ未設定、インスタレーション情報の保存・削除失敗</exception>
        /// <exception cref="NbHttpException">リクエスト送信失敗</exception>
        public static async Task <NbSsePushInstallation> RefreshCurrentInstallation()
        {
            NbSsePushInstallation installation = NbSsePushInstallation.GetCurrentInstallation();

            NbUtil.NotNullWithInvalidOperation(installation.InstallationId, "Null installationId");

            try
            {
                // リクエスト生成&送信
                var json = await installation.SendRequestForRefresh();

                // ストレージに保存
                installation.SaveAndLoad(json);
            }
            catch (NbHttpException e)
            {
                // 該当するインスタレーションが存在しない場合
                if (e.StatusCode == HttpStatusCode.NotFound)
                {
                    // ストレージ内のインスタレーション情報を削除
                    installation.DeleteAndLoad();
                }
                throw e;
            }
            return(installation);
        }
Esempio n. 2
0
        // インスタレーション情報(SSE情報含む)が存在するかどうかチェック
        private bool IsInstallationExists()
        {
            NbSsePushInstallation installation = NbSsePushInstallation.GetCurrentInstallation();

            if (!string.IsNullOrEmpty(installation.InstallationId) && HasSseInfo(installation))
            {
                return(true);
            }

            return(false);
        }
Esempio n. 3
0
        // 端末ストレージに保存されているインスタレーション情報を取得し、SSE情報を保持する
        private NbSsePushInstallation LoadCurrentInstallation()
        {
            NbSsePushInstallation installation = NbSsePushInstallation.GetCurrentInstallation();

            NbUtil.NotNullWithInvalidOperation(installation.InstallationId, "Null installationId");

            // SSE情報を保持
            this._username = installation.Username;
            this._password = installation.Password;
            this._uri      = installation.Uri;

            return(installation);
        }
Esempio n. 4
0
        // 自動回復処理
        internal bool AutoRecovery(HttpStatusCode statusCode, HttpWebResponse response)
        {
            try
            {
                // 排他ロック
                AcquireLock();
            }
            catch (InvalidOperationException)
            {
                Debug.WriteLine("NbSsePushReceiveClient: Auto recovery fails because of lock");
                return(false);
            }

            // インスタレーション(SSE情報含む)の存在チェック
            if (!IsInstallationExists())
            {
                Debug.WriteLine("NbSsePushReceiveClient: Auto recovery fails because Installation doesn't exist.");

                ReleaseLock();
                return(false);
            }

            // 自動回復処理を実施する
            try
            {
                // インスタレーション再登録
                var installation = NbSsePushInstallation.GetCurrentInstallation().Save().Result;

                ReleaseLock();

                // SSEサーバへ再接続
                _sseClient.Open(installation.Username, installation.Password);
                return(true);
            }
            // Save()失敗時の処理。Open()のエラーはデリゲート関数で通知される。
            catch (Exception)
            {
                Debug.WriteLine("NbSsePushReceiveClient: Auto recovery fails because Installation can't be Registered.");

                ReleaseLock();
                return(false);
            }
        }