/// <summary>
        /// Runs this instance.
        /// </summary>
        public void Run()
        {
            TraceService.WriteHeader("ProjectsController::Run");

            //// we open the nuget package manager console so we don't have a wait condition later!

            this.nugetService.OpenNugetWindow();

            this.projectFactory.RegisterWizardData();

            WizardFrameViewModel viewModel = this.ShowDialog <WizardFrameViewModel>(new WizardView());

            try
            {
                if (viewModel.Continue)
                {
                    ProjectsViewModel                  projectsViewModel                  = (ProjectsViewModel)viewModel.GetWizardStepViewModel("ProjectsViewModel").ViewModel;
                    ApplicationOptionsViewModel        applicationOptionsViewModel        = (ApplicationOptionsViewModel)viewModel.GetWizardStepViewModel("ApplicationOptionsViewModel").ViewModel;
                    NinjaCoderOptionsViewModel         ninjaCoderOptionsViewModel         = (NinjaCoderOptionsViewModel)viewModel.GetWizardStepViewModel("NinjaCoderOptionsViewModel").ViewModel;
                    ApplicationSamplesOptionsViewModel applicationSamplesOptionsViewModel = (ApplicationSamplesOptionsViewModel)viewModel.GetWizardStepViewModel("ApplicationSamplesOptionsViewModel").ViewModel;
                    ViewsViewModel            viewsViewModel            = (ViewsViewModel)viewModel.GetWizardStepViewModel("ViewsViewModel").ViewModel;
                    PluginsViewModel          pluginsViewModel          = (PluginsViewModel)viewModel.GetWizardStepViewModel("PluginsViewModel").ViewModel;
                    NugetPackagesViewModel    nugetPackagesViewModel    = (NugetPackagesViewModel)viewModel.GetWizardStepViewModel("NugetPackagesViewModel").ViewModel;
                    XamarinFormsLabsViewModel xamarinFormsLabsViewModel = (XamarinFormsLabsViewModel)viewModel.GetWizardStepViewModel("XamarinFormsLabsViewModel").ViewModel;

                    this.Process(
                        projectsViewModel,
                        applicationOptionsViewModel,
                        ninjaCoderOptionsViewModel,
                        applicationSamplesOptionsViewModel,
                        viewsViewModel,
                        pluginsViewModel,
                        nugetPackagesViewModel,
                        xamarinFormsLabsViewModel);
                }
            }
            catch (Exception exception)
            {
                //// TODO : this needs refactoring.

                this.VisualStudioService.WriteStatusBarMessage(string.Empty);
                TraceService.WriteError(exception);

                //// put the error messages in the readme!
                this.messages.InsertRange(0, TraceService.ErrorMessages);

                TraceService.ErrorMessages = new List <string>();

                this.CreateReadMe(true, true);
            }
        }
        /// <summary>
        /// Processes the specified solution path.
        /// </summary>
        /// <param name="projectsViewModel">The projects view model.</param>
        /// <param name="applicationOptionsViewModel">The application options view model.</param>
        /// <param name="ninjaCoderOptionsViewModel">The ninja coder options view model.</param>
        /// <param name="applicationSamplesOptionsViewModel">The application samples options view model.</param>
        /// <param name="viewsViewModel">The views view model.</param>
        /// <param name="pluginsViewModel">The plugins view model.</param>
        /// <param name="nugetPackagesViewModel">The nuget packages view model.</param>
        /// <param name="xamarinFormsLabsViewModel">The xamarin forms labs view model.</param>
        internal void Process(
            ProjectsViewModel projectsViewModel,
            ApplicationOptionsViewModel applicationOptionsViewModel,
            NinjaCoderOptionsViewModel ninjaCoderOptionsViewModel,
            ApplicationSamplesOptionsViewModel applicationSamplesOptionsViewModel,
            ViewsViewModel viewsViewModel,
            PluginsViewModel pluginsViewModel,
            NugetPackagesViewModel nugetPackagesViewModel,
            XamarinFormsLabsViewModel xamarinFormsLabsViewModel)
        {
            TraceService.WriteLine("ProjectsController::Process");

            foreach (SelectableItemViewModel<ProjectTemplateInfo> projectTemplateInfo in projectsViewModel.Projects)
            {
                TraceService.WriteLine(projectTemplateInfo.Item.Name + " project selected=" + projectTemplateInfo.IsSelected);
            }

            this.VisualStudioService.WriteStatusBarMessage(NinjaMessages.NinjaIsRunning);

            this.applicationService.SuspendResharperIfRequested();

            this.projectsService.IsNewSolution = this.VisualStudioService.SolutionAlreadyCreated;

            //// create the solution if we don't have one!
            if (this.projectsService.IsNewSolution == false)
            {
                this.VisualStudioService.SolutionService.CreateEmptySolution(projectsViewModel.GetSolutionPath(), projectsViewModel.Project);
            }

            if (this.SettingsService.CreateTestProjectsSolutionFolder)
            {
                this.VisualStudioService.SolutionService.AddSolutionFolder(this.SettingsService.TestProjectsSolutionFolderName);
                this.VisualStudioService.DTEService.SaveAll();
            }

               this.messages = this.projectsService.AddProjects(
                    this.VisualStudioService,
                    projectsViewModel.GetSolutionPath(),
                    projectsViewModel.GetFormattedRequiredTemplates())
                    .ToList();

            this.projectsService.SetStartUpProject();

            //// there is a bug in the xamarin iOS code that means it doesnt apply a couple of xml elements
            //// in the info.plist - here we fix that issue.

            if (this.SettingsService.FixInfoPlist)
            {
                this.applicationService.FixInfoPList(projectsViewModel.GetFormattedRequiredTemplates()
                        .FirstOrDefault(x => x.ProjectSuffix == this.SettingsService.iOSProjectSuffix));
            }

            IEnumerable<string> viewNugetCommands = new List<string>();

            if (this.SettingsService.FrameworkType != FrameworkType.NoFramework &&
                viewsViewModel != null)
            {
                //// if we dont have a viewmodel and view in memory - add one
                //// user will have dont show views and viewmodel options selected.
                if (!viewsViewModel.Views.Any())
                {
                    viewsViewModel.Add();
                }

                IEnumerable<string> viewModelMessages = this.viewModelViewsService.AddViewModelsAndViews(viewsViewModel.Views);

                this.messages.AddRange(viewModelMessages);

                viewNugetCommands = this.viewModelViewsService.GetNugetCommands();
            }

            TraceService.WriteLine("ProjectsController::Process GetApplication Commands");

            //// we need to get the post nuget commands that are now hosted in xml file that used to be in code
            CommandsList commandsList = this.applicationService.GetCommandsList();

            if (commandsList != null)
            {
                this.postNugetCommands.AddRange(commandsList.Commands);
                this.postNugetFileOperations.AddRange(commandsList.FileOperations);
            }

            IEnumerable<ProjectTemplateInfo> projectTemplateInfos = projectsViewModel.GetFormattedRequiredTemplates();

            this.commands += this.nugetService.GetNugetCommands(projectTemplateInfos);

            if (viewNugetCommands.Any())
            {
                foreach (string viewNugetCommand in viewNugetCommands)
                {
                    this.commands += viewNugetCommand + Environment.NewLine;
                }
            }

            this.PopulateNugetActions(applicationOptionsViewModel);
            this.PopulateNugetActions(ninjaCoderOptionsViewModel);
            this.PopulateNugetActions(applicationSamplesOptionsViewModel);
            this.PopulateNugetActions(pluginsViewModel);
            this.PopulateNugetActions(nugetPackagesViewModel);
            this.PopulateNugetActions(xamarinFormsLabsViewModel);

            this.cachingService.PostNugetCommands = this.postNugetCommands;
            this.cachingService.PostNugetFileOperations = this.postNugetFileOperations;

            //// a bit of (unnecessary) tidying up - replace double new lines!
            this.commands = this.commands.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);

            this.CreateReadMe(false, false);

            TraceService.WriteHeader("RequestedNugetCommands=" + this.commands);

            if (this.SettingsService.ProcessNugetCommands)
            {
                this.ProcessNugetCommands();
            }

            TraceService.WriteLine("ProjectsController::Process END");
        }
        /// <summary>
        /// Processes the specified solution path.
        /// </summary>
        /// <param name="projectsViewModel">The projects view model.</param>
        /// <param name="applicationOptionsViewModel">The application options view model.</param>
        /// <param name="ninjaCoderOptionsViewModel">The ninja coder options view model.</param>
        /// <param name="applicationSamplesOptionsViewModel">The application samples options view model.</param>
        /// <param name="viewsViewModel">The views view model.</param>
        /// <param name="pluginsViewModel">The plugins view model.</param>
        /// <param name="nugetPackagesViewModel">The nuget packages view model.</param>
        /// <param name="xamarinFormsLabsViewModel">The xamarin forms labs view model.</param>
        internal void Process(
            ProjectsViewModel projectsViewModel,
            ApplicationOptionsViewModel applicationOptionsViewModel,
            NinjaCoderOptionsViewModel ninjaCoderOptionsViewModel,
            ApplicationSamplesOptionsViewModel applicationSamplesOptionsViewModel,
            ViewsViewModel viewsViewModel,
            PluginsViewModel pluginsViewModel,
            NugetPackagesViewModel nugetPackagesViewModel,
            XamarinFormsLabsViewModel xamarinFormsLabsViewModel)
        {
            TraceService.WriteLine("ProjectsController::Process");

            foreach (SelectableItemViewModel <ProjectTemplateInfo> projectTemplateInfo in projectsViewModel.Projects)
            {
                TraceService.WriteLine(projectTemplateInfo.Item.Name + " project selected=" + projectTemplateInfo.IsSelected);
            }

            this.VisualStudioService.WriteStatusBarMessage(NinjaMessages.NinjaIsRunning);

            this.applicationService.SuspendResharperIfRequested();

            this.projectsService.IsNewSolution = this.VisualStudioService.SolutionAlreadyCreated;

            //// create the solution if we don't have one!
            if (this.projectsService.IsNewSolution == false)
            {
                this.VisualStudioService.SolutionService.CreateEmptySolution(projectsViewModel.GetSolutionPath(), projectsViewModel.Project);
            }

            if (this.SettingsService.CreateTestProjectsSolutionFolder)
            {
                this.VisualStudioService.SolutionService.AddSolutionFolder(this.SettingsService.TestProjectsSolutionFolderName);
                this.VisualStudioService.DTEService.SaveAll();
            }

            this.messages = this.projectsService.AddProjects(
                this.VisualStudioService,
                projectsViewModel.GetSolutionPath(),
                projectsViewModel.GetFormattedRequiredTemplates())
                            .ToList();

            this.projectsService.SetStartUpProject();

            //// there is a bug in the xamarin iOS code that means it doesnt apply a couple of xml elements
            //// in the info.plist - here we fix that issue.

            if (this.SettingsService.FixInfoPlist)
            {
                this.applicationService.FixInfoPList(projectsViewModel.GetFormattedRequiredTemplates()
                                                     .FirstOrDefault(x => x.ProjectSuffix == this.SettingsService.iOSProjectSuffix));
            }

            IEnumerable <string> viewNugetCommands = new List <string>();

            if (this.SettingsService.FrameworkType != FrameworkType.NoFramework &&
                viewsViewModel != null)
            {
                //// if we dont have a viewmodel and view in memory - add one
                //// user will have dont show views and viewmodel options selected.
                if (!viewsViewModel.Views.Any())
                {
                    viewsViewModel.Add();
                }

                IEnumerable <string> viewModelMessages = this.viewModelViewsService.AddViewModelsAndViews(viewsViewModel.Views);

                this.messages.AddRange(viewModelMessages);

                viewNugetCommands = this.viewModelViewsService.GetNugetCommands();
            }

            TraceService.WriteLine("ProjectsController::Process GetApplication Commands");

            //// we need to get the post nuget commands that are now hosted in xml file that used to be in code
            CommandsList commandsList = this.applicationService.GetCommandsList();

            if (commandsList != null)
            {
                this.postNugetCommands.AddRange(commandsList.Commands);
                this.postNugetFileOperations.AddRange(commandsList.FileOperations);
            }

            IEnumerable <ProjectTemplateInfo> projectTemplateInfos = projectsViewModel.GetFormattedRequiredTemplates();

            this.commands += this.nugetService.GetNugetCommands(projectTemplateInfos);

            if (viewNugetCommands.Any())
            {
                foreach (string viewNugetCommand in viewNugetCommands)
                {
                    this.commands += viewNugetCommand + Environment.NewLine;
                }
            }

            this.PopulateNugetActions(applicationOptionsViewModel);
            this.PopulateNugetActions(ninjaCoderOptionsViewModel);
            this.PopulateNugetActions(applicationSamplesOptionsViewModel);
            this.PopulateNugetActions(pluginsViewModel);
            this.PopulateNugetActions(nugetPackagesViewModel);
            this.PopulateNugetActions(xamarinFormsLabsViewModel);

            this.cachingService.PostNugetCommands       = this.postNugetCommands;
            this.cachingService.PostNugetFileOperations = this.postNugetFileOperations;

            //// a bit of (unnecessary) tidying up - replace double new lines!
            this.commands = this.commands.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);

            this.CreateReadMe(false, false);

            TraceService.WriteHeader("RequestedNugetCommands=" + this.commands);

            if (this.SettingsService.ProcessNugetCommands)
            {
                this.ProcessNugetCommands();
            }

            TraceService.WriteLine("ProjectsController::Process END");
        }