示例#1
0
文件: MAPIFolder.cs 项目: mo5h/omeo
        public static IResource FindOrCreate(FolderDescriptor folderDescriptor, IResource parentFolder)
        {
            Guard.NullArgument(folderDescriptor, "folderDescriptor");
            IResource MAPIStore = FindOrCreateMAPIStore(folderDescriptor.FolderIDs.StoreId);
            IResource resFolder =
                Core.ResourceStore.FindUniqueResource(STR.MAPIFolder, PROP.EntryID, folderDescriptor.FolderIDs.EntryId);

            if (resFolder != null)
            {
                resFolder.BeginUpdate();
            }
            else
            {
                resFolder = Core.ResourceStore.BeginNewResource(STR.MAPIFolder);
                Core.WorkspaceManager.AddToActiveWorkspaceRecursive(resFolder);
                resFolder.SetProp("EntryID", folderDescriptor.FolderIDs.EntryId);
                resFolder.SetProp("OwnerStore", MAPIStore);
                if (OutlookSession.IsDeletedItemsFolder(folderDescriptor.FolderIDs.EntryId))
                {
                    resFolder.SetProp(Core.Props.ShowDeletedItems, true);
                    resFolder.SetProp(PROP.DeletedItemsFolder, true);
                    resFolder.SetProp(PROP.DefaultDeletedItems, true);
                }
                if (parentFolder != null)
                {
                    SetIgnored(resFolder, IsIgnored(parentFolder));
                }
            }
            SetName(resFolder, folderDescriptor.Name);
            string containerClass = folderDescriptor.ContainerClass;

            resFolder.SetProp(PROP.PR_STORE_SUPPORT_MASK, folderDescriptor.StoreSupportMask);
            resFolder.SetProp(PROP.PR_CONTENT_COUNT, folderDescriptor.ContentCount);
            if (containerClass.Length > 0)
            {
                resFolder.SetProp(PROP.ContainerClass, containerClass);
            }
            containerClass = resFolder.GetPropText(PROP.ContainerClass);
            bool visible =
                (containerClass.Length == 0 || containerClass == FolderType.Mail ||
                 containerClass == FolderType.Post || containerClass == FolderType.IMAP || containerClass == FolderType.Dav);

            resFolder.SetProp(PROP.MAPIVisible, visible);

            if (parentFolder != null)
            {
                SetParent(resFolder, parentFolder);
            }
            else
            {
                Folder.SetAsRoot(resFolder);
            }
            resFolder.EndUpdate();
            _resourceTreeManager.SetResourceNodeSort(resFolder, STR.Name);
            return(resFolder);
        }