public static VsixApplication Create(IVisualStudioService visualStudioService, IDependencyResolver dependencyResolver, string applicationName, Guid commandSetId, bool isWizardContext = false) { var applicationController = new VsixApplicationController(dependencyResolver, applicationName); var vsixSettingsManager = new VsixSettingsManager(visualStudioService, new DesktopSettingsManager(applicationController)); var app = new VsixApplication(applicationController, vsixSettingsManager, commandSetId, isWizardContext); return(app); }
public override void RunStartedExtention(Dictionary <string, string> replacementsDictionary) { AddRootNamespaceReplacement(replacementsDictionary); var vsixSettingsManager = new VsixSettingsManager(VisualStudioService); var packageSettings = vsixSettingsManager.Resolve <XrmPackageSettings>(); if (packageSettings == null) { throw new NullReferenceException("packageSettings"); } AddReplacements(replacementsDictionary, packageSettings); }
protected override TestApplication CreateAndLoadTestApplication <TModule>(ApplicationControllerBase applicationController = null, ISettingsManager settingsManager = null, bool loadXrmConnection = true, bool addSavedConnectionAppConnectionModule = false) { var container = new VsixDependencyContainer(); var visualStudioService = VisualStudioService; container.RegisterInstance(typeof(IVisualStudioService), visualStudioService); var vsixController = new FakeVsixApplicationController(container); var vsixSettingsManager = new VsixSettingsManager(VisualStudioService, new DesktopSettingsManager(vsixController)); container.RegisterInstance(typeof(ISettingsManager), vsixSettingsManager); var app = base.CreateAndLoadTestApplication <TModule>(vsixController, vsixSettingsManager, loadXrmConnection: InitialiseModuleXrmConnection, addSavedConnectionAppConnectionModule: addSavedConnectionAppConnectionModule); app.AddModule <PackageSettingsAppConnectionModule>(); return(app); }
public override void RunFinishedExtention() { try { if (DestinationDirectory.EndsWith(SafeProjectName + Path.DirectorySeparatorChar + SafeProjectName)) { //The projects were created under a seperate folder -- lets fix it //first move each projects up a directory var projectsObjects = new List <Project>(); foreach (Project childProject in DTE.Solution.Projects) { var fileName = childProject.FileName; if (!string.IsNullOrEmpty(fileName)) //Solution Folder { var projectBadPath = fileName; var projectGoodPath = projectBadPath.Replace( SafeProjectName + Path.DirectorySeparatorChar + SafeProjectName + Path.DirectorySeparatorChar, SafeProjectName + Path.DirectorySeparatorChar); DTE.Solution.Remove(childProject); Directory.Move(Path.GetDirectoryName(projectBadPath), Path.GetDirectoryName(projectGoodPath)); DTE.Solution.AddFromFile(projectGoodPath); } } //now add the references to the plugin project //because they got removed when we move the project folders Project pluginProject = null; foreach (Project childProject in DTE.Solution.Projects) { var fileName = childProject.FileName; if (!string.IsNullOrEmpty(fileName)) //Solution Folder { if (fileName.EndsWith(".Plugins.csproj")) { pluginProject = childProject; } } } foreach (Project childProject in DTE.Solution.Projects) { var fileName = childProject.FileName; if (!string.IsNullOrEmpty(fileName)) //Solution Folder { if (fileName.EndsWith(".Test.csproj") || fileName.EndsWith(".Console.csproj")) { VSProject vsProj = (VSProject)childProject.Object; vsProj.References.AddProject(pluginProject); } } } } if (DestinationDirectory.EndsWith(SafeProjectName + Path.DirectorySeparatorChar + SafeProjectName)) { DestinationDirectory = DestinationDirectory.Substring(0, DestinationDirectory.Length - (Path.DirectorySeparatorChar + SafeProjectName).Length); } //okay so lets update the encrypt connection bat and the xrmsetting.txt files in the console project var consoleProjectPath = DestinationDirectory + Path.DirectorySeparatorChar + SafeProjectName + ".Console"; var encryptBatFileName = consoleProjectPath + Path.DirectorySeparatorChar + "Encrypt XRM Connection.bat"; if (File.Exists(encryptBatFileName)) { var read = File.ReadAllText(encryptBatFileName); read = read.Replace("$ext_safeprojectname$", SafeProjectName); File.WriteAllText(encryptBatFileName, read); } var consoleConnectionFileName = consoleProjectPath + Path.DirectorySeparatorChar + "XrmSetting.txt"; if (File.Exists(consoleConnectionFileName)) { if (XrmPackageSettings != null && XrmPackageSettings.Connections != null && XrmPackageSettings.Connections.Any()) { try { var connection = XrmPackageSettings.Connections.First(); var serialise = ObjectToJsonString(connection); File.WriteAllText(consoleConnectionFileName, serialise); } catch (Exception ex) { MessageBox.Show("Error setting console application connection: " + ex.DisplayString()); } } } var visualStudioService = new VisualStudioService(DTE, useSolutionDirectory: DestinationDirectory); //add xrm connection and package settings to solution items var vsixSettingsManager = new VsixSettingsManager(visualStudioService, null); vsixSettingsManager.SaveSettingsObject(XrmPackageSettings); if (XrmPackageSettings.Connections.Any()) { vsixSettingsManager.SaveSettingsObject(XrmPackageSettings.Connections.First()); } visualStudioService.CloseAllDocuments(); RemoveEmptyFolders(DestinationDirectory); VsixApplication.VsixApplicationController.LogEvent("Xrm Solution Template Wizard Completed", new Dictionary <string, string> { { "Is Completed Event", true.ToString() } }); } catch (Exception ex) { VsixApplication.VsixApplicationController.LogEvent("Xrm Solution Template Wizard Fatal Error", new Dictionary <string, string> { { "Is Error", true.ToString() }, { "Error", ex.Message }, { "Error Trace", ex.DisplayString() } }); throw; } }