public override bool GetNewOperations(ISyncWatermark minSyncWatermark, ISyncWatermark maxSyncWatermark, bool enumerateDeletes, int numOperations, QueryFilter filter, Dictionary <ISyncItemId, ServerManifestEntry> newServerManifest) { base.CheckDisposed("GetNewOperations"); AirSyncDiagnostics.TraceInfo <int>(ExTraceGlobals.RequestsTracer, this, "EntitySyncProvider.GetNewOperations. numOperations = {0}", numOperations); if (newServerManifest == null) { throw new ArgumentNullException("newServerManifest"); } if (!enumerateDeletes) { throw new NotImplementedException("enumerateDeletes is false!"); } if (filter != null) { throw new NotImplementedException("filter is non-null! Filters are not supported on EntitySyncProvider"); } SyncCalendar syncCalendar = new SyncCalendar(this.CalendarSyncState, base.Folder.Session, base.Folder.Id.ObjectId, (CalendarFolder folder) => EntitySyncProvider.PropertiesToSync, this.WindowStart, this.WindowEnd, false, numOperations); IFolderSyncState folderSyncState; IList <KeyValuePair <StoreId, LocalizedException> > list; SyncCalendarResponse syncCalendarResponse = syncCalendar.Execute(out folderSyncState, out list); AirSyncDiagnostics.TraceInfo <IFolderSyncState>(ExTraceGlobals.RequestsTracer, this, "newSyncState:{0}", folderSyncState); SyncCalendarFolderSyncState syncCalendarFolderSyncState = (SyncCalendarFolderSyncState)folderSyncState; this.CalendarSyncState = new AirSyncCalendarSyncState(syncCalendarFolderSyncState.SerializeAsBase64String(), syncCalendarResponse.QueryResumptionPoint, syncCalendarResponse.OldWindowEnd); if (list.Count > 0 && Command.CurrentCommand.MailboxLogger != null) { StringBuilder stringBuilder = new StringBuilder(); foreach (KeyValuePair <StoreId, LocalizedException> keyValuePair in list) { stringBuilder.AppendFormat("Exception caught for item {0}\r\n{1}\r\n\r\n", keyValuePair.Key, keyValuePair.Value); } Command.CurrentCommand.MailboxLogger.SetData(MailboxLogDataName.CalendarSync_Exception, stringBuilder.ToString()); } AirSyncDiagnostics.TraceInfo <int>(ExTraceGlobals.RequestsTracer, this, "DeletedItems:{0}", syncCalendarResponse.DeletedItems.Count); foreach (StoreId storeId in syncCalendarResponse.DeletedItems) { ISyncItemId syncItemId = EntitySyncItemId.CreateFromId(storeId); newServerManifest.Add(syncItemId, new ServerManifestEntry(ChangeType.Delete, syncItemId, null)); } this.CopyListToDictionary(syncCalendarResponse.UpdatedItems, "UpdatedItems", newServerManifest); this.CopyListToDictionary(syncCalendarResponse.RecurrenceMastersWithInstances, "RecurrenceMastersWithInstances", newServerManifest); this.CopyListToDictionary(syncCalendarResponse.RecurrenceMastersWithoutInstances, "RecurrenceMastersWithoutInstances", newServerManifest); this.CopyListToDictionary(syncCalendarResponse.UnchangedRecurrenceMastersWithInstances, "UnchangedRecurrenceMastersWithInstances", newServerManifest); AirSyncDiagnostics.TraceInfo <bool>(ExTraceGlobals.RequestsTracer, this, "MoreAvailable:{0}", !syncCalendarResponse.IncludesLastItemInRange); return(!syncCalendarResponse.IncludesLastItemInRange); }
private void CopyListToDictionary(IList <SyncCalendarItemType> items, string listName, Dictionary <ISyncItemId, ServerManifestEntry> newServerManifest) { AirSyncDiagnostics.TraceInfo <string, int>(ExTraceGlobals.RequestsTracer, this, "{0}:{1}", listName, items.Count); foreach (SyncCalendarItemType syncCalendarItemType in items) { EntitySyncWatermark watermark = null; object obj; if (syncCalendarItemType.RowData != null && syncCalendarItemType.RowData.TryGetValue(ItemSchema.ArticleId, out obj) && !(obj is PropertyError)) { watermark = EntitySyncWatermark.CreateWithChangeNumber((int)obj); } ISyncItemId syncItemId = EntitySyncItemId.CreateFromId(syncCalendarItemType.ItemId); ServerManifestEntry serverManifestEntry = new ServerManifestEntry(ChangeType.Add, syncItemId, watermark); serverManifestEntry.MessageClass = "IPM.APPOINTMENT"; serverManifestEntry.CalendarItemType = syncCalendarItemType.CalendarItemType; OccurrenceStoreObjectId occurrenceStoreObjectId = StoreId.GetStoreObjectId(syncCalendarItemType.ItemId) as OccurrenceStoreObjectId; if (occurrenceStoreObjectId != null) { serverManifestEntry.SeriesMasterId = occurrenceStoreObjectId.GetMasterStoreObjectId(); } newServerManifest.Add(syncItemId, serverManifestEntry); } }
protected override bool GetNewOperations(int windowSize, Dictionary <ISyncItemId, ServerManifestEntry> tempServerManifest) { bool newOperations = base.GetNewOperations(windowSize, tempServerManifest); Dictionary <ISyncItemId, EntityFolderSync.OcurrenceInformation> masterItems = this.MasterItems; Dictionary <ISyncItemId, ServerManifestEntry> dictionary = new Dictionary <ISyncItemId, ServerManifestEntry>(); foreach (ServerManifestEntry serverManifestEntry in tempServerManifest.Values) { if (serverManifestEntry.ChangeType == ChangeType.Delete) { if (masterItems.ContainsKey(serverManifestEntry.Id)) { EntityFolderSync.OcurrenceInformation ocurrenceInformation = masterItems[serverManifestEntry.Id]; foreach (ISyncItemId syncItemId in ocurrenceInformation.Ocurrences) { dictionary.Add(syncItemId, new ServerManifestEntry(ChangeType.Delete, syncItemId, null)); } masterItems.Remove(serverManifestEntry.Id); } } else if (serverManifestEntry.ChangeType == ChangeType.Add) { if (serverManifestEntry.CalendarItemType == CalendarItemType.RecurringMaster) { if (masterItems.ContainsKey(serverManifestEntry.Id)) { EntityFolderSync.OcurrenceInformation ocurrenceInformation = masterItems[serverManifestEntry.Id]; for (int i = ocurrenceInformation.Ocurrences.Count - 1; i >= 0; i--) { if (!tempServerManifest.ContainsKey(ocurrenceInformation.Ocurrences[i])) { dictionary.Add(ocurrenceInformation.Ocurrences[i], new ServerManifestEntry(ChangeType.Delete, ocurrenceInformation.Ocurrences[i], null)); ocurrenceInformation.Ocurrences.RemoveAt(i); } } } } else if (serverManifestEntry.CalendarItemType == CalendarItemType.Occurrence || serverManifestEntry.CalendarItemType == CalendarItemType.Exception) { EntitySyncItemId key = EntitySyncItemId.CreateFromId(serverManifestEntry.SeriesMasterId); EntityFolderSync.OcurrenceInformation ocurrenceInformation; if (masterItems.ContainsKey(key)) { ocurrenceInformation = masterItems[key]; } else { ocurrenceInformation = new EntityFolderSync.OcurrenceInformation(); masterItems[key] = ocurrenceInformation; } if (!ocurrenceInformation.Ocurrences.Contains(serverManifestEntry.Id)) { ocurrenceInformation.Ocurrences.Add(serverManifestEntry.Id); } } } } foreach (ServerManifestEntry serverManifestEntry2 in dictionary.Values) { if (!tempServerManifest.ContainsKey(serverManifestEntry2.Id)) { tempServerManifest.Add(serverManifestEntry2.Id, serverManifestEntry2); } } this.MasterItems = masterItems; return(newOperations); }
internal static string GetAttachment(MailboxSession mailboxSession, StoreObjectId itemId, string attachmentId, Stream outStream, int offset, int count, Unlimited <ByteQuantifiedSize> maxAttachmentSize, bool rightsManagementSupport, out int total) { string result; using (Item item = Item.Bind(mailboxSession, itemId)) { if ("DRMLicense".Equals(attachmentId, StringComparison.OrdinalIgnoreCase)) { total = AttachmentHelper.WriteDrmLicenseToStream(item, outStream, offset, count, maxAttachmentSize); result = "application/x-microsoft-rpmsg-message-license"; } else { if (rightsManagementSupport) { Command.CurrentCommand.DecodeIrmMessage(item, true); } Attachment attachment = null; try { AttachmentCollection attachmentCollection; if (BodyConversionUtilities.IsMessageRestrictedAndDecoded(item)) { attachmentCollection = ((RightsManagedMessageItem)item).ProtectedAttachmentCollection; } else { attachmentCollection = item.AttachmentCollection; } if (attachmentId.Length > 8) { AttachmentId attachmentId2 = EntitySyncItemId.GetAttachmentId(attachmentId); if (attachmentId2 != null) { attachment = attachmentCollection.Open(attachmentId2); } } if (attachment == null) { int num; if (!int.TryParse(attachmentId, NumberStyles.None, CultureInfo.InvariantCulture, out num) || num < 0) { throw new FormatException("Invalid Attachment Index format: " + attachmentId.ToString(CultureInfo.InvariantCulture)); } IList <AttachmentHandle> handles = attachmentCollection.GetHandles(); if (num < handles.Count) { attachment = attachmentCollection.Open(handles[num]); } } if (attachment == null) { throw new ObjectNotFoundException(ServerStrings.MapiCannotOpenAttachmentId(attachmentId)); } if (BodyConversionUtilities.IsMessageRestrictedAndDecoded(item) && AttachmentHelper.IsProtectedVoiceAttachment(attachment.FileName)) { RightsManagedMessageItem rightsManagedMessageItem = item as RightsManagedMessageItem; rightsManagedMessageItem.UnprotectAttachment(attachment.Id); AttachmentId id = attachment.Id; attachment.Dispose(); attachment = rightsManagedMessageItem.ProtectedAttachmentCollection.Open(id); } if (!maxAttachmentSize.IsUnlimited && attachment.Size > (long)maxAttachmentSize.Value.ToBytes()) { throw new DataTooLargeException(StatusCode.AttachmentIsTooLarge); } result = AttachmentHelper.GetAttachmentItself(attachment, outStream, offset, count, out total); } finally { if (attachment != null) { attachment.Dispose(); } if (rightsManagementSupport) { Command.CurrentCommand.SaveLicense(item); } } } } return(result); }