private void RefactorGlassReferences(Action <int, object> progressReport)
        {
            progressReport(-1, "Started package migration...");
            var sitecoreConfigModel = SitecoreVersionConfigManager.GetSitecoreConfigModel(projectsUpdateList.SelectedSitecoreVersion.Id);

            if (sitecoreConfigModel.Error != null)
            {
                progressReport(-1, sitecoreConfigModel.Error);
                return;
            }

            var hostProject = projectsUpdateList.Projects.FirstOrDefault(p => p.IsSelected);
            // check if host proj has the necessary Packages included.
            var installedPackages = pkgMnger.GetInstalledNugetPackages(hostProject.DteProject);
            var missingPackages   = sitecoreConfigModel.GlassPackages.Where(x => !installedPackages.Contains(x));

            foreach (var aPackage in missingPackages)
            {
                pkgMnger.UpdatePackage(hostProject.DteProject, aPackage, false);
            }

            // Add the abstraction class to a foundation projects
            var refactoringService = new GlassRefactorService();

            progressReport(1, $"Trying to add the abstraction classes to project {hostProject.Name} ");
            if (!refactoringService.AddAbstractionClass(hostProject.DteProject, _glassAbstractionFolderName))
            {
                progressReport(-2, refactoringService.ErrorMessage);
                return;
            }


            var selectedProjects = projectsUpdateList.Projects.Where(p => p.IsSelected);

            foreach (var project in selectedProjects)
            {
                foreach (ProjectItem item in project.DteProject.ProjectItems)
                {
                    //check if it is a class file
                    //check if file has reference to ISitecoreContext
                    if (!item.Name.Contains(".cs") || !File.ReadLines(item.Document.FullName)
                        .SkipWhile(x => !x.Contains("ISitecoreContext"))
                        .TakeWhile(line => !line.Contains("ISitecoreContext")).Any())
                    {
                        continue;
                    }
                    //add reference to IItemRepository
                    //item.FileCodeModel.CodeElements.;
                    // replace references to ISitecoreContext with IItemRepor
                }
            }
        }
        void UpdateMSSCPkgFired(Action <int, object> progressReport)
        {
            progressReport(0, "Started SC + MS Update...");
            var sitecoreConfigModel = SitecoreVersionConfigManager.GetSitecoreConfigModel(projectsUpdateList.SelectedSitecoreVersion.Id);

            if (sitecoreConfigModel.Error != null)
            {
                progressReport(-1, sitecoreConfigModel.Error);
                return;
            }


            var selectedProjects = projectsUpdateList.Projects.Where(p => p.IsSelected);
            var count            = selectedProjects.Count();
            var i = 1;

            foreach (var prj in selectedProjects)
            {
                progressReport(GetPercentage(i, count), $"Starting project {prj.Name}");
                var prjPkgs = pkgMnger.GetInstalledNugetPackages(prj.DteProject);
                //restoring packages first
                pkgMnger.RestorePackages(prj.DteProject);
                //MSPackages first
                var pkgToUpdate = prjPkgs.Where(x => x.Id.StartsWith("Microsoft."));
                if (pkgToUpdate.Any())
                {
                    UpdateMsPackages(sitecoreConfigModel, prj, pkgToUpdate, prjPkgs, progressReport);
                }

                //Sitecore package second
                pkgToUpdate = prjPkgs.Where(x => x.Id.StartsWith("Sitecore."));
                if (pkgToUpdate.Any())
                {
                    UpdateSCPackages(sitecoreConfigModel, prj, pkgToUpdate, prjPkgs, progressReport);
                }

                //other packages
                pkgToUpdate = prjPkgs.Where(x => !x.Id.StartsWith("Sitecore.") && !x.Id.StartsWith("Microsoft.") && !x.Id.StartsWith("Glass."));
                if (pkgToUpdate.Any())
                {
                    UpdateOtherPackages(sitecoreConfigModel, prj, pkgToUpdate, prjPkgs, progressReport);
                }

                //now build the project so it get saved and references get updated.
                BuildProject(prj);
                i++;
            }

            progressReport(100, "MS + Sitecore has been updated. Please verify and continue");
        }
        private void MigrateToPackageReferencing(Action <int, object> progressReport)
        {
            progressReport(1, "Started package migration...");
            var sitecoreConfigModel = SitecoreVersionConfigManager.GetSitecoreConfigModel(projectsUpdateList.SelectedSitecoreVersion.Id);

            if (sitecoreConfigModel.Error != null)
            {
                progressReport(-1, sitecoreConfigModel.Error);
                return;
            }


            var selectedProjects = projectsUpdateList.Projects.Where(p => p.IsSelected);

            var           dte2        = (DTE2)applicationObject;
            List <string> selectedPrj = selectedProjects.Select(x => x.DteProject.Name).ToList();

            pkgMnger.StartProjectMigration(dte2, applicationObject.Solution.FileName, selectedPrj);
            progressReport(100, "done...");
        }
        void Update(Action <int, object> progressReport)
        {
            progressReport(-1, "Reading config file...");
            var selectedProjects    = projectsUpdateList.Projects.Where(p => p.IsSelected);
            var sitecoreConfigModel = SitecoreVersionConfigManager.GetSitecoreConfigModel(projectsUpdateList.SelectedSitecoreVersion.Id);

            if (sitecoreConfigModel.Error != null)
            {
                progressReport(100, sitecoreConfigModel.Error);
                return;
            }

            progressReport(-1, "Updating dotnet Framework...");

            UpdateFrameworks(selectedProjects, sitecoreConfigModel.Framework, progressReport);

            //projectsUpdateList.EnableNextStep();
            //projectsUpdateList.Projects = LoadProjects();

            progressReport(100, "Dotnet Framework has been updated... please verify and then continue");
        }
        void UpdateGlassPkgFired(Action <int, object> progressReport)
        {
            progressReport(-1, "Started Glass Upgrade...");
            progressReport(-1, "Loading Config...");
            var sitecoreConfigModel = SitecoreVersionConfigManager.GetSitecoreConfigModel(projectsUpdateList.SelectedSitecoreVersion.Id);

            if (sitecoreConfigModel.Error != null)
            {
                progressReport(-1, sitecoreConfigModel.Error);
                return;
            }


            var selectedProjects = projectsUpdateList.Projects.Where(p => p.IsSelected);
            var count            = selectedProjects.Count();
            var i = 1;

            foreach (var prj in selectedProjects)
            {
                progressReport(GetPercentage(i, count), "Starting project " + prj.Name);
                var prjPkgs = pkgMnger.GetInstalledNugetPackages(prj.DteProject);
                //restoring packages first
                pkgMnger.RestorePackages(prj.DteProject);

                var pkgToUpdate = prjPkgs.Where(x => x.Id.StartsWith("Glass."));
                if (pkgToUpdate.Any())
                {
                    UpdateGlassPackages(sitecoreConfigModel, prj, pkgToUpdate, prjPkgs, progressReport);
                }
                //now build the project so it get saved and references get updated.
                BuildProject(prj);
                i++;
            }

            progressReport(-1, "Glass has been updated. Please verify and continue");
        }