コード例 #1
0
        private CoreAttachment InternalCreate(AttachmentType?type, string itemClass, CoreAttachment attachmentToClone, IItem itemToAttach)
        {
            this.InitCollection("InternalCreate", true);
            AttachmentPropertyBag attachmentPropertyBag = null;
            CoreAttachment        coreAttachment        = null;
            bool flag = false;

            try
            {
                bool flag2 = false;
                if (attachmentToClone != null)
                {
                    flag2 = this.attachmentProvider.SupportsCreateClone(attachmentToClone.PropertyBag);
                }
                attachmentPropertyBag = this.InternalCreateAttachmentPropertyBag(type, flag2 ? attachmentToClone : null, itemToAttach);
                if (itemClass != null)
                {
                    ((IDirectPropertyBag)attachmentPropertyBag).SetValue(InternalSchema.ItemClass, itemClass);
                }
                AttachmentHandle attachmentHandle = new AttachmentHandle(attachmentPropertyBag.AttachmentNumber);
                coreAttachment        = new CoreAttachment(this, attachmentPropertyBag, Origin.New);
                attachmentPropertyBag = null;
                if (attachmentToClone != null && !flag2)
                {
                    coreAttachment.CopyAttachmentContentFrom(attachmentToClone);
                }
                this.newAttachmentNumberMap.Add(attachmentHandle.AttachNumber, attachmentHandle);
                flag = true;
            }
            finally
            {
                if (!flag)
                {
                    if (coreAttachment != null)
                    {
                        coreAttachment.Dispose();
                        coreAttachment = null;
                    }
                    if (attachmentPropertyBag != null)
                    {
                        attachmentPropertyBag.Dispose();
                        attachmentPropertyBag = null;
                    }
                }
            }
            return(coreAttachment);
        }
コード例 #2
0
        internal Attachment Open(AttachmentHandle handle, AttachmentType?type, ICollection <PropertyDefinition> propertyDefinitions)
        {
            Util.ThrowOnNullArgument(handle, "handle");
            if (type != null)
            {
                EnumValidator.ThrowIfInvalid <AttachmentType>(type.Value, "type");
            }
            Attachment     attachment     = null;
            CoreAttachment coreAttachment = null;

            try
            {
                coreAttachment = this.CoreAttachmentCollection.Open(handle, propertyDefinitions);
                attachment     = AttachmentCollection.CreateTypedAttachment(coreAttachment, type);
            }
            finally
            {
                if (attachment == null && coreAttachment != null)
                {
                    coreAttachment.Dispose();
                }
            }
            return(attachment);
        }