public void OpenFeedPic(bool solved, PicItem picItem) { if (GeneralSettings.IsOldDesign) { if (SafeLayout.IsTablet) { this.navBarTablet.SetButtons(!solved, true, true); this.navBarTablet.SetIcon(picItem); base.Open(this.navBarTablet, FMPopupManager.FMPopupPriority.Normal); } else { this.navBarPhone.SetButtons(!solved, true, true); base.Open(this.navBarPhone, FMPopupManager.FMPopupPriority.Normal); } } else if (SafeLayout.IsTablet) { this.startGameFadePopup.SetButtons(!solved, true, true); this.startGameFadePopup.SetIcon(picItem); base.Open(this.startGameFadePopup, FMPopupManager.FMPopupPriority.Normal); } else { this.startGameSlidePopup.SetButtons(!solved, true, true); this.startGameSlidePopup.SetIcon(picItem); base.Open(this.startGameSlidePopup, FMPopupManager.FMPopupPriority.Normal); } }
private void OnPicDeleted(PictureData delPicData, PictureData replacePicData) { if (replacePicData == null) { return; } for (int i = 0; i < this.items.Count; i++) { PicItem picItem = null; FeaturedItem.ItemType type = this.items[i].Type; if (type != FeaturedItem.ItemType.Daily) { if (type == FeaturedItem.ItemType.PromoPic) { picItem = ((PromoPicItem)this.items[i]).PicItem; } } else { picItem = ((DailyPicItem)this.items[i]).PicItem; } if (picItem != null && picItem.PictureData.Id == replacePicData.Id) { FMLogger.Log("found and replaced in featured section " + replacePicData.Id); picItem.Reset(); picItem.Init(replacePicData, false, false, false); } } }
private IEnumerator IconUpdate(PicItem item) { bool hasIcon = this.iconLine.texture != null; bool hasSave = this.iconSave.texture != null; while (!hasIcon || !hasSave) { if (!hasIcon) { Texture iconTex = item.GetIconTex(); if (iconTex != null) { this.iconLine.texture = iconTex; hasIcon = true; } } if (!hasSave) { Texture saveTex = item.GetSaveTex(); if (saveTex != null) { this.iconSave.texture = saveTex; hasSave = true; } } this.iconUpdate = null; yield return(0); } yield break; }
public void CaculateState() { successItem = 0; for (int i = 0; i < listItems.Count; i++) { GameObject _g = listItems [i].gameObject.transform.parent.gameObject; int _parent_num = int.Parse(_g.name.Split('_')[0]); PicItem _myPicitem = listItems [i].gameObject.GetComponent <PicItem> (); int _myNum = _myPicitem.Num; if (_myNum == _parent_num) { successItem++; } } totalItem = listItems.Count; float _score = (float)successItem / (float)totalItem; _score = Mathf.RoundToInt(_score * 100) / 100.0f; scoreSlider.value = _score * (scoreSlider.maxValue - scoreSlider.minValue); scoreText.text = _score * 100 + "%"; if (_score >= 1.0f) { //SuccessPanel.gameObject.SetActive (true); TipManager.Instance.show("恭喜!拼图完成!"); } adu1.Play(); }
public void InitFromItem(PicItem copy) { this.labels.Clean(); this.labels.RemoveComplete(); this.pd = copy.pd; this.saveData = copy.saveData; if (!this.saveMask.gameObject.activeSelf && copy.saveMask.texture != null) { this.saveMask.gameObject.SetActive(true); } this.saveMask.texture = copy.saveMask.texture; if (this.saveData != null && this.saveData.progres == 100) { this.labels.AddComplete(); } if (!this.webImg.gameObject.activeSelf) { this.webImg.gameObject.SetActive(true); } this.webImg.texture = copy.webImg.texture; copy.pd = null; copy.saveData = null; copy.webImg.texture = null; copy.saveMask.texture = null; copy.labels.Clean(); copy.labels.RemoveComplete(); }
public void OnFeaturedItemClick(FeaturedItem featuredItem) { FeaturedItem.ItemType type = featuredItem.Type; if (type != FeaturedItem.ItemType.Daily) { if (type != FeaturedItem.ItemType.PromoPic) { if (type == FeaturedItem.ItemType.ExternalLink) { ExternalLinkItem externalLinkItem = (ExternalLinkItem)featuredItem; AnalyticsManager.FeaturedExternalLink(externalLinkItem.Id); SystemUtils.OpenUrl(externalLinkItem.TargetScheme, externalLinkItem.TargetUrl); FMLogger.vCore("External link click. " + externalLinkItem.TargetScheme + " url:" + externalLinkItem.TargetUrl); } } else { MenuScreen.PaintStartSource = PaintStartSource.LibFeaturedPromoPic; PromoPicItem promoPicItem = (PromoPicItem)featuredItem; PicItem picItem = promoPicItem.PicItem; AnalyticsManager.FeaturePromoPicClick(picItem.Id, promoPicItem.Order); this.ProcessPicItem(picItem); } } else { MenuScreen.PaintStartSource = PaintStartSource.LibFeaturedDailyPic; DailyPicItem dailyPicItem = (DailyPicItem)featuredItem; PicItem picItem = dailyPicItem.PicItem; AnalyticsManager.FeaturedDailyClick(picItem.Id, dailyPicItem.Order); this.ProcessPicItem(picItem); } }
public void Init(PicItem item) { ImageManager.Instance.UnloadUnusedTextures(); this.Inited = false; this.picItem = item; this.iconUpdate = base.StartCoroutine(this.IconUpdate(item)); this.coloringAnimation.Completed += this.OnAnimationCompleted; }
public void OnDailyTabPicClick(PicItem item) { MenuScreen.PaintStartSource = PaintStartSource.DailyOldPic; DailyEventInfo dailyDate = this.pageController.Daily.GetDailyDate(item.Id); AnalyticsManager.DailyTabPicClick(item.Id, dailyDate.row, dailyDate.day, dailyDate.month, dailyDate.year); this.ProcessPicItem(item); }
public void RemoveSave(int packId, int id) { ScrollRowItem rowWithId = this.scroll.GetRowWithId(id); if (rowWithId != null) { PicItem pictureItem = rowWithId.GetPictureItem(id); if (pictureItem != null) { pictureItem.RemoveSave(); } } }
private void PicItem_Click(object sender, EventArgs e) { // 피쳐박스 크기 최대화 및 이전 사이즈로 if (this.PicItem.Dock == System.Windows.Forms.DockStyle.Fill) { //이미지가 가득 채워져있으면 원상태로 바꾸어라. this.PicItem.Dock = System.Windows.Forms.DockStyle.None; } else { PicItem.Dock = System.Windows.Forms.DockStyle.Fill; PicItem.BringToFront(); // 이미지가 가득 채워져 있지 않으면 가득 채워라. //이미지를 가장 앞으로 가지고 온다. } }
private void ProcessPicItem(PicItem item) { PictureType picType = item.PictureData.picType; if (picType != PictureType.Web) { if (picType != PictureType.System) { if (picType == PictureType.Local) { if (item.PictureData.HasSave) { this.selectedItem = item; if (this.pageController.Feed.IsOpened) { this.popupManager.OpenFeedPic(this.selectedItem.SaveData.progres == 100, this.selectedItem); } else { this.popupManager.OpenSelectPic(this.selectedItem.SaveData.progres == 100, this.selectedItem); } } else { if (!item.PictureData.Solved) { Gameboard.StartAnalyticEvent = new Gameboard.StartEvent { type = Gameboard.StartEventType.New, id = item.PictureData.Id }; } Gameboard.pictureData = item.PictureData; this.AdsAndLoadScene(SceneName.game, false); } } } } else { this.selectedItem = item; this.sceneLoader.Open(true); this.DownloadPictureData(item); } }
public void OnPictureClick(PicItem item) { MenuState menuState = MenuScreen.MenuState; if (menuState != MenuState.Select) { if (menuState == MenuState.Feed) { MenuScreen.PaintStartSource = PaintStartSource.FeedPic; } } else { MenuScreen.PaintStartSource = PaintStartSource.LibPic; AnalyticsManager.SelectPicClick(item.Id, this.pageController.Select.GetItemPositionIndex(item), this.pageController.Select.ActiveCategory, this.pageController.Select.IsFilterCompletedOn); } this.ProcessPicItem(item); }
public void ReloadFailedIcon() { for (int i = 0; i < this.items.Count; i++) { PicItem picItem = null; FeaturedItem.ItemType type = this.items[i].Type; if (type != FeaturedItem.ItemType.Daily) { if (type == FeaturedItem.ItemType.PromoPic) { picItem = ((PromoPicItem)this.items[i]).PicItem; } } else { picItem = ((DailyPicItem)this.items[i]).PicItem; } if (picItem != null && picItem.IconLoadFailed()) { picItem.RetryLoadIcon(); } } }
private void dgvGrid_CellClick(object sender, DataGridViewCellEventArgs e) { // 선택 시 해당품목 이미지 가져오기 string sIC = dgvGrid.CurrentRow.Cells["ITEMCODE"].Value.ToString(); connect = new SqlConnection(strCon); connect.Open(); try { PicItem.Image = null;//이전 이미지를 날리기 위하여. 초기화. string sSQL = $"SELECT ITEMIMG FROM TB_TESTITEM_KBS WHERE ITEMCODE = '{sIC}' AND ITEMIMG IS NOT NULL"; SqlDataAdapter adapter = new SqlDataAdapter(sSQL, connect); DataTable dttemp = new(); adapter.Fill(dttemp); if (dttemp.Rows.Count == 0) { return; } byte[] bImage = null; bImage = (byte[])dttemp.Rows[0]["ITEMIMG"];// 이미지 컬럼의 값을 바이트화한다. if (bImage != null) { PicItem.Image = new Bitmap(new MemoryStream(bImage)); //메모리스트림을 이용해 파일을 그림 파일로 만든다. PicItem.BringToFront(); } } catch (Exception ex) { throw; } finally { connect.Close(); } }
/// <summary> /// 根据XML信息填充实实体 /// </summary> /// <typeparam name="T">MessageBase为基类的类型,Response和Request都可以</typeparam> /// <param name="entity">实体</param> /// <param name="doc">XML</param> public static void FillEntityWithXml <T>(this T entity, XDocument doc) where T : /*MessageBase*/ class, new() { entity = entity ?? new T(); var root = doc.Root; if (root == null) { return;//无法处理 } var props = entity.GetType().GetProperties(); foreach (var prop in props) { var propName = prop.Name; if (root.Element(propName) != null) { switch (prop.PropertyType.Name) { //case "String": // goto default; case "DateTime": case "Int32": case "Int64": case "Double": case "Nullable`1": //可为空对象 EntityUtility.FillSystemType(entity, prop, root.Element(propName).Value); break; case "Boolean": if (propName == "FuncFlag") { EntityUtility.FillSystemType(entity, prop, root.Element(propName).Value == "1"); } else { goto default; } break; //以下为枚举类型 case "RequestMsgType": //已设为只读 //prop.SetValue(entity, MsgTypeHelper.GetRequestMsgType(root.Element(propName).Value), null); break; case "ResponseMsgType": //Response适用 //已设为只读 //prop.SetValue(entity, MsgTypeHelper.GetResponseMsgType(root.Element(propName).Value), null); break; case "Event": //已设为只读 //prop.SetValue(entity, EventHelper.GetEventType(root.Element(propName).Value), null); break; //以下为实体类型 case "List`1": //List<T>类型,ResponseMessageNews适用 { var genericArguments = prop.PropertyType.GetGenericArguments(); var genericArgumentTypeName = genericArguments[0].Name; if (genericArgumentTypeName == "Article") { //文章下属节点item List <Article> articles = new List <Article>(); foreach (var item in root.Element(propName).Elements("item")) { var article = new Article(); FillEntityWithXml(article, new XDocument(item)); articles.Add(article); } prop.SetValue(entity, articles, null); } else if (genericArgumentTypeName == "Account") { List <CustomerServiceAccount> accounts = new List <CustomerServiceAccount>(); foreach (var item in root.Elements(propName)) { var account = new CustomerServiceAccount(); FillEntityWithXml(account, new XDocument(item)); accounts.Add(account); } prop.SetValue(entity, accounts, null); } else if (genericArgumentTypeName == "PicItem") { List <PicItem> picItems = new List <PicItem>(); foreach (var item in root.Elements(propName).Elements("item")) { var picItem = new PicItem(); var picMd5Sum = item.Element("PicMd5Sum").Value; Md5Sum md5Sum = new Md5Sum() { PicMd5Sum = picMd5Sum }; picItem.item = md5Sum; picItems.Add(picItem); } prop.SetValue(entity, picItems, null); } else if (genericArgumentTypeName == "AroundBeacon") { List <AroundBeacon> aroundBeacons = new List <AroundBeacon>(); foreach (var item in root.Elements(propName).Elements("AroundBeacon")) { var aroundBeaconItem = new AroundBeacon(); FillEntityWithXml(aroundBeaconItem, new XDocument(item)); aroundBeacons.Add(aroundBeaconItem); } prop.SetValue(entity, aroundBeacons, null); } else if (genericArgumentTypeName == "CopyrightCheckResult_ResultList") //RequestMessageEvent_MassSendJobFinish { List <CopyrightCheckResult_ResultList> resultList = new List <CopyrightCheckResult_ResultList>(); foreach (var item in root.Elements("ResultList").Elements("item")) { CopyrightCheckResult_ResultList resultItem = new CopyrightCheckResult_ResultList(); FillEntityWithXml(resultItem.item, new XDocument(item)); resultList.Add(resultItem); } prop.SetValue(entity, resultList, null); } break; } case "Music": //ResponseMessageMusic适用 FillClassValue <Music>(entity, root, propName, prop); break; case "Image": //ResponseMessageImage适用 FillClassValue <Image>(entity, root, propName, prop); break; case "Voice": //ResponseMessageVoice适用 FillClassValue <Voice>(entity, root, propName, prop); break; case "Video": //ResponseMessageVideo适用 FillClassValue <Video>(entity, root, propName, prop); break; case "ScanCodeInfo": //扫码事件中的ScanCodeInfo适用 FillClassValue <ScanCodeInfo>(entity, root, propName, prop); break; case "SendLocationInfo": //弹出地理位置选择器的事件推送中的SendLocationInfo适用 FillClassValue <SendLocationInfo>(entity, root, propName, prop); break; case "SendPicsInfo": //系统拍照发图中的SendPicsInfo适用 FillClassValue <SendPicsInfo>(entity, root, propName, prop); break; case "ChosenBeacon": //摇一摇事件通知 FillClassValue <ChosenBeacon>(entity, root, propName, prop); break; case "AroundBeacon": //摇一摇事件通知 FillClassValue <AroundBeacon>(entity, root, propName, prop); break; #region RequestMessageEvent_MassSendJobFinish case "CopyrightCheckResult": FillClassValue <CopyrightCheckResult>(entity, root, propName, prop); break; case "CopyrightCheckResult_ResultList_Item": FillClassValue <CopyrightCheckResult_ResultList_Item>(entity, root, "item", prop); break; #endregion default: var enumSuccess = false; if (prop.PropertyType.IsEnum) { //未知的枚举类型 try { prop.SetValue(entity, Enum.Parse(prop.PropertyType, root.Element(propName).Value, true), null); enumSuccess = true; } catch { } } if (!enumSuccess) { prop.SetValue(entity, root.Element(propName).Value, null); } break; } } } }
/// <summary> /// 根据XML信息填充实实体 /// </summary> /// <typeparam name="T">MessageBase为基类的类型,Response和Request都可以</typeparam> /// <param name="entity">实体</param> /// <param name="doc">XML</param> public static void FillEntityWithXml <T>(this T entity, XDocument doc) where T : /*MessageBase*/ class, new() { if (doc == null) { throw new ArgumentNullException(nameof(doc)); } var root = doc.Root; if (doc.Root == null) { throw new ArgumentNullException(nameof(doc.Root)); } if (entity == null) { throw new ArgumentNullException(nameof(entity)); } //entity = entity ?? new T(); var props = entity.GetType().GetProperties(); foreach (var prop in props) { if (!prop.CanWrite) { continue;//如果不可读则跳过 } var propName = prop.Name; if (root.Element(propName) != null) { switch (prop.PropertyType.Name) { //case "String": // goto default; case "DateTime": case "DateTimeOffset": case "Int32": case "Int64": case "Double": case "Nullable`1": //可为空对象 EntityUtility.FillSystemType(entity, prop, root.Element(propName).Value); break; case "Boolean": if (propName == "FuncFlag") { EntityUtility.FillSystemType(entity, prop, root.Element(propName).Value == "1"); } else { goto default; } break; //以下为枚举类型 case "RequestMsgType": //已设为只读 //prop.SetValue(entity, MsgTypeHelper.GetRequestMsgType(root.Element(propName).Value), null); break; case "ResponseMsgType": //Response适用 //已设为只读 //prop.SetValue(entity, MsgTypeHelper.GetResponseMsgType(root.Element(propName).Value), null); break; case "Event": //已设为只读 //prop.SetValue(entity, EventHelper.GetEventType(root.Element(propName).Value), null); break; //以下为实体类型 case "List`1": //List<T>类型,ResponseMessageNews适用 { var genericArguments = prop.PropertyType.GetGenericArguments(); var genericArgumentTypeName = genericArguments[0].Name; if (genericArgumentTypeName == "Article") { //文章下属节点item List <Article> articles = new List <Article>(); foreach (var item in root.Element(propName).Elements("item")) { var article = new Article(); FillEntityWithXml(article, new XDocument(item)); articles.Add(article); } prop.SetValue(entity, articles, null); } else if (genericArgumentTypeName == "Account") { List <CustomerServiceAccount> accounts = new List <CustomerServiceAccount>(); foreach (var item in root.Elements(propName)) { var account = new CustomerServiceAccount(); FillEntityWithXml(account, new XDocument(item)); accounts.Add(account); } prop.SetValue(entity, accounts, null); } else if (genericArgumentTypeName == "PicItem") { List <PicItem> picItems = new List <PicItem>(); foreach (var item in root.Elements(propName).Elements("item")) { var picItem = new PicItem(); var picMd5Sum = item.Element("PicMd5Sum").Value; Md5Sum md5Sum = new Md5Sum() { PicMd5Sum = picMd5Sum }; picItem.item = md5Sum; picItems.Add(picItem); } prop.SetValue(entity, picItems, null); } else if (genericArgumentTypeName == "AroundBeacon") { List <AroundBeacon> aroundBeacons = new List <AroundBeacon>(); foreach (var item in root.Elements(propName).Elements("AroundBeacon")) { var aroundBeaconItem = new AroundBeacon(); FillEntityWithXml(aroundBeaconItem, new XDocument(item)); aroundBeacons.Add(aroundBeaconItem); } prop.SetValue(entity, aroundBeacons, null); } else if (genericArgumentTypeName == "CopyrightCheckResult_ResultList") //RequestMessageEvent_MassSendJobFinish { List <CopyrightCheckResult_ResultList> resultList = new List <CopyrightCheckResult_ResultList>(); foreach (var item in root.Elements("ResultList").Elements("item")) { CopyrightCheckResult_ResultList resultItem = new CopyrightCheckResult_ResultList(); FillEntityWithXml(resultItem.item, new XDocument(item)); resultList.Add(resultItem); } prop.SetValue(entity, resultList, null); } //企业微信 else if (genericArguments[0].Name == "MpNewsArticle") { List <MpNewsArticle> mpNewsArticles = new List <MpNewsArticle>(); foreach (var item in root.Elements(propName)) { var mpNewsArticle = new MpNewsArticle(); FillEntityWithXml(mpNewsArticle, new XDocument(item)); mpNewsArticles.Add(mpNewsArticle); } prop.SetValue(entity, mpNewsArticles, null); } break; } case "Music": //ResponseMessageMusic适用 FillClassValue <Music>(entity, root, propName, prop); break; case "Image": //ResponseMessageImage适用 FillClassValue <Image>(entity, root, propName, prop); break; case "Voice": //ResponseMessageVoice适用 FillClassValue <Voice>(entity, root, propName, prop); break; case "Video": //ResponseMessageVideo适用 FillClassValue <Video>(entity, root, propName, prop); break; case "ScanCodeInfo": //扫码事件中的ScanCodeInfo适用 FillClassValue <ScanCodeInfo>(entity, root, propName, prop); break; case "SendLocationInfo": //弹出地理位置选择器的事件推送中的SendLocationInfo适用 FillClassValue <SendLocationInfo>(entity, root, propName, prop); break; case "SendPicsInfo": //系统拍照发图中的SendPicsInfo适用 FillClassValue <SendPicsInfo>(entity, root, propName, prop); break; case "ChosenBeacon": //摇一摇事件通知 FillClassValue <ChosenBeacon>(entity, root, propName, prop); break; case "AroundBeacon": //摇一摇事件通知 FillClassValue <AroundBeacon>(entity, root, propName, prop); break; #region 开放平台-小程序 case "ThirdFasteRegisterInfo": //开放平台-小程序-快速注册 FillClassValue <ThirdFasteRegisterInfo>(entity, root, propName, prop); break; #endregion #region RequestMessageEvent_MassSendJobFinish case "CopyrightCheckResult": FillClassValue <CopyrightCheckResult>(entity, root, propName, prop); break; case "CopyrightCheckResult_ResultList_Item": FillClassValue <CopyrightCheckResult_ResultList_Item>(entity, root, "item", prop); break; #region 企业号 /* 暂时放在Work.dll中 * case "AgentType": * { * AgentType tp; #if NET35 * try * { * tp = (AgentType)Enum.Parse(typeof(AgentType), root.Element(propName).Value, true); * prop.SetValue(entity, tp, null); * } * catch * { * * } #else * if (Enum.TryParse(root.Element(propName).Value, out tp)) * { * prop.SetValue(entity, tp, null); * } #endif * break; * } * case "Receiver": * { * Receiver receiver = new Receiver(); * FillEntityWithXml(receiver, new XDocument(root.Element(propName))); * prop.SetValue(entity, receiver, null); * break; * } */ #endregion #endregion default: var enumSuccess = false; if (prop.PropertyType.IsEnum) { //未知的枚举类型 try { prop.SetValue(entity, Enum.Parse(prop.PropertyType, root.Element(propName).Value, true), null); enumSuccess = true; } catch { } } if (!enumSuccess) { prop.SetValue(entity, root.Element(propName).Value, null); } break; } } } }
/// <summary> /// 根据XML信息填充实实体 /// </summary> /// <typeparam name="T">MessageBase为基类的类型,Response和Request都可以</typeparam> /// <param name="entity">实体</param> /// <param name="doc">XML</param> public static void FillEntityWithXml <T>(this T entity, XDocument doc) where T : /*MessageBase*/ class, new() { entity = entity ?? new T(); var root = doc.Root; if (root == null) { return;//无法处理 } var props = entity.GetType().GetProperties(); foreach (var prop in props) { var propName = prop.Name; if (root.Element(propName) != null) { switch (prop.PropertyType.Name) { //case "String": // goto default; case "DateTime": case "Int32": case "Int64": case "Double": case "Nullable`1": //可为空对象 EntityUtility.EntityUtility.FillSystemType(entity, prop, root.Element(propName).Value); break; case "Boolean": if (propName == "FuncFlag") { EntityUtility.EntityUtility.FillSystemType(entity, prop, root.Element(propName).Value == "1"); } else { goto default; } break; //以下为枚举类型 case "RequestMsgType": //已设为只读 //prop.SetValue(entity, MsgTypeHelper.GetRequestMsgType(root.Element(propName).Value), null); break; case "ResponseMsgType": //Response适用 //已设为只读 //prop.SetValue(entity, MsgTypeHelper.GetResponseMsgType(root.Element(propName).Value), null); break; case "Event": //已设为只读 //prop.SetValue(entity, EventHelper.GetEventType(root.Element(propName).Value), null); break; //以下为实体类型 case "List`1": //List<T>类型,ResponseMessageNews适用 { var genericArguments = prop.PropertyType.GetGenericArguments(); if (genericArguments[0].Name == "Article") //ResponseMessageNews适用 { //文章下属节点item List <Article> articles = new List <Article>(); foreach (var item in root.Element(propName).Elements("item")) { var article = new Article(); FillEntityWithXml(article, new XDocument(item)); articles.Add(article); } prop.SetValue(entity, articles, null); } else if (genericArguments[0].Name == "Account") { List <CustomerServiceAccount> accounts = new List <CustomerServiceAccount>(); foreach (var item in root.Elements(propName)) { var account = new CustomerServiceAccount(); FillEntityWithXml(account, new XDocument(item)); accounts.Add(account); } prop.SetValue(entity, accounts, null); } else if (genericArguments[0].Name == "PicItem") { List <PicItem> picItems = new List <PicItem>(); foreach (var item in root.Elements(propName).Elements("item")) { var picItem = new PicItem(); var picMd5Sum = item.Element("PicMd5Sum").Value; Md5Sum md5Sum = new Md5Sum() { PicMd5Sum = picMd5Sum }; picItem.item = md5Sum; picItems.Add(picItem); } prop.SetValue(entity, picItems, null); } else if (genericArguments[0].Name == "AroundBeacon") { List <AroundBeacon> aroundBeacons = new List <AroundBeacon>(); foreach (var item in root.Elements(propName).Elements("AroundBeacon")) { var aroundBeaconItem = new AroundBeacon(); FillEntityWithXml(aroundBeaconItem, new XDocument(item)); aroundBeacons.Add(aroundBeaconItem); } prop.SetValue(entity, aroundBeacons, null); } break; } case "Music": //ResponseMessageMusic适用 Music music = new Music(); FillEntityWithXml(music, new XDocument(root.Element(propName))); prop.SetValue(entity, music, null); break; case "Image": //ResponseMessageImage适用 Image image = new Image(); FillEntityWithXml(image, new XDocument(root.Element(propName))); prop.SetValue(entity, image, null); break; case "Voice": //ResponseMessageVoice适用 Voice voice = new Voice(); FillEntityWithXml(voice, new XDocument(root.Element(propName))); prop.SetValue(entity, voice, null); break; case "Video": //ResponseMessageVideo适用 Video video = new Video(); FillEntityWithXml(video, new XDocument(root.Element(propName))); prop.SetValue(entity, video, null); break; case "ScanCodeInfo": //扫码事件中的ScanCodeInfo适用 ScanCodeInfo scanCodeInfo = new ScanCodeInfo(); FillEntityWithXml(scanCodeInfo, new XDocument(root.Element(propName))); prop.SetValue(entity, scanCodeInfo, null); break; case "SendLocationInfo": //弹出地理位置选择器的事件推送中的SendLocationInfo适用 SendLocationInfo sendLocationInfo = new SendLocationInfo(); FillEntityWithXml(sendLocationInfo, new XDocument(root.Element(propName))); prop.SetValue(entity, sendLocationInfo, null); break; case "SendPicsInfo": //系统拍照发图中的SendPicsInfo适用 SendPicsInfo sendPicsInfo = new SendPicsInfo(); FillEntityWithXml(sendPicsInfo, new XDocument(root.Element(propName))); prop.SetValue(entity, sendPicsInfo, null); break; case "ChosenBeacon": //摇一摇事件通知 ChosenBeacon chosenBeacon = new ChosenBeacon(); FillEntityWithXml(chosenBeacon, new XDocument(root.Element(propName))); prop.SetValue(entity, chosenBeacon, null); break; case "AroundBeacon": //摇一摇事件通知 AroundBeacon aroundBeacon = new AroundBeacon(); FillEntityWithXml(aroundBeacon, new XDocument(root.Element(propName))); prop.SetValue(entity, aroundBeacon, null); break; default: prop.SetValue(entity, root.Element(propName).Value, null); break; } } } }
public void SetIcon(PicItem item) { this.icon.texture = item.GetIconTex(); this.save.texture = item.GetSaveTex(); this.iconUpdate = base.StartCoroutine(this.IconUpdate(item)); }
public int GetItemPositionIndex(PicItem picItem) { return(this.scroll.GetItemPositionIndex(picItem)); }
/// <summary> /// 获取请求XML /// </summary> /// <returns></returns> private XDocument GetrequestMessaageDoc(string url, string token, RequestMsgType requestType, Event? eventType) { RequestMessageBase requestMessaage = null; switch (requestType) { case RequestMsgType.Text: requestMessaage = new RequestMessageText() { Content = Request.Form["Content"], }; break; case RequestMsgType.Location: requestMessaage = new RequestMessageLocation() { Label = Request.Form["Label"], Location_X = double.Parse(Request.Form["Location_X"]), Location_Y = double.Parse(Request.Form["Location_Y"]), Scale = int.Parse(Request.Form["Scale"]) }; break; case RequestMsgType.Image: requestMessaage = new RequestMessageImage() { PicUrl = Request.Form["PicUrl"], }; break; case RequestMsgType.Voice: requestMessaage = new RequestMessageVoice() { Format = Request.Form["Format"], Recognition = Request.Form["Recognition"], }; break; case RequestMsgType.Video: requestMessaage = new RequestMessageVideo() { MsgId = long.Parse(Request.Form["MsgId"]), ThumbMediaId = Request.Form["ThumbMediaId"], }; break; //case RequestMsgType.Link: // break; case RequestMsgType.Event: if (eventType.HasValue) { RequestMessageEventBase requestMessageEvent = null; switch (eventType.Value) { //case Event.ENTER: // break; case Event.LOCATION: requestMessageEvent = new RequestMessageEvent_Location() { Latitude = long.Parse(Request.Form["Event.Latitude"]), Longitude = long.Parse(Request.Form["Event.Longitude"]), Precision = double.Parse(Request.Form["Event.Precision"]) }; break; case Event.subscribe: requestMessageEvent = new RequestMessageEvent_Subscribe() { EventKey = Request.Form["Event.EventKey"], Ticket = Request.Form["Event.Ticket"] }; break; case Event.unsubscribe: requestMessageEvent = new RequestMessageEvent_Unsubscribe(); break; case Event.CLICK: requestMessageEvent = new RequestMessageEvent_Click() { EventKey = Request.Form["Event.EventKey"] }; break; case Event.scan: requestMessageEvent = new RequestMessageEvent_Scan() { EventKey = Request.Form["Event.EventKey"], Ticket = Request.Form["Event.Ticket"] }; break; case Event.VIEW: requestMessageEvent = new RequestMessageEvent_View() { EventKey = Request.Form["Event.EventKey"] }; break; case Event.MASSSENDJOBFINISH: requestMessageEvent = new RequestMessageEvent_MassSendJobFinish() { FromUserName = "******",//系统指定 ErrorCount = int.Parse(Request.Form["Event.ErrorCount"]), FilterCount = int.Parse(Request.Form["Event.FilterCount"]), SentCount = int.Parse(Request.Form["Event.SentCount"]), Status = Request.Form["Event.Status"], TotalCount = int.Parse(Request.Form["Event.TotalCount"]) }; break; case Event.TEMPLATESENDJOBFINISH: requestMessageEvent = new RequestMessageEvent_TemplateSendJobFinish() { FromUserName = "******",//系统指定 MsgID = long.Parse(Request.Form["Event.MsgID"]), Status = Request.Form["Event.Status"], }; break; case Event.scancode_push: requestMessageEvent = new RequestMessageEvent_Scancode_Push() { FromUserName = "******",//系统指定 EventKey = Request.Form["Event.EventKey"], ScanCodeInfo = new ScanCodeInfo() { ScanResult = Request.Form["Event.ScanResult"], ScanType = Request.Form["Event.ScanType"], } }; break; case Event.scancode_waitmsg: requestMessageEvent = new RequestMessageEvent_Scancode_Waitmsg() { FromUserName = "******",//系统指定 EventKey = Request.Form["Event.EventKey"], ScanCodeInfo = new ScanCodeInfo() { ScanResult = Request.Form["Event.ScanResult"], ScanType = Request.Form["Event.ScanType"], } }; break; case Event.pic_sysphoto: var sysphotoPicMd5Sum = Request.Form["Event.PicMd5Sum"]; PicItem sysphotoPicItem = new PicItem() { item = new Md5Sum() { PicMd5Sum = sysphotoPicMd5Sum } }; List<PicItem> sysphotoPicItems = new List<PicItem>(); sysphotoPicItems.Add(sysphotoPicItem); requestMessageEvent = new RequestMessageEvent_Pic_Sysphoto() { FromUserName = "******",//系统指定 EventKey = Request.Form["Event.EventKey"], SendPicsInfo = new SendPicsInfo() { Count = Request.Form["Event.Count"], PicList = sysphotoPicItems } }; break; case Event.pic_photo_or_album: var photoOrAlbumPicMd5Sum = Request.Form["Event.PicMd5Sum"]; PicItem photoOrAlbumPicItem = new PicItem() { item = new Md5Sum() { PicMd5Sum = photoOrAlbumPicMd5Sum } }; List<PicItem> photoOrAlbumPicItems = new List<PicItem>(); photoOrAlbumPicItems.Add(photoOrAlbumPicItem); requestMessageEvent = new RequestMessageEvent_Pic_Sysphoto() { FromUserName = "******",//系统指定 EventKey = Request.Form["Event.EventKey"], SendPicsInfo = new SendPicsInfo() { Count = Request.Form["Event.Count"], PicList = photoOrAlbumPicItems } }; break; case Event.pic_weixin: var weixinPicMd5Sum = Request.Form["Event.PicMd5Sum"]; PicItem weixinPicItem = new PicItem() { item = new Md5Sum() { PicMd5Sum = weixinPicMd5Sum } }; List<PicItem> weixinPicItems = new List<PicItem>(); weixinPicItems.Add(weixinPicItem); requestMessageEvent = new RequestMessageEvent_Pic_Sysphoto() { FromUserName = "******",//系统指定 EventKey = Request.Form["Event.EventKey"], SendPicsInfo = new SendPicsInfo() { Count = Request.Form["Event.Count"], PicList = weixinPicItems } }; break; case Event.location_select: requestMessageEvent = new RequestMessageEvent_Location_Select() { FromUserName = "******",//系统指定 EventKey = Request.Form["Event.EventKey"], SendLocationInfo = new SendLocationInfo() { Label = Request.Form["Event.Label"], Location_X = Request.Form["Event.Location_X"], Location_Y = Request.Form["Event.Location_Y"], Poiname = Request.Form["Event.Poiname"], Scale = Request.Form["Event.Scale"], } }; break; default: throw new ArgumentOutOfRangeException("eventType"); } requestMessaage = requestMessageEvent; } else { throw new ArgumentOutOfRangeException("eventType"); } break; default: throw new ArgumentOutOfRangeException("requestType"); } requestMessaage.MsgId = long.Parse(Request.Form["MsgId"]); requestMessaage.CreateTime = DateTime.Now; requestMessaage.FromUserName = requestMessaage.FromUserName ?? "FromUserName(OpenId)";//用于区别不同的请求用户 requestMessaage.ToUserName = "******"; return requestMessaage.ConvertEntityToXml(); }
/// <summary> /// 根据XML信息填充实实体 /// </summary> /// <typeparam name="T">MessageBase为基类的类型,Response和Request都可以</typeparam> /// <param name="entity">实体</param> /// <param name="doc">XML</param> public static void FillEntityWithXml <T>(this T entity, XDocument doc) where T : /*MessageBase*/ class, new() { entity = entity ?? new T(); var root = doc.Root; var props = entity.GetType().GetProperties(); foreach (var prop in props) { var propName = prop.Name; if (root.Element(propName) != null) { switch (prop.PropertyType.Name) { //case "String": // goto default; case "DateTime": case "Int32": case "Int64": case "Double": case "Nullable`1": //可为空对象 EntityUtility.EntityUtility.FillSystemType(entity, prop, root.Element(propName).Value); break; case "Boolean": if (propName == "FuncFlag") { EntityUtility.EntityUtility.FillSystemType(entity, prop, root.Element(propName).Value == "1"); } else { goto default; } break; //以下为枚举类型 case "RequestMsgType": //已设为只读 //prop.SetValue(entity, MsgTypeHelper.GetRequestMsgType(root.Element(propName).Value), null); break; case "ResponseMsgType": //Response适用 //已设为只读 //prop.SetValue(entity, MsgTypeHelper.GetResponseMsgType(root.Element(propName).Value), null); break; case "ThirdPartyInfo": //ThirdPartyInfo适用 //已设为只读 //prop.SetValue(entity, MsgTypeHelper.GetResponseMsgType(root.Element(propName).Value), null); break; case "Event": //已设为只读 //prop.SetValue(entity, EventHelper.GetEventType(root.Element(propName).Value), null); break; //以下为实体类型 case "List`1": //List<T>类型,ResponseMessageNews适用 var genericArguments = prop.PropertyType.GetGenericArguments(); if (genericArguments[0].Name == "Article") //ResponseMessageNews适用 { //文章下属节点item List <Article> articles = new List <Article>(); foreach (var item in root.Element(propName).Elements("item")) { var article = new Article(); FillEntityWithXml(article, new XDocument(item)); articles.Add(article); } prop.SetValue(entity, articles, null); } else if (genericArguments[0].Name == "MpNewsArticle") { List <MpNewsArticle> mpNewsArticles = new List <MpNewsArticle>(); foreach (var item in root.Elements(propName)) { var mpNewsArticle = new MpNewsArticle(); FillEntityWithXml(mpNewsArticle, new XDocument(item)); mpNewsArticles.Add(mpNewsArticle); } prop.SetValue(entity, mpNewsArticles, null); } else if (genericArguments[0].Name == "PicItem") { List <PicItem> picItems = new List <PicItem>(); foreach (var item in root.Elements(propName).Elements("item")) { var picItem = new PicItem(); var picMd5Sum = item.Element("PicMd5Sum").Value; Md5Sum md5Sum = new Md5Sum() { PicMd5Sum = picMd5Sum }; picItem.item = md5Sum; picItems.Add(picItem); } prop.SetValue(entity, picItems, null); } break; case "Image": //ResponseMessageImage适用 Image image = new Image(); FillEntityWithXml(image, new XDocument(root.Element(propName))); prop.SetValue(entity, image, null); break; case "Voice": //ResponseMessageVoice适用 Voice voice = new Voice(); FillEntityWithXml(voice, new XDocument(root.Element(propName))); prop.SetValue(entity, voice, null); break; case "Video": //ResponseMessageVideo适用 Video video = new Video(); FillEntityWithXml(video, new XDocument(root.Element(propName))); prop.SetValue(entity, video, null); break; case "ScanCodeInfo": //扫码事件中的ScanCodeInfo适用 ScanCodeInfo scanCodeInfo = new ScanCodeInfo(); FillEntityWithXml(scanCodeInfo, new XDocument(root.Element(propName))); prop.SetValue(entity, scanCodeInfo, null); break; case "SendLocationInfo": //弹出地理位置选择器的事件推送中的SendLocationInfo适用 SendLocationInfo sendLocationInfo = new SendLocationInfo(); FillEntityWithXml(sendLocationInfo, new XDocument(root.Element(propName))); prop.SetValue(entity, sendLocationInfo, null); break; case "SendPicsInfo": //系统拍照发图中的SendPicsInfo适用 SendPicsInfo sendPicsInfo = new SendPicsInfo(); FillEntityWithXml(sendPicsInfo, new XDocument(root.Element(propName))); prop.SetValue(entity, sendPicsInfo, null); break; case "BatchJobInfo": //异步任务完成事件推送BatchJob BatchJobInfo batchJobInfo = new BatchJobInfo(); FillEntityWithXml(batchJobInfo, new XDocument(root.Element(propName))); prop.SetValue(entity, batchJobInfo, null); break; case "AgentType": { AgentType tp; #if NET35 try { tp = (AgentType)Enum.Parse(typeof(AgentType), root.Element(propName).Value, true); prop.SetValue(entity, tp, null); } catch { } #else if (Enum.TryParse(root.Element(propName).Value, out tp)) { prop.SetValue(entity, tp, null); } #endif break; } case "Receiver": { Receiver receiver = new Receiver(); FillEntityWithXml(receiver, new XDocument(root.Element(propName))); prop.SetValue(entity, receiver, null); break; } default: prop.SetValue(entity, root.Element(propName).Value, null); break; } } else if (prop.PropertyType.Name == "List`1")//客服回调特殊处理 { var genericArguments = prop.PropertyType.GetGenericArguments(); if (genericArguments[0].Name == "RequestBase") { List <RequestBase> items = new List <RequestBase>(); foreach (var item in root.Elements("Item")) { RequestBase reqItem = null; var msgTypeEle = item.Element("MsgType"); if (msgTypeEle != null) { RequestMsgType type = RequestMsgType.DEFAULT; var parseSuccess = false; #if NET35 try { type = (RequestMsgType)Enum.Parse(typeof(RequestMsgType), msgTypeEle.Value, true); parseSuccess = true; } catch { } #else parseSuccess = Enum.TryParse(msgTypeEle.Value, true, out type); #endif if (parseSuccess) { switch (type) { case RequestMsgType.Event: { reqItem = new RequestEvent(); break; } case RequestMsgType.File: { reqItem = new RequestMessageFile(); break; } case RequestMsgType.Image: { reqItem = new Entities.Request.KF.RequestMessageImage(); break; } case RequestMsgType.Link: { reqItem = new Entities.Request.KF.RequestMessageLink(); break; } case RequestMsgType.Location: { reqItem = new Entities.Request.KF.RequestMessageLocation(); break; } case RequestMsgType.Text: { reqItem = new Entities.Request.KF.RequestMessageText(); break; } case RequestMsgType.Voice: { reqItem = new Entities.Request.KF.RequestMessageVoice(); break; } } } } if (reqItem != null) { FillEntityWithXml(reqItem, new XDocument(item)); items.Add(reqItem); } } prop.SetValue(entity, items, null); } } } }
private void DownloadPictureData(PicItem item) { this.downloadPictureTask = new DownloadPictureTask(item.PictureData, new Action <bool, PictureData>(this.OnPictureDataDownloadResult), new Action(this.OnSlowPictureDataDownload), new Action(this.OnExtraSlowPictureDataDownload)); SharedData.Instance.DownloadPicture(this.downloadPictureTask); }
public void SetIcon(PicItem item) { this.picItem = item; this.shareIsOn = (item.SaveData != null && item.SaveData.progres == 100); }
/// <summary> /// 根据XML信息填充实实体 /// </summary> /// <typeparam name="T">MessageBase为基类的类型,Response和Request都可以</typeparam> /// <param name="entity">实体</param> /// <param name="doc">XML</param> public static void FillEntityWithXml <T>(this T entity, XDocument doc) where T : /*MessageBase*/ class, new() { entity = entity ?? new T(); var root = doc.Root; var props = entity.GetType().GetProperties(); foreach (var prop in props) { var propName = prop.Name; if (root.Element(propName) != null) { switch (prop.PropertyType.Name) { //case "String": // goto default; case "DateTime": prop.SetValue(entity, DateTimeHelper.GetDateTimeFromXml(root.Element(propName).Value), null); break; case "Boolean": if (propName == "FuncFlag") { prop.SetValue(entity, root.Element(propName).Value == "1", null); } else { goto default; } break; case "Int32": if (!string.IsNullOrEmpty(root.Element(propName).Value)) { prop.SetValue(entity, int.Parse(root.Element(propName).Value), null); } break; case "Int64": if (!string.IsNullOrEmpty(root.Element(propName).Value)) { prop.SetValue(entity, long.Parse(root.Element(propName).Value), null); } break; case "Double": if (!string.IsNullOrEmpty(root.Element(propName).Value)) { prop.SetValue(entity, double.Parse(root.Element(propName).Value), null); } break; //以下为枚举类型 case "RequestMsgType": //已设为只读 //prop.SetValue(entity, MsgTypeHelper.GetRequestMsgType(root.Element(propName).Value), null); break; case "ResponseMsgType": //Response适用 //已设为只读 //prop.SetValue(entity, MsgTypeHelper.GetResponseMsgType(root.Element(propName).Value), null); break; case "ThirdPartyInfo": //ThirdPartyInfo适用 //已设为只读 //prop.SetValue(entity, MsgTypeHelper.GetResponseMsgType(root.Element(propName).Value), null); break; case "Event": //已设为只读 //prop.SetValue(entity, EventHelper.GetEventType(root.Element(propName).Value), null); break; //以下为实体类型 case "List`1": //List<T>类型,ResponseMessageNews适用 var genericArguments = prop.PropertyType.GetGenericArguments(); if (genericArguments[0].Name == "Article") //ResponseMessageNews适用 { //文章下属节点item List <Article> articles = new List <Article>(); foreach (var item in root.Element(propName).Elements("item")) { var article = new Article(); FillEntityWithXml(article, new XDocument(item)); articles.Add(article); } prop.SetValue(entity, articles, null); } else if (genericArguments[0].Name == "MpNewsArticle") { List <MpNewsArticle> mpNewsArticles = new List <MpNewsArticle>(); foreach (var item in root.Elements(propName)) { var mpNewsArticle = new MpNewsArticle(); FillEntityWithXml(mpNewsArticle, new XDocument(item)); mpNewsArticles.Add(mpNewsArticle); } prop.SetValue(entity, mpNewsArticles, null); } else if (genericArguments[0].Name == "PicItem") { List <PicItem> picItems = new List <PicItem>(); foreach (var item in root.Elements(propName).Elements("item")) { var picItem = new PicItem(); var picMd5Sum = item.Element("PicMd5Sum").Value; Md5Sum md5Sum = new Md5Sum() { PicMd5Sum = picMd5Sum }; picItem.item = md5Sum; picItems.Add(picItem); } prop.SetValue(entity, picItems, null); } else if (genericArguments[0].Name.ToLower() == "irequestmessagebase") //群聊或者客服接口适用 { //文章下属节点item List <IRequestMessageBase> articles = new List <IRequestMessageBase>(); foreach (var item in root.Elements(propName)) { RequestMessageBase requestMessage; var msgType = MsgTypeHelper.GetRequestMsgType(item); switch (msgType) { case RequestMsgType.Text: requestMessage = new RequestMessageChatText(); break; case RequestMsgType.ShortVideo: requestMessage = new RequestMessageChatShortVideo(); break; case RequestMsgType.Image: requestMessage = new RequestMessageChatImage(); break; case RequestMsgType.Voice: requestMessage = new RequestMessageChatVoice(); break; case RequestMsgType.Event: var eventType = item.Element("Event").Value.ToLower(); switch (eventType) { case "create_chat": requestMessage = new RequestMessageChatEvent_Create(); break; case "update_chat": requestMessage = new RequestMessageChatEvent_Update(); break; case "quit_chat": requestMessage = new RequestMessageChatEvent_Quit(); break; default: throw new WeixinException(string.Format("EventType:{0} 在FillEntityWithXml中没有对应的处理程序!", eventType), new ArgumentOutOfRangeException()); //为了能够对类型变动最大程度容错(如微信目前还可以对公众账号suscribe等未知类型,但API没有开放),建议在使用的时候catch这个异常 } //requestMessage = new RequestMessageChatVoice(); break; default: requestMessage = new RequestMessageChatText(); break; } //var article = new Article(); FillEntityWithXml(requestMessage, new XDocument(item)); articles.Add(requestMessage); } prop.SetValue(entity, articles, null); } break; case "Image": //ResponseMessageImage适用 Image image = new Image(); FillEntityWithXml(image, new XDocument(root.Element(propName))); prop.SetValue(entity, image, null); break; case "Voice": //ResponseMessageVoice适用 Voice voice = new Voice(); FillEntityWithXml(voice, new XDocument(root.Element(propName))); prop.SetValue(entity, voice, null); break; case "Video": //ResponseMessageVideo适用 Video video = new Video(); FillEntityWithXml(video, new XDocument(root.Element(propName))); prop.SetValue(entity, video, null); break; case "ChatInfo": //ResponseMessageVideo适用 ChatInfo chat = new ChatInfo(); FillEntityWithXml(chat, new XDocument(root.Element(propName))); prop.SetValue(entity, chat, null); break; case "Receiver": //ResponseMessageVideo适用 Receiver Receiver = new Receiver(); FillEntityWithXml(Receiver, new XDocument(root.Element(propName))); prop.SetValue(entity, Receiver, null); break; case "ScanCodeInfo": //扫码事件中的ScanCodeInfo适用 ScanCodeInfo scanCodeInfo = new ScanCodeInfo(); FillEntityWithXml(scanCodeInfo, new XDocument(root.Element(propName))); prop.SetValue(entity, scanCodeInfo, null); break; case "SendLocationInfo": //弹出地理位置选择器的事件推送中的SendLocationInfo适用 SendLocationInfo sendLocationInfo = new SendLocationInfo(); FillEntityWithXml(sendLocationInfo, new XDocument(root.Element(propName))); prop.SetValue(entity, sendLocationInfo, null); break; case "SendPicsInfo": //系统拍照发图中的SendPicsInfo适用 SendPicsInfo sendPicsInfo = new SendPicsInfo(); FillEntityWithXml(sendPicsInfo, new XDocument(root.Element(propName))); prop.SetValue(entity, sendPicsInfo, null); break; case "BatchJobInfo": //异步任务完成事件推送BatchJob BatchJobInfo batchJobInfo = new BatchJobInfo(); FillEntityWithXml(batchJobInfo, new XDocument(root.Element(propName))); prop.SetValue(entity, batchJobInfo, null); break; default: prop.SetValue(entity, root.Element(propName).Value, null); break; } } } }
/// <summary> /// 根据XML信息填充实实体 /// </summary> /// <typeparam name="T">MessageBase为基类的类型,Response和Request都可以</typeparam> /// <param name="entity">实体</param> /// <param name="doc">XML</param> public static void FillEntityWithXml <T>(this T entity, XDocument doc) where T : /*MessageBase*/ class, new() { entity = entity ?? new T(); var root = doc.Root; var props = entity.GetType().GetProperties(); foreach (var prop in props) { var propName = prop.Name; if (root.Element(propName) != null) { switch (prop.PropertyType.Name) { //case "String": // goto default; case "DateTime": prop.SetValue(entity, DateTimeHelper.GetDateTimeFromXml(root.Element(propName).Value), null); break; case "Boolean": if (propName == "FuncFlag") { prop.SetValue(entity, root.Element(propName).Value == "1", null); } else { goto default; } break; case "Int32": prop.SetValue(entity, int.Parse(root.Element(propName).Value), null); break; case "Int64": prop.SetValue(entity, long.Parse(root.Element(propName).Value), null); break; case "Double": prop.SetValue(entity, double.Parse(root.Element(propName).Value), null); break; //以下为枚举类型 case "RequestMsgType": //已设为只读 //prop.SetValue(entity, MsgTypeHelper.GetRequestMsgType(root.Element(propName).Value), null); break; case "ResponseMsgType": //Response适用 //已设为只读 //prop.SetValue(entity, MsgTypeHelper.GetResponseMsgType(root.Element(propName).Value), null); break; case "ThirdPartyInfo": //ThirdPartyInfo适用 //已设为只读 //prop.SetValue(entity, MsgTypeHelper.GetResponseMsgType(root.Element(propName).Value), null); break; case "Event": //已设为只读 //prop.SetValue(entity, EventHelper.GetEventType(root.Element(propName).Value), null); break; //以下为实体类型 case "List`1": //List<T>类型,ResponseMessageNews适用 var genericArguments = prop.PropertyType.GetGenericArguments(); if (genericArguments[0].Name == "Article") //ResponseMessageNews适用 { //文章下属节点item List <Article> articles = new List <Article>(); foreach (var item in root.Element(propName).Elements("item")) { var article = new Article(); FillEntityWithXml(article, new XDocument(item)); articles.Add(article); } prop.SetValue(entity, articles, null); } else if (genericArguments[0].Name == "MpNewsArticle") { List <MpNewsArticle> mpNewsArticles = new List <MpNewsArticle>(); foreach (var item in root.Elements(propName)) { var mpNewsArticle = new MpNewsArticle(); FillEntityWithXml(mpNewsArticle, new XDocument(item)); mpNewsArticles.Add(mpNewsArticle); } prop.SetValue(entity, mpNewsArticles, null); } else if (genericArguments[0].Name == "PicItem") { List <PicItem> picItems = new List <PicItem>(); foreach (var item in root.Elements(propName).Elements("item")) { var picItem = new PicItem(); var picMd5Sum = item.Element("PicMd5Sum").Value; Md5Sum md5Sum = new Md5Sum() { PicMd5Sum = picMd5Sum }; picItem.item = md5Sum; picItems.Add(picItem); } prop.SetValue(entity, picItems, null); } break; case "Image": //ResponseMessageImage适用 Image image = new Image(); FillEntityWithXml(image, new XDocument(root.Element(propName))); prop.SetValue(entity, image, null); break; case "Voice": //ResponseMessageVoice适用 Voice voice = new Voice(); FillEntityWithXml(voice, new XDocument(root.Element(propName))); prop.SetValue(entity, voice, null); break; case "Video": //ResponseMessageVideo适用 Video video = new Video(); FillEntityWithXml(video, new XDocument(root.Element(propName))); prop.SetValue(entity, video, null); break; case "ScanCodeInfo": //扫码事件中的ScanCodeInfo适用 ScanCodeInfo scanCodeInfo = new ScanCodeInfo(); FillEntityWithXml(scanCodeInfo, new XDocument(root.Element(propName))); prop.SetValue(entity, scanCodeInfo, null); break; case "SendLocationInfo": //弹出地理位置选择器的事件推送中的SendLocationInfo适用 SendLocationInfo sendLocationInfo = new SendLocationInfo(); FillEntityWithXml(sendLocationInfo, new XDocument(root.Element(propName))); prop.SetValue(entity, sendLocationInfo, null); break; case "SendPicsInfo": //系统拍照发图中的SendPicsInfo适用 SendPicsInfo sendPicsInfo = new SendPicsInfo(); FillEntityWithXml(sendPicsInfo, new XDocument(root.Element(propName))); prop.SetValue(entity, sendPicsInfo, null); break; default: prop.SetValue(entity, root.Element(propName).Value, null); break; } } } }
public int GetItemPositionIndex(PicItem picItem) { return(this.GetItemPositionIndex(picItem.PictureData)); }