protected virtual WorkshopValidatedItem TestTags() { var originalTags = new TagsCollection(Target.Tags); var newTags = new TagsCollection(originalTags.Where(x => x != null && IsTagAllowed(x.ToLowerInvariant())) .Concat(GetForcedTags()).NonNull()).CleanUp().Sort(); for (var i = newTags.Count - 1; i >= MaxTagsCount; --i) { newTags.RemoveAt(i); } if (newTags.SequenceEqual(originalTags)) { return(new WorkshopValidatedItem("Tags are correct")); } return(new WorkshopValidatedItem($"Tags will be changed to {newTags.Select(x => $"“{x}”").JoinToString(", ")}", () => Target.Tags = newTags, () => Target.Tags = originalTags)); }
private void OnOkButtonClick(object sender, RoutedEventArgs e) { try { List <int> emptyIndices = new List <int>(); HashSet <string> original = new HashSet <string>(); HashSet <string> duplicates = new HashSet <string>(); int index = 0; foreach (UserTagView view in TagsCollection) { if (string.IsNullOrEmpty(view.Name)) { emptyIndices.Add(index); } else if (!original.Add(view.Name)) { duplicates.Add(view.Name); } index++; } StringBuilder sb = new StringBuilder(); if (emptyIndices.Count > 0) { sb.Append("Вы не указали имена для тегов: ").AppendLine(string.Join(", ", emptyIndices)); } if (duplicates.Count > 0) { sb.AppendLine("В таблице присутствуют теги с одинаковыми именами:"); foreach (string name in duplicates) { sb.AppendLine(name); } } if (sb.Length > 0) { MessageBox.Show(sb.ToString(), "Ошибка!", MessageBoxButton.OK, MessageBoxImage.Error); return; } int priority = 0; IEnumerable <UserTag> items = TagsCollection.Select(view => { UserTag tag = (UserTag)view; tag.Priority = priority++; return(tag); }); Options.UserTags.TrySync(items); Options.Save(); DialogResult = true; Close(); } catch (Exception ex) { UIHelper.ShowError(ex); } }