// mobile backendに接続して新規会員登録
 public void signUp( string id, string mail, string pw)
 {
     NCMBUser user = new NCMBUser ();
     user.UserName = id;
     //user.Email = mail;
     user.Password = pw;
     user.SignUpAsync ((NCMBException e) => {
         if (e == null) {
             currentPlayerName = id;
         }
     });
 }
Beispiel #2
0
    // mobile backendに接続して新規会員登録 ------------------------
    public void signUp( string id, string mail, string pw )
    {
        NCMBUser user = new NCMBUser();
        user.UserName = id;
        user.Email    = mail;
        user.Password = pw;

        user.SignUpAsync((NCMBException e) => {

            if( e == null ){
                currentPlayerName = id;
                Application.LoadLevel("scTitle");
            } else {
                isError = true;
            }
        });
    }
Beispiel #3
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;
            });
        }
        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
            }
        }
Beispiel #5
0
        /// <summary>
        /// 各型毎のURL作成
        /// </summary>
        private string _getSearchUrl(string className)
        {
            string url = "";

            if (className == null || className.Equals(""))
            {
                throw new ArgumentException("Not class name error. Please be sure to specify the class name.");
            }
            else if (className.Equals("push"))
            {
                // プッシュ検索API
                //url = new NCMBPush().getBaseUrl();
            }
            else if (className.Equals("installation"))
            {
                // 配信端末検索API
                //url = new NCMBInstallation().getBaseUrl();
            }
            else if (className.Equals("file"))
            {
                // ファイル検索API
                //url = new NCMBFile().getBaseUrl();
            }
            else if (className.Equals("user"))
            {
                // 会員検索API
                //url = new NCMBUser().getBaseUrl(NCMBUser.URL_TYPE_USER);
                url = new NCMBUser()._getBaseUrl();
            }
            else if (className.Equals("role"))
            {
                // ロール検索API
                url = new NCMBRole()._getBaseUrl();
                //url = new NCMBRole().getBaseUrl();
            }
            else
            {
                // オブジェクト検索API
                url = new NCMBObject(_className)._getBaseUrl();
            }
            return(url);
        }
Beispiel #6
0
        internal static void _logOutEvent()
        {
            string filePath = NCMBSettings.filePath + "/" + "currentUser";

            if (_currentUser != null)
            {
                //logOut with other linked services
                _currentUser._isCurrentUser = false;
            }
            _currentUser = null;
            //delete from disk "currentUser"
            try {
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                NCMBSettings.CurrentUser = "";
            } catch (Exception e) {
                throw new NCMBException(e);
            }
        }
Beispiel #7
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;
            });
        }
Beispiel #8
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;
            });
        }
Beispiel #9
0
 internal static void _logOutEvent()
 {
     string filePath = NCMBSettings.filePath + "/" + "currentUser";
     if (_currentUser != null) {
         //logOut with other linked services
         _currentUser._isCurrentUser = false;
     }
     _currentUser = null;
     //delete from disk "currentUser"
     try {
         if (File.Exists (filePath)) {
             File.Delete (filePath);
         }
         NCMBSettings.CurrentUser = "";
     } catch (Exception e) {
         throw new NCMBException (e);
     }
 }
Beispiel #10
0
        /// <summary>
        /// 非同期処理でファイルのダウンロードを行います。<br/>
        /// 通信結果が必要な場合はコールバックを指定するこちらを使用します。
        /// </summary>
        /// <param name="callback">コールバック</param>
        public void FetchAsync(NCMBGetFileCallback callback)
        {
            // fileName必須
            if ((this.FileName == null))
            {
                throw new NCMBException("fileName must not be null.");
            }

            // 通信処理
            NCMBConnection con = new NCMBConnection(_getBaseUrl(), ConnectType.GET, null, NCMBUser._getCurrentSessionToken(), this);

            con.Connect(delegate(int statusCode, byte[] responseData, NCMBException error) {
                NCMBDebug.Log("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData);
                this.estimatedData ["fileData"] = responseData;
                if (callback != null)
                {
                    callback(responseData, error);
                }
                return;
            });
        }
Beispiel #11
0
        /// <summary>
        /// 非同期処理でスクリプトの実行を行います。
        /// </summary>
        /// <param name="header">リクエストヘッダー.</param>
        /// <param name="body">リクエストボディ</param>
        /// <param name="query">クエリパラメーター</param>
        /// <param name="callback">コールバック</param>
        public void ExecuteAsync(IDictionary <string, object> header, IDictionary <string, object> body, IDictionary <string, object> query, NCMBExecuteScriptCallback callback)
        {
            new AsyncDelegate(delegate {
                //URL作成
                String endpoint  = DEFAULT_SCRIPT_ENDPOINT;
                String scriptUrl = DEFAULT_SCRIPT_ENDPOINT + "/" + DEFAULT_SCRIPT_API_VERSION + "/" + SERVICE_PATH + "/" + this._scriptName;
                if (this._baseUrl == null || this._baseUrl.Length == 0)
                {
                    throw new ArgumentException("Invalid baseUrl.");
                }
                else if (!this._baseUrl.Equals(DEFAULT_SCRIPT_ENDPOINT))
                {
                    //ユーザー設定時
                    endpoint  = _baseUrl;
                    scriptUrl = this._baseUrl + "/" + this._scriptName;
                }

                //メソッド作成
                ConnectType type;
                switch (_method)
                {
                case MethodType.POST:
                    type = ConnectType.POST;
                    break;

                case MethodType.PUT:
                    type = ConnectType.PUT;
                    break;

                case MethodType.GET:
                    type = ConnectType.GET;
                    break;

                case MethodType.DELETE:
                    type = ConnectType.DELETE;
                    break;

                default:
                    throw new ArgumentException("Invalid methodType.");
                }

                //コンテント作成
                String content = null;
                if (body != null)
                {
                    content = Json.Serialize(body);
                }

                //クエリ文字列作成
                String queryString = "?";
                if (query != null && query.Count > 0)
                {
                    int count = query.Count;
                    foreach (KeyValuePair <string, object> pair in query)
                    {
                        queryString += pair.Key + "=" + pair.Value.ToString();
                        if (count > 1)
                        {
                            queryString += "&";
                            --count;
                        }
                    }
                    scriptUrl += Uri.EscapeUriString(queryString);
                }

                ServicePointManager.ServerCertificateValidationCallback = delegate {
                    return(true);
                };

                //コネクション作成
                NCMBConnection connection = new NCMBConnection(scriptUrl, type, content, NCMBUser._getCurrentSessionToken(), null, endpoint);
                HttpWebRequest request    = connection._returnRequest();

                //コンテント設定
                if (content != null)
                {
                    byte[] postDataBytes = Encoding.Default.GetBytes(content);
                    Stream stream        = null;
                    try {
                        stream = request.GetRequestStream();
                        stream.Write(postDataBytes, 0, postDataBytes.Length);
                    } finally {
                        if (stream != null)
                        {
                            stream.Close();
                        }
                    }
                }

                //オリジナルヘッダー設定
                if (header != null && header.Count > 0)
                {
                    foreach (KeyValuePair <string, object> pair in header)
                    {
                        request.Headers.Add(pair.Key, pair.Value.ToString());
                    }
                }

                //通信
                Connect(connection, request, callback);
            }).BeginInvoke((IAsyncResult r) => {
            }, null);
        }
Beispiel #12
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.");
            }

            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)
                {
                    callback(error);
                }
                return;
            });
        }
Beispiel #13
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;
            });
        }
Beispiel #14
0
 internal static void _saveCurrentUser(NCMBUser user)
 {
     object obj;
     if (_currentUser != null) {
         Monitor.Enter (obj = _currentUser.mutex);
         try {
             if ((_currentUser != null) && (_currentUser != user)) {
                 _logOutEvent ();
             }
         } finally {
             Monitor.Exit (obj);
         }
     }
     object obj_user;
     Monitor.Enter (obj_user = user.mutex);
     try {
         user._isCurrentUser = true;
         //synchronize all auth data of other services
         user._saveToDisk ("currentUser"); //Save disk
         user._saveToVariable (); //Save to variable
         _currentUser = user;
     } finally {
         Monitor.Exit (obj_user);
     }
 }
Beispiel #15
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;
     });
 }
Beispiel #16
0
        /// <summary>
        /// 非同期処理でスクリプトの実行を行います。
        /// </summary>
        /// <param name="header">リクエストヘッダー.</param>
        /// <param name="body">リクエストボディ</param>
        /// <param name="query">クエリパラメーター</param>
        /// <param name="callback">コールバック</param>
        public void ExecuteAsync(IDictionary <string, object> header, IDictionary <string, object> body, IDictionary <string, object> query, NCMBExecuteScriptCallback callback)
        {
            //URL作成
            String endpoint  = DEFAULT_SCRIPT_ENDPOINT;
            String scriptUrl = DEFAULT_SCRIPT_ENDPOINT + "/" + DEFAULT_SCRIPT_API_VERSION + "/" + SERVICE_PATH + "/" + this._scriptName;

            if (this._baseUrl == null || this._baseUrl.Length == 0)
            {
                throw new ArgumentException("Invalid baseUrl.");
            }
            else if (!this._baseUrl.Equals(DEFAULT_SCRIPT_ENDPOINT))
            {
                //ユーザー設定時
                endpoint  = _baseUrl;
                scriptUrl = this._baseUrl + "/" + this._scriptName;
            }

            //メソッド作成
            ConnectType type;

            switch (_method)
            {
            case MethodType.POST:
                type = ConnectType.POST;
                break;

            case MethodType.PUT:
                type = ConnectType.PUT;
                break;

            case MethodType.GET:
                type = ConnectType.GET;
                break;

            case MethodType.DELETE:
                type = ConnectType.DELETE;
                break;

            default:
                throw new ArgumentException("Invalid methodType.");
            }

            //コンテント作成
            String content = null;

            if (body != null)
            {
                content = Json.Serialize(body);
            }

            //クエリ文字列作成
            String queryVal    = "";
            String queryString = "?";

            if (query != null && query.Count > 0)
            {
                int count = query.Count;
                foreach (KeyValuePair <string, object> pair in query)
                {
                    if (pair.Value is IList || pair.Value is IDictionary)
                    {
                        //value形式:array,ILis,IDictionaryの場合
                        queryVal = SimpleJSON.Json.Serialize(pair.Value);
                    }
                    else if (pair.Value is DateTime)
                    {
                        //value形式:DateTimeの場合
                        queryVal = NCMBUtility.encodeDate((DateTime)pair.Value);
                    }
                    else
                    {
                        //value形式:上の以外場合
                        queryVal = pair.Value.ToString();
                    }

                    queryString += pair.Key + "=" + Uri.EscapeDataString(queryVal);

                    if (count > 1)
                    {
                        queryString += "&";
                        --count;
                    }
                }

                scriptUrl += queryString;
            }

            ServicePointManager.ServerCertificateValidationCallback = delegate {
                return(true);
            };

            //コネクション作成
            NCMBConnection connection = new NCMBConnection(scriptUrl, type, content, NCMBUser._getCurrentSessionToken(), null, endpoint);

            //オリジナルヘッダー設定
            if (header != null && header.Count > 0)
            {
                foreach (KeyValuePair <string, object> pair in header)
                {
                    connection._request.SetRequestHeader(pair.Key, pair.Value.ToString());
                }
            }

            //通信
            Connect(connection, callback);
        }
Beispiel #17
0
        /// <summary>
        /// 非同期処理で指定したメールアドレスに対して、<br/>
        /// 会員登録を行うためのメールを送信するよう要求します。<br/>
        /// 通信結果が必要な場合はコールバックを指定するこちらを使用します。
        /// </summary>
        /// <param name="email">メールアドレス</param>
        /// <param name="callback">コールバック</param>
        public static void RequestAuthenticationMailAsync(string email, NCMBCallback callback)
        {
            new AsyncDelegate (delegate {
                //URL
                string url = _getmailAddressUserEntryUrl ();//URL

                //コンテント
                NCMBUser user = new NCMBUser ();
                user.Email = email;
                string content = user._toJSONObjectForSaving (user.StartSave ());

                //Type
                ConnectType type = ConnectType.POST;

                NCMBConnection con = new NCMBConnection (url, type, content, NCMBUser._getCurrentSessionToken ());
                NCMBDebug.Log ("【url】:" + url + Environment.NewLine + "【type】:" + type + Environment.NewLine + "【content】:" + content);
                con.Connect (delegate(int statusCode , string responseData, NCMBException error) {
                    NCMBDebug.Log ("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData);
                    if (callback != null) {
                        Platform.RunOnMainThread (delegate {
                            callback (error);
                        });
                    }
                    return;
                });
            }).BeginInvoke ((IAsyncResult r) => {
            }, null);
        }