public override void CheckResource(IResource res, IPropertyChangeSet cs) { object propValue = res.GetProp(_propId); if (propValue != null) { IResourceList resList = MyPalStorage.Storage.FindResources(res.Type, _propId, propValue); if (resList.Count > 1) { int dupId = -1; for (int i = 0; i < resList.Count; i++) { if (resList.ResourceIds [i] != res.Id) { dupId = resList.ResourceIds [i]; } } MyPalStorage.Storage.SetRepairRequired(); if (dupId != -1) { // it's an actual data consistency problem, not a problem with // the indexes throw new ResourceRestrictionException("Resource of type " + res.Type + ", ID=" + res.Id + " doesn't correspond to unique restriction on property " + MyPalStorage.Storage.GetPropName(_propId) + ": same value <" + propValue + "> as resource ID=" + dupId); } } } }
internal override PredicateMatch MatchResource(IResource res, IPropertyChangeSet cs) { PredicateMatch match = MatchResourceByLink(res, cs, _directPropType); if (match != PredicateMatch.Match && _directPropType != _reversePropType) { PredicateMatch match2 = MatchResourceByLink(res, cs, _reversePropType); if (match2 == PredicateMatch.Match) { return(match2); } if (match == PredicateMatch.Add && match2 == PredicateMatch.Del) { return(PredicateMatch.Match); } if (match == PredicateMatch.Del && match2 == PredicateMatch.Add) { return(PredicateMatch.Match); } if (match != PredicateMatch.None) { return(match); } return(match2); } return(match); }
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); } } } } }
private void NotifyList(ArrayList list, IResource resource, IPropertyChangeSet changeSet, bool deleting) { bool needCompact = false; int startCount = list.Count; for (int index = 0; index < startCount; index++) { IUpdateListener listener = null; lock ( list ) { WeakReference weakRef = (WeakReference)list [index]; if (!weakRef.IsAlive || weakRef.Target == null) { needCompact = true; continue; } listener = (IUpdateListener)weakRef.Target; } if (deleting) { listener.ResourceDeleting(resource); } else { listener.ResourceSaved(resource, changeSet); } } if (needCompact && _reentryLevel == 1) { CompactList(list); } }
void IUpdateListener.ResourceSaved(IResource resource, IPropertyChangeSet changeSet) { if (!_handlersAttached) { return; } switch (_predicate.MatchResource(resource, changeSet)) { case PredicateMatch.Add: Add(resource); break; case PredicateMatch.Match: if ((ResourceChangedInternal != null || _lastComparer != null) && ChangesIntersectWatches(changeSet)) { int index = -1; if (_list != null) { index = IndexOf(resource); } ProcessResourceChanged(resource, index, changeSet); } break; case PredicateMatch.Del: Remove(resource, changeSet); break; } }
public void NotifyResourceSaved(IResource resource, IPropertyChangeSet changeSet) { Interlocked.Increment(ref _reentryLevel); ArrayList list; lock ( _typedUpdateListeners ) { list = (ArrayList)_typedUpdateListeners [resource.TypeId]; } if (list != null) { NotifyList(list, resource, changeSet, false); } if (changeSet != null && changeSet.IsPropertyChanged(ResourceProps.Type)) { int oldType = (int)changeSet.GetOldValue(ResourceProps.Type); lock ( _typedUpdateListeners ) { list = (ArrayList)_typedUpdateListeners [oldType]; } if (list != null) { NotifyList(list, resource, changeSet, false); } } NotifyList(_priorityUpdateListeners, resource, changeSet, false); NotifyList(_untypedUpdateListeners, resource, changeSet, false); Interlocked.Decrement(ref _reentryLevel); }
public void ResourceChanged(IResource res, IPropertyChangeSet cs) { Core.UIManager.QueueUIJob(new ResourceDelegate(DoUpdateResource), res); if (cs.IsPropertyChanged(Core.Props.UserResourceOrder)) { Core.UserInterfaceAP.QueueJob("Rearrange Children", new RearrangeChildrenDelegate(_owner.RearrangeChildren), res); } }
internal override PredicateMatch MatchResource( IResource res, IPropertyChangeSet cs ) { int oldMatchL = 0, newMatchL = 0, oldMatchR = 0, newMatchR = 0; _lhs.GetMatchCounts( res, cs, ref oldMatchL, ref newMatchL ); _rhs.GetMatchCounts( res, cs, ref oldMatchR, ref newMatchR ); return MatchFromCounts( oldMatchL - oldMatchR, newMatchL - newMatchR ); }
public override void CheckResource(IResource res, IPropertyChangeSet cs) { if (_restriction == null) { throw new ResourceRestrictionException("Custom resource restriction implementation not registered"); } _restriction.CheckResource(res); }
public IPropertyChangeSet Merge(IPropertyChangeSet other) { MultiPropChangeSet mergeResult = new MultiPropChangeSet(_newResource || other.IsNewResource); MergeWith(mergeResult); (other as PropertyChangeSetBase).MergeWith(mergeResult); return(mergeResult); }
public bool IsThreadChanged(IResource res, IPropertyChangeSet changeSet) { IResourceThreadingHandler handler = GetResourceThreadingHandler(res); if (handler != null) { return(handler.IsThreadChanged(res, changeSet)); } return(false); }
private void OnContainerChanged(object sender, ResourcePropIndexEventArgs args) { IPropertyChangeSet set = args.ChangeSet; if (set.IsPropertyChanged(_itemLink) || (_folderLink >= 0 && set.IsPropertyChanged(_folderLink))) { if (DecorationChanged != null) { DecorationChanged(this, new ResourceEventArgs(args.Resource)); } } }
/** * 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)); } }
internal void GetMatchCounts(IResource res, IPropertyChangeSet cs, ref int oldMatch, ref int newMatch) { PredicateMatch match = MatchResource(res, cs); if (match == PredicateMatch.Add || match == PredicateMatch.Match) { newMatch++; } if (match == PredicateMatch.Del || match == PredicateMatch.Match) { oldMatch++; } }
/** * Checks if the specified property change set intersects the set of watched * properties on the resource list. */ private bool ChangesIntersectWatches(IPropertyChangeSet cs) { if (_watchedProperties == null || cs == null) { return(true); } if (_watchDisplayName && cs.IsDisplayNameAffected) { return(true); } return((cs as PropertyChangeSetBase).Intersects(_watchedProperties)); }
internal override PredicateMatch MatchResource(IResource res, IPropertyChangeSet cs) { if (Array.IndexOf(_resTypeIds, res.TypeId) >= 0) { return((cs != null && (cs.IsNewResource || cs.IsPropertyChanged(ResourceProps.Type))) ? PredicateMatch.Add : PredicateMatch.Match); } else if (cs != null && cs.IsPropertyChanged(ResourceProps.Type) && Array.IndexOf(_resTypeIds, (int)cs.GetOldValue(ResourceProps.Type)) >= 0) { return(PredicateMatch.Del); } return(PredicateMatch.None); }
internal override PredicateMatch MatchResource(IResource res, IPropertyChangeSet cs) { int oldMatch = 0; int newMatch = 0; for (int i = 0; i < _sourcePredicates.Length; i++) { _sourcePredicates [i].GetMatchCounts(res, cs, ref oldMatch, ref newMatch); if (newMatch > 0 && oldMatch > 0) { break; } } return(MatchFromCounts(oldMatch, newMatch)); }
internal override PredicateMatch MatchResource(IResource res, IPropertyChangeSet cs) { if (MatchValue(res.GetProp(_propId))) { if (cs != null && cs.IsPropertyChanged(_propId) && !MatchValue(cs.GetOldValue(_propId))) { return(CheckSnapshotAdd(res.Id)); } return(PredicateMatch.Match); } else if (cs != null && MatchValue(cs.GetOldValue(_propId))) { return(CheckSnapshotRemove(res.Id)); } return(CheckSnapshotNoMatch(res.Id)); }
protected internal void Remove(IResource res, IPropertyChangeSet cs) { if (_list == null) { RemoveAt(res, -1, cs); } else { lock (this) { int index = IndexOf(res.Id); if (index >= 0) { RemoveAt(res, index, cs); } } } }
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); }
/** * Returns the list of all link types for the given resource. If the resource * was changed, the list also includes the link types which were present on * the resource before the change. */ private IntArrayList GetAllLinkTypes(IResource res, IPropertyChangeSet cs) { IntArrayList linkTypeIDs = new IntArrayList(res.GetLinkTypeIds()); if (cs != null) { int[] changedPropIDs = cs.GetChangedProperties(); for (int i = 0; i < changedPropIDs.Length; i++) { int propID = changedPropIDs [i]; if (_store.PropTypes [propID].DataType == PropDataType.Link && linkTypeIDs.IndexOf(propID) < 0) { linkTypeIDs.Add(propID); } } } return(linkTypeIDs); }
private void WeblinkOrFolderChanged(object sender, ResourcePropIndexEventArgs e) { IResource webLink = e.Resource; IPropertyChangeSet set = e.ChangeSet; int propLastModified = Core.ResourceStore.PropTypes["LastModified"].Id; if (BookmarkService.DownloadMethod != 2 && webLink == _lastDisplayedWeblink && ((set.IsPropertyChanged(propLastModified) && webLink.HasProp("Source")) || (set.IsPropertyChanged(Core.Props.LastError) && webLink.HasProp(Core.Props.LastError)))) { // if the displayed web link has changed, redisplay it IResourceBrowser browser = Core.ResourceBrowser; if ((webLink == _favoritesTreePane.SelectedNode && Core.TabManager.CurrentTabId == "Web") || (browser.SelectedResources.Count == 1 && webLink == browser.SelectedResources[0])) { Core.UserInterfaceAP.QueueJobAt(DateTime.Now.AddSeconds(1), "RedisplaySelectedResource", browser.RedisplaySelectedResource); } } string URL = webLink.GetPropText(_propURL); if (URL.Length > 0) { if (set.IsPropertyChanged(_propLastUpdated) || set.IsPropertyChanged(_propUpdateFreq)) { BookmarkService.QueueWeblink(webLink, URL, BookmarkService.BookmarkSynchronizationTime(webLink)); } if (set.IsPropertyChanged(_propURL)) { BookmarkService.ImmediateQueueWeblink(webLink, URL); } } if (set.IsPropertyChanged(Core.PropIds.Name) || set.IsPropertyChanged(_propURL)) { IBookmarkProfile profile = _bookmarkService.GetOwnerProfile(webLink); string error; if (profile != null && profile.CanCreate(webLink, out error)) { profile.Create(webLink); } } }
internal override PredicateMatch MatchResource(IResource res, IPropertyChangeSet cs) { int linkCount = res.GetLinkCount(_propId); if (linkCount > 0) { if (cs != null && GetLinkCountDelta(cs, _propId) == linkCount) { return(CheckSnapshotAdd(res.Id)); } return(PredicateMatch.Match); } else if (cs != null && GetLinkCountDelta(cs, _propId) < 0) { return(CheckSnapshotRemove(res.Id)); } return(CheckSnapshotNoMatch(res.Id)); }
private PredicateMatch MatchResourceByLink(IResource res, IPropertyChangeSet cs, int propID) { LinkChangeType chg = LinkChangeType.None; if (cs != null) { chg = cs.GetLinkChange(propID, _baseResource.Id); } switch (chg) { case LinkChangeType.Add: return(PredicateMatch.Add); case LinkChangeType.Delete: return(PredicateMatch.Del); default: return(res.HasLink(propID, _baseResource) ? PredicateMatch.Match : PredicateMatch.None); } }
protected void RemoveAt(IResource res, int index, IPropertyChangeSet cs) { // proceed with delete even if the ResourceDeleting handler throws an exception try { if (ResourceDeletingInternal != null) { ResourceDeletingInternal(this, new ResourceIndexEventArgs(res, index)); } if (cs != null && ChangedResourceDeletingInternal != null) { ChangedResourceDeletingInternal(this, new ResourcePropIndexEventArgs(res, index, cs)); } } finally { if (index >= 0) { _list.RemoveAt(index); } } }
/// <summary> /// Copies <paramref name="record"/> and applies the changes in <paramref name="changeSet"/>. /// If there are no changes then <paramref name="record"/> is returned. /// </summary> /// <typeparam name="TRecord">The record type.</typeparam> /// <param name="changeSet"></param> /// <param name="record"></param> /// <returns> /// A copy of <paramref name="record"/> with changes or <paramref name="record"/> if there /// are no changes to apply. /// </returns> public static TRecord ToNewRecord <TRecord>(this IPropertyChangeSet <TRecord> changeSet, IRecord <TRecord> record) { // potentially unsafe cast? var original = (TRecord)record; if (changeSet.Mutators.Count > 0) { var copy = record.ShallowCopy(); foreach (var mutator in changeSet.Mutators) { mutator.ApplyMutation(original, copy); } record.ThrowIfConstraintsAreViolated(copy); return(copy); } else { return(original); } }
public static void CheckResource(IResource res, IPropertyChangeSet changeSet) { if (_active) { lock ( _restrictions ) { HashSet restrictionsSet = (HashSet)_restrictions[res.Type]; if (restrictionsSet != null) { foreach (HashSet.Entry E in restrictionsSet) { ResourceRestriction restriction = (ResourceRestriction)E.Key; if ((restriction.PropId != ResourceProps.Id && changeSet.IsNewResource) || changeSet.IsPropertyChanged(restriction.PropId)) { restriction.CheckResource(res, changeSet); } } } } } }
internal override PredicateMatch MatchResource(IResource res, IPropertyChangeSet cs) { int oldMatch = 0; int newMatch = 0; int len = _sourcePredicates.Length; for (int i = 0; i < len; i++) { PredicateMatch match = _sourcePredicates [i].MatchResource(res, cs); if (match == PredicateMatch.Add || match == PredicateMatch.Match) { newMatch++; } if (match == PredicateMatch.Del || match == PredicateMatch.Match) { oldMatch++; } if (newMatch == 0 && oldMatch == 0) { break; } } if (newMatch == len && oldMatch == len) { return(PredicateMatch.Match); } if (newMatch == len) { return(PredicateMatch.Add); } if (oldMatch == len) { return(PredicateMatch.Del); } return(PredicateMatch.None); }
/** * 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); } } } } }
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); } } } } }