private void _btnWeakCacheDetails_Click(object sender, System.EventArgs e) { HashSet hashSet = new HashSet(); int totalMemorySize = 0; CountedSet cacheEntries = new CountedSet(); foreach (IntHashTable.Entry entry in MyPalStorage.Storage.ResourceWeakCache) { WeakReference weakRef = (WeakReference)entry.Value; Resource res = (Resource)weakRef.Target; hashSet.Add(res.Id); cacheEntries.Add(res.Type); totalMemorySize += res.EstimateMemorySize(); } foreach (Resource res in MyPalStorage.Storage.ResourceCache) { if (res != null && !hashSet.Contains(res.Id)) { cacheEntries.Add(res.Type); totalMemorySize += res.EstimateMemorySize(); } } StringBuilder builder = new StringBuilder(); cacheEntries.SortByCount(); foreach (CountedSet.Entry de in cacheEntries) { builder.Append(de.Count + " - " + de.Value + "\n"); } builder.Append("Estimated memory size " + totalMemorySize / 1024 + "K"); _lblResourceWeakCacheDetails.Text = builder.ToString(); }
public void IfItemIsAddedToSetMultipleTimesRemoveDoesNotCompletelyRemoveItem() { var set = new CountedSet <string>(); set.Add("foo"); set.Add("foo"); set.Remove("foo"); Assert.IsTrue(set.Contains("foo")); }
public void CountedSetSupportsLookupByKey() { var set = new CountedSet <string>(); set.Add("foo"); set.Add("foo"); int count = set["foo"]; Assert.AreEqual(2, count); }
public void CountedSetAddsItem() { var set = new CountedSet <string>(); set.Add("foo"); Assert.AreEqual(1, set.Count); }
public void IfItemIsAddedToSetMultipleTimesRemoveReducesCountByOne() { int firstCount = 0; int secondCount = 0; var set = new CountedSet <string>(); set.Add("foo"); set.Add("foo"); set.TryGetCount("foo", out firstCount); set.Remove("foo"); set.TryGetCount("foo", out secondCount); Assert.AreEqual(2, firstCount); Assert.AreEqual(1, secondCount); }
public void IfItemIsAddedToSetOnceRemoveCompletelyRemovesItem() { var set = new CountedSet <string>(); set.Add("foo"); set.Remove("foo"); Assert.IsFalse(set.Contains("foo")); }
public void RemoveReturnsTrueIfSetDoesNotContainItem() { var set = new CountedSet <string>(); set.Add("foo"); bool result = set.Remove("foo"); Assert.IsTrue(result); }
public void IfItemIsAddedToSetOnceAssociatedCountIsOne() { int count = 0; var set = new CountedSet <string>(); set.Add("foo"); set.TryGetCount("foo", out count); Assert.AreEqual(1, count); }
public void CountedSetMaintainsDistinctCountForDifferentItems() { int fooCount = 0; int barCount = 0; var set = new CountedSet <string>(); set.Add("foo"); set.Add("foo"); set.Add("foo"); set.Add("bar"); set.Add("bar"); set.TryGetCount("foo", out fooCount); set.TryGetCount("bar", out barCount); Assert.AreEqual(3, fooCount); Assert.AreEqual(2, barCount); }
public void IfItemIsAddedToSetMutlipleTimesItMustBeRemovedAnEqualNumberOfTimes() { bool firstCheck = false; bool secondCheck = false; bool thirdCheck = false; var set = new CountedSet <string>(); set.Add("foo"); set.Add("foo"); set.Add("foo"); set.Remove("foo"); firstCheck = set.Contains("foo"); set.Remove("foo"); secondCheck = set.Contains("foo"); set.Remove("foo"); thirdCheck = set.Contains("foo"); Assert.IsTrue(firstCheck); Assert.IsTrue(secondCheck); Assert.IsFalse(thirdCheck); }
public void IfItemIsAddedToSetMultipleTimesAssociatedCountIsIncreasedByOne() { int firstCount = 0; int secondCount = 0; int thirdCount = 0; var set = new CountedSet <string>(); //add first time set.Add("foo"); set.TryGetCount("foo", out firstCount); //add second time set.Add("foo"); set.TryGetCount("foo", out secondCount); //add third time set.Add("foo"); set.TryGetCount("foo", out thirdCount); Assert.AreEqual(1, firstCount); Assert.AreEqual(2, secondCount); Assert.AreEqual(3, thirdCount); }
/// <summary> /// Shows the "See also" links for every resource type that is found in the /// specified resource list but not included in the specified array of resource types. /// </summary> public void ShowLinks(IResource ownerResource, IResourceList resList, string[] excludeResTypes, int excludeLinkPropId) { #region Preconditions if (!Core.UserInterfaceAP.IsOwnerThread) { throw new InvalidOperationException("See Also bar must be shown from the UI thread"); } #endregion Preconditions CountedSet countByTab = new CountedSet(); IntArrayList sourceLinkTypes = IntArrayListPool.Alloc(); try { foreach (IPropType propType in Core.ResourceStore.PropTypes) { if (propType.HasFlag(PropTypeFlags.SourceLink)) { sourceLinkTypes.Add(propType.Id); } } WorkspaceManager wspMgr = Core.WorkspaceManager as WorkspaceManager; IResource activeWorkspace = Core.WorkspaceManager.ActiveWorkspace; bool filterViewsExclusive = false; if (ownerResource.Type == "SearchView" && !ownerResource.HasProp("ShowInAllTabs")) { filterViewsExclusive = true; } int outsideWorkspaceCount = 0, unfoundCount = 0; IResourceList actualRcs = resList; lock ( actualRcs ) { foreach (IResource res in actualRcs.ValidResources) { string resType = res.Type; if (resType == "Fragment") { resType = res.GetStringProp(Core.Props.ContentType); // guard for broken DB (OM-12080) if (resType == null || !Core.ResourceStore.ResourceTypes.Exist(resType)) { continue; } } if (activeWorkspace != null && !activeWorkspace.HasLink(wspMgr.Props.WorkspaceVisible, res)) { outsideWorkspaceCount++; continue; } if (excludeResTypes != null && IsTabType(resType, excludeResTypes)) { continue; } if (excludeLinkPropId >= 0 && res.HasProp(excludeLinkPropId)) { continue; } if (filterViewsExclusive && Core.ResourceTreeManager.AreViewsExclusive(resType)) { continue; } bool found = false; if (Core.ResourceStore.ResourceTypes[resType].HasFlag(ResourceTypeFlags.FileFormat)) { foreach (int sourceLinkType in sourceLinkTypes) { if (res.HasProp(sourceLinkType)) { string tabId = Core.TabManager.FindLinkPropTab(sourceLinkType); if (tabId != null) { countByTab.Add(tabId); } found = true; break; } } } else { string resourceTabId = Core.TabManager.FindResourceTypeTab(resType); if (resourceTabId != null) { countByTab.Add(resourceTabId); found = true; } } if (!found) { unfoundCount++; } } } if (countByTab.Count == 0 && unfoundCount == 0 && outsideWorkspaceCount == 0) { Visible = false; return; } _iconPool.MoveControlsToPool(); _linkLabelPool.MoveControlsToPool(); int x = _title.Right + 4; int labelCount = 0; for (int i = 0; i < Core.TabManager.Tabs.Count; i++) { string tabId = Core.TabManager.Tabs[i].Id; int count = countByTab[tabId]; if (count > 0) { string text = Core.TabManager.Tabs[i].Name + " (" + count.ToString() + ")"; AddLinkLabel(tabId, text, ref x); labelCount++; } } if ((labelCount > 1 || unfoundCount > 0) && (excludeResTypes != null || excludeLinkPropId >= 0)) { AddLinkLabel("", "All Results (" + (resList.Count - outsideWorkspaceCount) + ")", ref x); } if (outsideWorkspaceCount > 0) { string sDefaultWspName = ((WorkspaceManager)Core.WorkspaceManager).Props.DefaultWorkspaceName; AddLinkLabel("<Main>", String.Format("{0} Workspace ({1})", sDefaultWspName, resList.Count), ref x); } _iconPool.RemovePooledControls(); _linkLabelPool.RemovePooledControls(); Visible = true; } finally { IntArrayListPool.Dispose(sourceLinkTypes); } }