public static string ReplyImage(ReplyImageModel entity) { if (null != entity && !string.IsNullOrWhiteSpace(entity.ToUserName) && null != entity.Image) { string xmlString = string.Empty; //var s1 = XmlHelper.Serialize(entity); #region xmlString System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument(); System.Xml.XmlNode rootNode; System.Xml.XmlElement ele; System.Xml.XmlCDataSection cdata; #region xml rootNode = xmlDoc.CreateNode(System.Xml.XmlNodeType.Element, "xml", null); ele = xmlDoc.CreateElement(nameof(entity.ToUserName)); cdata = xmlDoc.CreateCDataSection(entity.ToUserName); ele.AppendChild(cdata); rootNode.AppendChild(ele); ele = xmlDoc.CreateElement(nameof(entity.FromUserName)); cdata = xmlDoc.CreateCDataSection(entity.FromUserName); ele.AppendChild(cdata); rootNode.AppendChild(ele); ele = xmlDoc.CreateElement(nameof(entity.CreateTime)); ele.InnerXml = entity.CreateTime.ToString(); rootNode.AppendChild(ele); ele = xmlDoc.CreateElement(nameof(entity.MsgType)); cdata = xmlDoc.CreateCDataSection(entity.MsgType); ele.AppendChild(cdata); rootNode.AppendChild(ele); #endregion System.Xml.XmlNode nodeImage; nodeImage = xmlDoc.CreateNode(System.Xml.XmlNodeType.Element, nameof(entity.Image), null); if (null != entity.Image) { ele = xmlDoc.CreateElement(nameof(entity.Image.MediaId)); cdata = xmlDoc.CreateCDataSection(entity.Image.MediaId); ele.AppendChild(cdata); nodeImage.AppendChild(ele); } rootNode.AppendChild(nodeImage); xmlDoc.AppendChild(rootNode); xmlString = xmlDoc.OuterXml; #endregion if (!string.IsNullOrWhiteSpace(xmlString)) { return(xmlString); } } return(ReplyEmpty()); }
public System.Xml.XmlElement CreateXmlElement(System.Xml.XmlDocument document) { System.Xml.XmlElement templateElement = document.CreateElement("EmailTemplate"); System.Xml.XmlElement smtpElement = document.CreateElement("Smtp"); smtpElement.SetAttribute("host", this.Smtp.Host); smtpElement.SetAttribute("port", this.Smtp.Port.ToString()); smtpElement.SetAttribute("enableSSL", this.Smtp.EnableSsl.ToString()); smtpElement.SetAttribute("deliveryMethod", this.Smtp.DeliveryMethod.ToString()); smtpElement.SetAttribute("username", ((System.Net.NetworkCredential) this.Smtp.Credentials).UserName); smtpElement.SetAttribute("password", ((System.Net.NetworkCredential) this.Smtp.Credentials).Password); templateElement.AppendChild(smtpElement); System.Xml.XmlElement subjectElement = document.CreateElement("Subject"); subjectElement.AppendChild(document.CreateCDataSection(this.Subject)); templateElement.AppendChild(subjectElement); System.Xml.XmlElement bodyElement = document.CreateElement("Body"); bodyElement.AppendChild(document.CreateCDataSection(this.Body)); bodyElement.SetAttribute("isHtml", this.BodyIsHtml.ToString()); templateElement.AppendChild(bodyElement); if (this.Sender != null) { System.Xml.XmlElement senderElement = document.CreateElement("Sender"); senderElement.SetAttribute("address", this.Sender.Address); senderElement.SetAttribute("displayName", this.Sender.DisplayName); templateElement.AppendChild(senderElement); } if (this.From != null) { System.Xml.XmlElement fromElement = document.CreateElement("From"); fromElement.SetAttribute("address", this.From.Address); fromElement.SetAttribute("displayName", this.From.DisplayName); templateElement.AppendChild(fromElement); } if (this.ReplyTo != null) { System.Xml.XmlElement replyToElement = document.CreateElement("ReplyTo"); replyToElement.SetAttribute("address", this.ReplyTo.Address); replyToElement.SetAttribute("displayName", this.ReplyTo.DisplayName); templateElement.AppendChild(replyToElement); } return(templateElement); }
/// <summary> /// Gets the values of from cmsDataTypePreValues table by id and puts them into a CDATA section /// </summary> /// <param name="xmlDocument"></param> /// <returns></returns> public override System.Xml.XmlNode ToXMl(System.Xml.XmlDocument xmlDocument) { var value = string.Empty; try { // Don't query if there's nothing to query for.. if (string.IsNullOrWhiteSpace(Value.ToString()) == false) { var dr = SqlHelper.ExecuteReader(string.Format("Select [value] from cmsDataTypeprevalues where id in ({0})", SqlHelper.EscapeString(Value.ToString()))); while (dr.Read()) { value += value.Length == 0 ? dr.GetString("value") : string.Format(",{0}", dr.GetString("value")); } dr.Close(); } } catch (Exception ex) { LogHelper.Error <DefaultDataKeyValue>("An exception occurred converting the property data to XML", ex); } return(xmlDocument.CreateCDataSection(value)); }
//public T GetConfigVal<T>() where T : class, new() //{ // try // { // var value = GetConfigValue(typeof(T)); // if ((value is T) != true) // { // value = new T(); // } // return value as T; // } // catch (Exception ex) // { // return new T(); // } //} /// <summary> /// ユーザ設定項目を変更する /// </summary> /// <param name="keyname">"COMMON"または画面ID</param> /// <param name="value"></param> public void SetConfigValue(object value) { try { string keyname = value.GetType().Name; var nodelist = config.GetElementsByTagName(keyname); if (nodelist.Count == 0) { var elmnt = config.CreateElement(keyname); config.DocumentElement.AppendChild(elmnt); nodelist = config.GetElementsByTagName(keyname); } byte[] barray; System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(value.GetType()); var strm = new System.IO.MemoryStream(); serializer.Serialize(strm, value); barray = strm.ToArray(); strm.Close(); var dat = config.CreateCDataSection(Convert.ToBase64String(barray, Base64FormattingOptions.InsertLineBreaks)); nodelist.Item(0).RemoveAll(); nodelist.Item(0).AppendChild(dat); } catch (Exception ex) { throw ex; } }
/// <summary> /// Ov /// </summary> /// <param name="d"></param> /// <returns></returns> public override System.Xml.XmlNode ToXMl(System.Xml.XmlDocument d) { // Get the value from string v = ""; try { IRecordsReader dr = SqlHelper.ExecuteReader("Select [value] from cmsDataTypeprevalues where id in (" + SqlHelper.EscapeString(Value.ToString()) + ")"); while (dr.Read()) { if (v.Length == 0) { v += dr.GetString("value"); } else { v += "," + dr.GetString("value"); } } dr.Close(); } catch {} return(d.CreateCDataSection(v)); }
public virtual System.Xml.XmlNode ToXMl(System.Xml.XmlDocument d) { if (this._dataType.DBType == DBTypes.Ntext) { return(d.CreateCDataSection(this.Value.ToString())); } return(d.CreateTextNode(Value.ToString())); }
public static string ReplyNews(ReplyNewsModel entity) { if (null != entity && !string.IsNullOrWhiteSpace(entity.ToUserName) && null != entity.Articles && entity.Articles.list.Count > 0) { if (entity.Articles.list.Count <= 10) { string xmlString = string.Empty; //var s1 = XmlHelper.Serialize(entity); #region xmlString System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument(); System.Xml.XmlNode rootNode; System.Xml.XmlElement ele; System.Xml.XmlCDataSection cdata; #region xml rootNode = xmlDoc.CreateNode(System.Xml.XmlNodeType.Element, "xml", null); ele = xmlDoc.CreateElement(nameof(entity.ToUserName)); cdata = xmlDoc.CreateCDataSection(entity.ToUserName); ele.AppendChild(cdata); rootNode.AppendChild(ele); ele = xmlDoc.CreateElement(nameof(entity.FromUserName)); cdata = xmlDoc.CreateCDataSection(entity.FromUserName); ele.AppendChild(cdata); rootNode.AppendChild(ele); ele = xmlDoc.CreateElement(nameof(entity.CreateTime)); ele.InnerXml = entity.CreateTime.ToString(); rootNode.AppendChild(ele); ele = xmlDoc.CreateElement(nameof(entity.MsgType)); cdata = xmlDoc.CreateCDataSection(entity.MsgType); ele.AppendChild(cdata); rootNode.AppendChild(ele); #endregion ele = xmlDoc.CreateElement(nameof(entity.ArticleCount)); ele.InnerXml = entity.ArticleCount.ToString(); rootNode.AppendChild(ele); System.Xml.XmlNode nodeArticles, nodeItem; nodeArticles = xmlDoc.CreateNode(System.Xml.XmlNodeType.Element, nameof(entity.Articles), null); if (entity.ArticleCount > 0) { foreach (var i in entity.Articles.list) { nodeItem = xmlDoc.CreateNode(System.Xml.XmlNodeType.Element, "item", null); ele = xmlDoc.CreateElement(nameof(i.Title)); cdata = xmlDoc.CreateCDataSection(i.Title); ele.AppendChild(cdata); nodeItem.AppendChild(ele); ele = xmlDoc.CreateElement(nameof(i.Description)); cdata = xmlDoc.CreateCDataSection(i.Description); ele.AppendChild(cdata); nodeItem.AppendChild(ele); ele = xmlDoc.CreateElement(nameof(i.PicUrl)); cdata = xmlDoc.CreateCDataSection(i.PicUrl); ele.AppendChild(cdata); nodeItem.AppendChild(ele); ele = xmlDoc.CreateElement(nameof(i.Url)); cdata = xmlDoc.CreateCDataSection(i.Url); ele.AppendChild(cdata); nodeItem.AppendChild(ele); nodeArticles.AppendChild(nodeItem); } } rootNode.AppendChild(nodeArticles); xmlDoc.AppendChild(rootNode); xmlString = xmlDoc.OuterXml; #endregion if (!string.IsNullOrWhiteSpace(xmlString)) { return(xmlString); } } else { throw new Exception("如果图文数超过10,则将会无响应。详情情参考微信官方文档"); } } return(ReplyEmpty()); }