Ejemplo n.º 1
0
        private bool InternalLocalize(DefaultFolderData data, out PropertyError error)
        {
            error = null;
            if (data.FolderId == null)
            {
                return(false);
            }
            ExTraceGlobals.DefaultFoldersTracer.TraceDebug <DefaultFolder>((long)this.GetHashCode(), "DefaultFolder::InternalLocalize. We are trying to localize the default folder. defaultFolder = {0}.", this);
            string text = this.defaultFolderInfo.LocalizableDisplayName.ToString(this.cultureInfo);

            try
            {
                using (MapiPropertyBag mapiPropertyBag = MapiPropertyBag.CreateMapiPropertyBag(this.context.Session, data.FolderId))
                {
                    object[] properties = mapiPropertyBag.GetProperties(DefaultFolder.displayNameNativePropertyDefinition);
                    if (properties.Length <= 0)
                    {
                        return(false);
                    }
                    string text2 = properties[0] as string;
                    if (text2 == null || string.Compare(text, text2, StringComparison.OrdinalIgnoreCase) != 0)
                    {
                        PropertyDefinition[] propertyDefinitions;
                        if (this.defaultFolderInfo.DefaultFolderType == DefaultFolderType.ElcRoot)
                        {
                            propertyDefinitions = DefaultFolder.elcFolderLocalizedNamePropertyDefinition;
                        }
                        else
                        {
                            propertyDefinitions = DefaultFolder.displayNamePropertyDefinition;
                        }
                        PropertyError[] array = mapiPropertyBag.SetProperties(propertyDefinitions, new object[]
                        {
                            text
                        });
                        if (array != null && array.Length > 0)
                        {
                            if (array[0].PropertyErrorCode == PropertyErrorCode.FolderNameConflict)
                            {
                                ExTraceGlobals.DefaultFoldersTracer.TraceError <string, DefaultFolderType>((long)this.GetHashCode(), "DefaultFolder::InternalLocalize. Failed to localize default folder. Folder = {0}, defaultFolderType = {1}.", this.defaultFolderInfo.LocalizableDisplayName.ToString(this.cultureInfo), this.defaultFolderInfo.DefaultFolderType);
                                throw new DefaultFolderLocalizationException(new DefaultFolderNameClashException(this.defaultFolderInfo.LocalizableDisplayName));
                            }
                            error = array[0];
                            ExTraceGlobals.DefaultFoldersTracer.TraceError <DefaultFolder, PropertyError>((long)this.GetHashCode(), "DefaultFolder::InternalLocalize. We failed to localize default folder due to error. defaultFolder = {0}, error = {1}.", this, error);
                        }
                        mapiPropertyBag.SaveChanges(false);
                        return(true);
                    }
                }
            }
            catch (ObjectNotFoundException)
            {
                ExTraceGlobals.DefaultFoldersTracer.TraceError <DefaultFolder>((long)this.GetHashCode(), "DefaultFolder::InternalLocalize. The default folder was missing. Localization aborted. defaultFolder = {0}.", this);
            }
            return(false);
        }
Ejemplo n.º 2
0
        internal static Folder BindToSubfolderByName(StoreSession session, StoreObjectId containerId, string folderName, params PropertyDefinition[] propsToReturn)
        {
            Folder result;

            using (Folder folder = Folder.Bind(session, containerId))
            {
                MapiFolder mapiFolder = null;
                Folder     folder2    = null;
                bool       flag       = false;
                try
                {
                    object thisObject = null;
                    bool   flag2      = false;
                    try
                    {
                        if (session != null)
                        {
                            session.BeginMapiCall();
                            session.BeginServerHealthCall();
                            flag2 = true;
                        }
                        if (StorageGlobals.MapiTestHookBeforeCall != null)
                        {
                            StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                        }
                        mapiFolder = folder.MapiFolder.OpenSubFolderByName(folderName);
                    }
                    catch (MapiPermanentException ex)
                    {
                        throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotOpenFolder, ex, session, thisObject, "{0}. MapiException = {1}.", new object[]
                        {
                            string.Format("DefaultFolderCreator::BindToSubfolderByName. Unable to open folder by name.", new object[0]),
                            ex
                        });
                    }
                    catch (MapiRetryableException ex2)
                    {
                        throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotOpenFolder, ex2, session, thisObject, "{0}. MapiException = {1}.", new object[]
                        {
                            string.Format("DefaultFolderCreator::BindToSubfolderByName. Unable to open folder by name.", new object[0]),
                            ex2
                        });
                    }
                    finally
                    {
                        try
                        {
                            if (session != null)
                            {
                                session.EndMapiCall();
                                if (flag2)
                                {
                                    session.EndServerHealthCall();
                                }
                            }
                        }
                        finally
                        {
                            if (StorageGlobals.MapiTestHookAfterCall != null)
                            {
                                StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                            }
                        }
                    }
                    using (MapiPropertyBag mapiPropertyBag = new MapiPropertyBag(session, mapiFolder))
                    {
                        byte[] entryId = (byte[])mapiPropertyBag.GetProperties(new NativeStorePropertyDefinition[]
                        {
                            InternalSchema.EntryId
                        })[0];
                        StoreObjectId folderObjectId = StoreObjectId.FromProviderSpecificId(entryId);
                        folder2 = Folder.InternalBind <Folder>(session, mapiFolder, folderObjectId, null, propsToReturn);
                        mapiPropertyBag.DetachMapiProp();
                    }
                    flag   = true;
                    result = folder2;
                }
                finally
                {
                    if (!flag)
                    {
                        Util.DisposeIfPresent(folder2);
                        Util.DisposeIfPresent(mapiFolder);
                    }
                }
            }
            return(result);
        }