Ejemplo n.º 1
0
 private static void CopyCommonAttachmentProperties(IAttachment attachment, Attachment16Data attachmentData)
 {
     if (!string.IsNullOrEmpty(attachmentData.DisplayName))
     {
         attachment.FileName = attachmentData.DisplayName;
         if (!string.IsNullOrEmpty(attachmentData.ContentType))
         {
             attachment.ContentType = attachmentData.ContentType;
         }
         attachment.IsInline = attachmentData.IsInline;
         if (!string.IsNullOrEmpty(attachmentData.ContentId))
         {
             attachment[AttachmentSchema.AttachContentId] = attachmentData.ContentId;
         }
         if (!string.IsNullOrEmpty(attachmentData.ContentLocation))
         {
             attachment[AttachmentSchema.AttachContentLocation] = attachmentData.ContentLocation;
         }
         AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, null, "Attachment Properties copied:FileName: {0}, ContentType:{1}, IsInline:{2}, ContentId:{3}, ContentLocation:{4}", new object[]
         {
             attachmentData.DisplayName,
             attachmentData.ContentType,
             attachmentData.IsInline,
             attachmentData.ContentId,
             attachmentData.ContentLocation
         });
         return;
     }
     throw new ConversionException(" Attachment DisplayName can not be null.");
 }
Ejemplo n.º 2
0
        public override void CopyFrom(IProperty srcProperty)
        {
            IAttachments12Property attachments12Property = srcProperty as IAttachments12Property;

            if (attachments12Property == null)
            {
                throw new UnexpectedTypeException("IAttachments12Property", srcProperty);
            }
            List <IAttachment> list = new List <IAttachment>(attachments12Property.Count);

            foreach (Attachment12Data attachment12Data in attachments12Property)
            {
                Attachment16Data attachment16Data = attachment12Data as Attachment16Data;
                if (attachment16Data == null)
                {
                    throw new UnexpectedTypeException("Attachment16Data", attachment12Data);
                }
                IAttachment attachment = null;
                if (attachment16Data.ChangeType == AttachmentAction.Add)
                {
                    byte method = attachment16Data.Method;
                    if (method != 1)
                    {
                        if (method != 5)
                        {
                        }
                        throw new ConversionException(string.Format("The attachment method \"{0}\" is not suported.", attachment16Data.Method));
                    }
                    attachment = new FileAttachment
                    {
                        ContentId       = attachment16Data.ContentId,
                        ContentLocation = attachment16Data.ContentLocation,
                        Content         = attachment16Data.Content
                    };
                    attachment.Name        = attachment16Data.DisplayName;
                    attachment.IsInline    = attachment16Data.IsInline;
                    attachment.ContentType = attachment16Data.ContentType;
                    attachment.Id          = attachment16Data.ClientId;
                }
                else if (attachment16Data.ChangeType == AttachmentAction.Delete)
                {
                    if (!attachment16Data.FileReference.StartsWith(base.Item.Id + ":"))
                    {
                        throw new ConversionException(string.Format("The attachment \"{0}\" does not belog to the item \"{1}\".", attachment16Data.FileReference, base.Item.Id));
                    }
                    attachment    = new EntityDeleteAttachment();
                    attachment.Id = attachment16Data.FileReference.Substring(base.Item.Id.Length + 1);
                }
                list.Add(attachment);
            }
            base.Item.Attachments = list;
        }
Ejemplo n.º 3
0
 internal static void CreateAttachment(IItem parentItem, Attachment16Data attachmentData)
 {
     AirSyncDiagnostics.TraceDebug <byte>(ExTraceGlobals.RequestsTracer, null, "CreateAttachment with AttachMethod:{0}", attachmentData.Method);
     if (attachmentData.Method == 1)
     {
         if (attachmentData.Content == null)
         {
             throw new ConversionException(string.Format(" Attachment content can not be null.", new object[0]));
         }
         IStreamAttachment streamAttachment = parentItem.IAttachmentCollection.CreateIAttachment(AttachmentType.Stream) as IStreamAttachment;
         AttachmentHelper.CopyCommonAttachmentProperties(streamAttachment, attachmentData);
         using (Stream contentStream = streamAttachment.GetContentStream())
         {
             contentStream.Write(attachmentData.Content, 0, attachmentData.Content.Length);
         }
         streamAttachment.Save();
     }
     else
     {
         if (attachmentData.Method != 5)
         {
             throw new ConversionException(string.Format("UnSupported Value '{0}' for Attachment Method. Only 1 & 5 is supported AttachemntType", attachmentData.Method));
         }
         ItemAttachment itemAttachment = parentItem.IAttachmentCollection.CreateIAttachment(AttachmentType.EmbeddedMessage) as ItemAttachment;
         AttachmentHelper.CopyCommonAttachmentProperties(itemAttachment, attachmentData);
         using (Stream stream = new MemoryStream(attachmentData.Content))
         {
             stream.Seek(0L, SeekOrigin.Begin);
             InboundConversionOptions inboundConversionOptions = AirSyncUtility.GetInboundConversionOptions();
             inboundConversionOptions.ClearCategories = false;
             try
             {
                 using (Item item = itemAttachment.GetItem())
                 {
                     ItemConversion.ConvertAnyMimeToItem(item, stream, inboundConversionOptions);
                     item.Save(SaveMode.NoConflictResolution);
                 }
             }
             catch (ExchangeDataException innerException)
             {
                 throw new AirSyncPermanentException(HttpStatusCode.BadRequest, StatusCode.InvalidMIME, innerException, false);
             }
             catch (ConversionFailedException innerException2)
             {
                 throw new AirSyncPermanentException(HttpStatusCode.BadRequest, StatusCode.InvalidMIME, innerException2, false);
             }
         }
         itemAttachment.Save();
     }
     AirSyncDiagnostics.TraceDebug <int>(ExTraceGlobals.RequestsTracer, null, "AttachmentHelper:CreateAttachments:: AttachmentCreated successful. AttachmentCount:{0}", parentItem.IAttachmentCollection.Count);
 }
        protected override void InternalCopyFromModified(IProperty srcProperty)
        {
            Item item = base.XsoItem as Item;

            if (item == null)
            {
                AirSyncDiagnostics.TraceError(ExTraceGlobals.RequestsTracer, null, "XSO16AttachmentProperty:InternalCopyFromModified. msgItem can not be null.");
                throw new UnexpectedTypeException("Item", base.XsoItem);
            }
            IAttachments12Property attachments12Property = srcProperty as IAttachments12Property;

            if (attachments12Property == null)
            {
                throw new UnexpectedTypeException("IAttachments12Property", srcProperty);
            }
            new List <IAttachment>(attachments12Property.Count);
            List <string> list = new List <string>();

            foreach (Attachment12Data attachment12Data in attachments12Property)
            {
                Attachment16Data attachment16Data = attachment12Data as Attachment16Data;
                if (attachment16Data == null)
                {
                    throw new UnexpectedTypeException("Attachment16Data", attachment12Data);
                }
                if (attachment16Data.ChangeType == AttachmentAction.Delete)
                {
                    list.Add(attachment16Data.FileReference);
                }
            }
            if (list.Count > 0)
            {
                AttachmentHelper.DeleteAttachments(item, list);
            }
            foreach (Attachment12Data attachment12Data2 in attachments12Property)
            {
                Attachment16Data attachment16Data2 = attachment12Data2 as Attachment16Data;
                if (attachment16Data2 == null)
                {
                    throw new UnexpectedTypeException("Attachment16Data", attachment12Data2);
                }
                if (attachment16Data2.ChangeType == AttachmentAction.Add)
                {
                    AttachmentHelper.CreateAttachment(item, attachment16Data2);
                }
            }
        }
Ejemplo n.º 5
0
        // Token: 0x06000F4E RID: 3918 RVA: 0x0005793C File Offset: 0x00055B3C
        private Attachment16Data ParseAttachmentsData(XmlNode parentNode, AttachmentAction action)
        {
            Attachment16Data attachment16Data = new Attachment16Data(action);

            foreach (object obj in parentNode)
            {
                XmlNode xmlNode = (XmlNode)obj;
                string  name;
                switch (name = xmlNode.Name)
                {
                case "FileReference":
                    attachment16Data.FileReference = HttpUtility.UrlDecode(xmlNode.InnerText);
                    continue;

                case "ContentId":
                    attachment16Data.ContentId = xmlNode.InnerText;
                    continue;

                case "ContentLocation":
                    attachment16Data.ContentLocation = xmlNode.InnerText;
                    continue;

                case "Method":
                    attachment16Data.Method = Convert.ToByte(xmlNode.InnerText);
                    continue;

                case "DisplayName":
                    attachment16Data.DisplayName = xmlNode.InnerText;
                    continue;

                case "IsInline":
                    if (string.IsNullOrEmpty(xmlNode.InnerText))
                    {
                        attachment16Data.IsInline = true;
                        continue;
                    }
                    if (xmlNode.InnerText.Equals("1"))
                    {
                        attachment16Data.IsInline = true;
                        continue;
                    }
                    if (xmlNode.InnerText.Equals("0"))
                    {
                        attachment16Data.IsInline = false;
                        continue;
                    }
                    throw new ConversionException("Airsync16AttachmentProperty:ParseAttachmentsData. Invalid value passed in 'IsInline' Node.");

                case "Content":
                {
                    AirSyncBlobXmlNode airSyncBlobXmlNode = xmlNode as AirSyncBlobXmlNode;
                    if (airSyncBlobXmlNode == null)
                    {
                        continue;
                    }
                    if (airSyncBlobXmlNode.ByteArray != null)
                    {
                        attachment16Data.Content = airSyncBlobXmlNode.ByteArray;
                        continue;
                    }
                    if (airSyncBlobXmlNode.Stream != null && airSyncBlobXmlNode.Stream.CanSeek && airSyncBlobXmlNode.Stream.CanRead)
                    {
                        attachment16Data.Content = new byte[airSyncBlobXmlNode.Stream.Length];
                        airSyncBlobXmlNode.Stream.Seek(0L, SeekOrigin.Begin);
                        airSyncBlobXmlNode.Stream.Read(attachment16Data.Content, 0, (int)airSyncBlobXmlNode.Stream.Length);
                        continue;
                    }
                    throw new ConversionException("Airsync16AttachmentProperty:ParseAttachmentsData. Invalid value passed in 'Data' Node.");
                }

                case "ContentType":
                    attachment16Data.ContentType = xmlNode.InnerText;
                    continue;

                case "ClientId":
                    attachment16Data.ClientId = xmlNode.InnerText;
                    continue;
                }
                throw new ConversionException(string.Format("Airsync16AttachmentProperty:ParseAttachmentsData. invalid node {0}.", xmlNode.Name));
            }
            return(attachment16Data);
        }