PageRenderTime 54ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/SolutionFramework/Microsoft.VisualStudio.ServiceModel.DomainServices.Tools.10.0/Microsoft/VisualStudio/ServiceModel/DomainServices/Tools/BusinessApplicationProjectTemplateWizard.cs

#
C# | 166 lines | 153 code | 13 blank | 0 comment | 27 complexity | 5bdf12088cc4b6edc93db91ce2f6654d MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0
  1. namespace Microsoft.VisualStudio.ServiceModel.DomainServices.Tools
  2. {
  3. using EnvDTE;
  4. using EnvDTE80;
  5. using Microsoft.VisualStudio.OLE.Interop;
  6. using Microsoft.VisualStudio.Shell;
  7. using Microsoft.VisualStudio.Shell.Interop;
  8. using Microsoft.VisualStudio.TemplateWizard;
  9. using Microsoft.VisualStudio.Web.Silverlight;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Runtime.InteropServices;
  15. public class BusinessApplicationProjectTemplateWizard : IWizard
  16. {
  17. private object[] _customParams;
  18. private DTE2 _dte2;
  19. private Dictionary<string, string> _replacementsDictionary;
  20. private Project _selectedSolutionFolder;
  21. private Solution2 _solution2;
  22. private string _webProjectName;
  23. public void BeforeOpeningFile(ProjectItem projectItem)
  24. {
  25. }
  26. private ProjectItem GetAspxTestPage(Project project)
  27. {
  28. string testPage = this._dte2.Globals["safeclientprojectname"] + "TestPage.aspx";
  29. return project.ProjectItems.Cast<ProjectItem>().FirstOrDefault<ProjectItem>(item => item.Name.Equals(testPage, StringComparison.OrdinalIgnoreCase));
  30. }
  31. private Project GetProject(string projectName)
  32. {
  33. Project project = null;
  34. if (this._selectedSolutionFolder != null)
  35. {
  36. project = GetProject(from p in this._selectedSolutionFolder.ProjectItems.Cast<ProjectItem>()
  37. where p.SubProject != null
  38. select p.SubProject, projectName);
  39. }
  40. return (project ?? GetProject(this._dte2.Solution.Projects.Cast<Project>(), projectName));
  41. }
  42. private static Project GetProject(IEnumerable<Project> projects, string projectName)
  43. {
  44. foreach (Project project in projects)
  45. {
  46. if (Path.GetFileNameWithoutExtension(project.FullName).Equals(projectName))
  47. {
  48. return project;
  49. }
  50. }
  51. return null;
  52. }
  53. private Project GetSilverlightProject()
  54. {
  55. string projectName = this._replacementsDictionary["$safeprojectname$"];
  56. return this.GetProject(projectName);
  57. }
  58. private Project GetWebProject()
  59. {
  60. return this.GetProject(this._webProjectName);
  61. }
  62. public void ProjectFinishedGenerating(Project project)
  63. {
  64. }
  65. public void ProjectItemFinishedGenerating(ProjectItem projectItem)
  66. {
  67. }
  68. public void RunFinished()
  69. {
  70. Project silverlightProject = this.GetSilverlightProject();
  71. if ((this._customParams.Length > 0) && (this._customParams[0] != null))
  72. {
  73. string str = Path.GetDirectoryName((string) this._customParams[0]);
  74. string path = Path.Combine(str, "BA.Web");
  75. if (!Directory.Exists(path))
  76. {
  77. path = Path.Combine(str, "BusinessApplication.Web");
  78. }
  79. string fileName = Path.Combine(path, "server.vstemplate");
  80. string destination = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(silverlightProject.FullName)), this._webProjectName);
  81. this._solution2.AddFromTemplate(fileName, destination, this._webProjectName, false);
  82. }
  83. Project webProject = this.GetWebProject();
  84. if (webProject != null)
  85. {
  86. this._dte2.Solution.SolutionBuild.StartupProjects = webProject.UniqueName;
  87. Properties properties = webProject.Properties;
  88. ProjectItem aspxTestPage = this.GetAspxTestPage(webProject);
  89. if (aspxTestPage != null)
  90. {
  91. properties.Item("WebApplication.StartPageUrl").Value = aspxTestPage.Name;
  92. properties.Item("WebApplication.DebugStartAction").Value = 1;
  93. }
  94. if (silverlightProject != null)
  95. {
  96. IVsHierarchy hierarchy;
  97. IVsHierarchy hierarchy2;
  98. silverlightProject.Properties.Item("SilverlightProject.LinkedServerProject").Value = webProject.FullName;
  99. Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp = this._dte2 as Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
  100. IVsSolution service = null;
  101. using (ServiceProvider provider2 = new ServiceProvider(sp))
  102. {
  103. service = provider2.GetService(typeof(IVsSolution)) as IVsSolution;
  104. }
  105. if (((service.GetProjectOfUniqueName(webProject.UniqueName, out hierarchy) == 0) && (hierarchy != null)) && (service.GetProjectOfUniqueName(silverlightProject.UniqueName, out hierarchy2) == 0))
  106. {
  107. (hierarchy as IVsSilverlightProjectConsumer).LinkToSilverlightProject("ClientBin", true, false, hierarchy2 as IVsSilverlightProject);
  108. }
  109. }
  110. }
  111. FileInfo info = new FileInfo(webProject.FullName);
  112. string directoryName = info.DirectoryName;
  113. ProjectItem item2 = silverlightProject.ProjectItems.AddFolder("Web", null).ProjectItems.AddFolder("Resources", null);
  114. foreach (string str6 in Directory.GetFiles(Path.Combine(directoryName, "Resources"), "*.resx"))
  115. {
  116. item2.ProjectItems.AddFromFile(str6).Properties.Item("CustomTool").Value = "PublicResXFileCodeGenerator";
  117. }
  118. SolutionBuild solutionBuild = this._solution2.SolutionBuild;
  119. if (silverlightProject != null)
  120. {
  121. solutionBuild.BuildProject(solutionBuild.ActiveConfiguration.Name, silverlightProject.UniqueName, true);
  122. }
  123. this._solution2.FindProjectItem("MainPage.xaml").Open("{00000000-0000-0000-0000-000000000000}");
  124. }
  125. public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
  126. {
  127. this._dte2 = (DTE2) automationObject;
  128. this._solution2 = (Solution2) this._dte2.Solution;
  129. this._replacementsDictionary = replacementsDictionary;
  130. this._replacementsDictionary["$targetsilverlightversion$"] = TemplateUtilities.GetSilverlightToolsVersion();
  131. this._dte2.Globals["safeclientprojectname"] = replacementsDictionary["$safeprojectname$"];
  132. this._webProjectName = this._replacementsDictionary["$safeprojectname$"] + ".Web";
  133. this._customParams = customParams;
  134. Array source = null;
  135. try
  136. {
  137. source = (Array) this._dte2.ActiveSolutionProjects;
  138. }
  139. catch (COMException)
  140. {
  141. }
  142. Project project = (source == null) ? null : source.OfType<Project>().FirstOrDefault<Project>();
  143. if ((project != null) && (project.Kind == "{66A26720-8FB5-11D2-AA7E-00C04F688DDE}"))
  144. {
  145. this._selectedSolutionFolder = project;
  146. }
  147. }
  148. public bool ShouldAddProjectItem(string filePath)
  149. {
  150. return true;
  151. }
  152. }
  153. }