Example #1
0
        protected override void InternalSave(ConfigurableObject instance)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }
            MailboxFolder mailboxFolder = instance as MailboxFolder;

            if (mailboxFolder == null)
            {
                throw new NotSupportedException("Save: " + instance.GetType().FullName);
            }
            FolderSaveResult folderSaveResult = null;

            switch (mailboxFolder.ObjectState)
            {
            case ObjectState.New:
                try
                {
                    using (Folder folder = Folder.Create(base.MailboxSession, mailboxFolder.InternalParentFolderIdentity, ObjectClass.GetObjectType(mailboxFolder.FolderClass), mailboxFolder.Name, CreateMode.CreateNew))
                    {
                        mailboxFolder.SaveDataToXso(folder, new ReadOnlyCollection <XsoDriverPropertyDefinition>(new List <XsoDriverPropertyDefinition>
                        {
                            MailboxFolderSchema.Name,
                            MailboxFolderSchema.InternalParentFolderIdentity
                        }));
                        MailboxFolderDataProvider.ValidateXsoObjectAndThrowForError(mailboxFolder.Name, folder, mailboxFolder.Schema);
                        folderSaveResult = folder.Save();
                    }
                    goto IL_FD;
                }
                catch (ObjectExistedException innerException)
                {
                    throw new ObjectExistedException(ServerStrings.ErrorFolderAlreadyExists(mailboxFolder.Name), innerException);
                }
                break;

            case ObjectState.Unchanged:
                goto IL_FD;

            case ObjectState.Changed:
                break;

            case ObjectState.Deleted:
                throw new InvalidOperationException(ServerStrings.ExceptionObjectHasBeenDeleted);

            default:
                goto IL_FD;
            }
            throw new NotImplementedException("Save.Changed");
IL_FD:
            if (folderSaveResult != null && folderSaveResult.OperationResult != OperationResult.Succeeded)
            {
                throw folderSaveResult.ToException(ServerStrings.ErrorFolderSave(instance.Identity.ToString(), folderSaveResult.ToString()));
            }
        }
Example #2
0
        protected override IEnumerable <T> InternalFindPaged <T>(QueryFilter filter, ObjectId rootId, bool deepSearch, SortBy sortBy, int pageSize)
        {
            if (sortBy != null)
            {
                throw new NotSupportedException("sortBy");
            }
            if (rootId != null && !(rootId is MailboxFolderId))
            {
                throw new NotSupportedException("rootId: " + rootId.GetType().FullName);
            }
            if (!typeof(MailboxFolder).GetTypeInfo().IsAssignableFrom(typeof(T).GetTypeInfo()))
            {
                throw new NotSupportedException("FindPaged: " + typeof(T).FullName);
            }
            if (filter == null)
            {
                filter = MailboxFolderDataProvider.nonHiddenFilter;
            }
            else
            {
                filter = new AndFilter(new QueryFilter[]
                {
                    filter,
                    MailboxFolderDataProvider.nonHiddenFilter
                });
            }
            Dictionary <StoreObjectId, MapiFolderPath> knownFolderPathsCache = new Dictionary <StoreObjectId, MapiFolderPath>();

            knownFolderPathsCache.Add(base.MailboxSession.GetDefaultFolderId(DefaultFolderType.Root), MapiFolderPath.IpmSubtreeRoot);
            knownFolderPathsCache.Add(base.MailboxSession.GetDefaultFolderId(DefaultFolderType.Configuration), MapiFolderPath.NonIpmSubtreeRoot);
            StoreObjectId  xsoRootIdentity;
            MapiFolderPath xsoRootFolderPath;

            if (rootId == null)
            {
                xsoRootIdentity   = base.MailboxSession.SafeGetDefaultFolderId(DefaultFolderType.Root);
                xsoRootFolderPath = MapiFolderPath.IpmSubtreeRoot;
            }
            else
            {
                MailboxFolderId mailboxFolderId = (MailboxFolderId)rootId;
                if (mailboxFolderId.StoreObjectIdValue == null)
                {
                    StoreObjectId storeObjectId = base.ResolveStoreObjectIdFromFolderPath(mailboxFolderId.MailboxFolderPath);
                    if (storeObjectId == null)
                    {
                        yield break;
                    }
                    xsoRootIdentity = storeObjectId;
                }
                else
                {
                    xsoRootIdentity = mailboxFolderId.StoreObjectIdValue;
                }
                xsoRootFolderPath = mailboxFolderId.MailboxFolderPath;
            }
            MailboxFolder rootFolder = (MailboxFolder)((object)((default(T) == null) ? Activator.CreateInstance <T>() : default(T)));

            PropertyDefinition[] xsoProperties = rootFolder.Schema.AllDependentXsoProperties;
            Folder xsoFolder = Folder.Bind(base.MailboxSession, xsoRootIdentity, xsoProperties);

            rootFolder.LoadDataFromXso(base.MailboxSession.MailboxOwner.ObjectId, xsoFolder);
            rootFolder.SetDefaultFolderType(base.MailboxSession.IsDefaultFolderType(xsoRootIdentity));
            if (null == xsoRootFolderPath)
            {
                xsoRootFolderPath = MailboxFolderDataProvider.CalculateMailboxFolderPath(base.MailboxSession, rootFolder.InternalFolderIdentity.ObjectId, rootFolder.InternalParentFolderIdentity, rootFolder.Name, knownFolderPathsCache);
            }
            else if (!knownFolderPathsCache.ContainsKey(rootFolder.InternalFolderIdentity.ObjectId))
            {
                knownFolderPathsCache.Add(rootFolder.InternalFolderIdentity.ObjectId, xsoRootFolderPath);
            }
            rootFolder.FolderPath = xsoRootFolderPath;
            if (deepSearch)
            {
                yield return((T)((object)rootFolder));
            }
            QueryResult queryResults = xsoFolder.FolderQuery(deepSearch ? FolderQueryFlags.DeepTraversal : FolderQueryFlags.None, filter, null, new PropertyDefinition[]
            {
                FolderSchema.Id
            });

            for (;;)
            {
                object[][] folderRows = queryResults.GetRows((pageSize == 0) ? 1000 : pageSize);
                if (folderRows.Length <= 0)
                {
                    break;
                }
                foreach (object[] row in folderRows)
                {
                    MailboxFolder oneFolder = (MailboxFolder)((object)((default(T) == null) ? Activator.CreateInstance <T>() : default(T)));
                    using (Folder oneXsoFolder = Folder.Bind(base.MailboxSession, ((VersionedId)row[0]).ObjectId, xsoProperties))
                    {
                        oneFolder.LoadDataFromXso(base.MailboxSession.MailboxOwner.ObjectId, oneXsoFolder);
                        oneFolder.SetDefaultFolderType(base.MailboxSession.IsDefaultFolderType(oneFolder.InternalFolderIdentity));
                        oneFolder.FolderPath = MailboxFolderDataProvider.CalculateMailboxFolderPath(base.MailboxSession, oneFolder.InternalFolderIdentity.ObjectId, oneFolder.InternalParentFolderIdentity, oneFolder.Name, knownFolderPathsCache);
                        yield return((T)((object)oneFolder));
                    }
                }
            }
            yield break;
        }
        protected override void InternalSave(ConfigurableObject instance)
        {
            PublicFolder publicFolder = instance as PublicFolder;

            if (publicFolder == null)
            {
                throw new NotSupportedException("Save: " + instance.GetType().FullName);
            }
            FolderSaveResult folderSaveResult = null;

            switch (publicFolder.ObjectState)
            {
            case ObjectState.New:
                try
                {
                    using (Folder folder = Folder.Create(this.PublicFolderSession, publicFolder.InternalParentFolderIdentity, ObjectClass.GetObjectType(publicFolder.FolderClass), publicFolder.Name, CreateMode.CreateNew))
                    {
                        publicFolder.SaveDataToXso(folder, new ReadOnlyCollection <XsoDriverPropertyDefinition>(new List <XsoDriverPropertyDefinition>
                        {
                            PublicFolderSchema.Name,
                            MailboxFolderSchema.InternalParentFolderIdentity
                        }));
                        MailboxFolderDataProvider.ValidateXsoObjectAndThrowForError(publicFolder.Name, folder, publicFolder.Schema);
                        folderSaveResult            = folder.Save();
                        publicFolder.OrganizationId = this.PublicFolderSession.OrganizationId;
                    }
                    goto IL_157;
                }
                catch (ObjectExistedException innerException)
                {
                    throw new ObjectExistedException(ServerStrings.ErrorFolderAlreadyExists(publicFolder.Name), innerException);
                }
                break;

            case ObjectState.Unchanged:
                goto IL_157;

            case ObjectState.Changed:
                break;

            case ObjectState.Deleted:
                goto IL_147;

            default:
                goto IL_157;
            }
            using (Folder folder2 = Folder.Bind(this.PublicFolderSession, publicFolder.InternalFolderIdentity, null))
            {
                publicFolder.SaveDataToXso(folder2, new ReadOnlyCollection <XsoDriverPropertyDefinition>(new List <XsoDriverPropertyDefinition>
                {
                    MailboxFolderSchema.InternalParentFolderIdentity
                }));
                MailboxFolderDataProvider.ValidateXsoObjectAndThrowForError(publicFolder.Name, folder2, publicFolder.Schema);
                folderSaveResult = folder2.Save();
                goto IL_157;
            }
IL_147:
            throw new InvalidOperationException(ServerStrings.ExceptionObjectHasBeenDeleted);
IL_157:
            if (folderSaveResult != null && folderSaveResult.OperationResult != OperationResult.Succeeded && folderSaveResult.PropertyErrors.Length > 0)
            {
                foreach (PropertyError propertyError in folderSaveResult.PropertyErrors)
                {
                    if (propertyError.PropertyErrorCode == PropertyErrorCode.FolderNameConflict)
                    {
                        throw new ObjectExistedException(ServerStrings.ErrorFolderAlreadyExists(publicFolder.Name));
                    }
                }
                throw folderSaveResult.ToException(ServerStrings.ErrorFolderSave(instance.Identity.ToString(), folderSaveResult.ToString()));
            }
        }
        protected override IEnumerable <T> InternalFindPaged <T>(QueryFilter filter, ObjectId rootId, bool deepSearch, SortBy sortBy, int pageSize)
        {
            if (sortBy != null)
            {
                throw new NotSupportedException("sortBy");
            }
            if (rootId != null && !(rootId is PublicFolderId))
            {
                throw new NotSupportedException("rootId: " + rootId.GetType().FullName);
            }
            if (!typeof(PublicFolder).GetTypeInfo().IsAssignableFrom(typeof(T).GetTypeInfo()))
            {
                throw new NotSupportedException("FindPaged: " + typeof(T).FullName);
            }
            if (filter == null)
            {
                filter = PublicFolderDataProvider.nonHiddenFilter;
            }
            else
            {
                filter = new AndFilter(new QueryFilter[]
                {
                    filter,
                    PublicFolderDataProvider.nonHiddenFilter
                });
            }
            Dictionary <StoreObjectId, MapiFolderPath> knownFolderPathsCache = new Dictionary <StoreObjectId, MapiFolderPath>();

            knownFolderPathsCache.Add(this.PublicFolderSession.GetPublicFolderRootId(), MapiFolderPath.IpmSubtreeRoot);
            knownFolderPathsCache.Add(this.PublicFolderSession.GetIpmSubtreeFolderId(), MapiFolderPath.IpmSubtreeRoot);
            knownFolderPathsCache.Add(this.PublicFolderSession.GetNonIpmSubtreeFolderId(), MapiFolderPath.NonIpmSubtreeRoot);
            StoreObjectId  xsoRootIdentity;
            MapiFolderPath xsoRootFolderPath;

            if (rootId == null)
            {
                xsoRootIdentity   = this.PublicFolderSession.GetIpmSubtreeFolderId();
                xsoRootFolderPath = MapiFolderPath.IpmSubtreeRoot;
            }
            else
            {
                PublicFolderId publicFolderId = (PublicFolderId)rootId;
                if (publicFolderId.StoreObjectId == null)
                {
                    StoreObjectId storeObjectId = this.ResolveStoreObjectIdFromFolderPath(publicFolderId.MapiFolderPath);
                    if (storeObjectId == null)
                    {
                        yield break;
                    }
                    xsoRootIdentity = storeObjectId;
                }
                else
                {
                    xsoRootIdentity = publicFolderId.StoreObjectId;
                }
                xsoRootFolderPath = publicFolderId.MapiFolderPath;
            }
            PublicFolder rootFolder = new PublicFolder();

            PropertyDefinition[] xsoProperties = rootFolder.Schema.AllDependentXsoProperties;
            Folder xsoFolder = Folder.Bind(this.PublicFolderSession, xsoRootIdentity, xsoProperties);

            rootFolder.LoadDataFromXso(this.PublicFolderSession.MailboxPrincipal.ObjectId, xsoFolder);
            rootFolder.SetDefaultFolderType(DefaultFolderType.None);
            rootFolder.OrganizationId = this.PublicFolderSession.OrganizationId;
            StoreObjectId receoverableItemsDeletionFolderId = PublicFolderCOWSession.GetRecoverableItemsDeletionsFolderId(xsoFolder);

            rootFolder.DumpsterEntryId = ((receoverableItemsDeletionFolderId != null) ? receoverableItemsDeletionFolderId.ToHexEntryId() : null);
            if (null == xsoRootFolderPath)
            {
                xsoRootFolderPath = MailboxFolderDataProvider.CalculateMailboxFolderPath(this.PublicFolderSession, rootFolder.InternalFolderIdentity.ObjectId, rootFolder.InternalParentFolderIdentity, rootFolder.Name, knownFolderPathsCache);
            }
            else if (!knownFolderPathsCache.ContainsKey(rootFolder.InternalFolderIdentity.ObjectId))
            {
                knownFolderPathsCache.Add(rootFolder.InternalFolderIdentity.ObjectId, xsoRootFolderPath);
            }
            rootFolder.FolderPath = xsoRootFolderPath;
            if (deepSearch)
            {
                yield return((T)((object)rootFolder));
            }
            QueryResult queryResults = xsoFolder.FolderQuery(deepSearch ? FolderQueryFlags.DeepTraversal : FolderQueryFlags.None, filter, null, new PropertyDefinition[]
            {
                FolderSchema.Id
            });

            for (;;)
            {
                object[][] folderRows = queryResults.GetRows((pageSize == 0) ? 1000 : pageSize);
                if (folderRows.Length <= 0)
                {
                    break;
                }
                foreach (object[] row in folderRows)
                {
                    PublicFolder onePublicFolder = new PublicFolder();
                    using (Folder oneXsoFolder = Folder.Bind(this.PublicFolderSession, ((VersionedId)row[0]).ObjectId, xsoProperties))
                    {
                        onePublicFolder.LoadDataFromXso(this.PublicFolderSession.MailboxPrincipal.ObjectId, oneXsoFolder);
                        onePublicFolder.SetDefaultFolderType(DefaultFolderType.None);
                        onePublicFolder.OrganizationId    = this.PublicFolderSession.OrganizationId;
                        receoverableItemsDeletionFolderId = PublicFolderCOWSession.GetRecoverableItemsDeletionsFolderId(oneXsoFolder);
                        onePublicFolder.DumpsterEntryId   = ((receoverableItemsDeletionFolderId != null) ? receoverableItemsDeletionFolderId.ToHexEntryId() : null);
                        onePublicFolder.FolderPath        = MailboxFolderDataProvider.CalculateMailboxFolderPath(this.PublicFolderSession, onePublicFolder.InternalFolderIdentity.ObjectId, onePublicFolder.InternalParentFolderIdentity, onePublicFolder.Name, knownFolderPathsCache);
                        yield return((T)((object)onePublicFolder));
                    }
                }
            }
            yield break;
        }