public ICoreItem OpenAttachedItem(ICollection <PropertyDefinition> propertiesToLoad, AttachmentPropertyBag attachmentBag, bool isNew) { this.CheckDisposed(null); CoreItem coreItem = null; int attachmentNumber = attachmentBag.AttachmentNumber; if (this.attachedItems.TryGetValue(attachmentNumber, out coreItem)) { string text = coreItem.PropertyBag.TryGetProperty(InternalSchema.ItemClass) as string; Schema schema = (text != null) ? ObjectClass.GetSchema(text) : MessageItemSchema.Instance; propertiesToLoad = InternalSchema.Combine <PropertyDefinition>(schema.AutoloadProperties, propertiesToLoad); coreItem.PropertyBag.Load(propertiesToLoad); } else { if (!isNew) { throw new ObjectNotFoundException(ServerStrings.MapiCannotOpenEmbeddedMessage); } string text2 = attachmentBag.TryGetProperty(InternalSchema.ItemClass) as string; Schema schema2 = (text2 != null) ? ObjectClass.GetSchema(text2) : MessageItemSchema.Instance; propertiesToLoad = InternalSchema.Combine <PropertyDefinition>(schema2.AutoloadProperties, propertiesToLoad); coreItem = new CoreItem(null, new InMemoryPersistablePropertyBag(propertiesToLoad) { ExTimeZone = this.ExTimeZone }, StoreObjectId.DummyId, null, Origin.New, ItemLevel.Attached, propertiesToLoad, ItemBindOption.LoadRequiredPropertiesOnly); if (text2 != null) { coreItem.PropertyBag[InternalSchema.ItemClass] = text2; } this.attachedItems.Add(attachmentNumber, coreItem); } return(new CoreItemWrapper(coreItem)); }
public PersistablePropertyBag CreateAttachment(ICollection <PropertyDefinition> propertiesToLoad, CoreAttachment attachmentToClone, IItem itemToAttach, out int attachmentNumber) { this.CheckDisposed(null); InMemoryPersistablePropertyBag inMemoryPersistablePropertyBag = new InMemoryPersistablePropertyBag(propertiesToLoad); inMemoryPersistablePropertyBag.ExTimeZone = this.ExTimeZone; if (attachmentToClone != null) { throw new NotSupportedException("CreateAttachment for copied attachments is not supported"); } attachmentNumber = this.attachmentCounter++; inMemoryPersistablePropertyBag[InternalSchema.AttachNum] = attachmentNumber; this.newAttachmentList.Add(attachmentNumber, inMemoryPersistablePropertyBag); if (itemToAttach != null) { string text = itemToAttach.TryGetProperty(InternalSchema.ItemClass) as string; Schema schema = (text != null) ? ObjectClass.GetSchema(text) : ItemSchema.Instance; propertiesToLoad = InternalSchema.Combine <PropertyDefinition>(schema.AutoloadProperties, propertiesToLoad); using (DisposeGuard disposeGuard = default(DisposeGuard)) { PersistablePropertyBag persistablePropertyBag = new InMemoryPersistablePropertyBag(propertiesToLoad); disposeGuard.Add <PersistablePropertyBag>(persistablePropertyBag); persistablePropertyBag.ExTimeZone = this.ExTimeZone; CoreItem coreItem = new CoreItem(null, persistablePropertyBag, null, null, Origin.New, ItemLevel.Attached, propertiesToLoad, ItemBindOption.LoadRequiredPropertiesOnly); disposeGuard.Add <CoreItem>(coreItem); CoreItem.CopyItemContent(itemToAttach.CoreItem, coreItem); this.attachedItems.Add(attachmentNumber, coreItem); disposeGuard.Success(); } } return(inMemoryPersistablePropertyBag); }
public static Schema GetSchema(string className) { if (ObjectClass.IsOfClass(className, "IPM.OLE.CLASS.{00061055-0000-0000-C000-000000000046}") || ObjectClass.IsOfClass(className, "IPM.Appointment.Occurrence")) { return(CalendarItemOccurrenceSchema.Instance); } StoreObjectType objectType = ObjectClass.GetObjectType(className); return(ObjectClass.GetSchema(objectType)); }
public static bool IsItemLegallyDirty(StoreSession session, CoreItem item, bool verifyLegallyDirty, out List <string> dirtyProperties) { dirtyProperties = null; if (COWSettings.IsCalendarRepairAssistantAction(session)) { ExTraceGlobals.SessionTracer.TraceWarning <CoreItem>((long)session.GetHashCode(), "Update Item {0} skipped because the action was generated by Calendar Repair Assistant.", item); return(false); } if (item.PropertyBag.GetValueOrDefault <bool>(InternalSchema.IsDraft)) { ExTraceGlobals.SessionTracer.TraceWarning <CoreItem>((long)session.GetHashCode(), "Update Item {0} skipped because it is a draft.", item); return(false); } if (item.Id == null) { ExTraceGlobals.SessionTracer.TraceWarning <CoreItem>((long)session.GetHashCode(), "Update Item {0} skipped because it does not have an id.", item); return(false); } if (item.PropertyBag.GetValueOrDefault <bool>(InternalSchema.IsAssociated)) { ExTraceGlobals.SessionTracer.TraceWarning <CoreItem>((long)session.GetHashCode(), "Update Item {0} skipped because it is an associated item.", item); return(false); } if (item.Id == null) { ExTraceGlobals.SessionTracer.TraceWarning <CoreItem>((long)session.GetHashCode(), "Update Item {0} skipped because the id was null.", item); return(false); } string valueOrDefault = item.PropertyBag.GetValueOrDefault <string>(InternalSchema.ItemClass, string.Empty); if (ObjectClass.IsOfClass(valueOrDefault, "IPM.Post.RSS")) { ExTraceGlobals.SessionTracer.TraceWarning <CoreItem>((long)session.GetHashCode(), "Update Item {0} skipped because it is a RSS item.", item); return(false); } Schema schema = ObjectClass.GetSchema(valueOrDefault); if (!(schema is ItemSchema)) { schema = ItemSchema.Instance; } bool isLegallyDirty = item.IsLegallyDirty; CoreRecipientCollection recipients = ((ICoreItem)item).Recipients; CoreAttachmentCollection attachmentCollection = ((ICoreItem)item).AttachmentCollection; bool flag = (recipients != null && recipients.IsDirty) || item.IsLegallyDirtyProperty("RecipientCollection"); bool flag2 = (attachmentCollection != null && attachmentCollection.IsDirty) || item.IsLegallyDirtyProperty("AttachmentCollection"); if (!isLegallyDirty && !item.PropertyBag.IsDirty && !flag && !flag2) { ExTraceGlobals.SessionTracer.TraceWarning <CoreItem>((long)session.GetHashCode(), "Update Item {0} skipped because the property bag is not dirty.", item); return(false); } StorePropertyDefinition[] array = (from x in schema.LegalTrackingProperties where item.PropertyBag.IsPropertyDirty(x) || item.IsLegallyDirtyProperty(x.Name) select x).ToArray <StorePropertyDefinition>(); if (array.Length == 0 && !flag && !flag2) { ExTraceGlobals.SessionTracer.TraceWarning <CoreItem>((long)session.GetHashCode(), "Update Item {0} skipped because the property bag is not legally dirty.", item); return(false); } dirtyProperties = new List <string>(); if (!verifyLegallyDirty) { dirtyProperties = (from x in array select x.Name).ToList <string>(); if (flag) { dirtyProperties.Add("RecipientCollection"); } if (flag2) { dirtyProperties.Add("AttachmentCollection"); } } else { using (CoreItem coreItem = CoreItem.Bind(session, item.Id, array)) { CoreRecipientCollection recipients2 = coreItem.Recipients; if (flag) { flag = false; int num = (recipients == null) ? 0 : recipients.Count; int num2 = (recipients2 == null) ? 0 : recipients2.Count; if (num == num2) { if (recipients == null || recipients2 == null) { goto IL_36E; } using (IEnumerator <CoreRecipient> enumerator = recipients.GetEnumerator()) { while (enumerator.MoveNext()) { CoreRecipient value = enumerator.Current; if (!recipients2.Contains(value, COWDumpster.CoreRecipientParticipantEqualityComparer.Default)) { flag = true; break; } } goto IL_36E; } } flag = true; } else { int num3 = (recipients == null) ? 0 : recipients.Count; int num4 = (recipients2 == null) ? 0 : recipients2.Count; flag = (num3 != num4); } IL_36E: if (flag) { ExTraceGlobals.SessionTracer.TraceWarning <CoreItem>((long)session.GetHashCode(), "Update Item {0} is dirty because the recipient collection is dirty.", item); dirtyProperties.Add("RecipientCollection"); } if (!flag2) { CoreAttachmentCollection attachmentCollection2 = coreItem.AttachmentCollection; int num5 = (attachmentCollection == null) ? 0 : attachmentCollection.Count; int num6 = (attachmentCollection2 == null) ? 0 : attachmentCollection2.Count; flag2 = (num5 != num6); } if (flag2) { ExTraceGlobals.SessionTracer.TraceWarning <CoreItem>((long)session.GetHashCode(), "Update Item {0} is dirty because the attachment collection is dirty.", item); dirtyProperties.Add("AttachmentCollection"); } foreach (StorePropertyDefinition propertyDefinition in array) { object x2 = item.PropertyBag.TryGetProperty(propertyDefinition); object y = coreItem.PropertyBag.TryGetProperty(propertyDefinition); if (!COWDumpster.PropertyValuesAreEqual(propertyDefinition, x2, y)) { ExTraceGlobals.SessionTracer.TraceWarning <CoreItem, string, PropertyDefinition>((long)session.GetHashCode(), "Update Item {0}, class {1} is dirty because the {2} property is dirty.", item, valueOrDefault, propertyDefinition); dirtyProperties.Add(propertyDefinition.Name); } } } } if (dirtyProperties.Count > 0) { ExTraceGlobals.SessionTracer.TraceWarning((long)session.GetHashCode(), "Update Item {0}, class {1} is {2} dirty with {3} properties changed", new object[] { item, valueOrDefault, verifyLegallyDirty ? "verified" : "not verified", dirtyProperties.Count }); return(true); } ExTraceGlobals.SessionTracer.TraceWarning <CoreItem, string, int>((long)session.GetHashCode(), "Update Item {0}, class {1} skipped because no legal tracking property was found dirty out of {2} modified legal tracking properties.", item, valueOrDefault, array.Length); dirtyProperties = null; return(false); }
public ICoreItem OpenAttachedItem(ICollection <PropertyDefinition> propertiesToLoad, AttachmentPropertyBag attachmentBag, bool isNew) { MapiMessage mapiMessage = null; PersistablePropertyBag persistablePropertyBag = null; CoreItem coreItem = null; bool flag = false; StoreObjectId storeObjectId = null; byte[] array = null; ICoreItem result; try { StoreObjectPropertyBag storeObjectPropertyBag = (StoreObjectPropertyBag)attachmentBag.PersistablePropertyBag; MapiAttach mapiAttach = (MapiAttach)storeObjectPropertyBag.MapiProp; StoreSession session = this.AttachmentCollection.ContainerItem.Session; OpenPropertyFlags openPropertyFlags = isNew ? OpenPropertyFlags.Create : (this.AttachmentCollection.IsReadOnly ? OpenPropertyFlags.BestAccess : OpenPropertyFlags.BestAccess); openPropertyFlags |= OpenPropertyFlags.DeferredErrors; string text = storeObjectPropertyBag.TryGetProperty(InternalSchema.ItemClass) as string; Schema schema = (text != null) ? ObjectClass.GetSchema(text) : MessageItemSchema.Instance; propertiesToLoad = InternalSchema.Combine <PropertyDefinition>(schema.AutoloadProperties, propertiesToLoad); StoreSession session2 = this.AttachmentCollection.ContainerItem.Session; bool flag2 = false; try { if (session2 != null) { session2.BeginMapiCall(); session2.BeginServerHealthCall(); flag2 = true; } if (StorageGlobals.MapiTestHookBeforeCall != null) { StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod()); } mapiMessage = mapiAttach.OpenEmbeddedMessage(openPropertyFlags); } catch (MapiPermanentException ex) { throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotOpenEmbeddedMessage, ex, session2, this, "{0}. MapiException = {1}.", new object[] { string.Format("MapiAttachmentProvider::OpenAttachedItem", new object[0]), ex }); } catch (MapiRetryableException ex2) { throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotOpenEmbeddedMessage, ex2, session2, this, "{0}. MapiException = {1}.", new object[] { string.Format("MapiAttachmentProvider::OpenAttachedItem", new object[0]), ex2 }); } finally { try { if (session2 != null) { session2.EndMapiCall(); if (flag2) { session2.EndServerHealthCall(); } } } finally { if (StorageGlobals.MapiTestHookAfterCall != null) { StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod()); } } } persistablePropertyBag = new StoreObjectPropertyBag(session, mapiMessage, propertiesToLoad); if (!isNew) { StoreObjectType storeObjectType = ItemBuilder.ReadStoreObjectTypeFromPropertyBag(persistablePropertyBag); ItemCreateInfo itemCreateInfo = ItemCreateInfo.GetItemCreateInfo(storeObjectType); propertiesToLoad = InternalSchema.Combine <PropertyDefinition>(itemCreateInfo.Schema.AutoloadProperties, propertiesToLoad); if (this.AttachmentCollection.IsReadOnly) { StoreId.SplitStoreObjectIdAndChangeKey(StoreObjectId.DummyId, out storeObjectId, out array); } persistablePropertyBag = new AcrPropertyBag(persistablePropertyBag, itemCreateInfo.AcrProfile, storeObjectId, new RetryBagFactory(session), array); } coreItem = new CoreItem(session, persistablePropertyBag, storeObjectId, array, isNew ? Origin.New : Origin.Existing, ItemLevel.Attached, propertiesToLoad, ItemBindOption.None); if (text != null && isNew) { coreItem.PropertyBag[InternalSchema.ItemClass] = text; } flag = true; result = coreItem; } finally { if (!flag) { if (coreItem != null) { coreItem.Dispose(); coreItem = null; } if (persistablePropertyBag != null) { persistablePropertyBag.Dispose(); persistablePropertyBag = null; } if (mapiMessage != null) { mapiMessage.Dispose(); mapiMessage = null; } } } return(result); }
public static Schema GetSchema(StoreObject storeObject) { return(ObjectClass.GetSchema(storeObject.ClassName)); }