private void FSharpUpdateReferenceCallback(object sender, EventArgs e) { var projectItem = VSIXUtils.GetSelectObject <ProjectItem>(); _outputWindow.Show(); _outputWindow.WriteLine("--- Updating ServiceStack Reference '" + projectItem.Name + "' ---"); string projectItemPath = projectItem.Properties.Item("FullPath").Value.ToString(); var selectedFiles = projectItem.DTE.SelectedItems.Cast <SelectedItem>().ToList(); bool selectedFSharpDto = selectedFiles.Any((item) => item.Name.ToLowerInvariant().EndsWith(".dto.fs")); if (selectedFSharpDto) { string filePath = projectItemPath; var fSharpCodeAllLines = File.ReadAllLines(filePath).ToList(); string lineWithBaseUrl = fSharpCodeAllLines.FirstOrDefault(x => x.StartsWithIgnoreCase("BaseUrl: ")); if (lineWithBaseUrl == null) { _outputWindow.WriteLine("Unable to read URL from DTO file. Please ensure the file was generated correctly from a ServiceStack server."); return; } string baseUrl = lineWithBaseUrl.Substring(lineWithBaseUrl.IndexOf(" ", System.StringComparison.Ordinal)).Trim(); string appendFSharpPath = "types/fsharp"; string fSharpUrl = baseUrl.EndsWith("/") ? baseUrl + appendFSharpPath : baseUrl + "/" + appendFSharpPath; string updatedCode = new WebClient().DownloadString(fSharpUrl); using (var streamWriter = File.CreateText(filePath)) { streamWriter.Write(updatedCode); streamWriter.Flush(); } _outputWindow.WriteLine("--- Update ServiceStack Reference Complete ---"); } }
private void FSharpQueryAndAddUpdateMenuItem(object sender, EventArgs eventArgs) { OleMenuCommand command = (OleMenuCommand)sender; var monitorSelection = (IVsMonitorSelection)GetService(typeof(IVsMonitorSelection)); Guid guid = VSConstants.UICONTEXT.SolutionExistsAndNotBuildingAndNotDebugging_guid; uint contextCookie; int pfActive; monitorSelection.GetCmdUIContextCookie(ref guid, out contextCookie); var result = monitorSelection.IsCmdUIContextActive(contextCookie, out pfActive); var ready = result == VSConstants.S_OK && pfActive > 0; ProjectItem projectItem = VSIXUtils.GetSelectObject <ProjectItem>(); var selectedFiles = projectItem.DTE.SelectedItems.Cast <SelectedItem>(); bool selectedFSharpDto = selectedFiles.Any((item) => item.Name.ToLowerInvariant().EndsWith(".dto.fs")); command.Enabled = ready && selectedFSharpDto && projectItem.Kind != null && //Project is not unloaded !string.Equals(projectItem.ContainingProject.Kind, "{67294A52-A4F0-11D2-AA88-00C04F688DDE}", StringComparison.InvariantCultureIgnoreCase); command.Visible = selectedFSharpDto && projectItem.Kind != null && //Project is FSharp project string.Equals(projectItem.ContainingProject.Kind, "{F2A71F9B-5D33-465A-A702-920D77279786}", StringComparison.InvariantCultureIgnoreCase); }
/// <summary> /// This function is the callback used to execute a command when the a menu item is clicked. /// See the Initialize method to see how the menu item is associated to this function using /// the OleMenuCommandService service and the MenuCommand class. /// </summary> private void CSharpAddReferenceCallback(object sender, EventArgs e) { var t4TemplateBase = Resources.ServiceModelTemplate; var project = VSIXUtils.GetSelectedProject(); string projectPath = project.Properties.Item("FullPath").Value.ToString(); int fileNameNumber = 1; //Find a version of the default name that doesn't already exist, //mimicing VS default file name behaviour. while (File.Exists(Path.Combine(projectPath, "ServiceReference" + fileNameNumber + ".tt"))) { fileNameNumber++; } var dialog = new AddServiceStackReference("ServiceReference" + fileNameNumber); dialog.UseCSharpProvider(t4TemplateBase); dialog.ShowDialog(); if (!dialog.AddReferenceSucceeded) { return; } string templateCode = dialog.CodeTemplate; CreateAndAddTemplateToProject(dialog.FileNameTextBox.Text + ".tt", templateCode); }
private void AddNewDtoFileToProject(string fileName, string templateCode, List <string> nugetPackages = null) { nugetPackages = nugetPackages ?? new List <string>(); var project = VSIXUtils.GetSelectedProject() ?? VSIXUtils.GetSelectObject <ProjectItem>().ContainingProject; // This is a temporary work around for ServiceStack *.Core packages whilst they are separate/in beta. // This is to be removed/updated once the Text, Client and/or Interfaces NuGet packages support NetCore by default. nugetPackages = ApplyNetCoreNuGetPackages(nugetPackages, project); var path = VSIXUtils.GetSelectedProjectPath() ?? VSIXUtils.GetSelectedFolderPath(); string fullPath = Path.Combine(path, fileName); using (var streamWriter = File.CreateText(fullPath)) { streamWriter.Write(templateCode); streamWriter.Flush(); } // HACK avoid VS2015 Update 2 seems to detect file in use semi regularly. Thread.Sleep(20); var newDtoFile = project.ProjectItems.AddFromFile(fullPath); newDtoFile.Open(EnvDTE.Constants.vsViewKindCode); newDtoFile.Save(); foreach (var nugetPackage in nugetPackages) { AddNuGetDependencyIfMissing(project, nugetPackage); } project.Save(); }
private void FSharpQueryAndAddMenuItem(object sender, EventArgs eventArgs) { OleMenuCommand command = (OleMenuCommand)sender; var monitorSelection = (IVsMonitorSelection)GetService(typeof(IVsMonitorSelection)); Guid guid = VSConstants.UICONTEXT.SolutionExistsAndNotBuildingAndNotDebugging_guid; uint contextCookie; int pfActive; monitorSelection.GetCmdUIContextCookie(ref guid, out contextCookie); var result = monitorSelection.IsCmdUIContextActive(contextCookie, out pfActive); var ready = result == VSConstants.S_OK && pfActive > 0; Project project = VSIXUtils.GetSelectedProject(); command.Enabled = ready && project != null && project.Kind != null && //Project is not unloaded !string.Equals(project.Kind, "{67294A52-A4F0-11D2-AA88-00C04F688DDE}", StringComparison.InvariantCultureIgnoreCase); command.Visible = project != null && project.Kind != null && //Project is FSharp project string.Equals(project.Kind, "{F2A71F9B-5D33-465A-A702-920D77279786}", StringComparison.InvariantCultureIgnoreCase); }
private void VbNetAddReferenceCallback(object sender, EventArgs e) { var projectPath = VSIXUtils.GetSelectedProjectPath(); var typesHandler = NativeTypeHandlers.VbNetNativeTypesHandler; AddServiceStackReference(projectPath, typesHandler); }
private void TypeScriptQueryAddMenuItem(object sender, EventArgs eventArgs) { var command = (OleMenuCommand)sender; var monitorSelection = (IVsMonitorSelection)GetService(typeof(IVsMonitorSelection)); var guid = VSConstants.UICONTEXT.SolutionExistsAndNotBuildingAndNotDebugging_guid; // Adding static files while running supported by VS 2015+ if (MajorVisualStudioVersion > 11) { guid = VSConstants.UICONTEXT.SolutionExistsAndFullyLoaded_guid; } uint contextCookie; int pfActive; monitorSelection.GetCmdUIContextCookie(ref guid, out contextCookie); var result = monitorSelection.IsCmdUIContextActive(contextCookie, out pfActive); var ready = result == VSConstants.S_OK && pfActive > 0; var isProjectItemAFolder = VSIXUtils.IsSelectProjectItemAFolder(); var isAProjectAndLoaded = VSIXUtils.IsSelectedItemAReadyProject(); bool visible = isAProjectAndLoaded || isProjectItemAFolder; bool enabled = visible && ready; command.Visible = visible; command.Enabled = enabled; }
private void VbNetQueryAddMenuItem(object sender, EventArgs eventArgs) { var command = (OleMenuCommand)sender; var monitorSelection = (IVsMonitorSelection)GetService(typeof(IVsMonitorSelection)); var guid = VSConstants.UICONTEXT.SolutionExistsAndNotBuildingAndNotDebugging_guid; uint contextCookie; int pfActive; monitorSelection.GetCmdUIContextCookie(ref guid, out contextCookie); var result = monitorSelection.IsCmdUIContextActive(contextCookie, out pfActive); var ready = result == VSConstants.S_OK && pfActive > 0; var project = VSIXUtils.GetSelectedProject(); bool visible = project != null && project.Kind != null && //Project is not unloaded !string.Equals(project.Kind, VsHelperGuids.ProjectUnloaded, StringComparison.InvariantCultureIgnoreCase) && //Project is VbNet project string.Equals(project.Kind, VsHelperGuids.VbNetProjectKind, StringComparison.InvariantCultureIgnoreCase); bool enabled = visible && ready; command.Visible = visible; command.Enabled = enabled; }
private void AddNewDtoFileToProject(string fileName, string templateCode, List <string> nugetPackages = null) { nugetPackages = nugetPackages ?? new List <string>(); var project = VSIXUtils.GetSelectedProject() ?? VSIXUtils.GetSelectObject <ProjectItem>().ContainingProject; var path = VSIXUtils.GetSelectedProjectPath() ?? VSIXUtils.GetSelectedFolderPath(); string fullPath = Path.Combine(path, fileName); using (var streamWriter = File.CreateText(fullPath)) { streamWriter.Write(templateCode); streamWriter.Flush(); } // HACK avoid VS2015 Update 2 seems to detect file in use semi regularly. Thread.Sleep(20); var newDtoFile = project.ProjectItems.AddFromFile(fullPath); newDtoFile.Open(EnvDTE.Constants.vsViewKindCode); newDtoFile.Save(); foreach (var nugetPackage in nugetPackages) { AddNuGetDependencyIfMissing(project, nugetPackage); } project.Save(); }
private void TypeScriptAddReferenceCallback(object sender, EventArgs e) { var projectPath = VSIXUtils.GetSelectedProjectPath(); var folderPath = VSIXUtils.GetSelectedFolderPath(); string finalPath = projectPath ?? folderPath; var typesHandler = NativeTypeHandlers.TypeScriptNativeTypesHandler; AddServiceStackReference(finalPath, typesHandler); }
private void UpdateReferenceCallback(object sender, EventArgs e) { var projectItem = VSIXUtils.GetSelectObject <ProjectItem>(); var selectedFiles = projectItem.DTE.SelectedItems.Cast <SelectedItem>(); var selectedItems = selectedFiles as IList <SelectedItem> ?? selectedFiles.ToList(); var typeHandlers = selectedItems.GetTypeHandlerForSelectedFiles(); if (typeHandlers.Count == 0) { return; } var typesHandler = typeHandlers.First(); UpdateGeneratedDtos(projectItem, typesHandler); }
private void QueryUpdateMenuItem(object sender, EventArgs eventArgs) { var command = (OleMenuCommand)sender; var ready = IsProjectReady(); var projectItem = VSIXUtils.GetSelectObject <ProjectItem>(); var selectedFiles = projectItem.DTE.SelectedItems.Cast <SelectedItem>(); var selectedItems = selectedFiles as IList <SelectedItem> ?? selectedFiles.ToList(); bool visible = projectItem.ContainingProject != null && projectItem.ContainingProject.Kind != null && //Project is not unloaded !string.Equals(projectItem.ContainingProject.Kind, VsHelperGuids.ProjectUnloaded, StringComparison.InvariantCultureIgnoreCase); if (!visible) { command.Visible = false; command.Enabled = false; return; } var typeHandlers = selectedItems.GetTypeHandlerForSelectedFiles(); if (typeHandlers.Count == 0) { command.Visible = false; command.Enabled = false; return; } var typeHandler = typeHandlers.First(); bool validVsProjectType = typeHandler.ValidVsProjectTypeGuids().FirstOrDefault( projectTypeGuid => string.Equals(projectItem.ContainingProject.Kind, projectTypeGuid, StringComparison.InvariantCultureIgnoreCase)) != null; // Ensure update button is visable and project is 'ready' (of right type and not building) or item clicked is typescript dtos file. bool enabled = ready || (typeHandler.GetType() == typeof(TypeScriptNativeTypesHandler) || typeHandler.GetType() == typeof(TypeScriptConcreteNativeTypesHandler)); command.Visible = validVsProjectType; command.Enabled = enabled; }
private void CreateAndAddTemplateToProject(string fileName, string templateCode) { var project = VSIXUtils.GetSelectedProject(); string projectPath = project.Properties.Item("FullPath").Value.ToString(); string fullPath = Path.Combine(projectPath, fileName); using (var streamWriter = File.CreateText(fullPath)) { streamWriter.Write(templateCode); streamWriter.Flush(); } var t4TemplateProjectItem = project.ProjectItems.AddFromFile(fullPath); t4TemplateProjectItem.Open(EnvDTE.Constants.vsViewKindCode); t4TemplateProjectItem.Save(); AddNuGetDependencyIfMissing(project, "ServiceStack.Client"); AddNuGetDependencyIfMissing(project, "ServiceStack.Text"); project.Save(); }
private void QueryUpdateMenuItem(object sender, EventArgs eventArgs) { var command = (OleMenuCommand)sender; var ready = IsProjectReady(); var projectItem = VSIXUtils.GetSelectObject <ProjectItem>(); var selectedFiles = projectItem.DTE.SelectedItems.Cast <SelectedItem>(); var selectedItems = selectedFiles as IList <SelectedItem> ?? selectedFiles.ToList(); var typeHandlers = selectedItems.GetTypeHandlerForSelectedFiles(); if (typeHandlers.Count > 0) { var typeHandler = typeHandlers.First(); bool validVsProjectType = typeHandler.ValidVsProjectTypeGuids().FirstOrDefault( projectTypeGuid => string.Equals(projectItem.ContainingProject.Kind, projectTypeGuid, StringComparison.InvariantCultureIgnoreCase)) != null; bool visible = projectItem.ContainingProject != null && projectItem.ContainingProject.Kind != null && //Project is not unloaded !string.Equals(projectItem.ContainingProject.Kind, VsHelperGuids.ProjectUnloaded, StringComparison.InvariantCultureIgnoreCase) && validVsProjectType; bool enabled = visible && ready; command.Visible = enabled; command.Enabled = enabled; } else { command.Visible = false; command.Enabled = false; } }
private void AddNewDtoFileToProject(string fileName, string templateCode, List <string> nugetPackages = null) { nugetPackages = nugetPackages ?? new List <string>(); var project = VSIXUtils.GetSelectedProject() ?? VSIXUtils.GetSelectObject <ProjectItem>().ContainingProject; var path = VSIXUtils.GetSelectedProjectPath() ?? VSIXUtils.GetSelectedFolderPath(); string fullPath = Path.Combine(path, fileName); File.WriteAllText(fullPath, templateCode); try { // HACK avoid VS2015 Update 2 seems to detect file in use semi regularly. Thread.Sleep(50); var newDtoFile = project.ProjectItems.AddFromFile(fullPath); newDtoFile.Open(EnvDteConstants.vsViewKindCode); newDtoFile.Save(); } catch (Exception) {} try { foreach (var nugetPackage in nugetPackages) { AddNuGetDependencyIfMissing(project, nugetPackage); } } catch (Exception) {} try { project.Save(); } catch (Exception) {} }