public MainViewModel()
 {
     BindingPriority = DispatcherPriority.Send;
     solution = new Solution("Click here to open solution file...");
     checker = new ReferenceChecker(solution);
     SetModel("Solution", solution);
 }
        public void OpenProject()
        {
            var dlg = new OpenFileDialog
            {
                CheckFileExists = true,
                DefaultExt = ".sln",
                Filter = "Solution files|*.sln"
            };

            if (dlg.ShowDialog() != true)
                return;

            IsChecking = true;
            NotifyPropertiesChanged(new[] { nameof(ShowChecking), nameof(SolutionReady) });

            worker = new BackgroundWorker();
            worker.DoWork += (sender, args) =>
            {
                References = new List<Reference>();

                solution = new Solution();
                solution.Load(dlg.FileName);
                CheckSolution = solution.Name;
                SetModel("Solution", solution);

                checker = new ReferenceChecker(solution);
                checker.Processing += projectName =>
                {
                    this[nameof(CheckProgress)] = projectName;
                    Thread.Sleep(100);
                };
                checker.Check();
            };
            worker.RunWorkerCompleted += (sender, args) =>
            {
                UpdateReferences();
                IsChecking = false;
                NotifyPropertiesChanged(new[] { nameof(ShowChecking), nameof(SolutionReady), nameof(References), nameof(CheckResult) });
            };
            worker.RunWorkerAsync();
        }
Exemple #3
0
        private static ReturnCode ConsoleMain(string[] args)
        {
            Console.WriteLine(@"RefCheck");
            var defaultColor = Console.ForegroundColor;

            var fileName = args[0];
            if (!File.Exists(fileName))
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(@"Solution file not found: " + fileName);
                return ReturnCode.Fatal;
            }

            var solution = new Solution();
            solution.Load(fileName);
            Console.WriteLine(@"Solution: " + solution.Name);
            foreach (var error in solution.Errors)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(@"Error: " + error);
            }

            Console.WriteLine($"Checking {solution.Projects.Count} projects.");

            var checker = new ReferenceChecker(solution);
            Console.WriteLine($"Checking {checker.References.Count} references.");

            checker.Processing += projectName =>
            {
                Console.ForegroundColor = defaultColor;
                Console.WriteLine(projectName);
            };
            checker.Error += error =>
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(@"Error: " + error);
            };
            checker.Warning += warning =>
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine(@"Warning: " + warning);
            };

            checker.Check();

            Console.ForegroundColor = defaultColor;
            Console.WriteLine(@"Check done.");

            if (solution.Errors.Count > 0)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(checker.CheckResult);
                return ReturnCode.Error;
            }
            if (solution.Warnings.Count > 0)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine(checker.CheckResult);
                return ReturnCode.Warning;
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine(@"No Errors, no warnings.");
            return ReturnCode.Ok;
        }