Пример #1
0
        internal static MapiFolder RetrieveMapiFolder(MapiStore store, FolderId identity)
        {
            MapiFolder mapiFolder = null;
            MapiFolder result;

            try
            {
                FolderId folderId = null;
                result = Folder.RetrieveMapiFolder(store, identity, ref mapiFolder, null, out folderId);
            }
            finally
            {
                if (mapiFolder != null)
                {
                    mapiFolder.Dispose();
                }
            }
            return(result);
        }
Пример #2
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();
         }
     }
 }
Пример #3
0
        private static MapiFolder RetrieveParentMapiFolder(MapiStore store, FolderId identity, ref MapiFolder folder)
        {
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }
            Folder.CheckRequirementsOnIdentityToContinue(identity);
            MapiFolder mapiFolder = null;
            bool       flag       = false;
            bool       flag2      = false;
            MapiFolder result;

            try
            {
                byte[] array = null;
                if (null == identity.MapiEntryId)
                {
                    if (identity.LegacyDistinguishedName != null)
                    {
                        array = store.GetFolderEntryId(identity.LegacyDistinguishedName);
                    }
                }
                else
                {
                    array = (byte[])identity.MapiEntryId;
                }
                if (array != null)
                {
                    if (folder == null)
                    {
                        folder = (MapiFolder)store.OpenEntry(array);
                        flag   = true;
                    }
                    mapiFolder = (MapiFolder)store.OpenEntry(folder.GetProp(PropTag.ParentEntryId).GetBytes());
                }
                else if (null != identity.MapiFolderPath)
                {
                    MapiFolderPath parent = identity.MapiFolderPath.Parent;
                    if (null == parent)
                    {
                        mapiFolder = store.GetRootFolder();
                    }
                    else
                    {
                        mapiFolder = Folder.GetFolderByPath(store, parent);
                    }
                }
                flag2  = true;
                result = mapiFolder;
            }
            finally
            {
                if (!flag2)
                {
                    if (flag && folder != null)
                    {
                        folder.Dispose();
                        folder = null;
                    }
                    if (mapiFolder != null)
                    {
                        mapiFolder.Dispose();
                        mapiFolder = null;
                    }
                }
            }
            return(result);
        }
Пример #4
0
        internal static MapiFolder RetrieveMapiFolder(MapiStore store, FolderId identity, ref MapiFolder parent, Folder.IdentityConstructor idCtor, out FolderId realId)
        {
            realId = null;
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }
            Folder.CheckRequirementsOnIdentityToContinue(identity);
            MapiFolder mapiFolder = null;
            bool       flag       = false;
            bool       flag2      = false;
            MapiFolder result;

            try
            {
                byte[]         array      = null;
                MapiEntryId    entryId    = null;
                MapiFolderPath folderPath = null;
                string         legacyDn   = null;
                if (null == identity.MapiEntryId)
                {
                    if (identity.LegacyDistinguishedName != null)
                    {
                        legacyDn = identity.LegacyDistinguishedName;
                        array    = store.GetFolderEntryId(identity.LegacyDistinguishedName);
                    }
                }
                else
                {
                    array = (byte[])identity.MapiEntryId;
                }
                if (array != null)
                {
                    entryId    = new MapiEntryId(array);
                    mapiFolder = (MapiFolder)store.OpenEntry(array);
                    if (parent == null)
                    {
                        parent = (MapiFolder)store.OpenEntry(mapiFolder.GetProp(PropTag.ParentEntryId).GetBytes());
                        flag   = true;
                    }
                }
                else if (null != identity.MapiFolderPath)
                {
                    folderPath = identity.MapiFolderPath;
                    if (parent == null)
                    {
                        mapiFolder = Folder.GetFolderByPath(store, identity.MapiFolderPath, out parent);
                        flag       = true;
                    }
                    else
                    {
                        mapiFolder = Folder.GetFolderByPath(store, parent, identity.MapiFolderPath);
                    }
                }
                if (idCtor != null)
                {
                    realId = idCtor(entryId, folderPath, legacyDn);
                }
                flag2  = true;
                result = mapiFolder;
            }
            finally
            {
                if (!flag2)
                {
                    if (mapiFolder != null)
                    {
                        mapiFolder.Dispose();
                        mapiFolder = null;
                    }
                    if (flag && parent != null)
                    {
                        parent.Dispose();
                        parent = null;
                    }
                }
            }
            return(result);
        }