public override IAttachment Read(string attachmentId) { IList <AttachmentId> attachmentIds = IdConverter.GetAttachmentIds(attachmentId); IAttachment result; using (IItem item = this.BindToParentItem()) { using (DisposeGuard disposeGuard = default(DisposeGuard)) { IItem item2 = item; Attachment attachment = null; for (int i = 0; i < attachmentIds.Count; i++) { attachment = IrmUtils.GetAttachmentCollection(item2).Open(attachmentIds[i]); disposeGuard.Add <Attachment>(attachment); if (i < attachmentIds.Count - 1) { if (!(attachment is ItemAttachment)) { throw new CorruptDataException(Strings.ErrorAllButLastNestedAttachmentMustBeItemAttachment); } ItemAttachment itemAttachment = attachment as ItemAttachment; item2 = itemAttachment.GetItem(); disposeGuard.Add <IItem>(item2); } } StorageTranslator <IAttachment, IAttachment> attachmentTranslator = this.GetAttachmentTranslator(attachment.AttachmentType, false); IAttachment attachment2 = attachmentTranslator.ConvertToEntity(attachment); attachment2.Id = attachmentId; result = attachment2; } } return(result); }
public IAttachment Create(IAttachment entity, CommandContext commandContext) { IAttachment result; using (IItem item = this.BindToParentItem()) { item.OpenAsReadWrite(); AttachmentType attachmentType; if (entity is ItemIdAttachment) { attachmentType = AttachmentType.EmbeddedMessage; } else if (entity is ReferenceAttachment) { attachmentType = AttachmentType.Reference; } else { attachmentType = AttachmentType.Stream; } using (IAttachment attachment = this.CreateAttachment(item, entity, attachmentType)) { attachment.Save(); attachment.Load(); this.SaveParentItem(item, commandContext); item.Load(); StorageTranslator <IAttachment, IAttachment> attachmentTranslator = this.GetAttachmentTranslator(attachment.AttachmentType, true); IAttachment attachment2 = attachmentTranslator.ConvertToEntity(attachment); result = attachment2; } } return(result); }
public IEnumerable <IAttachment> GetAllAttachments() { using (IItem parentItem = this.BindToParentItem()) { AttachmentCollection attachmentCollection = IrmUtils.GetAttachmentCollection(parentItem); foreach (AttachmentHandle attachmentHandle in attachmentCollection.GetHandles()) { using (Attachment attachment = attachmentCollection.Open(attachmentHandle)) { StorageTranslator <IAttachment, IAttachment> translator = this.GetAttachmentTranslator(attachment.AttachmentType, false); IAttachment resultAttachment = translator.ConvertToEntity(attachment); yield return(resultAttachment); } } } yield break; }