public ThreadedWaitDialogProgressScope(string waitCaption) { IVsThreadedWaitDialogFactory factory = (IVsThreadedWaitDialogFactory)Package.GetGlobalService(typeof(SVsThreadedWaitDialogFactory)); Session = factory.StartWaitDialog(waitCaption); }
public async Task GeneratePageObjectsAsync(SynchronizePageObjectsModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var cancellationToken = CancellationToken.None; await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); // Generate project if new. if (model.SelectedProject.IsNew) { if (ErrorHandler.Failed(GenerateOrLocateProject(model))) { if (ErrorHandler.Failed(shellService.GetErrorInfo(out var errorText))) { errorText = "Failed to create the new project."; } VsShellUtilities.ShowMessageBox( ServiceProvider.GlobalProvider, errorText, String.Empty, OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); return; } } // Retrieve the project. var project = solutionService .GetProjects() .FirstOrDefault( p => p.Name.Equals( model.SelectedProject.Name, StringComparison.OrdinalIgnoreCase)); var vsProject = solutionService.GetProjectByFileName(project.FileName); if (project == null) { VsShellUtilities.ShowMessageBox( ServiceProvider.GlobalProvider, "Failed to locate the project.", String.Empty, OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); return; } // Verify the project has the necessary files installed. var isCodeGenPackageInstalled = packageInstallerService .IsPackageInstalled( project, PACKAGE_APT_SELENIUM_CODE_GENERATION); if (!AreCodeGenerationPackagesInstalled(project)) { try { packageInstaller.InstallPackage( source: null, project: project, packageId: PACKAGE_APT_SELENIUM_CODE_GENERATION, version: default(string), ignoreDependencies: false); } catch (Exception e) { VsShellUtilities.ShowMessageBox( ServiceProvider.GlobalProvider, e.ToString(), String.Empty, OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); return; } } // Retrieve all CodeGenerators. var codeGenerators = GetAllCodeGenerators(project); if (!codeGenerators.Any()) { VsShellUtilities.ShowMessageBox( ServiceProvider.GlobalProvider, "Failed to locate any code generators in the project.", String.Empty, OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); return; } // Create and display a wait dialog. var dialog = threadedWaitDialogFactory.StartWaitDialog( waitCaption: "Starting", initialProgress: new ThreadedWaitDialogProgressData( waitMessage: "Starting", progressText: String.Empty, statusBarText: String.Empty, isCancelable: true, currentStep: 0, totalSteps: model.FileMap.Count), delayToShowDialog: TimeSpan.Zero); using (dialog) { // Iterate over all file maps in the model. for (var currentStep = 0; currentStep < model.FileMap.Count; currentStep++) { // Exit loop if canceled. if (dialog.UserCancellationToken.IsCancellationRequested) { break; } var fileMap = model.FileMap[currentStep]; //var projectItem = default(ProjectItem); // Check if file exists. if (fileMap.IsNewFile) { // Create file. var fileInfo = new FileInfo(fileMap.NewPath); Directory.CreateDirectory(fileInfo.Directory.FullName); File.Create(fileMap.NewPath); // Add file to the project. if (project.Kind != "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" && vsProject != null) { var result = new VSADDRESULT[1]; vsProject.AddItem( itemidLoc: (uint)VSConstants.VSITEMID.Root, dwAddItemOperation: VSADDITEMOPERATION.VSADDITEMOP_LINKTOFILE, pszItemName: fileMap.NewPath, cFilesToOpen: 0, rgpszFilesToOpen: new[] { fileMap.NewPath }, hwndDlgOwner: IntPtr.Zero, pResult: result); if (result[0].Equals(VSADDRESULT.ADDRESULT_Failure)) { VsShellUtilities.ShowMessageBox( ServiceProvider.GlobalProvider, "Failed to add the item to the project.", String.Empty, OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); return; } } } // TODO: Generate code for file. // Update wait dialog. dialog.Progress.Report(new ThreadedWaitDialogProgressData( waitMessage: String.Empty, progressText: String.Empty, statusBarText: String.Empty, isCancelable: true, currentStep: currentStep, totalSteps: model.FileMap.Count)); } } }