Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        protected override void Execute()
        {
            IResource task = GetTaskResource();

            if (task == null)
            {
                Tracer._Trace("TASK IMPORT task not found");
            }
            if (task != null)
            {
                if (_folder.ContainerClass != FolderType.Task)
                {
                    Tracer._Trace("Delete task: id = " + task.Id);
                    task.Delete();
                    return;
                }
            }

            IResource resFolder     = Folder.Find(_folder.FolderIDs.EntryId);
            bool      folderIgnored = (resFolder != null && Folder.IsIgnored(resFolder)) || OutlookSession.IsDeletedItemsFolder(_folder.FolderIDs.EntryId);

            if (folderIgnored)
            {
                if (task != null)
                {
                    task.Delete();
                }
                return;
            }

            bool import = resFolder != null && !Folder.IsIgnoreImport(resFolder);

            if (!import && task == null)
            {
                return;
            }

            if (task == null)
            {
                task = Core.ResourceStore.BeginNewResource(STR.Task);
            }
            else
            {
                task.BeginUpdate();
            }

            string oldEntryID = task.GetStringProp(PROP.EntryID);

            if (oldEntryID == null)
            {
                task.SetProp(PROP.EntryID, _entryID);
            }
            else if (oldEntryID != _entryID)
            {
                throw new ApplicationException("Try to change entryID for task");
            }
            if (resFolder != null)
            {
                Folder.LinkMail(resFolder, task);
            }

            if (!import)
            {
                task.EndUpdate();
                if (Settings.TraceTaskChanges)
                {
                    _tracer.Trace(task);
                }
                return;
            }

            task.SetProp(Core.Props.Subject, _subject);

            SetDateProp(task, Core.Props.Date, _dueDate);
            SetDateProp(task, PROP.StartDate, _startDate);

            if (_reminderActive == 0)
            {
                SetDateProp(task, PROP.RemindDate, DateTime.MinValue);
            }
            else
            {
                SetDateProp(task, PROP.RemindDate, _remindDate);
            }

            task.SetProp(PROP.Status, _status);
            task.SetProp(PROP.Priority, _priority);
            task.SetProp(PROP.Description, _description);
            task.AddLink(PROP.Target, Core.ResourceTreeManager.GetRootForType(STR.Task));
            if (!task.HasProp(PROP.SuperTaskLink))
            {
                task.SetProp(PROP.SuperTaskLink, Core.ResourceTreeManager.GetRootForType(STR.Task));
            }

            if (Settings.SyncTaskCategory)
            {
                CategorySetter.DoJob(_outlookCategories, task);
            }

            bool wereChanges = task.IsChanged();

            task.EndUpdate();
            if (wereChanges && Core.TextIndexManager != null)
            {
                Guard.QueryIndexingWithCheckId(task);
            }
            if (Settings.TraceTaskChanges)
            {
                _tracer.Trace(task);
            }
        }