Beispiel #1
0
        // Token: 0x06000767 RID: 1895 RVA: 0x00029340 File Offset: 0x00027540
        protected override int InternalExecute(int count)
        {
            string[] array = HttpUtility.UrlDecode(base.FileReference).Split(new char[]
            {
                ':'
            });
            if (array.Length != 2)
            {
                throw new AirSyncPermanentException(StatusCode.Sync_TooManyFolders, false)
                      {
                          ErrorStringForProtocolLogger = "InvalidEntityAttachemtnId"
                      };
            }
            StoreObjectId itemId = StoreId.EwsIdToStoreObjectId(array[0]);
            IEvents       events = EntitySyncItem.GetEvents(this.CalendaringContainer, base.Session, itemId);

            if (events == null)
            {
                throw new AirSyncPermanentException(StatusCode.Sync_ClientServerConversion, false)
                      {
                          ErrorStringForProtocolLogger = "EventsNotFound"
                      };
            }
            IAttachments attachments = events[array[0]].Attachments;

            if (attachments == null)
            {
                throw new AirSyncPermanentException(StatusCode.Sync_ClientServerConversion, false)
                      {
                          ErrorStringForProtocolLogger = "EntityNotFound"
                      };
            }
            IAttachment attachment = attachments.Read(array[1], null);

            if (attachment == null)
            {
                throw new AirSyncPermanentException(StatusCode.Sync_ClientServerConversion, false)
                      {
                          ErrorStringForProtocolLogger = "EntityAttachementNotFound"
                      };
            }
            base.ContentType = attachment.ContentType;
            FileAttachment fileAttachment = attachment as FileAttachment;
            ItemAttachment itemAttachment = attachment as ItemAttachment;

            if (fileAttachment != null)
            {
                if (!base.MaxAttachmentSize.IsUnlimited && fileAttachment.Content.Length > (int)base.MaxAttachmentSize.Value.ToBytes())
                {
                    throw new DataTooLargeException(StatusCode.AttachmentIsTooLarge);
                }
                count = ((count == -1) ? fileAttachment.Content.Length : Math.Min(count, fileAttachment.Content.Length - base.MinRange));
                base.OutStream.Write(fileAttachment.Content, base.MinRange, count);
                return(count);
            }
            else
            {
                if (itemAttachment != null)
                {
                    int result;
                    AttachmentHelper.GetAttachment(base.Session, itemId, attachment.Id, base.OutStream, base.MinRange, count, base.MaxAttachmentSize, base.RightsManagementSupport, out result);
                    return(result);
                }
                throw new AirSyncPermanentException(StatusCode.Sync_InvalidWaitTime, new LocalizedString(string.Format("Attachment type \"{0}\" is not supported.", attachment.GetType().FullName)), false)
                      {
                          ErrorStringForProtocolLogger = "UnsupportedEntityAttachementType"
                      };
            }
        }