Пример #1
0
        private void InitializeFilter()
        {
            Filter.SolutionFilter = AllSolutions.FirstOrDefault();
            Filter.AnalyzeProjectsAndSolutions(AllProjects, AllSolutions);

            UsedProjectReferences.Initialize(AllProjects
                                             .SelectMany(p => p.ProjectReferences)
                                             .DistinctBy(p => p.Path)
                                             .OrderBy(p => p.Name));

            Filter.ProjectReferenceFilter = UsedProjectReferences.FirstOrDefault();

            UsedNuGetPackages.Initialize(AllProjects
                                         .SelectMany(p => p.NuGetReferences)
                                         .DistinctBy(n => n.Name + "-" + n.Version)
                                         .OrderByThenBy(p => p.Name, p => VersionUtilities.FromString(p.Version)));

            UsedNuGetPackageNames.Initialize(UsedNuGetPackages
                                             .OrderByThenBy(p => p.Name, p => p.Version)
                                             .GroupBy(p => p.Name)
                                             .Select(g => new NuGetPackageVersionGroup
            {
                Name     = g.Key,
                Versions = g.Count() == 1 ? g.First().Version : g.First().Version + " - " + g.Last().Version
            }));

            Filter.NuGetPackageFilter     = UsedNuGetPackages.FirstOrDefault();
            Filter.NuGetPackageNameFilter = UsedNuGetPackageNames.FirstOrDefault();
        }
Пример #2
0
        private async Task LoadProjectsAsync()
        {
            ClearLoadedProjects();

            var errors = new Dictionary <string, Exception>();
            var tuple  = await RunTaskAsync(async() =>
            {
                var projectsTask  = VsProject.LoadAllFromDirectoryAsync(RootDirectory, IncludedProjectPathFilter, ExcludedProjectPathFilter, IgnoreExceptions, _projectCollection, errors);
                var solutionsTask = VsSolution.LoadAllFromDirectoryAsync(RootDirectory, IncludedProjectPathFilter, ExcludedProjectPathFilter, IgnoreExceptions, _projectCollection, errors);

                await Task.WhenAll(projectsTask, solutionsTask);
                await Task.Run(() =>
                {
                    var projectCache = projectsTask.Result.ToDictionary(p => p.Path, p => p);
                    foreach (var solution in solutionsTask.Result)
                    {
                        solution.LoadProjects(IgnoreExceptions, projectCache, errors);
                    }
                });

                return(new Tuple <List <VsProject>, List <VsSolution> >(projectsTask.Result, solutionsTask.Result));
            });

            if (tuple != null)
            {
                var projects  = tuple.Item1;
                var solutions = tuple.Item2;

                AllSolutions.Initialize(solutions.OrderBy(p => p.Name));
                AllProjects.Initialize(projects.OrderBy(p => p.Name));

                SelectedProject = FilteredProjects.FirstOrDefault();

                foreach (var error in errors)
                {
                    AddLog(error.Key + "\n" + error.Value.Message);
                }

                InitializeFilter();
                IsLoaded = true;
            }
        }
Пример #3
0
        private void ClearLoadedProjects()
        {
            ClearPreviousProjects();

            _allAnalyzeResults.Clear();

            if (_projectCollection != null)
            {
                _projectCollection.UnloadAllProjects();
                _projectCollection.Dispose();
            }

            _projectCollection = new ProjectCollection();

            IsLoaded = false;

            ShowPreviousProjectCommand.RaiseCanExecuteChanged();
            AllSolutions.Clear();
            AllProjects.Clear();
        }
Пример #4
0
        private void Solve()
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            AssumeSolvingOrder();

            Node root = new Node(CurrentExample);

            for (int i = 0; i < SolvingOrder[0].Domain.Count; i++)
            {
                var domain = SolvingOrder[0].Domain.ToList();
                AllReturnCount = AllReturnCount + 9 - SolvingOrder[0].Domain.Count;
                Sudoku newSudoku = new Sudoku(CurrentExample);
                newSudoku[SolvingOrder[0].X, SolvingOrder[0].Y] = domain[i];
                Node newNode = new Node(newSudoku, root);
                root.AddChild(newNode);
                AllNodes += 13;
            }
            root.HasAllChildren = true;
            Node current = root;


            while (true)
            {
                //dodawanie dzieci
                if (!current.HasAllChildren)
                {
                    CurrentExample = current.CurrentSudokuState;
                    AssumeSolvingOrder();
                    if (SolvingOrder.Count != 0)
                    {
                        for (int i = 0; i < SolvingOrder[0].Domain.Count; i++)
                        {
                            var domain = SolvingOrder[0].Domain.ToList();
                            AllReturnCount = AllReturnCount + 9 - SolvingOrder[0].Domain.Count;
                            Sudoku newSudoku = new Sudoku(CurrentExample);
                            newSudoku[SolvingOrder[0].X, SolvingOrder[0].Y] = domain[i];
                            Node newNode = new Node(newSudoku, current);
                            current.AddChild(newNode);
                            AllNodes += 13;
                        }
                        current.HasAllChildren = true;
                    }
                }

                if (current.CurrentSudokuState.isSolved())
                {
                    if (AllSolutions.Count == 0)
                    {
                        AllNodes += 9;
                        AllNodes++;
                        var ts = stopwatch.Elapsed;

                        string elapsedTime = String.Format("{0:00}.{1:00}",
                                                           ts.Seconds,
                                                           ts.Milliseconds / 10);

                        FirstSolutionTime = elapsedTime;
                        FirstReturnCount  = AllNodes / 2;
                        FirstNodes        = AllNodes;
                    }

                    /*
                     * bool shouldBeAdded = true;
                     * for (int i = 0; i < Solutions.Count; i++)
                     * {
                     * if (checkIfIsTheSameSolution(Solutions[i], current.Current))
                     * {
                     * shouldBeAdded = false;
                     * }
                     * }
                     * if (shouldBeAdded)
                     * {
                     * Solutions.Add(current.Current);
                     * Console.WriteLine();
                     * current.Current.displaySudoku();
                     * Console.WriteLine();
                     * counter++;
                     * }
                     *
                     */

                    AllSolutions.Add(current.CurrentSudokuState);

                    AllNodes++;
                    AllNodes++;
                    current = current.Parent;
                    current.Children.RemoveAt(0);
                }
                else if (current.HasAllChildren)
                {
                    // Console.WriteLine(current.Children.Count);
                    //jesli nie ma dziecka
                    if (current.Children.Count == 0)
                    {
                        current = current.Parent;
                        AllNodes++;

                        //  Console.WriteLine("nawracam");
                        current.Children.RemoveAt(0);
                        AllNodes++;
                    }
                    //a jesli ma to biore pierwsze z brzegu
                    else
                    {
                        AllNodes++;
                        current = current.Children[0];
                    }
                    if (current.Equals(root) && current.Children.Count == 0 && AllSolutions.Count != 0)
                    {
                        stopwatch.Stop();
                        AllNodes++;

                        var ts = stopwatch.Elapsed;

                        string elapsedTime = String.Format("{0:00}.{1:00}",
                                                           ts.Seconds,
                                                           ts.Milliseconds / 10);
                        AllSolutionsTime = elapsedTime;

                        break;
                    }
                }
            }
        }