Ejemplo n.º 1
0
        public T GetRequest <T>(string action)
        {
            try
            {
                RestClient client = new RestClient
                {
                    BaseUrl = new Uri(_baseUrl)
                };
                IRestRequest request = new RestRequest
                {
                    Resource      = action,
                    RequestFormat = DataFormat.Json,
                    Method        = Method.GET
                };

                request.AddHeader("Accept", "application/json");

                IRestResponse response = client.Execute(request);

                return(NewtonJson.Deserialize <T>(response.Content));
            }
            catch (Exception ex)
            {
                Logger.WriteLog(Logger.LogType.Error, ex.ToString());
            }

            return(default(T));
        }
Ejemplo n.º 2
0
        public static ChecksumResult ValidateToken <T>(T entity, string token)
        {
            ChecksumResult result = new ChecksumResult();

            if (!string.IsNullOrWhiteSpace(token))
            {
                try
                {
                    ChecksumModel <T> requestModel = new ChecksumModel <T>(entity);

                    string decryptString = Crypton.DecryptByKey(token, privateKey);

                    ChecksumModel <T> checksumDecrypt = NewtonJson.Deserialize <ChecksumModel <T> >(decryptString);

                    if (!checksumDecrypt.IsExpired())
                    {
                        bool valid = requestModel.HashMD5.Equals(checksumDecrypt.HashMD5);
                        if (valid)
                        {
                            result = new ChecksumResult(ChecksumResult.ChecksumErrorCode.Success);
                        }
                    }
                    else
                    {
                        result = new ChecksumResult(ChecksumResult.ChecksumErrorCode.Expired);
                    }
                }
                catch
                {
                    // Logs
                }
            }

            return(result);
        }
        public JsonResult Index(string path)
        {
            ResultReturn rr = new ResultReturn()
            {
                Result = true
            };

            try
            {
                //if (!HttpContext.Current.User.Identity.IsAuthenticated)
                //{
                //    throw new Exception("Bạn không có quyền truy cập.");
                //}

                DateTime dtNow = DateTime.Now;
                if (string.IsNullOrEmpty(path))
                {
                    path = dtNow.ToString("yyyy/MM/dd");
                }
                string userName         = _userService.GetUserLogin().UserName;
                string key              = FileStorage.AESEncrypt(userName + "|" + DateTime.Now.ToString("yyyy-MM-dd HH:mm"));
                string folder           = string.Concat(path, "/", FileStorage.EncriptUsername(userName));
                NameValueCollection nvc = new NameValueCollection()
                {
                    { "project", Config.UploadProject },
                    { "folder", folder },
                    { "StringDecypt", key },
                    { "submit", "Check" }
                };
                string result = FileStorage.SendRequestWithParram(Config.FullLoadFileApi, nvc);

                if (!string.IsNullOrWhiteSpace(result))
                {
                    IList <string> images = NewtonJson.Deserialize <IList <string> >(result);
                    rr.FileInfos = new List <FileInfo>();

                    foreach (string image in images)
                    {
                        string virtualPath = string.Concat(folder, "/", image);
                        string fullPath    = string.Concat(Config.ViewDomain, virtualPath);

                        rr.FileInfos.Add(new FileInfo()
                        {
                            Result           = true,
                            Name             = image,
                            Path             = virtualPath,
                            FullPath         = fullPath,
                            FullOriginalPath = fullPath
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                rr.Result  = false;
                rr.Message = ex.Message;
            }
            return(Json(rr));
        }
Ejemplo n.º 4
0
 public static T Deserialize <T>(RedisValue value)
 {
     if (!value.HasValue || value.IsNullOrEmpty)
     {
         return(default(T));
     }
     return(NewtonJson.Deserialize <T>(value));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Json To Object
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="keys"></param>
 /// <returns></returns>
 public static IEnumerable <T> JsonToListObject <T>(this IEnumerable <string> listJson)
 {
     foreach (var key in listJson)
     {
         if (!string.IsNullOrEmpty(key))
         {
             yield return(NewtonJson.Deserialize <T>(key));
         }
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// From encrypt string
        /// Author: ThanhDT
        /// CreatedDate: 10/13/2014 3:30 PM
        /// </summary>
        /// <param name="packageEncrypt">The package encrypt.</param>
        /// <returns></returns>
        public static ClientPackage FromEncryptString(string packageEncrypt)
        {
            try
            {
                var           jsonContent   = EncryptUtils.Decrypt(packageEncrypt);
                ClientPackage clientPackage = NewtonJson.Deserialize <ClientPackage>(jsonContent);

                return(clientPackage);
            }
            catch (Exception ex)
            {
                Logger.WriteLog(Logger.LogType.Error, ex);
            }

            return(null);
        }
Ejemplo n.º 7
0
        public MetaConfig GetAll()
        {
            var rule = _cache.Get <MetaConfig>(cacheKey);

            if (rule == null)
            {
                var json = FileConfigHelper.GetFileContent(filePath);
                if (json != "")
                {
                    rule = NewtonJson.Deserialize <MetaConfig>(json);

                    var dependency = new FileCacheDependency(fileName);
                    _cache.Set(cacheKey, rule, dependency);
                }
            }
            return(rule);
        }
Ejemplo n.º 8
0
            public async Task <T> GetAsync <T>(string path, Dictionary <string, string> queries)
            {
                try
                {
                    var requestMessage  = InitRequest(HttpMethod.Get, path, queries);
                    var responseMessage = await SendAsync(requestMessage).ConfigureAwait(false);
                    await PreprocessResponse(responseMessage);

                    string bodyText = await responseMessage.Content.ReadAsStringAsync();

                    return(NewtonJson.Deserialize <T>(bodyText));
                    //return NewtonJson.Deserialize<T>(bodyText,JsonSettings.Snake);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    return(default);
Ejemplo n.º 9
0
        public IEnumerable <SuggestAddressModel> GetSuggestAddress(string keyword)
        {
            var lst = new List <SuggestAddressModel>();

            try
            {
                var model = new SearchSuggestAddressModel();
                model.text = keyword;

                var    apiurl = string.Format(StaticVariable.APISuggestAddress, model.text, model.rows);
                string strRes = Utils.MakeGetRequest(apiurl);
                if (!string.IsNullOrWhiteSpace(strRes))
                {
                    var lstResAPI = NewtonJson.Deserialize <ResponseAddressModel>(strRes);
                    lst = lstResAPI.suggestion.Select(x => new SuggestAddressModel(x)).ToList();
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
            return(lst);
        }