コード例 #1
0
        internal AVPushNotificationEventArgs(IDictionary <string, object> payload)
        {
            Payload = payload;

#if !IOS
            StringPayload = AVClient.SerializeJsonString(payload);
#endif
        }
コード例 #2
0
 private static IDictionary <string, object> PushJson(string jsonString)
 {
     try {
         return(AVClient.DeserializeJsonString(jsonString) ?? new Dictionary <string, object>());
     } catch (Exception) {
         return(new Dictionary <string, object>());
     }
 }
コード例 #3
0
 internal Task DeleteAsync(CancellationToken cancellationToken)
 {
     lock (this.mutex)
     {
         string currentSessionToken = AVUser.CurrentSessionToken;
         return(AVClient.RequestAsync("DELETE", new Uri(string.Format("/files/{0}", this.ObjectId), UriKind.Relative), currentSessionToken, null, cancellationToken));
     }
 }
コード例 #4
0
ファイル: AVUser.cs プロジェクト: aisk/LeanCloud-SDK-dotNET
        /// <summary>
        ///  请求重置密码,需要传入注册时使用的手机号。
        /// </summary>
        /// <param name="mobilePhoneNumber">注册时使用的手机号</param>
        /// <param name="cancellationToken">cancellationToken</param>
        /// <returns></returns>
        public static Task RequestPasswordResetBySmsCode(string mobilePhoneNumber, CancellationToken cancellationToken)
        {
            string currentSessionToken       = AVUser.CurrentSessionToken;
            Dictionary <string, object> strs = new Dictionary <string, object>()
            {
                { "mobilePhoneNumber", mobilePhoneNumber }
            };

            return(AVClient.RequestAsync("POST", "/requestPasswordResetBySmsCode", currentSessionToken, strs, cancellationToken));
        }
コード例 #5
0
ファイル: AVUser.cs プロジェクト: aisk/LeanCloud-SDK-dotNET
        /// <summary>
        /// 通过验证码重置密码。
        /// </summary>
        /// <param name="newPassword">新密码</param>
        /// <param name="smsCode">6位数验证码</param>
        /// <param name="cancellationToken">cancellationToken</param>
        /// <returns></returns>
        public static Task <bool> ResetPasswordBySmsCodeAsync(string newPassword, string smsCode, CancellationToken cancellationToken)
        {
            string currentSessionToken       = AVUser.CurrentSessionToken;
            Dictionary <string, object> strs = new Dictionary <string, object>()
            {
                { "password", newPassword }
            };

            return(AVClient.RequestAsync("PUT", "/resetPasswordBySmsCode/" + smsCode, currentSessionToken, strs, cancellationToken).OnSuccess <Tuple <HttpStatusCode, IDictionary <string, object> >, bool>((Task <Tuple <HttpStatusCode, IDictionary <string, object> > > t) => {
                return AVClient.IsSuccessStatusCode(t.Result.Item1);
            }));
        }
コード例 #6
0
ファイル: AVUser.cs プロジェクト: aisk/LeanCloud-SDK-dotNET
        /// <summary>
        /// 发送认证码到需要认证的手机上
        /// </summary>
        /// <param name="mobilePhoneNumber">手机号</param>
        /// <param name="cancellationToken">CancellationToken</param>
        /// <returns></returns>
        public static Task <bool> RequestMobilePhoneVerifyAsync(string mobilePhoneNumber, CancellationToken cancellationToken)
        {
            string currentSessionToken       = AVUser.CurrentSessionToken;
            Dictionary <string, object> strs = new Dictionary <string, object>()
            {
                { "mobilePhoneNumber", mobilePhoneNumber }
            };

            return(AVClient.RequestAsync("POST", "/requestMobilePhoneVerify", currentSessionToken, strs, cancellationToken).OnSuccess <Tuple <HttpStatusCode, IDictionary <string, object> >, bool>((Task <Tuple <HttpStatusCode, IDictionary <string, object> > > t) => {
                return AVClient.IsSuccessStatusCode(t.Result.Item1);
            }));
        }
コード例 #7
0
ファイル: AVCloud.cs プロジェクト: longyunzhou/NFC
        /// <summary>
        /// 验证是否是有效短信验证码。
        /// </summary>
        /// <returns>是否验证通过。</returns>
        /// <param name="code">验证码。</param>
        /// <param name="mobilePhoneNumber">手机号</param>
        /// <param name="cancellationToken">Cancellation token.</param>
        public static Task <bool> VerifySmsCodeAsync(string code, string mobilePhoneNumber, CancellationToken cancellationToken)
        {
            var command = new AVCommand("verifySmsCode/" + code.Trim() + "?mobilePhoneNumber=" + mobilePhoneNumber.Trim(),
                                        method: "POST",
                                        sessionToken: null,
                                        data: null);

            return(AVPlugins.Instance.CommandRunner.RunCommandAsync(command, cancellationToken: cancellationToken).ContinueWith(t =>
            {
                return AVClient.IsSuccessStatusCode(t.Result.Item1);
            }));
        }
コード例 #8
0
ファイル: AVCloud.cs プロジェクト: aisk/LeanCloud-SDK-dotNET
        /// <summary>
        /// 验证是否是有效短信验证码。
        /// </summary>
        /// <returns>是否验证通过。</returns>
        /// <param name="code">验证码。</param>
        /// <param name="mobilePhoneNumber">手机号</param>
        /// <param name="cancellationToken">Cancellation token.</param>
        public static Task <bool> VerifySmsCodeAsync(string code, string mobilePhoneNumber, CancellationToken cancellationToken)
        {
            Dictionary <string, object> strs = new Dictionary <string, object>()
            {
                { "code", code.Trim() },
                { "mobilePhoneNumber", mobilePhoneNumber.Trim() },
            };

            return(AVClient.RequestAsync("POST", "/verifySmsCode/" + code.Trim() + "?mobilePhoneNumber=" + mobilePhoneNumber.Trim(), null, null, cancellationToken).OnSuccess <Tuple <HttpStatusCode, IDictionary <string, object> >, bool>((Task <Tuple <HttpStatusCode, IDictionary <string, object> > > t) => {
                return AVClient.IsSuccessStatusCode(t.Result.Item1);
            }));
        }
コード例 #9
0
 private SettingsWrapper()
 {
     if (string.IsNullOrEmpty(Settings.Default.ApplicationSettings))
     {
         data = new Dictionary <string, object>();
         Save();
     }
     else
     {
         data = AVClient.DeserializeJsonString(Settings.Default.ApplicationSettings);
     }
 }
コード例 #10
0
ファイル: AVClient.cs プロジェクト: longyunzhou/NFC
        internal static Task <Tuple <HttpStatusCode, string> > RequestAsync(Uri uri, string method, IList <KeyValuePair <string, string> > headers, IDictionary <string, object> body, string contentType, CancellationToken cancellationToken)
        {
            //HttpRequest request = new HttpRequest()
            //{
            //    Data = data != null ? new MemoryStream(Encoding.UTF8.GetBytes(Json.Encode(data))) : null,
            //    Headers = headers,
            //    Method = method,
            //    Uri = uri
            //};
            var dataStream = body != null ? new MemoryStream(Encoding.UTF8.GetBytes(Json.Encode(body))) : null;

            return(AVClient.RequestAsync(uri, method, headers, dataStream, contentType, cancellationToken));
            //return AVPlugins.Instance.HttpClient.ExecuteAsync(request, null, null, cancellationToken);
        }
コード例 #11
0
        private void Initialize()
        {
            if (!isInitialized)
            {
                isInitialized = true;
                // Keep this gameObject around, even when the scene changes.
                GameObject.DontDestroyOnLoad(gameObject);

                AVClient.Initialize(applicationID, applicationKey);

                // Kick off the dispatcher.
                StartCoroutine(PlatformHooks.RunDispatcher());
            }
        }
コード例 #12
0
        internal static IDictionary <string, object> PushJson(string uri)
        {
            var queryTokens = uri.Substring(uri.LastIndexOf('?') + 1).Split('&');

            foreach (var token in queryTokens)
            {
                if (token.StartsWith("pushJson="))
                {
                    var rawValue = token.Substring("pushJson=".Length);
                    var decoded  = HttpUtility.UrlDecode(rawValue);
                    return(AVClient.DeserializeJsonString(decoded));
                }
            }
            return(new Dictionary <string, object>());
        }
コード例 #13
0
ファイル: AVUser.cs プロジェクト: aisk/LeanCloud-SDK-dotNET
        /// <summary>
        /// Requests the login SMS code asynchronous.
        /// </summary>
        /// <param name="mobilePhoneNumber">The mobile phone number.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public static Task <bool> RequestLoginSmsCodeAsync(string mobilePhoneNumber, CancellationToken cancellationToken)
        {
            Dictionary <string, object> strs = new Dictionary <string, object>()
            {
                { "mobilePhoneNumber", mobilePhoneNumber }
            };
            var command = new AVCommand("/requestLoginSmsCode",
                                        method: "POST",
                                        sessionToken: CurrentSessionToken,
                                        data: null);

            return(AVClient.RequestAsync("POST", "/requestLoginSmsCode", null, strs, cancellationToken).OnSuccess <Tuple <HttpStatusCode, IDictionary <string, object> >, bool>((Task <Tuple <HttpStatusCode, IDictionary <string, object> > > t) => {
                return AVClient.IsSuccessStatusCode(t.Result.Item1);
            }));
        }
コード例 #14
0
        internal static Tuple <HttpStatusCode, IDictionary <string, object> > ReponseResolve(Tuple <HttpStatusCode, string> response, CancellationToken cancellationToken)
        {
            Tuple <HttpStatusCode, string> result = response;
            HttpStatusCode code  = result.Item1;
            string         item2 = result.Item2;

            if (httpDebugLog)
            {
                LogTracker("Http Code =" + code);
                LogTracker("Http Response =" + item2);
            }

            if (item2 == null)
            {
                cancellationToken.ThrowIfCancellationRequested();
                return(new Tuple <HttpStatusCode, IDictionary <string, object> >(code, null));
            }
            IDictionary <string, object> strs = null;

            try
            {
                strs = (!item2.StartsWith("[") ? AVClient.DeserializeJsonString(item2) : new Dictionary <string, object>()
                {
                    { "results", Json.Parse(item2) }
                });
            }
            catch (Exception exception)
            {
                throw new AVException(AVException.ErrorCode.OtherCause, "Invalid response from server", exception);
            }
            var codeValue = (int)code;

            if (codeValue > 203 || codeValue < 200)
            {
                if (httpDebugLog)
                {
                    LogTracker("Http error code=" + codeValue);
                    foreach (string k in strs?.Keys)
                    {
                        LogTracker(k + "=" + strs?[k]);
                    }
                }
                throw new AVException((AVException.ErrorCode)((int)((strs.ContainsKey("code") ? (long)strs["code"] : (long)-1))), (strs.ContainsKey("error") ? strs["error"] as string : item2), null);
            }

            cancellationToken.ThrowIfCancellationRequested();
            return(new Tuple <HttpStatusCode, IDictionary <string, object> >(code, strs));
        }
コード例 #15
0
ファイル: AVCloud.cs プロジェクト: aisk/LeanCloud-SDK-dotNET
        /// <summary>
        ///
        /// </summary>
        /// <param name="mobilePhoneNumber"></param>
        /// <returns></returns>
        public static Task <bool> RequestVoiceCodeAsync(string mobilePhoneNumber)
        {
            if (string.IsNullOrEmpty(mobilePhoneNumber))
            {
                throw new AVException(AVException.ErrorCode.MobilePhoneInvalid, "Moblie Phone number is invalid.", null);
            }
            Dictionary <string, object> strs = new Dictionary <string, object>()
            {
                { "mobilePhoneNumber", mobilePhoneNumber },
                { "smsType", "voice" },
                { "IDD", "+86" }
            };

            return(AVClient.RequestAsync("POST", "/requestSmsCode", null, strs, CancellationToken.None).OnSuccess <Tuple <HttpStatusCode, IDictionary <string, object> >, bool>((Task <Tuple <HttpStatusCode, IDictionary <string, object> > > t) => {
                return AVClient.IsSuccessStatusCode(t.Result.Item1);
            }));
        }
コード例 #16
0
        /// <summary>
        /// 根据 ObjectId 获取文件
        /// </summary>
        /// <remarks>获取之后并没有实际执行下载,只是加载了文件的元信息以及物理地址(Url)
        /// </remarks>
        public static Task <AVFile> GetFileWithObjectIdAsync(string objectId, CancellationToken cancellationToken)
        {
            string currentSessionToken = AVUser.CurrentSessionToken;

            return(AVClient.RequestAsync("GET", new Uri(string.Format("/files/{0}", objectId), UriKind.Relative), currentSessionToken, null, cancellationToken).OnSuccess <Tuple <HttpStatusCode, IDictionary <string, object> >, AVFile>((Task <Tuple <HttpStatusCode, IDictionary <string, object> > > t) =>
            {
                AVFile rtn = null;
                if (AVClient.IsSuccessStatusCode(t.Result.Item1))
                {
                    var metaData = t.Result.Item2["metaData"] as IDictionary <string, object>;

                    rtn = new AVFile(t.Result.Item2["name"] as string, t.Result.Item2["url"] as string, metaData);
                    rtn.MergeFromJSON(t.Result.Item2);
                }
                return rtn;
            }));
        }
コード例 #17
0
ファイル: AVCloud.cs プロジェクト: aisk/LeanCloud-SDK-dotNET
 public static Task <DateTime> GetServerDateTime()
 {
     return(AVClient.RequestAsync("GET", "/date", null, null, CancellationToken.None).OnSuccess <Tuple <HttpStatusCode, IDictionary <string, object> >, DateTime>((Task <Tuple <HttpStatusCode, IDictionary <string, object> > > t) => {
         DateTime rtn = DateTime.MinValue;
         if (AVClient.IsSuccessStatusCode(t.Result.Item1))
         {
             var date = AVDecoder.Instance.Decode(t.Result.Item2);
             if (date != null)
             {
                 if (date is DateTime)
                 {
                     rtn = (DateTime)date;
                 }
             }
         }
         return rtn;
     }));
 }
コード例 #18
0
ファイル: AVConfig.cs プロジェクト: aisk/LeanCloud-SDK-dotNET
        /// <summary>
        /// Populates result with the value for the key, if possible.
        /// </summary>
        /// <typeparam name="T">The desired type for the value.</typeparam>
        /// <param name="key">The key to retrieve a value for.</param>
        /// <param name="result">The value for the given key, converted to the
        /// requested type, or null if unsuccessful.</param>
        /// <returns>true if the lookup and conversion succeeded, otherwise false.</returns>
        public bool TryGetValue <T>(string key, out T result)
        {
            if (this.properties.ContainsKey(key))
            {
                var temp = AVClient.ConvertTo <T>(this.properties[key]);
                if (temp is T ||
                    (temp == null &&
                     (!typeof(T).GetTypeInfo().IsValueType || typeof(T).IsNullable()))
                    )
                {
                    result = (T)temp;
                    return(true);
                }
            }

            result = default(T);
            return(false);
        }
コード例 #19
0
ファイル: AVCloud.cs プロジェクト: aisk/LeanCloud-SDK-dotNET
        /// <summary>
        ///
        // 发送手机短信,并指定模板以及传入模板所需的参数。
        //
        // Exceptions:
        //   AVOSCloud.AVException:
        //   手机号为空。
        ///
        /// <param name="mobilePhoneNumber"></param>
        /// <param name="template"></param>
        /// <param name="env"></param>
        /// <returns></returns>
        public static Task <bool> RequestSMSCodeAsync(string mobilePhoneNumber, string template, IDictionary <string, object> env)
        {
            if (string.IsNullOrEmpty(mobilePhoneNumber))
            {
                throw new AVException(AVException.ErrorCode.MobilePhoneInvalid, "Moblie Phone number is invalid.", null);
            }
            Dictionary <string, object> strs = new Dictionary <string, object>()
            {
                { "mobilePhoneNumber", mobilePhoneNumber },
            };

            strs.Add("template", template);
            foreach (var key in env.Keys)
            {
                strs.Add(key, env[key]);
            }
            return(AVClient.RequestAsync("POST", "/requestSmsCode", null, strs, CancellationToken.None).OnSuccess <Tuple <HttpStatusCode, IDictionary <string, object> >, bool>((Task <Tuple <HttpStatusCode, IDictionary <string, object> > > t) => {
                return AVClient.IsSuccessStatusCode(t.Result.Item1);
            }));
        }
コード例 #20
0
ファイル: AVCloud.cs プロジェクト: longyunzhou/NFC
        /// <summary>
        /// 发送手机短信,并指定模板以及传入模板所需的参数。
        /// Exceptions:
        ///   AVOSCloud.AVException:
        ///   手机号为空。
        /// <param name="mobilePhoneNumber"></param>
        /// <param name="template">Sms's template</param>
        /// <param name="env">Template variables env.</param>
        /// <param name="sign">Sms's sign.</param>
        /// <param name="cancellationToken">Cancellation token.</param>
        /// <returns></returns>
        public static Task <bool> RequestSMSCodeAsync(
            string mobilePhoneNumber,
            string template,
            IDictionary <string, object> env,
            string sign          = "",
            string validateToken = "",
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (string.IsNullOrEmpty(mobilePhoneNumber))
            {
                throw new AVException(AVException.ErrorCode.MobilePhoneInvalid, "Moblie Phone number is invalid.", null);
            }
            Dictionary <string, object> strs = new Dictionary <string, object>()
            {
                { "mobilePhoneNumber", mobilePhoneNumber },
            };

            strs.Add("template", template);
            if (String.IsNullOrEmpty(sign))
            {
                strs.Add("sign", sign);
            }
            if (String.IsNullOrEmpty(validateToken))
            {
                strs.Add("validate_token", validateToken);
            }
            foreach (var key in env.Keys)
            {
                strs.Add(key, env[key]);
            }
            var command = new AVCommand("requestSmsCode",
                                        method: "POST",
                                        sessionToken: null,
                                        data: strs);

            return(AVPlugins.Instance.CommandRunner.RunCommandAsync(command).ContinueWith(t =>
            {
                return AVClient.IsSuccessStatusCode(t.Result.Item1);
            }));
        }
コード例 #21
0
ファイル: AVCloud.cs プロジェクト: longyunzhou/NFC
        /// <summary>
        ///
        /// </summary>
        /// <param name="mobilePhoneNumber"></param>
        /// <returns></returns>
        public static Task <bool> RequestVoiceCodeAsync(string mobilePhoneNumber)
        {
            if (string.IsNullOrEmpty(mobilePhoneNumber))
            {
                throw new AVException(AVException.ErrorCode.MobilePhoneInvalid, "Moblie Phone number is invalid.", null);
            }
            Dictionary <string, object> strs = new Dictionary <string, object>()
            {
                { "mobilePhoneNumber", mobilePhoneNumber },
                { "smsType", "voice" },
                { "IDD", "+86" }
            };

            var command = new AVCommand("requestSmsCode",
                                        method: "POST",
                                        sessionToken: null,
                                        data: strs);

            return(AVPlugins.Instance.CommandRunner.RunCommandAsync(command).ContinueWith(t =>
            {
                return AVClient.IsSuccessStatusCode(t.Result.Item1);
            }));
        }
コード例 #22
0
ファイル: AVCloud.cs プロジェクト: longyunzhou/NFC
        /// <summary>
        /// 获取 LeanCloud 服务器的时间
        /// <remarks>
        /// 如果获取失败,将返回 DateTime.MinValue
        /// </remarks>
        /// </summary>
        /// <returns>服务器的时间</returns>
        public static Task <DateTime> GetServerDateTimeAsync()
        {
            var command = new AVCommand(relativeUri: "date",
                                        method: "GET",
                                        sessionToken: null,
                                        data: null);

            return(AVPlugins.Instance.CommandRunner.RunCommandAsync(command).ContinueWith(t =>
            {
                DateTime rtn = DateTime.MinValue;
                if (AVClient.IsSuccessStatusCode(t.Result.Item1))
                {
                    var date = AVDecoder.Instance.Decode(t.Result.Item2);
                    if (date != null)
                    {
                        if (date is DateTime)
                        {
                            rtn = (DateTime)date;
                        }
                    }
                }
                return rtn;
            }));
        }
コード例 #23
0
ファイル: AVConfig.cs プロジェクト: aisk/LeanCloud-SDK-dotNET
 /// <summary>
 /// Gets a value for the key of a particular type.
 /// </summary>
 /// <typeparam name="T">The type to convert the value to. Supported types are
 /// AVObject and its descendents, LeanCloud types such as AVRelation and AVGeopoint,
 /// primitive types,IList&lt;T&gt;, IDictionary&lt;string, T&gt; and strings.</typeparam>
 /// <param name="key">The key of the element to get.</param>
 /// <exception cref="System.Collections.Generic.KeyNotFoundException">The property is retrieved
 /// and <paramref name="key"/> is not found.</exception>
 /// <exception cref="System.FormatException">The property under this <paramref name="key"/>
 /// key was found, but of a different type.</exception>
 public T Get <T>(string key)
 {
     return((T)AVClient.ConvertTo <T>(this.properties[key]));
 }
コード例 #24
0
// Obj-C type -> .NET type is impossible to do flawlessly (especially
// on NSNumber). We can't transform NSDictionary into string because of this reason.
#if !IOS
        internal AVPushNotificationEventArgs(string stringPayload)
        {
            StringPayload = stringPayload;

            Payload = AVClient.DeserializeJsonString(stringPayload);
        }
コード例 #25
0
 private void Save()
 {
     Settings.Default.ApplicationSettings = AVClient.SerializeJsonString(data);
     Settings.Default.Save();
 }
コード例 #26
0
 /// <summary>
 /// Convenience alias for RequestAsync that takes a string instead of a Uri.
 /// </summary>
 internal static Task <Tuple <HttpStatusCode, IDictionary <string, object> > > RequestAsync(string method, string relativeUri, string sessionToken, IDictionary <string, object> data, CancellationToken cancellationToken)
 {
     return(AVClient.RequestAsync(method, new Uri(relativeUri, UriKind.Relative), sessionToken, data, cancellationToken));
 }