private void GenerateResearchButtons() { foreach (Transform child in ResearchOptionParent) { Destroy(child.gameObject); } ResearchOption[] available = Controller.GetAvailable(); ResourceComparer resourceComparer = new ResourceComparer(); Array.Sort(available, new Comparison <ResearchOption>((x, y) => resourceComparer.Compare(x.ResourceCost, y.ResourceCost))); foreach (var option in available) { GameObject butt = Instantiate(ResearchButtonPrefab, ResearchOptionParent); ResearchOptionButton button = butt.GetComponent <ResearchOptionButton>(); button.Assign(option); Button actualButton = butt.GetComponent <Button>(); actualButton.interactable = ShouldButtonBeAvailable(button); actualButton.onClick.AddListener(() => OnReseachButtonClick(option)); } UpdateAllButtonAvailability(); }
public ICollection <DetectedImportChange> DetectChanges(ICollection <LocalizationResource> importingResources, IEnumerable <LocalizationResource> existingResources) { var result = new List <DetectedImportChange>(); // deleted deletes var resourceComparer = new ResourceComparer(); var deletes = existingResources.Except(importingResources, resourceComparer); result.AddRange(deletes.Select(d => new DetectedImportChange(ChangeType.Delete, LocalizationResource.CreateNonExisting(d.ResourceKey), d))); foreach (var incomingResource in importingResources.Except(deletes, resourceComparer)) { // clean up nulls from translations incomingResource.Translations = incomingResource.Translations.Where(t => t != null).ToList(); var existing = existingResources.FirstOrDefault(r => r.ResourceKey == incomingResource.ResourceKey); if (existing != null) { var comparer = new TranslationComparer(true); var existingTranslations = existing.Translations.Where(_ => _ != null).ToList(); var differences = incomingResource.Translations.Except(existingTranslations, comparer).Where(_ => _ != null).ToList(); // some of the translations are different - so marking this resource as potential update if (differences.Any()) { // here we need to check whether incoming resource is overriding existing translation (exists translation in given language) // or we are maybe importing exported language that had no translations // this could happen if you export language with no translations in xliff format // then new exported target language will have translation as empty string // these cases we need to filter out var detectedChangedLanguages = differences.Select(_ => _.Language).Distinct().ToList(); var existingLanguages = existingTranslations.Select(_ => _.Language).Distinct().ToList(); if (!differences.All(r => string.IsNullOrEmpty(r.Value)) || !detectedChangedLanguages.Except(existingLanguages).Any()) { result.Add(new DetectedImportChange(ChangeType.Update, incomingResource, existing) { ChangedLanguages = detectedChangedLanguages }); } } } else { result.Add(new DetectedImportChange(ChangeType.Insert, incomingResource, LocalizationResource.CreateNonExisting(incomingResource.ResourceKey)) { ChangedLanguages = incomingResource.Translations.Select(t => t.Language).ToList() }); } } return(result); }
public ResourcesControllerFixture() { _sutBuilder = new ResourcesControllerBuilder(); _resourceComparer = new ResourceComparer(); _resourceStore = new ResourceStoreBuilder() .WithDefaultResources() .Build(); _sut = new ResourcesController(_resourceStore); }
[Test] public void TypeComparer() { SortSettings settings = SortSettings.Parse(_storage, "Type- FirstName"); Assert.AreEqual(2, settings.SortProps.Length); Assert.AreEqual(2, settings.SortDirections.Length); Assert.AreEqual(ResourceProps.Type, settings.SortProps [0]); Assert.AreEqual(_propFirstName, settings.SortProps [1]); Assert.AreEqual(false, settings.SortDirections [0]); Assert.AreEqual(true, settings.SortDirections [1]); ResourceComparer comparer = new ResourceComparer(_ownerList, settings, false); IResource res1 = _storage.NewResource("Email"); IResource res2 = _storage.NewResource("Person"); Assert.IsTrue(comparer.CompareResources(res1, res2) > 0); }
public void ApplySortSettings(JetListView listView, SortSettings sortSettings) { if (sortSettings != null) { _curSortSettings = sortSettings; bool foundComparerColumn = false; foreach (JetListViewColumn col in listView.Columns) { ResourcePropsColumn propsCol = col as ResourcePropsColumn; if (propsCol != null && propsCol.PropIdsEqual(sortSettings.SortProps)) { _lastComparer = CreateColumnComparer(propsCol, sortSettings); propsCol.SortIcon = sortSettings.SortAscending ? SortIcon.Ascending : SortIcon.Descending; _lastSortColumn = propsCol; _listView.GroupProvider = _lastSortColumn.GroupProvider; foundComparerColumn = true; } else { col.SortIcon = SortIcon.None; } } if (!foundComparerColumn) { _lastComparer = new ResourceComparer(_resourceList, _curSortSettings, true); } if (_lastComparer != null) { _listView.NodeCollection.SetItemComparer(null, _lastComparer); if (_nodesAdded) { _listView.NodeCollection.Sort(); } } } }
public void HandeColumnClick(ResourcePropsColumn col) { ComparableArrayList propList = new ComparableArrayList(col.PropIds); if (_lastComparer != null && col == _lastSortColumn) { Guard.NullMember(_curSortSettings, "_curSortSettings"); _curSortSettings = _curSortSettings.Reverse(); _lastSortDirections [propList] = (col.SortIcon == SortIcon.Descending); // reverse } else { bool sortAscending = true; if (_lastSortDirections.ContainsKey(propList)) { sortAscending = (bool)_lastSortDirections [propList]; } _curSortSettings = new SortSettings(col.PropIds, sortAscending); if (_lastSortColumn != null) { _lastSortColumn.SortIcon = SortIcon.None; } _lastSortColumn = col; } _lastComparer = CreateColumnComparer(col, _curSortSettings); Guard.NullMember(_lastSortColumn, "_lastSortColumn"); _lastSortColumn.SortIcon = _curSortSettings.SortAscending ? SortIcon.Ascending : SortIcon.Descending; Guard.NullMember(_listView, "_listView"); _listView.NodeCollection.SetItemComparer(null, _lastComparer); _listView.NodeCollection.Sort(); _listView.GroupProvider = _lastSortColumn.GroupProvider; OnSortChanged(); }
public IEnumerable <DetectedImportChange> DetectChanges(IEnumerable <LocalizationResource> importingResources, IEnumerable <LocalizationResource> existingResources) { var result = new List <DetectedImportChange>(); // deleted deletes var resourceComparer = new ResourceComparer(); var deletes = existingResources.Except(importingResources, resourceComparer); result.AddRange(deletes.Select(d => new DetectedImportChange(ChangeType.Delete, LocalizationResource.CreateNonExisting(d.ResourceKey), d))); foreach (var incomingResource in importingResources.Except(deletes, resourceComparer)) { var existing = existingResources.FirstOrDefault(r => r.ResourceKey == incomingResource.ResourceKey); if (existing != null) { var comparer = new TranslationComparer(); var differences = incomingResource.Translations.Except(existing.Translations, comparer) .ToList(); // some of the translations are different - so marking this resource as potential update if (differences.Any()) { result.Add(new DetectedImportChange(ChangeType.Update, incomingResource, existing) { ChangedLanguages = differences.Select(t => t.Language).Distinct().ToList() }); } } else { result.Add(new DetectedImportChange(ChangeType.Insert, incomingResource, LocalizationResource.CreateNonExisting(incomingResource.ResourceKey))); } } return(result); }
internal ConversationNodeComparer(ResourceComparer comparer) { _resourceComparer = comparer; }