Esempio n. 1
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)
                {
                    callback(error);
                }
                return;
            });
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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;
            });
        }
Esempio n. 5
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;
            });
        }