public override object Deserialize(BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options) { dynamic item = new ebayItemDataForSeller(); IDictionary<String, Object> dict = new Dictionary<String, Object>(); bsonReader.ReadStartDocument(); while (bsonReader.ReadBsonType() != BsonType.EndOfDocument) { var elementName = bsonReader.ReadName(); var pi = nominalType.GetProperty(elementName); if (pi != null) { dynamic data = null; if (bsonReader.CurrentBsonType.Equals(BsonType.Null)) { bsonReader.ReadNull(); } else { data = BsonDefaultSerializer.Instance.GetSerializer(pi.PropertyType).Deserialize(bsonReader, pi.PropertyType, options); this.GetType().GetProperty(pi.Name).SetValue(item, data, null); } } else { if (bsonReader.CurrentBsonType.Equals(BsonType.Null)) { bsonReader.SkipValue(); } else dict[elementName] = bsonReader.ReadString(); } } bsonReader.ReadEndDocument(); item.SetDynamics(dict); return this; }
/// <summary> /// forSeller와 thirft통신하여 카테고리별 상세 정보를 가져온다. /// </summary> /// <param name="siteid">사이트 아이디</param> /// <param name="categoryID">카테고리 아이디</param> /// <returns></returns> public ebayItemDataForSeller GetForSellerDataParseJSON(int siteid, long categoryID) { var req = new GetSiteDetailsRequest { SiteID = siteid , CategoryID = categoryID.ToString() }; var res = new ItemService(apiUrl).GetSiteDetails(req); //thirft통신으로 인코딩되서 넘어온것을 디코딩 한다. string JsonData = Encoding.ASCII.GetString(Convert.FromBase64String(res.Response)); ebayItemDataForSeller Data = new ebayItemDataForSeller(); List<ebayItemDataForSellerDetail> Details = new List<ebayItemDataForSellerDetail>(); JSONObject jsonObject = JSONObject.CreateFromString(JsonData); JSONObject jsonDetails = jsonObject.Dictionary["details"]; Data.site = jsonObject.Dictionary["site"].String; //카테고리값이 잘못 들어갈 경우 이값이 안들어와서 에러가 날수 있다. if (jsonObject.Dictionary.Keys.Contains("translated_category_full_path")) { JSONObject KorCateName = jsonObject.Dictionary["translated_category_full_path"]; Data.translated_category_full_path = KorCateName.String; } #region currency 채움. JSONObject jsonCurrency = jsonObject.Dictionary["currency"]; Data.currency.buy = jsonCurrency.Dictionary["buy"].String; Data.currency.change_val = jsonCurrency.Dictionary["change_val"].String; Data.currency.hname = jsonCurrency.Dictionary["hname"].String; Data.currency.receive = jsonCurrency.Dictionary["receive"].String; Data.currency.sell = jsonCurrency.Dictionary["sell"].String; Data.currency.send = jsonCurrency.Dictionary["send"].String; Data.currency.sign = jsonCurrency.Dictionary["sign"].String; Data.currency.standard = jsonCurrency.Dictionary["standard"].String; #endregion #region categories 채움 //categories 채움 foreach (var SubData in jsonObject.Dictionary["categories"].Array) { Data.categories.Add(new Categori() { AutoPayEnabled = Convert.ToBoolean(SubData.Dictionary["AutoPayEnabled"].String) , BestOfferEnabled = Convert.ToBoolean(SubData.Dictionary["BestOfferEnabled"].String) , CategoryName = SubData.Dictionary["CategoryName"].String , CategoryID = Convert.ToInt32(SubData.Dictionary["CategoryID"].String) , CategoryLevel = Convert.ToInt32(SubData.Dictionary["CategoryLevel"].String) , CategoryParentID = Convert.ToInt32(SubData.Dictionary["CategoryParentID"].String) }); } #endregion #region Controll 채움 List<JSONObject> detailObject = new List<JSONObject>(); foreach (var data in jsonDetails.Array) { ebayItemDataForSellerDetail Detail = new ebayItemDataForSellerDetail(); Detail.fieldName = data.Dictionary["field_name"].String; Detail.fieldNameKr = data.Dictionary["field_name_kr"].String; Detail.type = data.Dictionary["type"].String; Detail.isrequire = data.Dictionary.Keys.Contains("isrequire") == true ? data.Dictionary["isrequire"].String : ""; Detail.length = data.Dictionary.Keys.Contains("length") == true ? Util.GetSafeInt(data.Dictionary["length"].String) : 900; //Value 부분 List<ebayItemDataForSellerValues> Values = new List<ebayItemDataForSellerValues>(); // value안에 depth가 있는 특이부분 if (data.Dictionary.Keys.Contains("values") && Detail.type != "LIST" && Detail.fieldName == "ListingDuration") { foreach (var valuesData in data.Dictionary["values"].Dictionary) { ebayItemDataForSellerValues settingsValues = new ebayItemDataForSellerValues(); settingsValues.key = valuesData.Key; List<ebayItemDataForSellerValuesDepth1> listDepth = new List<ebayItemDataForSellerValuesDepth1>(); foreach (var valuesDataDepth1 in valuesData.Value.Array) { ebayItemDataForSellerValuesDepth1 depth1 = new ebayItemDataForSellerValuesDepth1(); depth1.key = valuesDataDepth1.Dictionary["key"].String; depth1.value = valuesDataDepth1.Dictionary["value"].String; depth1.show_value = valuesDataDepth1.Dictionary["show_value"].String; listDepth.Add(depth1); } settingsValues.settingsValuesDepth1 = listDepth; Values.Add(settingsValues); } Detail.values = Values; } //상품 상세 정보 채움. else if (Detail.fieldName == "ItemSpecifics") { foreach (var SubData in data.Dictionary["values"].Array) { string Name = SubData.Dictionary["Name"].String; ValidationRules ValidationRules = new GEP.Data.ValidationRules(); List<ValueRecommendation> ValueRecommendations = new List<GEP.Data.ValueRecommendation>(); if (SubData.Dictionary.Keys.Contains("ValueRecommendation")) { if (SubData.Dictionary["ValueRecommendation"].Array != null) { foreach (var t in SubData.Dictionary["ValueRecommendation"].Array) { ValueRecommendation ValueRecommendation = new ValueRecommendation(); if (t.Dictionary.Keys.Contains("Value")) { ValueRecommendation.Value = t.Dictionary["Value"].String; } if (t.Dictionary.Keys.Contains("ValidationRules")) { ValueRecommendation.ValidationRules = CreateValidationRules(t.Dictionary["ValidationRules"]); } ValueRecommendations.Add(ValueRecommendation); } } } if (SubData.Dictionary.Keys.Contains("ValidationRules")) { ValidationRules = CreateValidationRules(SubData.Dictionary["ValidationRules"]); } ebayItemDataForSellerValues Value = new ebayItemDataForSellerValues(); Value.Name = Name; Value.ValidationRules = ValidationRules; Value.ValueRecommendation = ValueRecommendations; Values.Add(Value); } Detail.values = Values; } //나머지 데이터 else { if (data.Dictionary.Keys.Contains("values")) { if (data.Dictionary["values"].Array != null) { foreach (var valuesData in data.Dictionary["values"].Array) { //데이터가 들쑥날쑥해서 있는지 없는지 꼭 체크 해줘야함. ebayItemDataForSellerValues Value = new ebayItemDataForSellerValues(); if (valuesData.Dictionary.Keys.Contains("key")) { Value.key = valuesData.Dictionary["key"].String; } if (valuesData.Dictionary.Keys.Contains("value")) { Value.value = valuesData.Dictionary["value"].String; } if (valuesData.Dictionary.Keys.Contains("Description")) { Value.description = valuesData.Dictionary["Description"].String; } if (valuesData.Dictionary.Keys.Contains("Location")) { Value.location = valuesData.Dictionary["Location"].String; } if (valuesData.Dictionary.Keys.Contains("Region")) { Value.region = valuesData.Dictionary["Region"].String; } if (valuesData.Dictionary.Keys.Contains("show_value")) { Value.show_value = valuesData.Dictionary["show_value"].String; } Values.Add(Value); } } else { var valuesData = data.Dictionary["values"]; ebayItemDataForSellerValues Value = new ebayItemDataForSellerValues(); if (valuesData.Dictionary.Keys.Contains("key")) { Value.key = valuesData.Dictionary["key"].String; } if (valuesData.Dictionary.Keys.Contains("value")) { Value.value = valuesData.Dictionary["value"].String; } if (valuesData.Dictionary.Keys.Contains("Description")) { Value.description = valuesData.Dictionary["Description"].String; } if (valuesData.Dictionary.Keys.Contains("Location")) { Value.location = valuesData.Dictionary["Location"].String; } if (valuesData.Dictionary.Keys.Contains("Region")) { Value.region = valuesData.Dictionary["Region"].String; } if (valuesData.Dictionary.Keys.Contains("show_value")) { Value.show_value = valuesData.Dictionary["show_value"].String; } Values.Add(Value); } } Detail.values = Values; } Details.Add(Detail); } Data.details = Details; #endregion return Data; }