Exemplo n.º 1
0
        /// <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;
        }