public ConfigurationViewModel()
        {
            TargetDirectory = "test";

            var p1 = new ProjectViewModel();

            p1.Name       = "shield.exe";
            p1.IsEnabled  = true;
            p1.FolderName = "common";
            p1.Files.Add(new ProjectFileViewModel {
                FileName = "file1"
            });
            p1.Files.Add(new ProjectFileViewModel {
                FileName = "file2"
            });
            p1.Files.Add(new ProjectFileViewModel {
                FileName = "file3"
            });
            p1.OutputFullPath  = "C:\\Windows";
            p1.TargetDirectory = "C:\\Temp";

            var p2 = new ProjectViewModel();

            p2.Name       = "shield2.exe";
            p2.IsEnabled  = false;
            p1.FolderName = "common/lib";
            p2.Files.Add(new ProjectFileViewModel {
                FileName = "file4"
            });
            p2.Files.Add(new ProjectFileViewModel {
                FileName = "file5"
            });
            p2.Files.Add(new ProjectFileViewModel {
                FileName = "file6"
            });

            var p3 = new ProjectViewModel();

            p2.Name           = "shield3.exe";
            p2.IsEnabled      = true;
            p1.FolderName     = "common";
            p3.OutputFullPath = "C:\\Windows";

            Projects = new Collection <ProjectViewModel>
            {
                p1,
                p2,
                p3
            };

            SelectedProject = p1;

            _solutionConfiguration = new Configuration.SolutionConfiguration();
        }
        public ConfigurationViewModel(DTE2 dte, Configuration.SolutionConfiguration solutionConfiguration)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            _solutionConfiguration = solutionConfiguration;

            var projects    = new List <ProjectViewModel>();
            var dteProjects = dte.Solution.GetProjects()
                              .OrderBy(p => Path.GetDirectoryName(p.UniqueName))
                              .ThenBy(p => p.UniqueName)
                              .ToArray();

            foreach (var dteProject in dteProjects)
            {
                try
                {
                    var projectConfiguration = solutionConfiguration.Projects.FirstOrDefault(p => p.ProjectName == dteProject.UniqueName) ??
                                               new ProjectConfiguration();

                    var projectViewModel = new ProjectViewModel(dteProject, projectConfiguration.Files)
                    {
                        IsEnabled             = projectConfiguration.IsEnabled,
                        IncludeSubDirectories = projectConfiguration.IncludeSubDirectories,
                        TargetDirectory       = projectConfiguration.TargetDirectory,
                        InheritFromProject    = projectConfiguration.InheritFromProject,
                        ApplicationPreset     = projectConfiguration.ApplicationPreset,
                        ReplaceOriginalFile   = projectConfiguration.ReplaceOriginalFile,
                    };

                    if (!string.IsNullOrEmpty(projectConfiguration.FileToProtect))
                    {
                        projectViewModel.FileToProtect = projectConfiguration.FileToProtect;
                    }

                    projects.Add(projectViewModel);
                }
                catch
                {
                    // ignored
                }
            }

            Projects       = projects;
            ProjectPresets = new ObservableCollection <ProjectPreset>
            {
                new ProjectPreset {
                    Id = 1, Name = "Maximum"
                }
                , new ProjectPreset {
                    Id = 2, Name = "Balance"
                }
                , new ProjectPreset {
                    Id = 3, Name = "Optimized"
                }
            };
            ProjectEditions = new ObservableCollection <string>
            {
                "Keep my plan",
                "Essentials",
                "Professional",
                "Enterprise"
            };
            TargetDirectory = solutionConfiguration.TargetDirectory;
            CreateShieldProjectIfNotExists = solutionConfiguration.CreateShieldProjectIfNotExists;
            FindCustomConfigurationFile    = solutionConfiguration.FindCustomConfigurationFile;
            ProjectPreset        = solutionConfiguration.ProjectPreset;
            ShieldProjectEdition = solutionConfiguration.ShieldProjectEdition;
            ShieldProjectName    = solutionConfiguration.ShieldProjectName;
            BuildConfiguration   = solutionConfiguration.BuildConfiguration;
            SelectedProjects     = new ObservableCollection <ProjectViewModel>();
            IsValidClient        = false;

            if (string.IsNullOrEmpty(ShieldProjectName))
            {
                ShieldProjectName = Path.GetFileNameWithoutExtension(dte.Solution.FileName);
            }

            if (dte.Solution.SolutionBuild.StartupProjects is object[] startupProjects)
            {
                var startupProject = startupProjects.OfType <string>().FirstOrDefault();
                if (startupProject != null)
                {
                    SelectedProject = Projects.FirstOrDefault(p => p.Project.UniqueName == startupProject);
                }
            }

            if (SelectedProject == null)
            {
                SelectedProject = Projects.FirstOrDefault();
            }
        }