Example #1
0
        protected override IConfigurable PrepareDataObject()
        {
            MailboxFolder mailboxFolder  = (MailboxFolder)base.PrepareDataObject();
            MailboxFolder mailboxFolder2 = (MailboxFolder)base.GetDataObject <MailboxFolder>(this.Parent, base.DataSession, null, new LocalizedString?(Strings.ErrorMailboxFolderNotFound(this.Parent.ToString())), new LocalizedString?(Strings.ErrorMailboxFolderNotUnique(this.Parent.ToString())));

            if (mailboxFolder2.FolderPath.IsNonIpmPath)
            {
                base.WriteError(new InvalidOperationException(Strings.ErrorCannotCreateFolderUnderNonIpmSubtree(this.Name, this.Parent.ToString())), ErrorCategory.InvalidOperation, this.Name);
            }
            if (mailboxFolder2.ExtendedFolderFlags != null && ((mailboxFolder2.ExtendedFolderFlags.Value & ExtendedFolderFlags.ExclusivelyBound) != (ExtendedFolderFlags)0 || (mailboxFolder2.ExtendedFolderFlags.Value & ExtendedFolderFlags.RemoteHierarchy) != (ExtendedFolderFlags)0))
            {
                base.WriteError(new InvalidOperationException(Strings.ErrorInvalidParentExtendedFolderFlags(this.Name, this.Parent.ToString(), string.Join(",", new string[]
                {
                    ExtendedFolderFlags.ExclusivelyBound.ToString(),
                    ExtendedFolderFlags.RemoteHierarchy.ToString()
                }))), ErrorCategory.InvalidOperation, this.Name);
            }
            mailboxFolder[MailboxFolderSchema.InternalParentFolderIdentity] = mailboxFolder2.InternalFolderIdentity.ObjectId;
            mailboxFolder.FolderPath     = MapiFolderPath.GenerateFolderPath(mailboxFolder2.FolderPath, mailboxFolder.Name);
            mailboxFolder.MailboxOwnerId = mailboxFolder2.MailboxOwnerId;
            mailboxFolder.SetDefaultFolderType(DefaultFolderType.None);
            if (string.IsNullOrEmpty(mailboxFolder.FolderClass))
            {
                if (DefaultFolderType.Root == mailboxFolder2.DefaultFolderType || string.IsNullOrEmpty(mailboxFolder2.FolderClass))
                {
                    mailboxFolder.FolderClass = "IPF.Note";
                }
                else
                {
                    mailboxFolder.FolderClass = mailboxFolder2.FolderClass;
                }
            }
            return(mailboxFolder);
        }
Example #2
0
        internal static MapiFolderPath CalculateMailboxFolderPath(StoreSession session, StoreObjectId storeFolderId, StoreObjectId parentStoreFolderId, string displayName, Dictionary <StoreObjectId, MapiFolderPath> knownFolderPathsCache)
        {
            if (storeFolderId == null)
            {
                throw new ArgumentNullException("storeFolderId");
            }
            if (parentStoreFolderId == null)
            {
                throw new ArgumentNullException("parentStoreFolderId");
            }
            if (knownFolderPathsCache == null)
            {
                throw new ArgumentNullException("knownFolderPathsCache");
            }
            Stack <string>        stack          = new Stack <string>();
            Stack <StoreObjectId> stack2         = new Stack <StoreObjectId>();
            MapiFolderPath        mapiFolderPath = null;

            while (null == mapiFolderPath)
            {
                if (knownFolderPathsCache.ContainsKey(storeFolderId))
                {
                    mapiFolderPath = knownFolderPathsCache[storeFolderId];
                }
                else if (knownFolderPathsCache.ContainsKey(parentStoreFolderId))
                {
                    mapiFolderPath = knownFolderPathsCache[parentStoreFolderId];
                    stack.Push(displayName);
                    stack2.Push(storeFolderId);
                }
                else
                {
                    using (Folder folder = Folder.Bind(session, parentStoreFolderId, new PropertyDefinition[]
                    {
                        FolderSchema.DisplayName,
                        StoreObjectSchema.ParentItemId
                    }))
                    {
                        stack.Push(displayName);
                        stack2.Push(storeFolderId);
                        storeFolderId       = parentStoreFolderId;
                        parentStoreFolderId = (StoreObjectId)folder[StoreObjectSchema.ParentItemId];
                        displayName         = (string)folder[FolderSchema.DisplayName];
                    }
                }
            }
            MapiFolderPath mapiFolderPath2 = mapiFolderPath;

            while (0 < stack.Count)
            {
                mapiFolderPath2 = MapiFolderPath.GenerateFolderPath(mapiFolderPath2, stack.Pop());
                StoreObjectId key = stack2.Pop();
                if (!knownFolderPathsCache.ContainsKey(key))
                {
                    knownFolderPathsCache.Add(key, mapiFolderPath2);
                }
            }
            return(mapiFolderPath2);
        }
        protected override IConfigurable PrepareDataObject()
        {
            if (this.Path == null)
            {
                this.Path = new PublicFolderIdParameter(new PublicFolderId(MapiFolderPath.IpmSubtreeRoot));
            }
            PublicFolder publicFolder = null;

            try
            {
                publicFolder = (PublicFolder)base.GetDataObject <PublicFolder>(this.Path, base.DataSession, null, new LocalizedString?(Strings.ErrorPublicFolderNotFound(this.Path.ToString())), new LocalizedString?(Strings.ErrorPublicFolderNotUnique(this.Path.ToString())));
            }
            catch (NotSupportedException exception)
            {
                base.WriteError(exception, ErrorCategory.InvalidType, this.Name);
            }
            if (publicFolder.ExtendedFolderFlags != null && ((publicFolder.ExtendedFolderFlags.Value & ExtendedFolderFlags.ExclusivelyBound) != (ExtendedFolderFlags)0 || (publicFolder.ExtendedFolderFlags.Value & ExtendedFolderFlags.RemoteHierarchy) != (ExtendedFolderFlags)0))
            {
                base.WriteError(new InvalidOperationException(Strings.ErrorInvalidParentExtendedFolderFlags(this.Name, this.Path.ToString(), string.Join(",", new string[]
                {
                    ExtendedFolderFlags.ExclusivelyBound.ToString(),
                    ExtendedFolderFlags.RemoteHierarchy.ToString()
                }))), ErrorCategory.InvalidOperation, this.Name);
            }
            PublicFolder publicFolder2 = (PublicFolder)base.PrepareDataObject();

            publicFolder2.MailboxOwnerId = this.publicFolderDataProvider.PublicFolderSession.MailboxPrincipal.ObjectId;
            publicFolder2[MailboxFolderSchema.InternalParentFolderIdentity] = publicFolder.InternalFolderIdentity.ObjectId;
            publicFolder2.FolderPath = MapiFolderPath.GenerateFolderPath(publicFolder.FolderPath, this.Name);
            publicFolder2.Name       = this.Name;
            publicFolder2.PerUserReadStateEnabled = publicFolder.PerUserReadStateEnabled;
            publicFolder2.EformsLocaleId          = this.EformsLocaleId;
            if (this.Mailbox != null)
            {
                IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(ConsistencyMode.FullyConsistent, base.SessionSettings, 237, "PrepareDataObject", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\MapiTasks\\PublicFolder\\NewPublicFolder.cs");
                ADUser            aduser = (ADUser)base.GetDataObject <ADUser>(this.Mailbox, tenantOrRootOrgRecipientSession, null, new LocalizedString?(Strings.ErrorMailboxNotFound(this.Mailbox.ToString())), new LocalizedString?(Strings.ErrorMailboxNotUnique(this.Mailbox.ToString())));
                if (aduser.RecipientTypeDetails != RecipientTypeDetails.PublicFolderMailbox)
                {
                    base.WriteError(new ManagementObjectNotFoundException(Strings.ErrorMailboxNotFound(this.Mailbox.ToString())), ExchangeErrorCategory.Client, this.Mailbox);
                }
                publicFolder2.ContentMailboxGuid = aduser.ExchangeGuid;
            }
            publicFolder2.SetDefaultFolderType(DefaultFolderType.None);
            if (string.IsNullOrEmpty(publicFolder2.FolderClass))
            {
                if (DefaultFolderType.Root == publicFolder.DefaultFolderType || string.IsNullOrEmpty(publicFolder.FolderClass))
                {
                    publicFolder2.FolderClass = "IPF.Note";
                }
                else
                {
                    publicFolder2.FolderClass = publicFolder.FolderClass;
                }
            }
            return(publicFolder2);
        }
Example #4
0
 internal override void Save(bool keepUnmanagedResources)
 {
     if (ObjectState.Unchanged == base.ObjectState)
     {
         return;
     }
     if (ObjectState.Deleted == base.ObjectState)
     {
         throw new MapiInvalidOperationException(Strings.ExceptionObjectStateInvalid(base.ObjectState.ToString()));
     }
     base.EnableDisposeTracking();
     using (MapiStore messageStore = this.GetMessageStore())
     {
         MapiFolder mapiFolder        = null;
         MapiFolder parentFolder      = null;
         bool       isFolderRetrieved = false;
         try
         {
             MapiSession mapiSession = base.MapiSession;
             Folder.CheckRequirementsOnSessionToContinue(base.MapiSession);
             bool creating = false;
             if (base.ObjectState == ObjectState.New)
             {
                 creating = true;
                 string text = null;
                 if (this.newFolderIdentity == null)
                 {
                     if (null == this.Identity)
                     {
                         throw new MapiInvalidOperationException(Strings.ExceptionIdentityNull);
                     }
                     if (null == this.Identity.MapiFolderPath)
                     {
                         throw new MapiInvalidOperationException(Strings.ExceptionIdentityInvalid);
                     }
                     MapiFolder mapiFolder2 = null;
                     try
                     {
                         parentFolder = Folder.RetrieveParentMapiFolder(messageStore, this.Identity, ref mapiFolder2);
                     }
                     finally
                     {
                         if (mapiFolder2 != null)
                         {
                             mapiFolder2.Dispose();
                         }
                     }
                     if (parentFolder != null && !parentFolder.AllowWarnings)
                     {
                         parentFolder.AllowWarnings = true;
                     }
                     text = this.Identity.MapiFolderPath.Name;
                 }
                 else
                 {
                     this.Identity = this.ConstructIdentity(null, MapiFolderPath.GenerateFolderPath(this.newFolderIdentity.ParentIdentity.MapiFolderPath, this.newFolderIdentity.FolderName, false), null);
                     parentFolder  = Folder.RetrieveMapiFolder(messageStore, this.newFolderIdentity.ParentIdentity);
                     if (parentFolder != null && !parentFolder.AllowWarnings)
                     {
                         parentFolder.AllowWarnings = true;
                     }
                     text = this.newFolderIdentity.FolderName;
                 }
                 ExTraceGlobals.FolderTracer.TraceDebug <FolderId, string>((long)this.GetHashCode(), "To Create Folder '{0}' on server '{1}'.", this.Identity, base.MapiSession.ServerName);
                 try
                 {
                     mapiFolder = parentFolder.CreateFolder(text, string.Empty, false);
                     if (mapiFolder != null && !mapiFolder.AllowWarnings)
                     {
                         mapiFolder.AllowWarnings = true;
                     }
                     isFolderRetrieved = true;
                 }
                 catch (MapiExceptionCollision innerException)
                 {
                     this.DetectFolderExistence(messageStore, parentFolder, text, innerException);
                     throw;
                 }
                 this.UpdateIdentity(this.UpdateIdentityFlagsForCreating);
             }
             if (creating || ObjectState.Changed == base.ObjectState)
             {
                 Folder.CheckRequirementsOnIdentityToContinue(this.Identity);
                 this.DetectDisallowedModification(messageStore);
                 if (ObjectState.Changed == base.ObjectState && base.IsChanged(MapiPropertyDefinitions.Name))
                 {
                     string name = (string)this[MapiPropertyDefinitions.Name];
                     if (parentFolder == null)
                     {
                         MapiFolder mapiFolder3 = null;
                         try
                         {
                             parentFolder = Folder.RetrieveParentMapiFolder(messageStore, this.Identity, ref mapiFolder3);
                         }
                         finally
                         {
                             if (mapiFolder3 != null)
                             {
                                 mapiFolder3.Dispose();
                             }
                         }
                     }
                     this.DetectFolderExistence(messageStore, parentFolder, name, null);
                 }
                 PropProblem[] array    = null;
                 PropProblem[] array2   = null;
                 FolderId      folderId = null;
                 if (mapiFolder != null)
                 {
                     mapiFolder.Dispose();
                     mapiFolder = null;
                 }
                 mapiFolder = Folder.RetrieveMapiFolder(messageStore, this.Identity, ref parentFolder, new Folder.IdentityConstructor(this.ConstructIdentity), out folderId);
                 ParameterlessReturnlessDelegate parameterlessReturnlessDelegate = delegate()
                 {
                     if (creating && isFolderRetrieved)
                     {
                         ExTraceGlobals.FolderTracer.TraceDebug <FolderId, string>((long)this.GetHashCode(), "To Remove Folder '{0}' for rolling back creating on server '{1}'.", this.Identity, this.MapiSession.ServerName);
                         try
                         {
                             parentFolder.DeleteFolder((byte[])this.Identity.MapiEntryId);
                         }
                         catch (MapiRetryableException ex)
                         {
                             ExTraceGlobals.FolderTracer.TraceError <FolderId, string, string>((long)this.GetHashCode(), "Removing Folder '{0}' for rolling back caughting an exception on server '{1}': {2}", this.Identity, this.MapiSession.ServerName, ex.Message);
                         }
                         catch (MapiPermanentException ex2)
                         {
                             ExTraceGlobals.FolderTracer.TraceError <FolderId, string, string>((long)this.GetHashCode(), "Removing Folder '{0}' for rolling back caughting an exception on server '{1}': {2}", this.Identity, this.MapiSession.ServerName, ex2.Message);
                         }
                     }
                 };
                 try
                 {
                     PropValue[] propertyValuesToUpdate = base.GetPropertyValuesToUpdate();
                     if (0 < propertyValuesToUpdate.Length)
                     {
                         ExTraceGlobals.FolderTracer.TraceDebug <FolderId, string>((long)this.GetHashCode(), "To Set PropValues against Folder '{0}' on server '{1}'.", this.Identity, base.MapiSession.ServerName);
                         array = mapiFolder.SetProps(propertyValuesToUpdate);
                     }
                     PropTag[] propertyTagsToDelete = base.GetPropertyTagsToDelete();
                     if (0 < propertyTagsToDelete.Length)
                     {
                         ExTraceGlobals.FolderTracer.TraceDebug <FolderId, string>((long)this.GetHashCode(), "To Delete PropTags against Folder '{0}' on server '{1}'.", this.Identity, base.MapiSession.ServerName);
                         array2 = mapiFolder.DeleteProps(propertyTagsToDelete);
                     }
                 }
                 catch (DataValidationException)
                 {
                     parameterlessReturnlessDelegate();
                     throw;
                 }
                 catch (MapiRetryableException)
                 {
                     parameterlessReturnlessDelegate();
                     throw;
                 }
                 catch (MapiPermanentException)
                 {
                     parameterlessReturnlessDelegate();
                     throw;
                 }
                 base.ResetChangeTrackingAndObjectState();
                 StringBuilder stringBuilder = new StringBuilder();
                 if (array != null && 0 < array.Length)
                 {
                     stringBuilder.AppendLine(Strings.ErrorSetPropsProblem(this.Identity.ToString(), array.Length.ToString()));
                     foreach (PropProblem propProblem in array)
                     {
                         stringBuilder.Append('\t');
                         stringBuilder.AppendLine(Strings.ErrorPropProblem(propProblem.PropTag.ToString(), propProblem.PropType.ToString(), propProblem.Scode.ToString()));
                     }
                     stringBuilder.AppendLine();
                 }
                 if (array2 != null && 0 < array2.Length)
                 {
                     stringBuilder.AppendLine(Strings.ErrorDeletePropsProblem(this.Identity.ToString(), array2.Length.ToString()));
                     foreach (PropProblem propProblem2 in array2)
                     {
                         stringBuilder.Append('\t');
                         stringBuilder.Append(Strings.ErrorPropProblem(propProblem2.PropTag.ToString(), propProblem2.PropType.ToString(), propProblem2.Scode.ToString()));
                         stringBuilder.AppendLine();
                     }
                     stringBuilder.AppendLine();
                 }
                 if (0 < stringBuilder.Length)
                 {
                     string text2 = stringBuilder.ToString();
                     ExTraceGlobals.FolderTracer.TraceDebug <FolderId, string, string>((long)this.GetHashCode(), "Setting Folder '{0}' on server '{1}' returns error '{2}'.", this.Identity, base.MapiSession.ServerName, text2);
                     parameterlessReturnlessDelegate();
                     throw new MapiInvalidOperationException(new LocalizedString(text2));
                 }
             }
         }
         finally
         {
             if (mapiFolder != null)
             {
                 mapiFolder.Dispose();
             }
             if (parentFolder != null)
             {
                 parentFolder.Dispose();
             }
             base.Dispose();
         }
     }
 }
Example #5
0
        private static MapiFolderPath GetFolderPath(MapiEntryId folderEntryId, MapiFolder mapiFolder, MapiStore mapiStore)
        {
            MapiFolderPath result;

            try
            {
                if (null == folderEntryId)
                {
                    if (mapiFolder == null)
                    {
                        throw new ArgumentNullException("mapiFolder");
                    }
                    PropValue prop = mapiFolder.GetProp(PropTag.EntryId);
                    if (PropType.Error == prop.PropType)
                    {
                        return(null);
                    }
                    folderEntryId = new MapiEntryId(prop.GetBytes());
                }
                if (mapiStore == null)
                {
                    throw new ArgumentNullException("mapiStore");
                }
                MapiEntryId operand;
                using (MapiFolder rootFolder = mapiStore.GetRootFolder())
                {
                    operand = new MapiEntryId(rootFolder.GetProp(PropTag.EntryId).GetBytes());
                }
                MapiEntryId    operand2         = new MapiEntryId(mapiStore.GetIpmSubtreeFolderEntryId());
                MapiEntryId    operand3         = new MapiEntryId(mapiStore.GetNonIpmSubtreeFolderEntryId());
                MapiFolderPath mapiFolderPath   = null;
                MapiEntryId    mapiEntryId      = folderEntryId;
                MapiEntryId    mapiEntryId2     = null;
                string         parentFolderName = null;
                while (!(operand2 == mapiEntryId))
                {
                    if (operand3 == mapiEntryId || operand == mapiEntryId)
                    {
                        mapiFolderPath = MapiFolderPath.GenerateFolderPath("NON_IPM_SUBTREE", mapiFolderPath, true);
                    }
                    else
                    {
                        using (MapiFolder mapiFolder2 = (MapiFolder)mapiStore.OpenEntry((byte[])mapiEntryId))
                        {
                            PropValue[] props = mapiFolder2.GetProps(new PropTag[]
                            {
                                PropTag.ParentEntryId,
                                PropTag.DisplayName
                            });
                            if (PropType.Error == props[0].PropType || PropType.Error == props[1].PropType)
                            {
                                return(null);
                            }
                            mapiEntryId2     = new MapiEntryId(props[0].GetBytes());
                            parentFolderName = props[1].GetString();
                        }
                        if (!(mapiEntryId2 == mapiEntryId))
                        {
                            mapiFolderPath = MapiFolderPath.GenerateFolderPath(parentFolderName, mapiFolderPath, false);
                            mapiEntryId    = mapiEntryId2;
                            continue;
                        }
                    }
IL_19C:
                    return(mapiFolderPath);
                }
                mapiFolderPath = MapiFolderPath.GenerateFolderPath("IPM_SUBTREE", mapiFolderPath, true);
                goto IL_19C;
            }
            catch (MapiPermanentException)
            {
                result = null;
            }
            catch (MapiRetryableException)
            {
                result = null;
            }
            return(result);
        }