public override string ToString()
        {
            StoreObjectId storeObjectId = (this.StorageType == StorageType.Folder) ? this.FolderSyncStateId : this.ItemSyncStateId;
            string        arg           = (storeObjectId == null) ? "NULL" : storeObjectId.ToBase64String();

            return(string.Format("{0}[{1}]- {2}", this.Name, this.StorageType, arg));
        }
Esempio n. 2
0
        internal static DeferredAction Create(MailboxSession session, StoreObjectId ruleFolderId, string providerName)
        {
            Util.ThrowOnNullArgument(session, "session");
            Util.ThrowOnNullArgument(ruleFolderId, "ruleFolderId");
            Util.ThrowOnNullArgument(providerName, "providerName");
            if (!IdConverter.IsFolderId(ruleFolderId))
            {
                throw new ArgumentException(ServerStrings.InvalidFolderId(ruleFolderId.ToBase64String()));
            }
            DeferredAction deferredAction = new DeferredAction();

            deferredAction.actions = new List <RuleAction>();
            deferredAction.ruleIds = new List <long>();
            deferredAction.message = MessageItem.Create(session, session.GetDefaultFolderId(DefaultFolderType.DeferredActionFolder));
            deferredAction.message[InternalSchema.ItemClass]         = "IPC.Microsoft Exchange 4.0.Deferred Action";
            deferredAction.message[InternalSchema.RuleFolderEntryId] = ruleFolderId.ProviderLevelItemId;
            deferredAction.message[InternalSchema.RuleProvider]      = providerName;
            return(deferredAction);
        }
Esempio n. 3
0
        public static DeferredError Create(MailboxSession session, StoreObjectId folderId, string providerName, long ruleId, RuleAction.Type actionType, int actionNumber, DeferredError.RuleError ruleError)
        {
            Util.ThrowOnNullArgument(session, "session");
            Util.ThrowOnNullArgument(folderId, "folderId");
            Util.ThrowOnNullArgument(providerName, "providerName");
            EnumValidator.ThrowIfInvalid <RuleAction.Type>(actionType, "actionType");
            EnumValidator.ThrowIfInvalid <DeferredError.RuleError>(ruleError, "ruleError");
            if (!IdConverter.IsFolderId(folderId))
            {
                throw new ArgumentException(ServerStrings.InvalidFolderId(folderId.ToBase64String()));
            }
            DeferredError deferredError = new DeferredError();

            deferredError.message = MessageItem.Create(session, session.GetDefaultFolderId(DefaultFolderType.DeferredActionFolder));
            deferredError.message[InternalSchema.ItemClass]         = "IPC.Microsoft Exchange 4.0.Deferred Error";
            deferredError.message[InternalSchema.RuleFolderEntryId] = folderId.ProviderLevelItemId;
            deferredError.message[InternalSchema.RuleId]            = ruleId;
            deferredError.message[InternalSchema.RuleActionType]    = (int)actionType;
            deferredError.message[InternalSchema.RuleActionNumber]  = actionNumber;
            deferredError.message[InternalSchema.RuleError]         = ruleError;
            deferredError.message[InternalSchema.RuleProvider]      = providerName;
            return(deferredError);
        }
Esempio n. 4
0
        public AggregateOperationResult DeleteFolderSyncState(ISyncProviderFactory syncFactory)
        {
            this.CheckDisposed("DeleteFolderSyncState");
            this.syncLogger.Information <int>(ExTraceGlobals.SyncTracer, (long)this.GetHashCode(), "SyncStateStorage::DeleteFolderSyncState. Hashcode = {0}", this.GetHashCode());
            ArgumentValidator.ThrowIfNull("syncFactory", syncFactory);
            StoreObjectId           storeObjectId = StoreObjectId.Deserialize(syncFactory.GetCollectionIdBytes());
            FolderSyncStateMetadata folderSyncStateMetadata;

            if (this.DeviceMetadata.SyncStatesByIPMFolderId.TryGetValue(storeObjectId, out folderSyncStateMetadata))
            {
                return(this.InternalDeleteSyncState(folderSyncStateMetadata.Name));
            }
            this.syncLogger.TraceDebug <string>(ExTraceGlobals.SyncTracer, (long)this.GetHashCode(), "[SyncStateStorage.DeleteFolderSyncState] Did not find cached mapping for IPM Folder Id {0}", storeObjectId.ToBase64String());
            return(null);
        }
Esempio n. 5
0
 private SyncStateMetadata GetSyncStateItemMetadata(MailboxSession mailboxSession, Folder parentFolder, string displayName, ISyncLogger syncLogger = null)
 {
     if (syncLogger == null)
     {
         syncLogger = TracingLogger.Singleton;
     }
     using (QueryResult queryResult = parentFolder.ItemQuery(ItemQueryType.None, null, new SortBy[]
     {
         new SortBy(ItemSchema.Subject, SortOrder.Ascending)
     }, DeviceSyncStateMetadata.NullSyncPropertiesItems))
     {
         if (queryResult.SeekToCondition(SeekReference.OriginBeginning, new ComparisonFilter(ComparisonOperator.Equal, ItemSchema.Subject, displayName)))
         {
             IStorePropertyBag storePropertyBag = queryResult.GetPropertyBags(1)[0];
             StoreObjectId     objectId         = ((VersionedId)storePropertyBag.TryGetProperty(ItemSchema.Id)).ObjectId;
             syncLogger.TraceDebug <string, SmtpAddress, string>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.GetSyncStateItemMetadata] Sync state '{0}' for mailbox '{1}' is stored on item id '{2}'", displayName, mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress, objectId.ToBase64String());
             SyncStateMetadata metadataFromPropertyBag = this.GetMetadataFromPropertyBag(storePropertyBag, displayName, syncLogger);
             metadataFromPropertyBag.FolderSyncStateId = parentFolder.Id.ObjectId;
             metadataFromPropertyBag.ItemSyncStateId   = objectId;
             return(metadataFromPropertyBag);
         }
     }
     syncLogger.TraceDebug <string>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.GetSyncStateItemMetadata] Did not find child item with name {0}", displayName);
     return(null);
 }
Esempio n. 6
0
 public void ChangeIPMFolderId(FolderSyncStateMetadata folderSyncStateMetadata, StoreObjectId oldId, ISyncLogger syncLogger = null)
 {
     if (syncLogger == null)
     {
         syncLogger = TracingLogger.Singleton;
     }
     if (oldId != null)
     {
         FolderSyncStateMetadata folderSyncStateMetadata2;
         this.ipmToFolderSyncStateMap.TryRemove(oldId, out folderSyncStateMetadata2);
     }
     syncLogger.TraceDebug <string, string, string>(ExTraceGlobals.SyncTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.ChangeIPMFolderId] IPM Folder Id for collection '{0}' changed from '{1}' to '{2}'", folderSyncStateMetadata.Name, (oldId == null) ? "<NULL>" : oldId.ToBase64String(), (folderSyncStateMetadata.IPMFolderId == null) ? "<NULL>" : folderSyncStateMetadata.IPMFolderId.ToBase64String());
     if (folderSyncStateMetadata.IPMFolderId != null)
     {
         this.ipmToFolderSyncStateMap.TryAdd(folderSyncStateMetadata.IPMFolderId, folderSyncStateMetadata);
     }
 }
Esempio n. 7
0
        internal static FolderSyncState GetSyncState(SyncStateStorage syncStateStorage, Folder deviceFolder, ISyncProviderFactory syncProviderFactory, Func <SyncStateStorage, StoreObject, FolderSyncStateMetadata, SyncStateInfo, ISyncProviderFactory, bool, ISyncLogger, FolderSyncState> creator, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            ArgumentValidator.ThrowIfNull("syncStateStorage", syncStateStorage);
            ArgumentValidator.ThrowIfNull("deviceFolder", deviceFolder);
            ArgumentValidator.ThrowIfNull("syncProviderFactory", syncProviderFactory);
            byte[] collectionIdBytes = syncProviderFactory.GetCollectionIdBytes();
            if (collectionIdBytes == null || collectionIdBytes.Length == 0)
            {
                throw new ArgumentException("SyncProviderFactory CollectionId bytes cannot be null or empty.");
            }
            StoreObjectId storeObjectId = null;

            try
            {
                storeObjectId = StoreObjectId.Deserialize(collectionIdBytes);
            }
            catch (ArgumentException innerException)
            {
                syncLogger.TraceError <string>(ExTraceGlobals.SyncTracer, 0L, "[FolderSyncState.GetSyncState(syncProviderFactory)] The IPMFolderBytes that the provider gave us are invalid for folder {0}", deviceFolder.DisplayName);
                throw new CorruptSyncStateException(ServerStrings.ExSyncStateCorrupted(deviceFolder.DisplayName), innerException);
            }
            FolderSyncStateMetadata folderSyncStateMetadata = null;

            if (!syncStateStorage.DeviceMetadata.SyncStatesByIPMFolderId.TryGetValue(storeObjectId, out folderSyncStateMetadata))
            {
                syncLogger.TraceDebug <DeviceIdentity, string>(ExTraceGlobals.SyncTracer, 0L, "[FolderSyncState.GetSyncState(syncProviderFactory)] Cache miss for device {0}, IPM folder Id {1}", syncStateStorage.DeviceMetadata.Id, storeObjectId.ToBase64String());
                return(null);
            }
            SyncStateMetadata syncStateMetadata = folderSyncStateMetadata;
            StoreObject       storeObject       = SyncState.GetSyncStateStoreObject(deviceFolder, ref syncStateMetadata, syncLogger, new PropertyDefinition[]
            {
                InternalSchema.SyncFolderSourceKey
            });

            if (!object.ReferenceEquals(folderSyncStateMetadata, syncStateMetadata))
            {
                FolderSyncStateMetadata folderSyncStateMetadata2 = syncStateMetadata as FolderSyncStateMetadata;
                if (folderSyncStateMetadata2 == null)
                {
                    syncLogger.TraceDebug <string, string>(ExTraceGlobals.SyncProcessTracer, 0L, "[FolderSyncState.GetSyncState] Device {0} has non-folder sync state for {1}.  Returning null.", deviceFolder.DisplayName, folderSyncStateMetadata.Name);
                    if (storeObject != null)
                    {
                        storeObject.Dispose();
                        storeObject = null;
                    }
                }
                else
                {
                    syncLogger.TraceDebug <string, string>(ExTraceGlobals.SyncProcessTracer, 0L, "[FolderSyncState.GetSyncState] Device {0} had  state folder sync state metadata for {1}.  Replacing.", deviceFolder.DisplayName, folderSyncStateMetadata.Name);
                    folderSyncStateMetadata = folderSyncStateMetadata2;
                }
            }
            if (storeObject == null)
            {
                return(null);
            }
            SyncStateInfo syncStateInfo = new FolderSyncStateInfo(folderSyncStateMetadata.Name);

            if (creator == null)
            {
                return(new FolderSyncState(syncStateStorage, storeObject, folderSyncStateMetadata, syncStateInfo, syncProviderFactory, false, syncLogger));
            }
            return(creator(syncStateStorage, storeObject, folderSyncStateMetadata, syncStateInfo, syncProviderFactory, false, syncLogger));
        }