/// <summary> /// add virtual definition as an asynchronous operation. /// </summary> /// <param name="definitions">The definitions.</param> protected async Task AddVirtualDefinitionAsync(IEnumerable <IDefinition> definitions) { if (previousDefinitions != definitions) { if (!IsBinaryConflict) { var col = definitions.OrderBy(p => SelectedModsOrder.IndexOf(p.ModName)).ToHashSet(); var priorityDefinition = modPatchCollectionService.EvalDefinitionPriority(col); if (priorityDefinition == null || priorityDefinition.Definition == null) { if (priorityDefinition == null) { priorityDefinition = DIResolver.Get <IPriorityDefinitionResult>(); priorityDefinition.PriorityType = DefinitionPriorityType.None; } if (priorityDefinition.Definition == null) { priorityDefinition.Definition = col.First(); } } var newDefinition = await modPatchCollectionService.CreatePatchDefinitionAsync(priorityDefinition.Definition, CollectionName); if (newDefinition != null) { col.Add(newDefinition); } VirtualDefinitions = col.ToObservableCollection(); if (VirtualDefinitions.Count() > 0) { // No reason to anymore not select a default definition on either side, wait a bit first to allow the UI to settle down await Task.Delay(100); LeftSelectedDefinition = null; RightSelectedDefinition = null; await Task.Delay(50); LeftSelectedDefinition = VirtualDefinitions.FirstOrDefault(p => p != newDefinition && p != priorityDefinition.Definition); RightSelectedDefinition = newDefinition; } } else { VirtualDefinitions = definitions.OrderBy(p => SelectedModsOrder.IndexOf(p.ModName)).ToHashSet(); if (VirtualDefinitions.Count() > 0) { // No reason to anymore not select a default definition on either side, wait a bit first to allow the UI to settle down await Task.Delay(100); LeftSelectedDefinition = null; RightSelectedDefinition = null; await Task.Delay(50); LeftSelectedDefinition = definitions.ElementAt(0); RightSelectedDefinition = definitions.ElementAt(1); } } } previousDefinitions = definitions; }
/// <summary> /// add virtual definition as an asynchronous operation. /// </summary> /// <param name="definitions">The definitions.</param> /// <param name="token">The token.</param> /// <returns>A Task representing the asynchronous operation.</returns> protected async Task AddVirtualDefinitionAsync(IEnumerable <IDefinition> definitions, CancellationToken token) { addingVirtualDefinition = true; if (previousDefinitions != definitions) { if (!IsBinaryConflict) { var col = definitions.OrderBy(p => SelectedModsOrder.IndexOf(p.ModName)).ToHashSet(); var priorityDefinition = modPatchCollectionService.EvalDefinitionPriority(col); if (priorityDefinition == null || priorityDefinition.Definition == null) { if (priorityDefinition == null) { priorityDefinition = DIResolver.Get <IPriorityDefinitionResult>(); priorityDefinition.PriorityType = DefinitionPriorityType.None; } if (priorityDefinition.Definition == null) { priorityDefinition.Definition = col.First(); } } IDefinition newDefinition = null; if (priorityDefinition.PriorityType != DefinitionPriorityType.NoProvider) { newDefinition = await modPatchCollectionService.CreatePatchDefinitionAsync(priorityDefinition.Definition, CollectionName); if (newDefinition != null) { col.Add(newDefinition); } } VirtualDefinitions = col.ToObservableCollection(); var virtualDefinitions = VirtualDefinitions; if (virtualDefinitions.Any()) { // No reason to anymore not select a default definition on either side, wait a bit first to allow the UI to settle down await Task.Delay(100, token); if (!token.IsCancellationRequested) { DefinitionSelection = null; LeftSelectedDefinition = null; RightSelectedDefinition = null; } await Task.Delay(50, token); if (!token.IsCancellationRequested) { int virtualDefCount = virtualDefinitions.Count(); var left = newDefinition != null?virtualDefinitions.FirstOrDefault(p => p != newDefinition && p != priorityDefinition.Definition && !(virtualDefCount >= 4 && p.IsFromGame)) : virtualDefinitions.FirstOrDefault(p => p != priorityDefinition.Definition); if (left == null) { left = virtualDefinitions.FirstOrDefault(p => p != newDefinition && p != priorityDefinition.Definition); } var right = newDefinition ?? priorityDefinition.Definition; DefinitionSelection = new CompareSelection(left, right); LeftSelectedDefinition = left; RightSelectedDefinition = right; } } } else { VirtualDefinitions = definitions.OrderBy(p => SelectedModsOrder.IndexOf(p.ModName)).ToHashSet(); var virtualDefinitions = VirtualDefinitions; var priorityDefinition = modPatchCollectionService.EvalDefinitionPriority(virtualDefinitions); if (priorityDefinition == null || priorityDefinition.Definition == null) { if (priorityDefinition == null) { priorityDefinition = DIResolver.Get <IPriorityDefinitionResult>(); priorityDefinition.PriorityType = DefinitionPriorityType.None; } if (priorityDefinition.Definition == null) { priorityDefinition.Definition = virtualDefinitions.First(); } } if (virtualDefinitions.Any()) { // No reason to anymore not select a default definition on either side, wait a bit first to allow the UI to settle down await Task.Delay(100, token); if (!token.IsCancellationRequested) { DefinitionSelection = null; LeftSelectedDefinition = null; RightSelectedDefinition = null; } await Task.Delay(50, token); if (!token.IsCancellationRequested) { var left = virtualDefinitions.FirstOrDefault(p => p != priorityDefinition.Definition); var right = priorityDefinition.Definition; DefinitionSelection = new CompareSelection(left, right); LeftSelectedDefinition = left; RightSelectedDefinition = right; } } } } previousDefinitions = definitions; addingVirtualDefinition = false; }