private void UpdateTags(TagAction action, IReadOnlyCollection <string> hashes, string tag) { _lock.Write(() => { var touched = new List <ItemPreviewModel>(); foreach (var hash in hashes) { if (_previewModels.TryGetValue(hash, out var item)) { if (action == TagAction.Add) { item.Tags.Add(tag); _tagManager.Add(tag); } else { item.Tags.Remove(tag); } touched.Add(item); } } _previewStreams.ForEach(s => s.Update(touched)); }); }
public static void Reflect(TagManager dest, TagTreeViewItemModelManager source) { foreach (var deletedTag in source.DeletedTags) { dest.Remove(deletedTag.Id); } dest.ReconnectAllToBaseTag(); foreach (var tag in source.AddedTags) { var addNewTag = new TagModel(tag.Id) { Name = tag.Name }; dest.Add(addNewTag); dest.ConnectTags(dest.GetBaseTag(), addNewTag); } foreach (var tag in dest.TagDictionary.Values) { if (tag.IsBase()) { continue; } var sourceTag = source.TagDictionary[tag.Id]; var parent = dest.TagDictionary[sourceTag.Parent.Id]; dest.DisconnectFromParent(tag); dest.ConnectTags(parent, tag); tag.Name = sourceTag.Name; } }
public static void Expand(IEnumerable <SaveTagModel> tagModels, TagManager manager) { foreach (var saveTagModel in tagModels) { manager.Add(GetTag(saveTagModel)); } foreach (var saveTagModel in tagModels) { var parent = manager.TagDictionary[saveTagModel.ParentId]; var self = manager.TagDictionary[saveTagModel.Id]; manager.ConnectTags(parent, self); } }
public void RecommendationsForTaggingShouldIncludeUnmatched() { var search = "test"; var previous = new[] { "test1" }; var expected = new[] { "test2" }; var tagged = new[] { new Tagged { Tags = { "test1" } } }; var tagManager = new TagManager(); tagManager.AddFrom(tagged); tagManager.Add("test2"); var results = tagManager.GetRecommendations(tagged, previous, search, Tagging); Assert.IsTrue(expected.SequenceEqual(results.Select(r => r.SearchTag))); }
public void Create(string text, Color color) { #region create new tag function goes here Tag tag = new Tag() { Text = text, Color = new SolidColorBrush(color), item = new TagItem() { TagColor = new System.Drawing.Color(), Content = text, ID = currentTagList.Count } }; tag.StateChanged += new EventHandler(this.Tag_StateChange); tag.Remove += new EventHandler(this.Tag_Remove); StpTagList.Children.Add(tag); tagManager.Add(tag.item); #endregion }