public static bool GetAttachmentValue(XmlNode node, out Attachment result)
 {
     if ((node != null) && (node.InnerText != string.Empty))
     {
         try
         {
             string bytes;
             string name;
             string mediaType;
             if ((XmlLoader.GetStringValue(node, "Bytes", out bytes) &&
                  XmlLoader.GetStringValue(node, "Name", out name)) &&
                 XmlLoader.GetStringValue(node, "MediaType", out mediaType))
             {
                 int          num;
                 MemoryStream contentStream = new MemoryStream(Serializer.ConvertToBytes(bytes));
                 result = new Attachment(contentStream, XmlLoader.XMLDecode(name), XmlLoader.XMLDecode(mediaType));
                 if (XmlLoader.GetIntValue(node, "NameEncoding", out num))
                 {
                     result.NameEncoding = Encoding.GetEncoding(num);
                 }
                 return(true);
             }
         }
         catch (Exception exception)
         {
             Console.WriteLine(exception.ToString());
         }
     }
     result = null;
     return(false);
 }
Exemplo n.º 2
0
        public void ReadXml(XmlReader reader)
        {
            string      address;
            XmlDocument doc = new XmlDocument();

            doc.Load(reader);
            XmlNode xml = doc.SelectSingleNode("MailAddress");

            if (XmlLoader.GetStringValue(xml, "//Address", out address))
            {
                string displayname;
                if (XmlLoader.GetStringValue(xml, "//Name", out displayname))
                {
                    this.mailAddress = new MailAddress(address, displayname);
                }
                else
                {
                    this.mailAddress = new MailAddress(address);
                }
            }
        }
        public void ReadXml(XmlReader reader)
        {
            string str;
            object obj;
            int    num;
            bool   flag;
            NameValueCollection          values;
            IList <Attachment>           attachment;
            ICollection <MailAddressXml> address;
            XmlDocument doc = new XmlDocument();

            doc.Load(reader);
            XmlNode xml = doc.SelectSingleNode("MailMessage");

            if (XmlLoader.GetStringValue(xml, "Body", out str))
            {
                base.Body = str;
            }
            if (XmlLoader.GetStringValue(xml, "Subject", out str))
            {
                base.Subject = str;
            }
            if (XmlLoader.GetCollectionValue <MailAddressXml>(xml, "Bcc/*", new MailAddressXml(), out address))
            {
                MailAddressXml.CopyCollection(address, base.Bcc);
            }
            if (XmlLoader.GetCollectionValue <MailAddressXml>(xml, "Cc/MailAddress", new MailAddressXml(), out address))
            {
                MailAddressXml.CopyCollection(address, base.CC);
            }
            if (XmlLoader.GetCollectionValue <MailAddressXml>(xml, "To/MailAddress", new MailAddressXml(), out address))
            {
                MailAddressXml.CopyCollection(address, base.To);
            }
            if (XmlLoader.GetSerializedObject(xml, "From/MailAddress", new MailAddressXml(), out obj))
            {
                base.From = ((MailAddressXml)obj).MailAddress;
            }
            if (XmlLoader.GetSerializedObject(xml, "ReplyTo/MailAddress", new MailAddressXml(), out obj))
            {
                base.ReplyTo = ((MailAddressXml)obj).MailAddress;
            }
            if (XmlLoader.GetSerializedObject(xml, "Sender/MailAddress", new MailAddressXml(), out obj))
            {
                base.Sender = ((MailAddressXml)obj).MailAddress;
            }
            if (XmlLoader.GetEnumValue(xml, "Priority", typeof(MailPriority), out obj))
            {
                base.Priority = (MailPriority)obj;
            }
            if (XmlLoader.GetBoolValue(xml, "IsBodyHtml", out flag))
            {
                base.IsBodyHtml = flag;
            }
            if (XmlLoader.GetCollectionValue(xml, "Headers", out values))
            {
                TypeHelper.CopyCollection(values, base.Headers);
            }
            if (XmlLoader.GetEnumValue(xml, "DeliveryNotificationOptions", typeof(DeliveryNotificationOptions), out obj))
            {
                base.DeliveryNotificationOptions = (DeliveryNotificationOptions)obj;
            }
            if (XmlLoader.GetIntValue(xml, "BodyEncoding", out num))
            {
                base.BodyEncoding = Encoding.GetEncoding(num);
            }
            if (XmlLoader.GetIntValue(xml, "SubjectEncoding", out num))
            {
                base.SubjectEncoding = Encoding.GetEncoding(num);
            }
            if (GetCollectionValue(xml, "Attachments/Attachment", out attachment))
            {
                TypeHelper.CopyCollection <Attachment>(attachment, base.Attachments);
            }
        }