Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public static AttachmentId GetAttachmentId(string attachmentId)
        {
            IList <AttachmentId> attachmentIds = IdConverter.GetAttachmentIds(attachmentId);

            if (attachmentIds.Count > 0)
            {
                return(attachmentIds[0]);
            }
            return(null);
        }
Esempio n. 3
0
		private void UpdateNestedAttachmentIds(List<IAttachment> attachments, string embededItemAttachmentId)
		{
			if (attachments.Count > 0)
			{
				IList<AttachmentId> attachmentIds = IdConverter.GetAttachmentIds(embededItemAttachmentId);
				int count = attachmentIds.Count;
				foreach (IAttachment attachment in attachments)
				{
					IList<AttachmentId> attachmentIds2 = IdConverter.GetAttachmentIds(attachment.Id);
					attachmentIds.Add(attachmentIds2[0]);
					attachment.Id = IdConverter.GetHierarchicalAttachmentStringId(attachmentIds);
					attachmentIds.RemoveAt(count);
				}
			}
		}
Esempio n. 4
0
        public void Delete(string attachmentId, CommandContext commandContext = null)
        {
            IList <AttachmentId> attachmentIds = IdConverter.GetAttachmentIds(attachmentId);

            if (attachmentIds.Count > 1)
            {
                throw new InvalidRequestException(Strings.ErrorNestedAttachmentsCannotBeRemoved);
            }
            using (IItem item = this.BindToParentItem())
            {
                item.OpenAsReadWrite();
                this.GetAttachmentCollection(item).Remove(attachmentIds[0]);
                this.SaveParentItem(item, commandContext);
            }
        }