Exemplo n.º 1
0
        private void ProcessUnreadCountedLinksChange(IResource res, IPropertyChangeSet cs)
        {
            UnreadState[] unreadStates = GetResourceUnreadStates(res);

            int[] propIDs = cs.GetChangedProperties();
            for (int i = 0; i < propIDs.Length; i++)
            {
                int propID = propIDs [i];
                if (_store.PropTypes [propID].HasFlag(PropTypeFlags.CountUnread))
                {
                    foreach (LinkChange change in cs.GetLinkChanges(propID))
                    {
                        IResource target = _store.TryLoadResource(change.TargetId);
                        if (target == null)
                        {
                            continue;
                        }

                        int delta = (change.ChangeType == LinkChangeType.Add) ? 1 : -1;

                        foreach (UnreadState state in unreadStates)
                        {
                            AdjustUnreadCount(target, delta, state);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        /**
         * main checking predicate
         * returns true if a resource corresponds to the restriction
         */
        public override void CheckResource(IResource res, IPropertyChangeSet cs)
        {
            if (res.Type != _resourceType)
            {
                return;
            }

            bool hasAdds = false, hasDeletes = false;

            LinkChange[] changes = cs.GetLinkChanges(_propId);
            for (int i = 0; i < changes.Length; i++)
            {
                if (changes [i].ChangeType == LinkChangeType.Add)
                {
                    hasAdds = true;
                    if (_toResourceType != null)
                    {
                        IResource target = MyPalStorage.Storage.TryLoadResource(changes [i].TargetId);
                        if (target != null && target.Type != _toResourceType)
                        {
                            throw new ResourceRestrictionException("Resource of type " + res.Type +
                                                                   " doesn't correspond to link resource type restriction on property " +
                                                                   MyPalStorage.Storage.GetPropName(_propId) +
                                                                   ": required links to " + _toResourceType + ", found link to " + target.Type);
                        }
                    }
                }
                else if (changes [i].ChangeType == LinkChangeType.Delete)
                {
                    hasDeletes = true;
                }
            }

            int linkCount = res.GetLinkCount(_propId);

            /**
             * at first check counts
             */
            if ((hasDeletes || changes.Length == 0) && linkCount < _minCount)
            {
                throw new ResourceRestrictionException("Resource of type " + res.Type +
                                                       " doesn't correspond to minimum link count restriction on property " +
                                                       MyPalStorage.Storage.GetPropName(_propId));
            }
            if (hasAdds && _maxCount >= 0 && linkCount > _maxCount)
            {
                throw new ResourceRestrictionException("Resource of type " + res.Type +
                                                       " doesn't correspond to maximum link count restriction on property " +
                                                       MyPalStorage.Storage.GetPropName(_propId));
            }
        }
Exemplo n.º 3
0
        private int GetLinkCountDelta(IPropertyChangeSet cs, int propId)
        {
            LinkChange[] linkChanges = cs.GetLinkChanges(propId);
            int          count       = 0;

            foreach (LinkChange change in linkChanges)
            {
                if (change.ChangeType == LinkChangeType.Add)
                {
                    count++;
                }
                else
                {
                    count--;
                }
            }
            return(count);
        }
Exemplo n.º 4
0
        /**
         * Increments the unread counters of resources linked with unread-counted links
         * to the specified resource by 'delta'. If cs is not null, the affected resources
         * are not the currently linked ones, but rather the ones linked before the changes
         * described by cs happened.
         */

        private void ProcessResourceUnreadChange(IResource res, int delta, IPropertyChangeSet cs)
        {
            UnreadState[] unreadStates = GetResourceUnreadStates(res);

            IntArrayList linkTypeIDs = GetAllLinkTypes(res, cs);

            for (int i = 0; i < linkTypeIDs.Count; i++)
            {
                int linkType = linkTypeIDs [i];
                if (IsUnreadCountedLink(linkType))
                {
                    IntArrayList linkedResList = new IntArrayList(res.GetLinksOfType(null, linkType).ResourceIds);
                    if (cs != null)
                    {
                        foreach (LinkChange change in cs.GetLinkChanges(linkType))
                        {
                            if (change.ChangeType == LinkChangeType.Add)
                            {
                                linkedResList.Remove(change.TargetId);
                            }
                            else
                            {
                                linkedResList.Add(change.TargetId);
                            }
                        }
                    }
                    for (int j = 0; j < linkedResList.Count; j++)
                    {
                        IResource linkRes = _store.LoadResource(linkedResList [j]);
                        foreach (UnreadState state in unreadStates)
                        {
                            AdjustUnreadCount(linkRes, delta, state);
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        private void ProcessWorkspaceChange(IResource res, IPropertyChangeSet cs)
        {
            IntHashTable defaultTabMap  = (IntHashTable)_unreadStateTabMap [_tabProvider.GetDefaultTab()];
            IntHashTable specificTabMap = null;
            string       resourceTab    = _tabProvider.GetResourceTab(res);

            if (resourceTab != null)
            {
                specificTabMap = (IntHashTable)_unreadStateTabMap [resourceTab];
            }

            LinkChange[] wsLinkChanges = cs.GetLinkChanges(_workspaceManager.Props.WorkspaceVisible);

            int[] linkTypes = res.GetLinkTypeIds();
            for (int i = 0; i < linkTypes.Length; i++)
            {
                if (IsUnreadCountedLink(linkTypes [i]))
                {
                    IResourceList linkList = res.GetLinksOfType(null, linkTypes [i]);
                    foreach (IResource link in linkList)
                    {
                        if (cs.GetLinkChange(linkTypes [i], link.Id) == LinkChangeType.Add)
                        {
                            continue;
                        }

                        foreach (LinkChange linkChange in wsLinkChanges)
                        {
                            int delta = (linkChange.ChangeType == LinkChangeType.Add) ? 1 : -1;
                            AdjustCounterInState(defaultTabMap, linkChange.TargetId, link, delta);
                            AdjustCounterInState(specificTabMap, linkChange.TargetId, link, delta);
                        }
                    }
                }
            }
        }