private async Task ExecuteAsync(object sender, EventArgs e) { Telemetry.TrackUserTask("Execute-ManageLibrariesCommand"); Project project = await VsHelpers.GetProjectOfSelectedItemAsync(); if (project != null) { string rootFolder = await project.GetRootFolderAsync(); string configFilePath = Path.Combine(rootFolder, Constants.ConfigFileName); if (File.Exists(configFilePath)) { await VsHelpers.OpenFileAsync(configFilePath); } else { var dependencies = _dependenciesFactory.FromConfigFile(configFilePath); Manifest manifest = await Manifest.FromFileAsync(configFilePath, dependencies, CancellationToken.None); manifest.DefaultProvider = "cdnjs"; manifest.Version = Manifest.SupportedVersions.Max().ToString(); await manifest.SaveAsync(configFilePath, CancellationToken.None); await project.AddFileToProjectAsync(configFilePath); Telemetry.TrackUserTask("Create-ConfigFile"); } await VsHelpers.OpenFileAsync(configFilePath); } }
public void ShowOutputWindowPane() { ThreadHelper.Generic.BeginInvoke(() => { VsHelpers.ShowOutputWindow(); }); }
public async Task <bool> DeleteFilesAsync(IEnumerable <string> relativeFilePaths, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); List <string> absolutePaths = new List <string>(); foreach (string filePath in relativeFilePaths) { string absoluteFilePath = Path.Combine(WorkingDirectory, filePath); FileInfo file = new FileInfo(absoluteFilePath); if (file.Exists) { absolutePaths.Add(absoluteFilePath); } } //Delete from project Project project = VsHelpers.GetDTEProjectFromConfig(_configFilePath); bool isCoreProject = await VsHelpers.IsDotNetCoreWebProjectAsync(project); if (!isCoreProject) { var logAction = new Action <string, LogLevel>((message, level) => { Logger.Log(message, level); }); bool deleteFromProject = await VsHelpers.DeleteFilesFromProjectAsync(project, absolutePaths, logAction, cancellationToken); if (deleteFromProject) { return(true); } } // Delete from file system return(await DeleteFilesFromDisk(absolutePaths, cancellationToken)); }
public void VsTextViewCreated(IVsTextView textViewAdapter) { IWpfTextView textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter); if (!DocumentService.TryGetTextDocument(textView.TextBuffer, out ITextDocument doc)) { return; } string fileName = Path.GetFileName(doc.FilePath); if (!fileName.Equals(Constants.ConfigFileName, StringComparison.OrdinalIgnoreCase)) { return; } new CompletionController(textViewAdapter, textView, CompletionBroker); _dependencies = Dependencies.FromConfigFile(doc.FilePath); _manifest = Manifest.FromFileAsync(doc.FilePath, _dependencies, CancellationToken.None).Result; _manifestPath = doc.FilePath; _project = VsHelpers.GetDTEProjectFromConfig(_manifestPath); if (_manifest == null) { AddErrorToList(PredefinedErrors.ManifestMalformed()); } doc.FileActionOccurred += OnFileSaved; textView.Closed += OnViewClosed; }
public async Task <bool> WriteFileAsync(string relativePath, Func <Stream> content, ILibraryInstallationState state, CancellationToken cancellationToken) { FileInfo absolutePath = new FileInfo(Path.Combine(WorkingDirectory, relativePath)); if (absolutePath.Exists) { return(true); } // Note: using OrdinalIgnoreCase comparison as this code path is exclusive to Windows if (!absolutePath.FullName.StartsWith(WorkingDirectory, StringComparison.OrdinalIgnoreCase)) { throw new UnauthorizedAccessException(); } absolutePath.Directory.Create(); using (Stream stream = content.Invoke()) { if (stream == null) { return(false); } await VsHelpers.CheckFileOutOfSourceControlAsync(absolutePath.FullName); await FileHelpers.SafeWriteToFileAsync(absolutePath.FullName, stream, cancellationToken); } Logger.Log(string.Format(LibraryManager.Resources.Text.FileWrittenToDisk, relativePath.Replace(Path.DirectorySeparatorChar, '/')), LogLevel.Operation); return(true); }
public int Exec(List <WorkspaceVisualNodeBase> selection, Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut) { ThreadHelper.ThrowIfNotOnUIThread(); if (IsSupportedCommand(pguidCmdGroup, nCmdID)) { if (selection.Count == 1 && selection[0] is IFolderNode folder) { string fileName = Path.Combine(folder.FullPath, Constants.FileName); if (File.Exists(fileName)) { MessageBox.Show(Resources.Text.EditorConfigFileAlreadyExist, Vsix.Name, MessageBoxButton.OK, MessageBoxImage.Information); } else { File.WriteAllText(fileName, Constants.DefaultFileContent); VsHelpers.OpenFile(fileName); } return(VSConstants.S_OK); } } return((int)Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED); }
private async Task BeforeQueryStatusAsync(object sender, EventArgs e) { var button = (OleMenuCommand)sender; button.Visible = button.Enabled = false; if (VsHelpers.DTE.SelectedItems.MultiSelect) { return; } ProjectItem item = await VsHelpers.GetSelectedItemAsync(); if (item != null && item.IsConfigFile()) { button.Visible = true; button.Enabled = KnownUIContexts.SolutionExistsAndNotBuildingAndNotDebuggingContext.IsActive; _isPackageInstalled = IsPackageInstalled(item.ContainingProject); if (_isPackageInstalled) { button.Text = Resources.Text.DisableRestoreOnBuild; } else { button.Text = Resources.Text.EnableRestoreOnBuild; } } }
public void VsTextViewCreated(IVsTextView textViewAdapter) { IWpfTextView textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter); if (!DocumentService.TryGetTextDocument(textView.TextBuffer, out ITextDocument doc)) { return; } string fileName = Path.GetFileName(doc.FilePath); if (!fileName.Equals(Constants.ConfigFileName, StringComparison.OrdinalIgnoreCase)) { return; } new CompletionController(textViewAdapter, textView, CompletionBroker); _dependencies = Dependencies.FromConfigFile(doc.FilePath); _manifest = Manifest.FromFileAsync(doc.FilePath, _dependencies, CancellationToken.None).Result; _manifestPath = doc.FilePath; _project = VsHelpers.GetDTEProjectFromConfig(_manifestPath); doc.FileActionOccurred += OnFileSaved; textView.Closed += OnViewClosed; Task.Run(async() => { IEnumerable <ILibraryOperationResult> results = await LibrariesValidator.GetManifestErrorsAsync(_manifest, _dependencies, CancellationToken.None).ConfigureAwait(false); if (!results.All(r => r.Success)) { AddErrorsToList(results); } }); }
private static void OnInstallationDone(object sender, InstallResult results) { if (!_handler.UserCancellation.IsCancellationRequested && results.MustRestart) { VsHelpers.PromptForRestart(_settings); } }
public IDialController TryCreateController(IDialControllerHost host) { string iconFilePath = VsHelpers.GetFileInVsix("Providers\\Customizable\\icon.png"); host.AddMenuItem(Moniker, iconFilePath); return(new CustomizableController()); }
public IDialController TryCreateController(IDialControllerHost host) { string iconFilePath = VsHelpers.GetFileInVsix("Providers\\Bookmarks\\icon.png"); host.AddMenuItem(Moniker, iconFilePath); return(new BookmarksController(host)); }
private void AddItem_BeforeQueryStatus(object sender, EventArgs e) { var button = sender as OleMenuCommand; button.Visible = false; var items = VsHelpers.GetSelectedItems(_dte); System.Diagnostics.Debugger.Break(); }
private async Task ExecuteAsync() { Telemetry.TrackUserTask("Execute-CleanCommand"); ProjectItem configProjectItem = await VsHelpers.GetSelectedItemAsync(); if (configProjectItem != null) { await _libraryCommandService.CleanAsync(configProjectItem, CancellationToken.None); } }
private async Task ExecuteAsync(object sender, EventArgs e) { Telemetry.TrackUserTask("Execute-RestoreCommand"); ProjectItem configProjectItem = await VsHelpers.GetSelectedItemAsync(); if (configProjectItem != null) { await _libraryCommandService.RestoreAsync(configProjectItem.get_FileNames(1), CancellationToken.None); } }
public static void ShowOutputWindowPane() { ThreadHelper.Generic.BeginInvoke(() => { if (EnsurePane()) { VsHelpers.ShowOutputWindow(); _pane.Activate(); } }); }
public override bool OnRotate(RotationDirection direction) { if (direction == RotationDirection.Right) { VsHelpers.ExecuteCommand(DialPackage.CustomOptions.RightAction); } else { VsHelpers.ExecuteCommand(DialPackage.CustomOptions.LeftAction); } return(true); }
public override bool OnRotate(RotationDirection direction) { if (direction == RotationDirection.Right) { VsHelpers.ExecuteCommand("Edit.GoToNextLocation"); } else { VsHelpers.ExecuteCommand("Edit.GoToPrevLocation"); } return(true); }
public override bool OnRotate(RotationDirection direction) { if (direction == RotationDirection.Right) { VsHelpers.ExecuteCommand("View.NavigateForward"); } else { VsHelpers.ExecuteCommand("View.NavigateBackward"); } return(true); }
public void OnRotate(RotationDirection direction, DialEventArgs e) { if (direction == RotationDirection.Right) { VsHelpers.ExecuteCommand("View.NavigateForward"); } else { VsHelpers.ExecuteCommand("View.NavigateBackward"); } e.Handled = true; }
private RestoreOnBuildCommand(AsyncPackage package, OleMenuCommandService commandService, IDependenciesFactory dependenciesFactory) { _package = package; _componentModel = VsHelpers.GetService <SComponentModel, IComponentModel>(); _dependenciesFactory = dependenciesFactory; var cmdId = new CommandID(PackageGuids.guidLibraryManagerPackageCmdSet, PackageIds.RestoreOnBuild); var cmd = new OleMenuCommand((s, e) => _package.JoinableTaskFactory.RunAsync(() => ExecuteAsync(s, e)), cmdId); cmd.BeforeQueryStatus += (s, e) => _package.JoinableTaskFactory.RunAsync(() => BeforeQueryStatusAsync(s, e)); commandService.AddCommand(cmd); }
public void OnRotate(RotationDirection direction, DialEventArgs e) { if (direction == RotationDirection.Right) { VsHelpers.ExecuteCommand("Edit.NextBookmark"); e.Action = "Go to next bookmark"; } else { VsHelpers.ExecuteCommand("Edit.PreviousBookmark"); e.Action = "Go to previous bookmark"; } e.Handled = true; }
private async Task BeforeQueryStatusAsync(object sender, EventArgs e) { var button = (OleMenuCommand)sender; button.Visible = button.Enabled = false; ProjectItem item = await VsHelpers.GetSelectedItemAsync(); if (item != null && item.Name.Equals(Constants.ConfigFileName, StringComparison.OrdinalIgnoreCase)) { button.Visible = true; button.Enabled = KnownUIContexts.SolutionExistsAndNotBuildingAndNotDebuggingContext.IsActive && !_libraryCommandService.IsOperationInProgress; } }
private void AddSwaggerCommand(object sender, EventArgs e) { var project = VsHelpers.GetActiveProject(_dte); //todo: figure out if we doing CS or TS based on project type - if possible //todo: if we on a folder node, path should be folder var uiOptions = new UIOptions { Overwrite = true }; uiOptions.Target = Path.Combine(Path.GetDirectoryName(project.FullName), "api.cs"); var window = new MainWindow(); window.SetUI(uiOptions); window.ShowDialog(); }
private static void OnUpdate(object sender, Progress progress) { var data = new TaskProgressData { ProgressText = progress.Text, PercentComplete = progress.Percent, CanBeCanceled = true }; _handler.Progress.Report(data); if (!_hasShownProgress) { _hasShownProgress = true; VsHelpers.ShowTaskStatusCenter(); } }
private async Task BeforeQueryStatusAsync(object sender, EventArgs e) { var button = (OleMenuCommand)sender; button.Visible = button.Enabled = false; if (VsHelpers.DTE.SelectedItems.MultiSelect) { return; } var solution = (IVsSolution)ServiceProvider.GetService(typeof(SVsSolution)); if (await VsHelpers.SolutionContainsManifestFileAsync(solution)) { button.Visible = true; button.Enabled = KnownUIContexts.SolutionExistsAndNotBuildingAndNotDebuggingContext.IsActive && !_libraryCommandService.IsOperationInProgress; } }
private async Task BeforeQueryStatusAsync(object sender, EventArgs e) { OleMenuCommand button = (OleMenuCommand)sender; button.Visible = button.Enabled = false; // When command is invooked from a folder ProjectItem item = await VsHelpers.GetSelectedItemAsync().ConfigureAwait(false); // When command is invoked from project scope Project project = await VsHelpers.GetProjectOfSelectedItemAsync().ConfigureAwait(false); // We won't enable the command if it was not invoked from a project or a folder if (item?.ContainingProject == null && project == null) { return; } button.Visible = true; button.Enabled = KnownUIContexts.SolutionExistsAndNotBuildingAndNotDebuggingContext.IsActive && !_libraryCommandService.IsOperationInProgress; }
public void VsTextViewCreated(IVsTextView textViewAdapter) { IWpfTextView textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter); if (!DocumentService.TryGetTextDocument(textView.TextBuffer, out ITextDocument doc)) { return; } string fileName = Path.GetFileName(doc.FilePath); if (!fileName.Equals(Constants.ConfigFileName, StringComparison.OrdinalIgnoreCase)) { return; } new CompletionController(textViewAdapter, textView, CompletionBroker); IDependencies dependencies = DependenciesFactory.FromConfigFile(doc.FilePath); #pragma warning disable VSTHRD002 // Avoid problematic synchronous waits // Justification: Manifest is free-threaded, don't need to use JTF here _manifest = Manifest.FromFileAsync(doc.FilePath, dependencies, CancellationToken.None).Result; #pragma warning restore VSTHRD002 // Avoid problematic synchronous waits _manifestPath = doc.FilePath; _project = VsHelpers.GetDTEProjectFromConfig(_manifestPath); doc.FileActionOccurred += OnFileSaved; textView.Closed += OnViewClosed; _ = Task.Run(async() => { IEnumerable <ILibraryOperationResult> results = await LibrariesValidator.GetManifestErrorsAsync(_manifest, dependencies, CancellationToken.None).ConfigureAwait(false); if (!results.All(r => r.Success)) { AddErrorsToList(results); Telemetry.LogErrors("Fail-ManifestFileOpenWithErrors", results); } }); }
/// <inheritdoc /> public async Task <bool> CopyFileAsync(string sourcePath, string destinationPath, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); string absoluteDestinationPath = Path.Combine(WorkingDirectory, destinationPath); if (!FileHelpers.IsUnderRootDirectory(absoluteDestinationPath, WorkingDirectory)) { throw new UnauthorizedAccessException(); } await VsHelpers.CheckFileOutOfSourceControlAsync(absoluteDestinationPath); bool result = await FileHelpers.CopyFileAsync(sourcePath, absoluteDestinationPath, cancellationToken); if (result) { Logger.Log(string.Format(LibraryManager.Resources.Text.FileWrittenToDisk, destinationPath.Replace(Path.DirectorySeparatorChar, '/')), LogLevel.Operation); } return(result); }
public static async Tasks.Task RunAsync() { _log.Debug("RunAsync"); bool hasUpdates = await Installer.CheckForUpdatesAsync(); if (!hasUpdates) { _log.Debug("Noupdates. Exiting"); return; } _hasShownProgress = false; _log.Debug("Getting services"); // Waits for MEF to initialize before the extension manager is ready to use await _package.GetServiceAsync(typeof(SComponentModel)); var repository = await _package.GetServiceAsync(typeof(SVsExtensionRepository)) as IVsExtensionRepository; var manager = await _package.GetServiceAsync(typeof(SVsExtensionManager)) as IVsExtensionManager; _log.Debug("services complete"); Version vsVersion = VsHelpers.GetVisualStudioVersion(); _log.Debug("Setuptaskstatuscenter"); _handler = await SetupTaskStatusCenter(); _log.Debug("Setuptaskstatuscenter complete"); _log.Debug("running installer async"); var task = Installer.RunAsync(vsVersion, repository, manager, _handler.UserCancellation); _handler.RegisterTask(task); await task; _log.Debug("RunAsync complete"); }
private async Task ExecuteAsync(object sender, EventArgs e) { Telemetry.TrackUserTask("Execute-RestoreSolutionCommand"); var solution = (IVsSolution)ServiceProvider.GetService(typeof(SVsSolution)); IEnumerable <IVsHierarchy> hierarchies = VsHelpers.GetProjectsInSolution(solution, __VSENUMPROJFLAGS.EPF_LOADEDINSOLUTION); var configFiles = new List <string>(); foreach (IVsHierarchy hierarchy in hierarchies) { Project project = VsHelpers.GetDTEProject(hierarchy); if (await VsHelpers.ProjectContainsManifestFileAsync(project)) { string rootPath = await project.GetRootFolderAsync(); string configFilePath = Path.Combine(rootPath, Constants.ConfigFileName); configFiles.Add(configFilePath); } } await _libraryCommandService.RestoreAsync(configFiles, CancellationToken.None); }