private void ToolStripItemClicked(MruItem item) { if (MruItemClicked != null) { MruItemClicked(item.FilePathName); } }
/// <summary> /// Insert item into caceh /// </summary> /// <param name="key">Dictionary Key</param> /// <param name="value">Dictionary Value</param> /// <returns>Key did not exist already</returns> public bool TryAddValue(TKey key, TValue value) { lock (_dictionary) { MruItem item; if (_dictionary.TryGetValue(key, out item)) { var version = _currentVersion; if (item.Version != version || !EqualityComparer <TValue> .Default.Equals(value, item.Value)) { _dictionary[key] = new MruItem(value, version, false); } return(false); // Already exists } else { if (_dictionary.Count >= _maxCapacity) { ++_currentVersion; PruneCache(); } _dictionary.Add(key, new MruItem(value, _currentVersion, true)); return(true); } } }
private void DownloadAndOpenDataServicePackage(MruItem item) { if (!NetworkInterface.GetIsNetworkAvailable()) { UIServices.Show( PackageExplorer.Resources.Resources.NoNetworkConnection, MessageLevel.Warning); return; } Uri downloadUrl; if (Uri.TryCreate(item.Path, UriKind.Absolute, out downloadUrl)) { var progressWindow = new DownloadProgressWindow(downloadUrl, item.Id, item.Version) { Owner = this }; var result = progressWindow.ShowDialog(); if (result ?? false) { LoadPackage(progressWindow.DownloadedPackage, item.Path, PackageType.DataServicePackage); } } }
public void NotifyFileAdded(IPackageMetadata package, string filepath, PackageType packageType) { var item = new MruItem { Path = filepath.ToLowerInvariant(), Id = package.Id, Version = package.Version, PackageType = packageType }; AddFile(item); }
private void AddFile(MruItem mruItem) { if (mruItem == null) { throw new ArgumentNullException(nameof(mruItem)); } Files.Remove(mruItem); Files.Insert(0, mruItem); if (Files.Count > MaxFile) { Files.RemoveAt(Files.Count - 1); } }
private void AddFile(MruItem mruItem) { if (mruItem == null) { throw new ArgumentNullException("mruItem"); } _files.Remove(mruItem); _files.Insert(0, mruItem); if (_files.Count > MaxFile) { _files.RemoveAt(_files.Count - 1); } }
public override CacheItem GetCacheItem(string key, string regionName = null) { if (key == null) { throw new ArgumentNullException("key"); } MruItem mruEntry = null; var cacheKey = new CacheKey(key); // code block to get item from store and if found, return it if not expired. Func <bool> block = (() => { lock (_locker) { // try to get from the store mruEntry = MruManager.GetItem(cacheKey); if (mruEntry != null) { cacheKey = (CacheKey)mruEntry.Key; if (IsNotExpired(cacheKey, (CacheEntry)mruEntry.Value, false)) { return(true); } } return(false); } }); if (block()) { return(new CacheItem(key, mruEntry.Value)); } #region try to update the Cache entry if it is expired by calling the Update callback. if (CacheEntrySetUpdateCallback == null) { return(null); } CacheEntrySetUpdateCallback(new CacheEntryUpdateArguments[] { new CacheEntryUpdateArguments(this, CacheEntryRemovedReason.Expired, key, null) }); // try to get from the store a 2nd time and see if item got updated & no longer expired... if (block()) { return(new CacheItem(key, mruEntry.Value)); } #endregion return(null); }
public MruManager(ISettingsManager settingsManager) { IList <string> savedFiles = settingsManager.GetMruFiles(); _files = new ObservableCollection <MruItem>(); for (int i = savedFiles.Count - 1; i >= 0; --i) { string s = savedFiles[i]; MruItem item = ConvertStringToMruItem(s); if (item != null) { AddFile(item); } } _settingsManager = settingsManager; }
/// <summary> /// Lookup existing item in cache /// </summary> /// <param name="key">Dictionary Key</param> /// <param name="value">Dictionary Value [out]</param> /// <returns>Key found</returns> public bool TryGetValue(TKey key, out TValue value) { MruItem item; try { if (!_dictionary.TryGetValue(key, out item)) { value = default(TValue); return(false); } } catch { item = default(MruItem); // Too many people in the same room } if (item.Version != _currentVersion || item.Virgin) { // Update item version to mark as recently used lock (_dictionary) { var version = _currentVersion; if (_dictionary.TryGetValue(key, out item)) { if (item.Version != version || item.Virgin) { if (item.Virgin) { version = ++_currentVersion; } _dictionary[key] = new MruItem(item.Value, version, false); } } else { value = default(TValue); return(false); } } } value = item.Value; return(true); }
public void UsedFile(string filePath) { var item = _items.Find((compareItem) => string.Equals(compareItem.FilePathName, filePath, StringComparison.InvariantCultureIgnoreCase)); if (item == null) { item = new MruItem(this, filePath); } else { //remove it because below we are going to add it to the top again: item.Owner.Items.Remove(item); _items.Remove(item); } _items.Insert(0, item); PlaceHolderOwner.Items.Insert(PlaceHolderIndexInOwner + 1, item); OnItemsChanged(); }
public void UsedFile(string filePath) { var item = _items.Find((compareItem) => string.Equals(compareItem.FilePathName, filePath, StringComparison.InvariantCultureIgnoreCase)); if (item == null) { item = new MruItem(this, filePath); _items.Add(item); //since this might be the first item, make sure the placeholder is now invisible: this._placeHolderItem.Visible = false; } else { //remove it because below we are going to add it to the top again: item.Owner.Items.Remove(item); } PlaceHolderOwner.Items.Insert(PlaceHolderIndexInOwner + 1, item); // enumerate items and make sure that they have the proper number in front of their caption & proper keyboard shortcut FixupMenuItems(); }
internal Task DownloadAndOpenDataServicePackage(MruItem item) { return(DownloadAndOpenDataServicePackage(item.Path, item.Id, item.Version?.SemanticVersion)); }
private void ToolStripItemClicked(MruItem item) { if (MruItemClicked != null) MruItemClicked(item.FilePathName); }
public void UsedFile(string filePath) { var item = _items.Find((compareItem) => string.Equals(compareItem.FilePathName, filePath, StringComparison.InvariantCultureIgnoreCase)); if (item == null) { item = new MruItem(this, filePath); } else { //remove it because below we are going to add it to the top again: item.Owner.Items.Remove(item); _items.Remove(item); } _items.Insert(0,item); PlaceHolderOwner.Items.Insert(PlaceHolderIndexInOwner + 1, item); OnItemsChanged(); }
/// <summary> /// Insert item into caceh /// </summary> /// <param name="key">Dictionary Key</param> /// <param name="value">Dictionary Value</param> /// <returns>Key did not exist already</returns> public bool TryAddValue(TKey key, TValue value) { lock (_dictionary) { MruItem item; if (_dictionary.TryGetValue(key, out item)) { var version = _currentVersion; if (item.Version != version || !EqualityComparer <TValue> .Default.Equals(value, item.Value)) { _dictionary[key] = new MruItem(value, version); } return(false); // Already exists } else { var version = ++_currentVersion; if (_dictionary.Count >= _maxCapacity) { // Make 3 sweeps: // 1) Versions below _currentVerison - _maxCapacity / 1.5 // 2) Versions below _currentVerison - _maxCapacity / 10 // 3) Versions below _currentVerison - 2 var pruneKeys = new List <TKey>(_dictionary.Count); for (int i = 1; i <= 3; ++i) { long oldVersion = version - 2; switch (i) { case 1: oldVersion = version - (int)(_maxCapacity / 1.5); break; case 2: oldVersion = version - _maxCapacity / 10; break; } foreach (var element in _dictionary) { if (element.Value.Version <= oldVersion) { pruneKeys.Add(element.Key); if (_dictionary.Count - pruneKeys.Count < _maxCapacity / 1.5) { i = 3; break; // Do not clear the entire cache } } } } foreach (var pruneKey in pruneKeys) { _dictionary.Remove(pruneKey); } if (_dictionary.Count >= _maxCapacity) { _dictionary.Clear(); // Failed to perform sweep, fallback to fail safe } } _dictionary.Add(key, new MruItem(value, version)); return(true); } } }
public Node(MruItem data) { this.Data = data; }
private static string ConvertMruItemToString(MruItem item) { // in v1.0, we stored MruItem as "{path}|{package name}|{package type}" return(string.Format(CultureInfo.InvariantCulture, "{0}|{1}|{2}|{3}", item.Id, item.Version, item.Path, item.PackageType)); }
private BaseItem CreateMruPlaceView(MruItem item) { ItemDockContainer container = new ItemDockContainer(); container.LastChildFill = true; // Create Pin Button ButtonItem pinButton = new ButtonItem(); pinButton.ImagePaddingHorizontal = 6; pinButton.Image = global::Einstein.Platform.Properties.Resources.Unpinned; container.SetDock(pinButton, eItemDock.Right); // Position pin button on right side container.SubItems.Add(pinButton); // Create button with file name and folder ButtonItem fileButton = new ButtonItem(); fileButton.ForeColor = Color.Black; fileButton.ButtonStyle = eButtonStyle.ImageAndText; fileButton.ImagePosition = eImagePosition.Left; fileButton.Text = item.FileName + "<br/><font color=\"Gray\">" + item.Folder + "</font>"; fileButton.Image = global::Einstein.Platform.Properties.Resources.OpenExistingPlace; container.SubItems.Add(fileButton); return container; }
private static string ConvertMruItemToString(MruItem item) { // in v1.0, we stored MruItem as "{path}|{package name}|{package type}" return String.Format(CultureInfo.InvariantCulture, "{0}|{1}|{2}|{3}", item.Id, item.Version, item.Path, item.PackageType); }
public Node(MruItem <TKey, TValue> data) { this.Data = data; }