Пример #1
0
 //save後処理  オーバーライド用 新規登録時のみログインを行う
 internal override void _afterSave(int statusCode, NCMBException error)
 {
     if (statusCode == 201 && error == null)
     {
         _saveCurrentUser((NCMBUser)this);
     }
 }
Пример #2
0
        /// <summary>
        /// 指定IDのオブジェクトを取得を行います。<br/>
        /// 通信結果を受け取るために必ずコールバックを設定を行います。
        /// </summary>
        /// <param name="objectId">  オブジェクトID</param>
        /// <param name="callback">  コールバック</param>
        public void GetAsync(string objectId, NCMBGetCallback <T> callback)
        {
            if (callback == null)
            {
                throw new ArgumentException("It is necessary to always set a callback.");
            }

            new AsyncDelegate(delegate {
                string url = _getSearchUrl(this._className);                 //クラス毎のURL作成
                //オブジェクト取得API
                url += "/" + objectId;
                ConnectType type = ConnectType.GET;                //メソッドタイプの設定
                //通信処理
                NCMBConnection con = new NCMBConnection(url, type, null, NCMBUser._getCurrentSessionToken());
                con.Connect(delegate(int statusCode, string responseData, NCMBException error) {
                    Dictionary <string, object> resultObj;
                    NCMBObject objectData = null;
                    try {
                        if (error == null)
                        {
                            resultObj  = MiniJSON.Json.Deserialize(responseData) as Dictionary <string, object>;
                            objectData = _convertGetResponse(resultObj);
                        }
                    } catch (Exception e) {
                        error = new NCMBException(e);
                    }
                    //引数はリスト(中身NCMBObject)とエラーをユーザーに返す
                    Platform.RunOnMainThread(delegate {
                        callback((T)objectData, error);
                    });
                    return;
                });
            }).BeginInvoke((IAsyncResult r) => {
            }, null);
        }
 //save後処理  オーバーライド用 ローカルのcurrentUserを反映する
 internal override void _afterSave(int statusCode, NCMBException error)
 {
     // register by SNS
     if (statusCode == 201 && error == null &&
         this.ContainsKey("authData") && this["authData"] != null)
     {
         _saveCurrentUser((NCMBUser)this);
     }
     else if (statusCode == 200 && error == null)
     {
         // reauthen by SNS
         if (_currentUser == null &&
             this.ContainsKey("authData") && this["authData"] != null)
         {
             _saveCurrentUser((NCMBUser)this);
             // update logged user
         }
         else if (_currentUser != null && _currentUser.ObjectId.Equals(this.ObjectId))
         {
             this.SessionToken = _currentUser.SessionToken;
             _saveCurrentUser((NCMBUser)this);
             this._currentOperations.Clear();
         }
     }
 }
Пример #4
0
        internal static void _logOut(NCMBCallback callback)
        {
            string      url     = _getLogOutUrl();    //URL作成
            ConnectType type    = ConnectType.GET;
            string      content = null;

            //ログを確認(通信前)
            NCMBDebug.Log("【url】:" + url + Environment.NewLine + "【type】:" + type + Environment.NewLine + "【content】:" + content);
            //通信処理
            NCMBConnection con = new NCMBConnection(url, type, content, NCMBUser._getCurrentSessionToken());

            con.Connect(delegate(int statusCode, string responseData, NCMBException error) {
                try {
                    NCMBDebug.Log("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData);
                    if (error != null)
                    {
                        NCMBDebug.Log("[DEBUG AFTER CONNECT] Error: " + error.ErrorMessage);
                    }
                    else
                    {
                        _logOutEvent();
                    }
                } catch (Exception e) {
                    error = new NCMBException(e);
                }
                if (callback != null)
                {
                    Platform.RunOnMainThread(delegate {
                        callback(error);
                    });
                }
                return;
            });
        }
Пример #5
0
 //delete後処理  オーバーライド用
 internal override void _afterDelete(NCMBException error)
 {
     if (error == null)
     {
         _logOutEvent();
     }
 }
Пример #6
0
        private static void _ncmbLogIn(string name, string password, string email, NCMBCallback callback)
        {
            string      url  = _getLogInUrl();
            ConnectType type = ConnectType.GET;

            Dictionary <string, object> paramDic = new Dictionary <string, object>();

            paramDic["password"] = password;

            //nameがあればLogInAsync経由 無ければLogInWithMailAddressAsync経由、どちらも無ければエラー
            if (name != null)
            {
                paramDic["userName"] = name;
            }
            else if (email != null)
            {
                paramDic["mailAddress"] = email;
            }
            else
            {
                throw new NCMBException(new ArgumentException("UserName or Email can not be null."));
            }

            url = _makeParamUrl(url + "?", paramDic);

            //ログを確認(通信前)
            NCMBDebug.Log("【url】:" + url + Environment.NewLine + "【type】:" + type);
            //通信処理
            NCMBConnection con = new NCMBConnection(url, type, null, null);

            con.Connect(delegate(int statusCode, string responseData, NCMBException error)
            {
                try
                {
                    NCMBDebug.Log("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData);
                    if (error != null)
                    {
                        NCMBDebug.Log("[DEBUG AFTER CONNECT] Error: " + error.ErrorMessage);
                    }
                    else
                    {
                        Dictionary <string, object> responseDic = MiniJSON.Json.Deserialize(responseData) as Dictionary <string, object>;
                        //save Current user
                        NCMBUser logInUser = new NCMBUser();
                        logInUser._handleFetchResult(true, responseDic);
                        _saveCurrentUser(logInUser);
                    }
                }
                catch (Exception e)
                {
                    error = new NCMBException(e);
                }
                if (callback != null)
                {
                    callback(error);
                }
                return;
            });
        }
Пример #7
0
        private static void _ncmbLogIn(string name, string password, string email, NCMBCallback callback)
        {
            string      url  = _getLogInUrl();       //URL作成
            ConnectType type = ConnectType.GET;
            //set username, password
            NCMBUser logInUser = new NCMBUser();

            logInUser.Password = password;

            //nameがあればLogInAsync経由 無ければLogInWithMailAddressAsync経由、どちらも無ければエラー
            if (name != null)
            {
                logInUser.UserName = name;
            }
            else if (email != null)
            {
                logInUser.Email = email;
            }
            else
            {
                throw new NCMBException(new ArgumentException("UserName or Email can not be null."));
            }

            string content = logInUser._toJSONObjectForSaving(logInUser.StartSave());
            Dictionary <string, object> paramDic = (Dictionary <string, object>)MiniJSON.Json.Deserialize(content);

            url = _makeParamUrl(url + "?", paramDic);
            //ログを確認(通信前)
            NCMBDebug.Log("【url】:" + url + Environment.NewLine + "【type】:" + type + Environment.NewLine + "【content】:" + content);
            //通信処理
            NCMBConnection con = new NCMBConnection(url, type, content, NCMBUser._getCurrentSessionToken());

            con.Connect(delegate(int statusCode, string responseData, NCMBException error) {
                try {
                    NCMBDebug.Log("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData);
                    if (error != null)
                    {
                        NCMBDebug.Log("[DEBUG AFTER CONNECT] Error: " + error.ErrorMessage);
                    }
                    else
                    {
                        Dictionary <string, object> responseDic = MiniJSON.Json.Deserialize(responseData) as Dictionary <string, object>;
                        logInUser._handleFetchResult(true, responseDic);
                        //save Current user
                        _saveCurrentUser(logInUser);
                    }
                } catch (Exception e) {
                    error = new NCMBException(e);
                }
                if (callback != null)
                {
                    Platform.RunOnMainThread(delegate {
                        callback(error);
                    });
                }
                return;
            });
        }
Пример #8
0
 //delete後処理  オーバーライド用
 internal override void _afterDelete(NCMBException error)
 {
     if (error == null)
     {
         if ((_currentUser != null) && (_currentUser.ObjectId == this.ObjectId))
         {
             _logOutEvent();
         }
     }
 }
Пример #9
0
        internal static void TrackAppOpened(string _pushId)             //(Android/iOS)-NCMBManager.onAnalyticsReceived-this.NCMBAnalytics
        {
            //ネイティブから取得したpushIdからリクエストヘッダを作成
            if (_pushId != null && NCMBManager._token != null && NCMBSettings.UseAnalytics)
            {
                string deviceType = "";
                if (SystemInfo.operatingSystem.IndexOf("Android") != -1)
                {
                    deviceType = "android";
                }
                else if (SystemInfo.operatingSystem.IndexOf("iPhone") != -1)
                {
                    deviceType = "ios";
                }

                //RESTリクエストデータ生成
                Dictionary <string, object> requestData = new Dictionary <string, object> {
                    { "pushId", _pushId },
                    { "deviceToken", NCMBManager._token },
                    { "deviceType", deviceType }
                };

                var         json    = Json.Serialize(requestData);
                string      url     = CommonConstant.DOMAIN_URL + "/" + CommonConstant.API_VERSION + "/push/" + _pushId + "/openNumber";
                ConnectType type    = ConnectType.POST;
                string      content = json.ToString();
                NCMBDebug.Log("content:" + content);
                //ログを確認(通信前)
                NCMBDebug.Log("【url】:" + url + Environment.NewLine + "【type】:" + type + Environment.NewLine + "【content】:" + content);
                // 通信処理
                NCMBConnection con = new NCMBConnection(url, type, content, NCMBUser._getCurrentSessionToken());
                con.Connect(delegate(int statusCode, string responseData, NCMBException error) {
                    try {
                        NCMBDebug.Log("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData);
                    } catch (Exception e) {
                        error = new NCMBException(e);
                    }
                    return;
                });

                                #if UNITY_IOS
                                        #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7
                NotificationServices.ClearRemoteNotifications();
                                        #else
                UnityEngine.iOS.NotificationServices.ClearRemoteNotifications();
                                        #endif
                                #endif
            }
        }
Пример #10
0
        /// <summary>
        /// 非同期処理でファイルの保存を行います。<br/>
        /// 通信結果が必要な場合はコールバックを指定するこちらを使用します。
        /// </summary>
        /// <param name="callback">コールバック</param>
        public override void SaveAsync(NCMBCallback callback)
        {
            if ((this.FileName == null))
            {
                throw new NCMBException("fileName must not be null.");
            }

            new AsyncDelegate(delegate {
                ConnectType type;
                if (this.CreateDate != null)
                {
                    type = ConnectType.PUT;
                }
                else
                {
                    type = ConnectType.POST;
                }
                IDictionary <string, INCMBFieldOperation> currentOperations = null;
                currentOperations  = this.StartSave();
                string content     = _toJSONObjectForSaving(currentOperations);
                NCMBConnection con = new NCMBConnection(_getBaseUrl(), type, content, NCMBUser._getCurrentSessionToken(), this);
                con.Connect(delegate(int statusCode, string responseData, NCMBException error) {
                    try {
                        NCMBDebug.Log("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData);
                        if (error != null)
                        {
                            // 失敗
                            this._handleSaveResult(false, null, currentOperations);
                        }
                        else
                        {
                            Dictionary <string, object> responseDic = MiniJSON.Json.Deserialize(responseData) as Dictionary <string, object>;
                            this._handleSaveResult(true, responseDic, currentOperations);
                        }
                    } catch (Exception e) {
                        error = new NCMBException(e);
                    }

                    if (callback != null)
                    {
                        Platform.RunOnMainThread(delegate {
                            callback(error);
                        });
                    }
                    return;
                });
            }).BeginInvoke((IAsyncResult r) => {
            }, null);
        }
Пример #11
0
        //(Android/iOS)-NCMBManager.onAnalyticsReceived-this.NCMBAnalytics
        internal static void TrackAppOpened(string _pushId)
        {
            //ネイティブから取得したpushIdからリクエストヘッダを作成
            if (_pushId != null && NCMBManager._token != null && NCMBSettings.UseAnalytics) {

                string deviceType = "";
                if (SystemInfo.operatingSystem.IndexOf ("Android") != -1) {
                    deviceType = "android";
                } else if (SystemInfo.operatingSystem.IndexOf ("iPhone") != -1) {
                    deviceType = "ios";
                }

                //RESTリクエストデータ生成
                Dictionary<string,object> requestData = new Dictionary<string,object> {
                    { "pushId", _pushId },
                    { "deviceToken", NCMBManager._token },
                    { "deviceType", deviceType }
                };

                var json = Json.Serialize (requestData);
                string url = CommonConstant.DOMAIN_URL + "/" + CommonConstant.API_VERSION + "/push/" + _pushId + "/openNumber";
                ConnectType type = ConnectType.POST;
                string content = json.ToString ();
                NCMBDebug.Log ("content:" + content);
                //ログを確認(通信前)
                NCMBDebug.Log ("【url】:" + url + Environment.NewLine + "【type】:" + type + Environment.NewLine + "【content】:" + content);
                // 通信処理
                NCMBConnection con = new NCMBConnection (url, type, content, NCMBUser._getCurrentSessionToken ());
                con.Connect (delegate(int statusCode, string responseData, NCMBException error) {
                    try {
                        NCMBDebug.Log ("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData);
                    } catch (Exception e) {
                        error = new NCMBException (e);
                    }
                    return;
                });

                #if UNITY_IOS
                    #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7
                    NotificationServices.ClearRemoteNotifications ();
                    #else
                    UnityEngine.iOS.NotificationServices.ClearRemoteNotifications ();
                    #endif
                #endif

            }
        }
Пример #12
0
 //save後処理  オーバーライド用 ローカルのcurrentUserを反映する
 internal override void _afterSave(int statusCode, NCMBException error)
 {
     // Base on AuthData
     if (statusCode == 201 && this.AuthData != null && error == null)
     {
         _saveCurrentUser((NCMBUser)this);
     }
     else if (statusCode == 200 && error == null)
     {
         // Base on SessionToken
         if (_currentUser != null && _currentUser.ObjectId.Equals(this.ObjectId))
         {
             this.SessionToken = _currentUser.SessionToken;
             _saveCurrentUser((NCMBUser)this);
         }
     }
 }
Пример #13
0
        /// <summary>
        /// クエリにマッチするオブジェクト数の取得を行います。<br/>
        /// 通信結果を受け取るために必ずコールバックの設定を行います。
        /// </summary>
        /// <param name="callback">  コールバック</param>
        public void CountAsync(NCMBCountCallback callback)
        {
            if (callback == null)
            {
                throw new ArgumentException("It is necessary to always set a callback.");
            }

            new AsyncDelegate(delegate {
                string url = _getSearchUrl(this._className);                   //クラス毎のURL作成
                url       += WHERE_URL;                                        //「?」をつける

                Dictionary <string, object> beforeJsonData = _getFindParams(); //パラメータDictionaryの作成

                beforeJsonData ["count"] = 1;                                  // カウント条件を追加する

                url = _makeWhereUrl(url, beforeJsonData);                      //urlにパラメータDictionaryを変換して結合

                ConnectType type = ConnectType.GET;                            //メソッドタイプの設定
                //通信処理
                NCMBConnection con = new NCMBConnection(url, type, null, NCMBUser._getCurrentSessionToken());
                con.Connect(delegate(int statusCode, string responseData, NCMBException error) {
                    Dictionary <string, object> resultObj;
                    int count = 0;
                    if (error == null)
                    {
                        try {
                            resultObj          = MiniJSON.Json.Deserialize(responseData) as Dictionary <string, object>;
                            object objectCount = null;
                            if (resultObj.TryGetValue("count", out objectCount))
                            {
                                count = Convert.ToInt32(objectCount);                                 //キーcountの値は必ず同じ型なので型チェック時の変換チェックは無し
                            }
                        } catch (Exception e) {
                            error = new NCMBException(e);
                        }
                    }
                    //引数は検索条件のカウント数とエラーをユーザーに返す
                    Platform.RunOnMainThread(delegate {
                        callback(count, error);
                    });
                    return;
                });
            }).BeginInvoke((IAsyncResult r) => {
            }, null);
        }
Пример #14
0
        internal static void TrackAppOpened(string _pushId)             //(Android/iOS)-NCMBManager.onAnalyticsReceived-this.NCMBAnalytics
        {
            //ネイティブから取得したpushIdからリクエストヘッダを作成
            if (_pushId != null && NCMBManager._token != null && NCMBSettings.UseAnalytics)
            {
                string deviceType = "";
                                #if UNITY_ANDROID
                deviceType = "android";
                                #elif UNITY_IOS
                deviceType = "ios";
                                #endif

                //RESTリクエストデータ生成
                Dictionary <string, object> requestData = new Dictionary <string, object> {
                    { "pushId", _pushId },
                    { "deviceToken", NCMBManager._token },
                    { "deviceType", deviceType }
                };

                var         json    = Json.Serialize(requestData);
                string      url     = NCMBAnalytics._getBaseUrl(_pushId);
                ConnectType type    = ConnectType.POST;
                string      content = json.ToString();

                //ログを確認(通信前)
                NCMBDebug.Log("【url】:" + url + Environment.NewLine + "【type】:" + type + Environment.NewLine + "【content】:" + content);
                // 通信処理
                NCMBConnection con = new NCMBConnection(url, type, content, NCMBUser._getCurrentSessionToken());
                con.Connect(delegate(int statusCode, string responseData, NCMBException error) {
                    try {
                        NCMBDebug.Log("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData);
                    } catch (Exception e) {
                        error = new NCMBException(e);
                    }
                    return;
                });

                /*
                 #if UNITY_IOS
                 *      UnityEngine.iOS.NotificationServices.ClearRemoteNotifications ();
                 #endif
                 */
            }
        }
Пример #15
0
        /// <summary>
        /// 同期用の検索メソッド。FindeAsyncで呼び出される。またNCMBObjecとのFetchAllAsyncで扱う。
        /// </summary>
        internal void Find(NCMBQueryCallback <T> callback)
        {
            string url = _getSearchUrl(this._className); //クラス毎のURL作成

            url += WHERE_URL;                            //「?」を末尾に追加する。
            //条件データの作成
            Dictionary <string, object> beforeJsonData = _getFindParams();

            url = _makeWhereUrl(url, beforeJsonData);      //URLの結合
            ConnectType type = ConnectType.GET;            //メソッドタイプの設定

            NCMBDebug.Log("【url】:" + url + Environment.NewLine + "【type】:" + type);
            //通信処理
            NCMBConnection con = new NCMBConnection(url, type, null, NCMBUser._getCurrentSessionToken());

            con.Connect(delegate(int statusCode, string responseData, NCMBException error) {
                NCMBDebug.Log("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData);

                Dictionary <string, object> resultObj;
                List <T> resultList         = new List <T> ();
                ArrayList convertResultList = null;
                //中でエラー処理いるかも
                try {
                    if (error == null)
                    {
                        resultObj         = MiniJSON.Json.Deserialize(responseData) as Dictionary <string, object>;
                        convertResultList = _convertFindResponse(resultObj);
                        foreach (T obj in convertResultList)
                        {
                            resultList.Add(obj);
                        }
                    }
                } catch (Exception e) {
                    error = new NCMBException(e);
                }

                Platform.RunOnMainThread(delegate {
                    callback(resultList, error);
                });

                return;
            });
        }
Пример #16
0
 //SaveAsync通信後の処理
 internal override void _afterSave(int statusCode, NCMBException error)
 {
     if (error != null)
     {
         if (error.ErrorCode == "E404001")
         {
             //No data available時にcurrentInstallationを削除
             NCMBManager.DeleteCurrentInstallation(NCMBManager.SearchPath());
         }
     }
     else if (statusCode == 201 || statusCode == 200)
     {
         string path = NCMBManager.SearchPath();
         if (path != NCMBSettings.currentInstallationPath)
         {
             //成功時にv1のファイルを削除
             NCMBManager.DeleteCurrentInstallation(path);
         }
         _saveInstallationToDisk("currentInstallation");
     }
 }
Пример #17
0
        internal static void _logOut(NCMBCallback callback)
        {
            string      url     = _getLogOutUrl();    //URL作成
            ConnectType type    = ConnectType.GET;
            string      content = null;

            //ログを確認(通信前)
            NCMBDebug.Log("【url】:" + url + Environment.NewLine + "【type】:" + type + Environment.NewLine + "【content】:" + content);
            //通信処理
            NCMBConnection con = new NCMBConnection(url, type, content, NCMBUser._getCurrentSessionToken());

            con.Connect(delegate(int statusCode, string responseData, NCMBException error) {
                try {
                    NCMBDebug.Log("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData);
                    if (error != null)
                    {
                        NCMBDebug.Log("[DEBUG AFTER CONNECT] Error: " + error.ErrorMessage);
                    }
                    else
                    {
                        _logOutEvent();
                    }
                } catch (Exception e) {
                    error = new NCMBException(e);
                }
                if (callback != null)
                {
                    //If the system get ErrorCode is E401001 when LogOutAsync, We will return null.
                    if (error != null && NCMBException.INCORRECT_HEADER.Equals(error.ErrorCode))
                    {
                        callback(null);
                    }
                    else
                    {
                        callback(error);
                    }
                }
                return;
            });
        }
Пример #18
0
        internal static void _requestPasswordReset(string email, NCMBCallback callback)
        {
            string      url  = _getRequestPasswordResetUrl();       //URL
            ConnectType type = ConnectType.POST;
            //set username, password
            NCMBUser pwresetUser = new NCMBUser();

            pwresetUser.Email = email;
            string content = pwresetUser._toJSONObjectForSaving(pwresetUser.StartSave());

            //ログを確認(通信前)
            NCMBDebug.Log("【url】:" + url + Environment.NewLine + "【type】:" + type + Environment.NewLine + "【content】:" + content);
            //通信処理
            NCMBConnection con = new NCMBConnection(url, type, content, NCMBUser._getCurrentSessionToken());

            con.Connect(delegate(int statusCode, string responseData, NCMBException error) {
                try {
                    NCMBDebug.Log("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData);
                    if (error != null)
                    {
                        NCMBDebug.Log("[DEBUG AFTER CONNECT] Error: " + error.ErrorMessage);
                    }
                    else
                    {
                        NCMBDebug.Log("[DEBUG AFTER CONNECT] Successful: ");
                    }
                } catch (Exception e) {
                    error = new NCMBException(e);
                }
                if (callback != null)
                {
                    Platform.RunOnMainThread(delegate {
                        callback(error);
                    });
                }
                return;
            });
        }
Пример #19
0
 //SaveAsync通信後の処理
 internal override void _afterSave(int statusCode, NCMBException error)
 {
     if (error != null) {
         if (error.ErrorCode == "E404001") {
             //No data available時にcurrentInstallationを削除
             NCMBManager.DeleteCurrentInstallation (NCMBManager.SearchPath ());
         }
     } else if (statusCode == 201 || statusCode == 200) {
         string path = NCMBManager.SearchPath ();
         if (path != NCMBSettings.currentInstallationPath) {
             //成功時にv1のファイルを削除
             NCMBManager.DeleteCurrentInstallation (path);
         }
         _saveInstallationToDisk ("currentInstallation");
     }
 }
Пример #20
0
 internal static void _logOut(NCMBCallback callback)
 {
     string url = _getLogOutUrl ();//URL作成
     ConnectType type = ConnectType.GET;
     string content = null;
     //ログを確認(通信前)
     NCMBDebug.Log ("【url】:" + url + Environment.NewLine + "【type】:" + type + Environment.NewLine + "【content】:" + content);
     //通信処理
     NCMBConnection con = new NCMBConnection (url, type, content, NCMBUser._getCurrentSessionToken ());
     con.Connect (delegate(int statusCode , string responseData, NCMBException error) {
         try {
             NCMBDebug.Log ("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData);
             if (error != null) {
                 NCMBDebug.Log ("[DEBUG AFTER CONNECT] Error: " + error.ErrorMessage);
             } else {
                 _logOutEvent ();
             }
         } catch (Exception e) {
             error = new NCMBException (e);
         }
         if (callback != null) {
             Platform.RunOnMainThread (delegate {
                 callback (error);
             });
         }
         return;
     });
 }
Пример #21
0
 internal static void _requestPasswordReset(string email, NCMBCallback callback)
 {
     string url = _getRequestPasswordResetUrl ();//URL
     ConnectType type = ConnectType.POST;
     //set username, password
     NCMBUser pwresetUser = new NCMBUser ();
     pwresetUser.Email = email;
     string content = pwresetUser._toJSONObjectForSaving (pwresetUser.StartSave ());
     //ログを確認(通信前)
     NCMBDebug.Log ("【url】:" + url + Environment.NewLine + "【type】:" + type + Environment.NewLine + "【content】:" + content);
     //通信処理
     NCMBConnection con = new NCMBConnection (url, type, content, NCMBUser._getCurrentSessionToken ());
     con.Connect (delegate(int statusCode , string responseData, NCMBException error) {
         try {
             NCMBDebug.Log ("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData);
             if (error != null) {
                 NCMBDebug.Log ("[DEBUG AFTER CONNECT] Error: " + error.ErrorMessage);
             } else {
                 NCMBDebug.Log ("[DEBUG AFTER CONNECT] Successful: ");
             }
         } catch (Exception e) {
             error = new NCMBException (e);
         }
         if (callback != null) {
             Platform.RunOnMainThread (delegate {
                 callback (error);
             });
         }
         return;
     });
 }
Пример #22
0
 //delete後処理  オーバーライド用
 internal override void _afterDelete(NCMBException error)
 {
     if (error == null) {
         _logOutEvent ();
     }
 }
Пример #23
0
 //save後処理  オーバーライド用 新規登録時のみログインを行う
 internal override void _afterSave(int statusCode, NCMBException error)
 {
     if (statusCode == 201 && error == null) {
         _saveCurrentUser ((NCMBUser)this);
     }
 }
Пример #24
0
        private static void _ncmbLogIn(string name, string password, string email, NCMBCallback callback)
        {
            string url = _getLogInUrl ();//URL作成
            ConnectType type = ConnectType.GET;
            //set username, password
            NCMBUser logInUser = new NCMBUser ();

            logInUser.Password = password;

            //nameがあればLogInAsync経由 無ければLogInWithMailAddressAsync経由、どちらも無ければエラー
            if (name != null) {
                logInUser.UserName = name;
            } else if (email != null) {
                logInUser.Email = email;
            } else {
                throw new NCMBException (new ArgumentException ("UserName or Email can not be null."));
            }

            string content = logInUser._toJSONObjectForSaving (logInUser.StartSave ());
            Dictionary<string, object> paramDic = (Dictionary<string, object>)MiniJSON.Json.Deserialize (content);
            url = _makeParamUrl (url + "?", paramDic);
            //ログを確認(通信前)
            NCMBDebug.Log ("【url】:" + url + Environment.NewLine + "【type】:" + type + Environment.NewLine + "【content】:" + content);
            //通信処理
            NCMBConnection con = new NCMBConnection (url, type, content, NCMBUser._getCurrentSessionToken ());
            con.Connect (delegate(int statusCode , string responseData, NCMBException error) {
                try {
                    NCMBDebug.Log ("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData);
                    if (error != null) {
                        NCMBDebug.Log ("[DEBUG AFTER CONNECT] Error: " + error.ErrorMessage);
                    } else {
                        Dictionary<string, object> responseDic = MiniJSON.Json.Deserialize (responseData) as Dictionary<string, object>;
                        logInUser._handleFetchResult (true, responseDic);
                        //save Current user
                        _saveCurrentUser (logInUser);

                    }
                } catch (Exception e) {
                    error = new NCMBException (e);
                }
                if (callback != null) {
                    Platform.RunOnMainThread (delegate {
                        callback (error);
                    });
                }
                return;
            });
        }
Пример #25
0
        //通信
        internal void Connect(NCMBConnection connection, HttpWebRequest request, NCMBExecuteScriptCallback callback)
        {
            string          responseData   = null;
            NCMBException   error          = null;
            HttpWebResponse httpResponse   = null;
            Stream          streamResponse = null;
            StreamReader    streamRead     = null;

            byte[] result = new byte[32768];
            try {
                //レスポンスデータの書き込み
                httpResponse   = (HttpWebResponse)request.GetResponse();
                streamResponse = httpResponse.GetResponseStream();
                for (; ;)
                {
                    int readSize = streamResponse.Read(result, 0, result.Length);
                    if (readSize == 0)
                    {
                        break;
                    }
                }
            } catch (WebException ex) {
                //失敗
                using (WebResponse webResponse = ex.Response) {                //WebExceptionからWebResponseを取得
                    error = new NCMBException();
                    error.ErrorMessage = ex.Message;
                    if (webResponse != null)
                    {
                        streamResponse = webResponse.GetResponseStream();
                        streamRead     = new StreamReader(streamResponse);
                        responseData   = streamRead.ReadToEnd();                       //データを全てstringに書き出し

                        error.ErrorMessage = responseData;
                        httpResponse       = (HttpWebResponse)webResponse;
                        error.ErrorCode    = httpResponse.StatusCode.ToString();

                        var jsonData = MiniJSON.Json.Deserialize(responseData) as Dictionary <string, object>;                       //Dictionaryに変換
                        if (jsonData != null)
                        {
                            var hashtableData = new Hashtable(jsonData);
                            //statusCode
                            if (hashtableData.ContainsKey("code"))
                            {
                                error.ErrorCode = (hashtableData ["code"].ToString());
                            }
                            else if (hashtableData.ContainsKey("status"))
                            {
                                error.ErrorCode = (hashtableData ["status"].ToString());
                            }
                            //message
                            if (hashtableData.ContainsKey("error"))
                            {
                                error.ErrorMessage = (hashtableData ["error"].ToString());
                            }
                        }
                    }
                }
            } finally {
                //close
                if (httpResponse != null)
                {
                    httpResponse.Close();
                }
                if (streamResponse != null)
                {
                    streamResponse.Close();
                }
                if (streamRead != null)
                {
                    streamRead.Close();
                }
                //check E401001 error
                if (error != null)
                {
                    connection._checkInvalidSessionToken(error.ErrorCode);
                }
                //enqueue callback
                if (callback != null)
                {
                    Platform.RunOnMainThread(delegate {
                        callback(result, error);
                    });
                }
            }
        }