Ejemplo n.º 1
0
        public static PublishedFolder Create(PublishingUrl publishingUrl)
        {
            Util.ThrowOnNullArgument(publishingUrl, "publishingUrl");
            PublishedFolder.SleepIfNecessary();
            SharingAnonymousIdentityCache      instance = SharingAnonymousIdentityCache.Instance;
            SharingAnonymousIdentityCacheKey   key      = publishingUrl.CreateKey();
            SharingAnonymousIdentityCacheValue sharingAnonymousIdentityCacheValue = instance.Get(key);

            if (!sharingAnonymousIdentityCacheValue.IsAccessAllowed)
            {
                ExTraceGlobals.SharingTracer.TraceError <PublishingUrl, Type>(0L, "PublishedFolder.Create(PublishingUrl): Cannot find access allowed folder from the request url: path = {0}, type = {1}.", publishingUrl, publishingUrl.GetType());
                throw new PublishedFolderAccessDeniedException();
            }
            ExTraceGlobals.SharingTracer.TraceDebug <SecurityIdentifier, string, string>(0L, "PublishedFolder.Create(PublishingUrl): User {0} has Sharing Anonymous identity {1}. The corresponding folder identity is {2}.", sharingAnonymousIdentityCacheValue.Sid, publishingUrl.Identity, sharingAnonymousIdentityCacheValue.FolderId);
            StoreObjectId storeObjectId = null;

            try
            {
                storeObjectId = StoreObjectId.Deserialize(sharingAnonymousIdentityCacheValue.FolderId);
            }
            catch (CorruptDataException innerException)
            {
                ExTraceGlobals.SharingTracer.TraceError <string>(0L, "PublishedFolder.Create(PublishingUrl): The folder identity '{0}' is invalid.", sharingAnonymousIdentityCacheValue.FolderId);
                throw new PublishedFolderAccessDeniedException(innerException);
            }
            if (publishingUrl.DataType == SharingDataType.ReachCalendar || publishingUrl.DataType == SharingDataType.Calendar)
            {
                ObscureUrl obscureUrl = publishingUrl as ObscureUrl;
                return(new PublishedCalendar(publishingUrl.Domain, sharingAnonymousIdentityCacheValue.Sid, storeObjectId, (obscureUrl == null) ? null : new ObscureKind?(obscureUrl.ObscureKind), (obscureUrl == null) ? null : obscureUrl.ReachUserSid));
            }
            throw new NotSupportedException();
        }
Ejemplo n.º 2
0
        public SyncStateMetadata GetMetadataFromPropertyBag(IStorePropertyBag propertyBag, string displayName, ISyncLogger syncLogger = null)
        {
            byte[] byteArray = null;
            if (!DeviceSyncStateMetadata.TryGetPropertyFromBag <byte[]>(propertyBag, InternalSchema.SyncFolderSourceKey, out byteArray, syncLogger))
            {
                syncLogger.TraceDebug <string>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.GetMetadataFromPropertyBag] Creating custom sync state metadata for folder '{0}'", displayName);
                return(new SyncStateMetadata(this, displayName, null, null));
            }
            StoreObjectId storeObjectId = StoreObjectId.Deserialize(byteArray);

            syncLogger.TraceDebug <string, StoreObjectId>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.GetMetadataFromPropertyBag] Found SyncFolderSourceKey for {0}, so it is a FolderSyncState: {1}", displayName, storeObjectId);
            long localCommitTimeMax  = 0L;
            int  deletedCountTotal   = 0;
            int  syncKey             = 0;
            int  airSyncFilter       = 0;
            bool conversationMode    = false;
            int  airSyncSettingsHash = 0;
            int  airSyncMaxItems     = 0;
            VariantConfigurationSnapshot snapshot = VariantConfiguration.GetSnapshot(MachineSettingsContext.Local, null, null);
            bool flag = snapshot != null && snapshot.DataStorage.IgnoreInessentialMetaDataLoadErrors != null && snapshot.DataStorage.IgnoreInessentialMetaDataLoadErrors.Enabled;

            syncLogger.TraceDebug <bool>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.GetMetadataFromPropertyBag] ignoreInessentialMetaDataLoadErrors: {0}", flag);
            long airSyncLastSyncTime;
            bool flag2 = DeviceSyncStateMetadata.TryGetPropertyFromBag <long>(propertyBag, AirSyncStateSchema.MetadataLastSyncTime, out airSyncLastSyncTime, syncLogger) && DeviceSyncStateMetadata.TryGetPropertyFromBag <long>(propertyBag, AirSyncStateSchema.MetadataLocalCommitTimeMax, out localCommitTimeMax, syncLogger) && DeviceSyncStateMetadata.TryGetPropertyFromBag <int>(propertyBag, AirSyncStateSchema.MetadataDeletedCountTotal, out deletedCountTotal, syncLogger) && DeviceSyncStateMetadata.TryGetPropertyFromBag <int>(propertyBag, AirSyncStateSchema.MetadataSyncKey, out syncKey, syncLogger) && DeviceSyncStateMetadata.TryGetPropertyFromBag <int>(propertyBag, AirSyncStateSchema.MetadataFilter, out airSyncFilter, syncLogger) && DeviceSyncStateMetadata.TryGetPropertyFromBag <bool>(propertyBag, AirSyncStateSchema.MetadataConversationMode, out conversationMode, syncLogger) && DeviceSyncStateMetadata.TryGetPropertyFromBag <int>(propertyBag, AirSyncStateSchema.MetadataSettingsHash, out airSyncSettingsHash, syncLogger);
            bool flag3 = flag2 && DeviceSyncStateMetadata.TryGetPropertyFromBag <int>(propertyBag, AirSyncStateSchema.MetadataMaxItems, out airSyncMaxItems, syncLogger);

            flag2 = (flag ? flag2 : flag3);
            if (flag2)
            {
                syncLogger.TraceDebug <string>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.GetMetadataFromPropertyBag] Creating FolderSync metadata for folder '{0}'", displayName);
                return(new FolderSyncStateMetadata(this, displayName, null, null, localCommitTimeMax, deletedCountTotal, syncKey, conversationMode, airSyncFilter, airSyncLastSyncTime, airSyncSettingsHash, airSyncMaxItems, storeObjectId));
            }
            syncLogger.TraceDebug <string>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.GetMetadataFromPropertyBag] Failed to get nullSync properties for sync folder '{0}'.", displayName);
            return(new FolderSyncStateMetadata(this, displayName, null, null, 0L, 0, 0, false, 0, 0L, 0, 0, storeObjectId));
        }
Ejemplo n.º 3
0
 public StoreObjectId TryGetStoreObjectId()
 {
     base.CheckDisposed("TryGetStoreObjectId");
     byte[] collectionIdBytes = this.syncProviderFactory.GetCollectionIdBytes();
     if (collectionIdBytes == null)
     {
         return(null);
     }
     return(StoreObjectId.Deserialize(collectionIdBytes));
 }
Ejemplo n.º 4
0
        public StoreObjectId ToStoreObjectId()
        {
            switch (this.IdProcessingInstruction)
            {
            case IdProcessingInstruction.Normal:
                return(StoreObjectId.FromProviderSpecificId(this.StoreIdBytes));

            case IdProcessingInstruction.Series:
                return(StoreObjectId.FromProviderSpecificId(this.StoreIdBytes, StoreObjectType.CalendarItemSeries));
            }
            return(StoreObjectId.Deserialize(this.StoreIdBytes));
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        protected override PublishingSubscriptionData CreateDataObjectFromItem(object[] properties)
        {
            VersionedId versionedId = SharingItemManagerBase <PublishingSubscriptionData> .TryGetPropertyRef <VersionedId>(properties, 1);

            if (versionedId == null)
            {
                ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal>((long)this.GetHashCode(), "{0}: subscription is missing ID", base.MailboxSession.MailboxOwner);
                return(null);
            }
            string text = SharingItemManagerBase <PublishingSubscriptionData> .TryGetPropertyRef <string>(properties, 4);

            if (string.IsNullOrEmpty(text))
            {
                ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId>((long)this.GetHashCode(), "{0}: subscription {1} is missing ExternalSharingDataType", base.MailboxSession.MailboxOwner, versionedId);
                return(null);
            }
            string text2 = SharingItemManagerBase <PublishingSubscriptionData> .TryGetPropertyRef <string>(properties, 5);

            if (string.IsNullOrEmpty(text2))
            {
                ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId>((long)this.GetHashCode(), "{0}: subscription {1} is missing ExternalSharingUrl", base.MailboxSession.MailboxOwner, versionedId);
                return(null);
            }
            if (!Uri.IsWellFormedUriString(text2, UriKind.Absolute))
            {
                ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId, string>((long)this.GetHashCode(), "{0}: subscription {1} has invalid ExternalSharingUrl: {2}", base.MailboxSession.MailboxOwner, versionedId, text2);
                return(null);
            }
            string text3 = SharingItemManagerBase <PublishingSubscriptionData> .TryGetPropertyRef <string>(properties, 6);

            if (string.IsNullOrEmpty(text3))
            {
                ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId>((long)this.GetHashCode(), "{0}: subscription {1} is missing ExternalSharingRemoteFolderName", base.MailboxSession.MailboxOwner, versionedId);
                return(null);
            }
            byte[] array = SharingItemManagerBase <PublishingSubscriptionData> .TryGetPropertyRef <byte[]>(properties, 2);

            if (array == null || array.Length == 0)
            {
                ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId>((long)this.GetHashCode(), "{0}: subscription {1} is missing ExternalSharingLocalFolderId", base.MailboxSession.MailboxOwner, versionedId);
                return(null);
            }
            return(new PublishingSubscriptionData(versionedId, text, new Uri(text2), text3, StoreObjectId.Deserialize(array)));
        }
Ejemplo n.º 7
0
        internal static FolderSyncState CreateSyncState(SyncStateStorage syncStateStorage, Folder syncStateParentFolder, ISyncProviderFactory syncProviderFactory, string syncFolderId, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            SyncStateInfo syncStateInfo = new FolderSyncStateInfo(syncFolderId);
            StoreObject   storeObject   = SyncState.CreateSyncStateStoreObject(syncStateStorage, syncStateInfo, syncStateParentFolder, new PropertyDefinition[]
            {
                InternalSchema.SyncFolderSourceKey
            }, new object[]
            {
                syncProviderFactory.GetCollectionIdBytes()
            }, syncLogger);

            if (syncStateStorage.DeviceMetadata.TryRemove(syncStateInfo.UniqueName, syncLogger) != null)
            {
                syncLogger.TraceDebug <DeviceIdentity, string>(ExTraceGlobals.SyncTracer, 0L, "[FolderSyncState.CreateSyncState] Removed stale cached sync state metadata for device {0}, sync state {1}", syncStateStorage.DeviceMetadata.Id, syncStateInfo.UniqueName);
            }
            FolderSyncStateMetadata syncStateMetadata = (storeObject is Item) ? new FolderSyncStateMetadata(syncStateStorage.DeviceMetadata, syncStateInfo.UniqueName, syncStateStorage.SaveOnDirectItems ? null : storeObject.ParentId, storeObject.Id.ObjectId, StoreObjectId.Deserialize(syncProviderFactory.GetCollectionIdBytes())) : new FolderSyncStateMetadata(syncStateStorage.DeviceMetadata, syncStateInfo.UniqueName, storeObject.Id.ObjectId, null, StoreObjectId.Deserialize(syncProviderFactory.GetCollectionIdBytes()));

            return(new FolderSyncState(syncStateStorage, storeObject, syncStateMetadata, syncStateInfo, syncProviderFactory, true, syncLogger));
        }
Ejemplo n.º 8
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));
        }
        protected override SharingSubscriptionData CreateDataObjectFromItem(object[] properties)
        {
            VersionedId versionedId = SharingItemManagerBase <SharingSubscriptionData> .TryGetPropertyRef <VersionedId>(properties, 1);

            if (versionedId == null)
            {
                ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal>((long)this.GetHashCode(), "{0}: subscription is missing ID", base.MailboxSession.MailboxOwner);
                return(null);
            }
            string text = SharingItemManagerBase <SharingSubscriptionData> .TryGetPropertyRef <string>(properties, 4);

            if (string.IsNullOrEmpty(text))
            {
                ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId>((long)this.GetHashCode(), "{0}: subscription {1} is missing ExternalSharingDataType", base.MailboxSession.MailboxOwner, versionedId);
                return(null);
            }
            string text2 = SharingItemManagerBase <SharingSubscriptionData> .TryGetPropertyRef <string>(properties, 5);

            if (string.IsNullOrEmpty(text2))
            {
                ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId>((long)this.GetHashCode(), "{0}: subscription {1} is missing ExternalSharingSharerIdentity", base.MailboxSession.MailboxOwner, versionedId);
                return(null);
            }
            string text3 = SharingItemManagerBase <SharingSubscriptionData> .TryGetPropertyRef <string>(properties, 6);

            if (string.IsNullOrEmpty(text3))
            {
                ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId>((long)this.GetHashCode(), "{0}: subscription {1} is missing ExternalSharingSharerName", base.MailboxSession.MailboxOwner, versionedId);
                return(null);
            }
            string text4 = SharingItemManagerBase <SharingSubscriptionData> .TryGetPropertyRef <string>(properties, 7);

            if (string.IsNullOrEmpty(text4))
            {
                ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId>((long)this.GetHashCode(), "{0}: subscription {1} is missing ExternalSharingRemoteFolderId", base.MailboxSession.MailboxOwner, versionedId);
                return(null);
            }
            string text5 = SharingItemManagerBase <SharingSubscriptionData> .TryGetPropertyRef <string>(properties, 8);

            if (string.IsNullOrEmpty(text5))
            {
                ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId>((long)this.GetHashCode(), "{0}: subscription {1} is missing ExternalSharingRemoteFolderName", base.MailboxSession.MailboxOwner, versionedId);
                return(null);
            }
            bool?flag = SharingItemManagerBase <SharingSubscriptionData> .TryGetPropertyVal <bool>(properties, 9);

            if (flag == null)
            {
                ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId>((long)this.GetHashCode(), "{0}: subscription {1} is missing ExternalSharingIsPrimary", base.MailboxSession.MailboxOwner, versionedId);
                return(null);
            }
            bool   value = flag.Value;
            string text6 = SharingItemManagerBase <SharingSubscriptionData> .TryGetPropertyRef <string>(properties, 10);

            if (string.IsNullOrEmpty(text6))
            {
                ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId>((long)this.GetHashCode(), "{0}: subscription {1} is missing ExternalSharingSharerIdentityFederationUri", base.MailboxSession.MailboxOwner, versionedId);
                return(null);
            }
            if (!Uri.IsWellFormedUriString(text6, UriKind.Absolute))
            {
                ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId, string>((long)this.GetHashCode(), "{0}: subscription {1} has invalid ExternalSharingSharerIdentityFederationUri: {2}", base.MailboxSession.MailboxOwner, versionedId, text6);
                return(null);
            }
            string text7 = SharingItemManagerBase <SharingSubscriptionData> .TryGetPropertyRef <string>(properties, 11);

            if (string.IsNullOrEmpty(text7))
            {
                ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId>((long)this.GetHashCode(), "{0}: subscription {1} is missing ExternalSharingUrl", base.MailboxSession.MailboxOwner, versionedId);
                return(null);
            }
            if (!Uri.IsWellFormedUriString(text7, UriKind.Absolute))
            {
                ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId, string>((long)this.GetHashCode(), "{0}: subscription {1} has invalid ExternalSharingUrl: {2}", base.MailboxSession.MailboxOwner, versionedId, text7);
                return(null);
            }
            byte[] array = SharingItemManagerBase <SharingSubscriptionData> .TryGetPropertyRef <byte[]>(properties, 2);

            if (array == null || array.Length == 0)
            {
                ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId>((long)this.GetHashCode(), "{0}: subscription {1} is missing ExternalSharingLocalFolderId", base.MailboxSession.MailboxOwner, versionedId);
                return(null);
            }
            string text8 = SharingItemManagerBase <SharingSubscriptionData> .TryGetPropertyRef <string>(properties, 12);

            if (string.IsNullOrEmpty(text8))
            {
                ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId>((long)this.GetHashCode(), "{0}: subscription {1} is missing ExternalSharingSharingKey", base.MailboxSession.MailboxOwner, versionedId);
                return(null);
            }
            string text9 = SharingItemManagerBase <SharingSubscriptionData> .TryGetPropertyRef <string>(properties, 13);

            if (string.IsNullOrEmpty(text9))
            {
                ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId>((long)this.GetHashCode(), "{0}: subscription {1} is missing ExternalSharingSubscriberIdentity", base.MailboxSession.MailboxOwner, versionedId);
                return(null);
            }
            return(new SharingSubscriptionData(versionedId, text, text2, text3, text4, text5, value, new Uri(text6), new Uri(text7), StoreObjectId.Deserialize(array), text8, text9));
        }
 public void SetCollectionIdFromBytes(byte[] collectionBytes)
 {
     this.folderId = StoreObjectId.Deserialize(collectionBytes);
 }