Beispiel #1
0
        private static void ParseResult(this CommonRespMsg result)
        {
            JsonObject resultObj;
            var        ok = JsonObject.TryParse(result.JsonSrc, out resultObj);

            if (ok)
            {
                var errorCode = JsonParser.GetStringFromJsonObj(resultObj, "error_code");
                var errorMsg  = JsonParser.GetStringFromJsonObj(resultObj, "error_message");

                if (!string.IsNullOrEmpty(errorCode))
                {
                    if (errorCode != "0")
                    {
                        throw new MyerListException()
                              {
                                  ErrorCode = errorCode,
                                  ErrorMsg  = errorMsg
                              };
                    }
                }
                else
                {
                    throw new MyerListException()
                          {
                              ErrorCode = errorCode,
                              ErrorMsg  = errorMsg
                          };
                }
            }
        }
Beispiel #2
0
        //TODO: Test this method
        /// <summary>
        /// 获取商店页面的信息
        /// </summary>
        /// <param name="type">0 代表字体,1代表图形包</param>
        /// <returns></returns>
        public static async Task <CommonRespMsg> GetProductList(int type, int page, int limit)
        {
            try
            {
                var dic = new List <KeyValuePair <string, string> >();
                dic.Add(new KeyValuePair <string, string>("access_token", UrlHelper.ACCESS_TOKEN));
                dic.Add(new KeyValuePair <string, string>("uid", UrlHelper.UID));
                dic.Add(new KeyValuePair <string, string>("appkey", UrlHelper.APP_KEY));
                dic.Add(new KeyValuePair <string, string>("page_s", (page * 10).ToString()));
                dic.Add(new KeyValuePair <string, string>("limit", limit.ToString()));

                var url = UrlHelper.MakeFullUrlForGetReq(type == 0 ? UrlHelper.GetFontProductsUrl : UrlHelper.GetPackageProductsUrl, dic);
                return(await APIHelper.SendGetRequestAsync(url));
            }
            catch (Exception e)
            {
                var task      = ExceptionHelper.WriteRecord(e, nameof(CloudServices), nameof(GetProductList));
                var resultMsg = new CommonRespMsg()
                {
                    IsSuccessful = false,
                    ErrorMsg     = e.Message
                };
                return(resultMsg);
            }
        }
Beispiel #3
0
 public async static Task <CommonRespMsg> DingFont(List <int> missedIDs, string imgID)
 {
     try
     {
         var dic = new List <KeyValuePair <string, string> >();
         dic.Add(new KeyValuePair <string, string>("access_token", UrlHelper.ACCESS_TOKEN));
         dic.Add(new KeyValuePair <string, string>("uid", UrlHelper.UID));
         dic.Add(new KeyValuePair <string, string>("imgid", imgID));
         dic.Add(new KeyValuePair <string, string>("appkey", UrlHelper.APP_KEY));
         foreach (var item in missedIDs)
         {
             dic.Add(new KeyValuePair <string, string>("missing_fonts[]", item.ToString()));
         }
         return(await APIHelper.SendPostRequestAsync(UrlHelper.DingFontUrl, dic));
     }
     catch (Exception e)
     {
         var task      = ExceptionHelper.WriteRecord(e, nameof(CloudServices), nameof(DingFont));
         var resultMsg = new CommonRespMsg()
         {
             IsSuccessful = false,
             ErrorMsg     = e.Message
         };
         return(resultMsg);
     }
 }
Beispiel #4
0
        /// <summary>
        /// 获取队形里的图片
        /// </summary>
        /// <param name="activityID">活动ID</param>
        /// <param name="type">类型,0 是最新的,1是精选的</param>
        /// <param name="lastID">上一个分页最后的ID</param>
        /// <param name="limit">返回的数目</param>
        /// <returns></returns>
        public async static Task <CommonRespMsg> GetActivityImage(string activityID, int type, string lastID, int limit)
        {
            CommonRespMsg resultToReturn = new CommonRespMsg();

            try
            {
                var dic = new List <KeyValuePair <string, string> >();
                dic.Add(new KeyValuePair <string, string>("lastid", lastID == null ? "" : lastID));
                dic.Add(new KeyValuePair <string, string>("limit", limit.ToString()));
                dic.Add(new KeyValuePair <string, string>("access_token", UrlHelper.ACCESS_TOKEN));
                dic.Add(new KeyValuePair <string, string>("uid", UrlHelper.UID));
                dic.Add(new KeyValuePair <string, string>("appkey", UrlHelper.APP_KEY));
                dic.Add(new KeyValuePair <string, string>("type", type.ToString()));
                dic.Add(new KeyValuePair <string, string>("activity_id", activityID.ToString()));

                string url = UrlHelper.MakeFullUrlForGetReq(UrlHelper.GetActivityImagesUrl, dic);

                resultToReturn = await APIHelper.SendGetRequestAsync(url);

                return(resultToReturn);
            }
            catch (Exception e)
            {
                var task      = ExceptionHelper.WriteRecord(e, nameof(CloudServices), nameof(GetActivityImage));
                var resultMsg = new CommonRespMsg()
                {
                    IsSuccessful = false,
                    ErrorMsg     = e.Message
                };
                return(resultMsg);
            }
        }
Beispiel #5
0
        public static void ParseAPIResult(this CommonRespMsg result)
        {
            var json      = JsonObject.Parse(result.JsonSrc);
            var isSuccess = JsonParser.GetBooleanFromJsonObj(json, "isSuccessed");

            result.IsSuccessful = isSuccess;
            result.ErrorCode    = (int)JsonParser.GetNumberFromJsonObj(json, "error_code");
            result.ErrorMsg     = JsonParser.GetStringFromJsonObj(json, "error_message");
        }
Beispiel #6
0
 public static async Task <CommonRespMsg> GetShapeProductDownloadUrl(string packetID)
 {
     try
     {
         var dic = new List <KeyValuePair <string, string> >();
         dic.Add(new KeyValuePair <string, string>("access_token", UrlHelper.ACCESS_TOKEN));
         dic.Add(new KeyValuePair <string, string>("uid", UrlHelper.UID));
         dic.Add(new KeyValuePair <string, string>("appkey", UrlHelper.APP_KEY));
         dic.Add(new KeyValuePair <string, string>("packetid", packetID));
         return(await APIHelper.SendPostRequestAsync(UrlHelper.GetShapeProductDownloadUrl, dic));
     }
     catch (Exception e)
     {
         var task      = ExceptionHelper.WriteRecord(e, nameof(CloudServices), nameof(GetShapeProductDownloadUrl));
         var resultMsg = new CommonRespMsg()
         {
             IsSuccessful = false,
             ErrorMsg     = e.Message
         };
         return(resultMsg);
     }
 }
Beispiel #7
0
        /// <summary>
        /// 获取字体/图形包的详情页
        /// </summary>
        /// <param name="type">0  是字体 1 是图形包</param>
        /// <param name="productID"></param>
        /// <returns></returns>
        public static async Task <CommonRespMsg> GetProductDetailList(int type, string productID)
        {
            try
            {
                var dic = new List <KeyValuePair <string, string> >();
                dic.Add(new KeyValuePair <string, string>("access_token", UrlHelper.ACCESS_TOKEN));
                dic.Add(new KeyValuePair <string, string>("uid", UrlHelper.UID));
                dic.Add(new KeyValuePair <string, string>("appkey", UrlHelper.APP_KEY));
                dic.Add(new KeyValuePair <string, string>(type == 0 ? "productid" : "packetid", productID));

                var url = UrlHelper.MakeFullUrlForGetReq(type == 0 ? UrlHelper.GetFontProductsDetailUrl : UrlHelper.GetShapeProductsDetailUrl, dic);
                return(await APIHelper.SendGetRequestAsync(url));
            }
            catch (Exception e)
            {
                var task      = ExceptionHelper.WriteRecord(e, nameof(CloudServices), nameof(GetProductDetailList));
                var resultMsg = new CommonRespMsg();
                resultMsg.IsSuccessful = false;
                resultMsg.ErrorMsg     = e.Message;
                return(resultMsg);
            }
        }
Beispiel #8
0
        public async static Task <CommonRespMsg> DingShape(List <string> missedShapeName)
        {
            try
            {
                var dic = new List <KeyValuePair <string, string> >();
                dic.Add(new KeyValuePair <string, string>("access_token", UrlHelper.ACCESS_TOKEN));
                dic.Add(new KeyValuePair <string, string>("uid", UrlHelper.UID));
                dic.Add(new KeyValuePair <string, string>("appkey", UrlHelper.APP_KEY));
                dic.Add(new KeyValuePair <string, string>("icon_name", string.Join(",", missedShapeName.ToArray())));

                return(await APIHelper.SendPostRequestAsync(UrlHelper.DingShapeUrl, dic));
            }
            catch (Exception e)
            {
                var task      = ExceptionHelper.WriteRecord(e, nameof(CloudServices), nameof(DingShape));
                var resultMsg = new CommonRespMsg()
                {
                    IsSuccessful = false,
                    ErrorMsg     = e.Message
                };
                return(resultMsg);
            }
        }
Beispiel #9
0
        public async static Task <CommonRespMsg> GetImgeInfoAsync(string imgID, bool isLogined)
        {
            try
            {
                var dic = new List <KeyValuePair <string, string> >();
                dic.Add(new KeyValuePair <string, string>("access_token", UrlHelper.ACCESS_TOKEN));
                dic.Add(new KeyValuePair <string, string>("uid", UrlHelper.UID));
                dic.Add(new KeyValuePair <string, string>("appkey", UrlHelper.APP_KEY));
                dic.Add(new KeyValuePair <string, string>("imgid", imgID));

                var url = UrlHelper.MakeFullUrlForGetReq(isLogined?UrlHelper.GetImageDetailUrl:UrlHelper.GetPublicImageDetailUrl, dic);
                return(await APIHelper.SendGetRequestAsync(url));
            }
            catch (Exception e)
            {
                var task      = ExceptionHelper.WriteRecord(e, nameof(CloudServices), nameof(GetImgeInfoAsync));
                var resultMsg = new CommonRespMsg()
                {
                    IsSuccessful = false,
                    ErrorMsg     = e.Message
                };
                return(resultMsg);
            }
        }
 public static async Task<CommonRespMsg> GetShapeProductDownloadUrl(string packetID)
 {
     try
     {
         var dic = new List<KeyValuePair<string, string>>();
         dic.Add(new KeyValuePair<string, string>("access_token", UrlHelper.ACCESS_TOKEN));
         dic.Add(new KeyValuePair<string, string>("uid", UrlHelper.UID));
         dic.Add(new KeyValuePair<string, string>("appkey", UrlHelper.APP_KEY));
         dic.Add(new KeyValuePair<string, string>("packetid", packetID));
         return await APIHelper.SendPostRequestAsync(UrlHelper.GetShapeProductDownloadUrl, dic);
     }
     catch (Exception e)
     {
         var task = ExceptionHelper.WriteRecord(e, nameof(CloudServices), nameof(GetShapeProductDownloadUrl));
         var resultMsg = new CommonRespMsg()
         {
             IsSuccessful = false,
             ErrorMsg = e.Message
         };
         return resultMsg;
     }
 }
        /// <summary>
        /// 获取字体/图形包的详情页
        /// </summary>
        /// <param name="type">0  是字体 1 是图形包</param>
        /// <param name="productID"></param>
        /// <returns></returns>
        public static async Task<CommonRespMsg> GetProductDetailList(int type, string productID)
        {
            try
            {
                var dic = new List<KeyValuePair<string, string>>();
                dic.Add(new KeyValuePair<string, string>("access_token", UrlHelper.ACCESS_TOKEN));
                dic.Add(new KeyValuePair<string, string>("uid", UrlHelper.UID));
                dic.Add(new KeyValuePair<string, string>("appkey", UrlHelper.APP_KEY));
                dic.Add(new KeyValuePair<string, string>(type == 0 ? "productid" : "packetid", productID));

                var url = UrlHelper.MakeFullUrlForGetReq(type == 0 ? UrlHelper.GetFontProductsDetailUrl : UrlHelper.GetShapeProductsDetailUrl, dic);
                return await APIHelper.SendGetRequestAsync(url);
            }
            catch (Exception e)
            {
                var task = ExceptionHelper.WriteRecord(e, nameof(CloudServices), nameof(GetProductDetailList));
                var resultMsg = new CommonRespMsg();
                resultMsg.IsSuccessful = false;
                resultMsg.ErrorMsg = e.Message;
                return resultMsg;
            }
        }
        //TODO: Test this method
        /// <summary>
        /// 获取商店页面的信息
        /// </summary>
        /// <param name="type">0 代表字体,1代表图形包</param>
        /// <returns></returns>
        public static async Task<CommonRespMsg> GetProductList(int type, int page, int limit)
        {
            try
            {
                var dic = new List<KeyValuePair<string, string>>();
                dic.Add(new KeyValuePair<string, string>("access_token", UrlHelper.ACCESS_TOKEN));
                dic.Add(new KeyValuePair<string, string>("uid", UrlHelper.UID));
                dic.Add(new KeyValuePair<string, string>("appkey", UrlHelper.APP_KEY));
                dic.Add(new KeyValuePair<string, string>("page_s", (page * 10).ToString()));
                dic.Add(new KeyValuePair<string, string>("limit", limit.ToString()));

                var url = UrlHelper.MakeFullUrlForGetReq(type == 0 ? UrlHelper.GetFontProductsUrl : UrlHelper.GetPackageProductsUrl, dic);
                return await APIHelper.SendGetRequestAsync(url);
            }
            catch (Exception e)
            {
                var task = ExceptionHelper.WriteRecord(e, nameof(CloudServices), nameof(GetProductList));
                var resultMsg = new CommonRespMsg()
                {
                    IsSuccessful = false,
                    ErrorMsg = e.Message
                };
                return resultMsg;
            }
        }
        public async static Task<CommonRespMsg> GetImgeInfoAsync(string imgID,bool isLogined)
        {
            try
            {
                var dic = new List<KeyValuePair<string, string>>();
                dic.Add(new KeyValuePair<string, string>("access_token", UrlHelper.ACCESS_TOKEN));
                dic.Add(new KeyValuePair<string, string>("uid", UrlHelper.UID));
                dic.Add(new KeyValuePair<string, string>("appkey", UrlHelper.APP_KEY));
                dic.Add(new KeyValuePair<string, string>("imgid", imgID));

                var url = UrlHelper.MakeFullUrlForGetReq(isLogined?UrlHelper.GetImageDetailUrl:UrlHelper.GetPublicImageDetailUrl, dic);
                return await APIHelper.SendGetRequestAsync(url);
            }
            catch (Exception e)
            {
                var task = ExceptionHelper.WriteRecord(e, nameof(CloudServices), nameof(GetImgeInfoAsync));
                var resultMsg = new CommonRespMsg()
                {
                    IsSuccessful = false,
                    ErrorMsg = e.Message
                };
                return resultMsg;
            }
        }
        public async static Task<CommonRespMsg> DingShape(List<string> missedShapeName)
        {
            try
            {
                var dic = new List<KeyValuePair<string, string>>();
                dic.Add(new KeyValuePair<string, string>("access_token", UrlHelper.ACCESS_TOKEN));
                dic.Add(new KeyValuePair<string, string>("uid", UrlHelper.UID));
                dic.Add(new KeyValuePair<string, string>("appkey", UrlHelper.APP_KEY));
                dic.Add(new KeyValuePair<string, string>("icon_name", string.Join(",", missedShapeName.ToArray())));

                return await APIHelper.SendPostRequestAsync(UrlHelper.DingShapeUrl, dic);
            }
            catch (Exception e)
            {
                var task = ExceptionHelper.WriteRecord(e, nameof(CloudServices), nameof(DingShape));
                var resultMsg = new CommonRespMsg()
                {
                    IsSuccessful = false,
                    ErrorMsg = e.Message
                };
                return resultMsg;
            }
        }
 public async static Task<CommonRespMsg> DingFont(List<int> missedIDs, string imgID)
 {
     try
     {
         var dic = new List<KeyValuePair<string, string>>();
         dic.Add(new KeyValuePair<string, string>("access_token", UrlHelper.ACCESS_TOKEN));
         dic.Add(new KeyValuePair<string, string>("uid", UrlHelper.UID));
         dic.Add(new KeyValuePair<string, string>("imgid", imgID));
         dic.Add(new KeyValuePair<string, string>("appkey", UrlHelper.APP_KEY));
         foreach (var item in missedIDs)
         {
             dic.Add(new KeyValuePair<string, string>("missing_fonts[]", item.ToString()));
         }
         return await APIHelper.SendPostRequestAsync(UrlHelper.DingFontUrl, dic);
     }
     catch (Exception e)
     {
         var task = ExceptionHelper.WriteRecord(e, nameof(CloudServices), nameof(DingFont));
         var resultMsg = new CommonRespMsg()
         {
             IsSuccessful = false,
             ErrorMsg = e.Message
         };
         return resultMsg;
     }
 }
        /// <summary>
        /// 上传图片
        /// </summary>
        /// <param name="fileData">包含图片信息的对象</param>
        /// <param name="imgKind">照片类型</param>
        /// <returns></returns>
        public async static Task<CommonRespMsg> UploadImageAsnyc(ButterFileToUpload fileData, UploadImageKind imgKind,CancellationToken ctoken)
        {
            var kindstr = "1:1";
            if (fileData.ScaleKind == ScaleKind.Scale_3x4) kindstr = "3:4";
            else if (fileData.ScaleKind == ScaleKind.Scale_4x3) kindstr = "4:3";

            CommonRespMsg result = new CommonRespMsg();
            try
            {
                using (var client = new HttpClient())
                {
                    Dictionary<string, string> dic = new Dictionary<string, string>();
                    dic.Add("uid", LocalSettingHelper.GetValue("uid"));
                    dic.Add("access_token", LocalSettingHelper.GetValue("access_token"));
                    dic.Add("appkey", UrlHelper.APP_KEY);
                    dic.Add("img_info", "{\"scale\":\"" + kindstr + "\"}");
                    dic.Add("ps", fileData.PsData);
                    dic.Add("is_private", fileData.IsPrivate ? "1" : "0");
                    if (fileData.ActivityID != null) dic.Add("activity_id", fileData.ActivityID);
                    if (fileData.OriginalImageID != -1) dic.Add("ding_imgid", fileData.OriginalImageID.ToString());

                    var resp = await client.PostAsync(new Uri(imgKind==UploadImageKind.Photo?UrlHelper.UploadImageUrl:UrlHelper.UploadAvatarUrl), new HttpFormUrlEncodedContent(dic));
                    var json = JsonObject.Parse(await resp.Content.ReadAsStringAsync());

                    var token = JsonParser.GetStringFromJsonObj(json, "token");
                    var key = JsonParser.GetStringFromJsonObj(json, "key");

                    Settings setting = new Settings();
                    ResumablePutExtra extra = new ResumablePutExtra();
                    ResumablePut rclient = new ResumablePut(setting, extra);
                    extra.Notify += ((sendern, en) =>
                      {

                      });

                    ctoken.ThrowIfCancellationRequested();
                   
                    var ioresult = await Task.Run(async () =>
                      {
                          ctoken.ThrowIfCancellationRequested();

                          return await rclient.PutFile(token, fileData.File.Path, key,ctoken);
                      });

                    if (!ioresult.OK) throw new APIException(int.Parse(ioresult.StatusCode.ToString()), ioresult.Exception.Message);
                    else
                    {
                        return result;
                    }
                }
            }
            catch (APIException)
            {
                result.IsSuccessful = false;
                return result;
            }
            catch(OperationCanceledException)
            {
                throw;
            }
            catch (Exception ee)
            {
                var task = ExceptionHelper.WriteRecord(ee, nameof(CloudServices), nameof(UploadImageAsnyc));
                var resultMsg = new CommonRespMsg()
                {
                    IsSuccessful = false,
                    ErrorMsg = ee.Message
                };
                return resultMsg;
            }
        }
        /// <summary>
        /// 获取队形里的图片
        /// </summary>
        /// <param name="activityID">活动ID</param>
        /// <param name="type">类型,0 是最新的,1是精选的</param>
        /// <param name="lastID">上一个分页最后的ID</param>
        /// <param name="limit">返回的数目</param>
        /// <returns></returns>
        public async static Task<CommonRespMsg> GetActivityImage(string activityID, int type, string lastID, int limit)
        {
            CommonRespMsg resultToReturn = new CommonRespMsg();
            try
            {
                var dic = new List<KeyValuePair<string, string>>();
                dic.Add(new KeyValuePair<string, string>("lastid", lastID == null ? "" : lastID));
                dic.Add(new KeyValuePair<string, string>("limit", limit.ToString()));
                dic.Add(new KeyValuePair<string, string>("access_token", UrlHelper.ACCESS_TOKEN));
                dic.Add(new KeyValuePair<string, string>("uid", UrlHelper.UID));
                dic.Add(new KeyValuePair<string, string>("appkey", UrlHelper.APP_KEY));
                dic.Add(new KeyValuePair<string, string>("type", type.ToString()));
                dic.Add(new KeyValuePair<string, string>("activity_id", activityID.ToString()));

                string url = UrlHelper.MakeFullUrlForGetReq(UrlHelper.GetActivityImagesUrl, dic);

                resultToReturn = await APIHelper.SendGetRequestAsync(url);

                return resultToReturn;
            }
            catch (Exception e)
            {
                var task = ExceptionHelper.WriteRecord(e, nameof(CloudServices), nameof(GetActivityImage));
                var resultMsg = new CommonRespMsg()
                {
                    IsSuccessful = false,
                    ErrorMsg = e.Message
                };
                return resultMsg;
            }
        }
Beispiel #18
0
        /// <summary>
        /// 上传图片
        /// </summary>
        /// <param name="fileData">包含图片信息的对象</param>
        /// <param name="imgKind">照片类型</param>
        /// <returns></returns>
        public async static Task <CommonRespMsg> UploadImageAsnyc(ButterFileToUpload fileData, UploadImageKind imgKind, CancellationToken ctoken)
        {
            var kindstr = "1:1";

            if (fileData.ScaleKind == ScaleKind.Scale_3x4)
            {
                kindstr = "3:4";
            }
            else if (fileData.ScaleKind == ScaleKind.Scale_4x3)
            {
                kindstr = "4:3";
            }

            CommonRespMsg result = new CommonRespMsg();

            try
            {
                using (var client = new HttpClient())
                {
                    Dictionary <string, string> dic = new Dictionary <string, string>();
                    dic.Add("uid", LocalSettingHelper.GetValue("uid"));
                    dic.Add("access_token", LocalSettingHelper.GetValue("access_token"));
                    dic.Add("appkey", UrlHelper.APP_KEY);
                    dic.Add("img_info", "{\"scale\":\"" + kindstr + "\"}");
                    dic.Add("ps", fileData.PsData);
                    dic.Add("is_private", fileData.IsPrivate ? "1" : "0");
                    if (fileData.ActivityID != null)
                    {
                        dic.Add("activity_id", fileData.ActivityID);
                    }
                    if (fileData.OriginalImageID != -1)
                    {
                        dic.Add("ding_imgid", fileData.OriginalImageID.ToString());
                    }

                    var resp = await client.PostAsync(new Uri(imgKind == UploadImageKind.Photo?UrlHelper.UploadImageUrl:UrlHelper.UploadAvatarUrl), new HttpFormUrlEncodedContent(dic));

                    var json = JsonObject.Parse(await resp.Content.ReadAsStringAsync());

                    var token = JsonParser.GetStringFromJsonObj(json, "token");
                    var key   = JsonParser.GetStringFromJsonObj(json, "key");

                    Settings          setting = new Settings();
                    ResumablePutExtra extra   = new ResumablePutExtra();
                    ResumablePut      rclient = new ResumablePut(setting, extra);
                    extra.Notify += ((sendern, en) =>
                    {
                    });

                    ctoken.ThrowIfCancellationRequested();

                    var ioresult = await Task.Run(async() =>
                    {
                        ctoken.ThrowIfCancellationRequested();

                        return(await rclient.PutFile(token, fileData.File.Path, key, ctoken));
                    });

                    if (!ioresult.OK)
                    {
                        throw new APIException(int.Parse(ioresult.StatusCode.ToString()), ioresult.Exception.Message);
                    }
                    else
                    {
                        return(result);
                    }
                }
            }
            catch (APIException)
            {
                result.IsSuccessful = false;
                return(result);
            }
            catch (OperationCanceledException)
            {
                throw;
            }
            catch (Exception ee)
            {
                var task      = ExceptionHelper.WriteRecord(ee, nameof(CloudServices), nameof(UploadImageAsnyc));
                var resultMsg = new CommonRespMsg()
                {
                    IsSuccessful = false,
                    ErrorMsg     = ee.Message
                };
                return(resultMsg);
            }
        }