PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
C# | 171 lines | 159 code | 12 blank | 0 comment | 33 complexity | ec2ad004d011badbaa5809c85e012dc2 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.ManagedInterfaces9;
  6. using Microsoft.VisualStudio.OLE.Interop;
  7. using Microsoft.VisualStudio.Shell;
  8. using Microsoft.VisualStudio.Shell.Interop;
  9. using Microsoft.VisualStudio.TemplateWizard;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Configuration;
  13. using System.IO;
  14. using System.Threading;
  15. using System.Windows.Forms;
  16. using System.Windows.Forms.Design;
  17. internal class AuthenticationDomainServiceWizard : IWizard
  18. {
  19. private DTE2 _dte2;
  20. private Project _project;
  21. public void BeforeOpeningFile(ProjectItem projectItem)
  22. {
  23. }
  24. private object GetService(System.Type serviceType)
  25. {
  26. Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp = this.Dte2 as Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
  27. if (sp == null)
  28. {
  29. return null;
  30. }
  31. using (ServiceProvider provider2 = new ServiceProvider(sp))
  32. {
  33. return provider2.GetService(serviceType);
  34. }
  35. }
  36. public void ProjectFinishedGenerating(Project project)
  37. {
  38. }
  39. public void ProjectItemFinishedGenerating(ProjectItem projectItem)
  40. {
  41. this._project = projectItem.ContainingProject;
  42. }
  43. public void RunFinished()
  44. {
  45. Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp = this.Dte2 as Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
  46. IVsApplicationConfigurationManager manager = null;
  47. IVsHierarchy ppHierarchy = null;
  48. using (ServiceProvider provider2 = new ServiceProvider(sp))
  49. {
  50. IVsSolution service = provider2.GetService(typeof(IVsSolution)) as IVsSolution;
  51. if (service != null)
  52. {
  53. manager = provider2.GetService(typeof(IVsApplicationConfigurationManager)) as IVsApplicationConfigurationManager;
  54. if ((manager != null) && ((service.GetProjectOfUniqueName(this._project.UniqueName, out ppHierarchy) == 0) && (ppHierarchy != null)))
  55. {
  56. goto Label_0083;
  57. }
  58. }
  59. return;
  60. }
  61. Label_0083:
  62. using (IVsApplicationConfiguration configuration = manager.GetApplicationConfiguration(ppHierarchy, 0xfffffffe))
  63. {
  64. if ((configuration != null) && configuration.FileExists())
  65. {
  66. System.Configuration.Configuration configuration2 = configuration.LoadConfiguration();
  67. if (configuration2 != null)
  68. {
  69. WebConfigUtil util = new WebConfigUtil(configuration2);
  70. bool flag = util.DoWeNeedToAddHttpModule();
  71. bool flag2 = util.DoWeNeedToAddModuleToWebServer();
  72. bool flag3 = !util.IsAspNetCompatibilityEnabled();
  73. bool flag4 = !util.IsMultipleSiteBindingsEnabled();
  74. bool flag5 = util.DoWeNeedToValidateIntegratedModeToWebServer();
  75. if ((flag || flag2) || ((flag3 || flag4) || flag5))
  76. {
  77. string domainServiceModuleTypeName = WebConfigUtil.GetDomainServiceModuleTypeName();
  78. configuration.QueryEditConfiguration();
  79. if (flag)
  80. {
  81. util.AddHttpModule(domainServiceModuleTypeName);
  82. }
  83. if (flag2)
  84. {
  85. util.AddModuleToWebServer(domainServiceModuleTypeName);
  86. }
  87. if (flag3)
  88. {
  89. util.SetAspNetCompatibilityEnabled(true);
  90. }
  91. if (flag4)
  92. {
  93. util.SetMultipleSiteBindingsEnabled(true);
  94. }
  95. if (flag5)
  96. {
  97. util.AddValidateIntegratedModeToWebServer();
  98. }
  99. configuration2.Save();
  100. }
  101. }
  102. }
  103. }
  104. }
  105. public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
  106. {
  107. this._dte2 = (DTE2) automationObject;
  108. string str = replacementsDictionary["$rootname$"];
  109. str = str.Trim();
  110. if (string.IsNullOrEmpty(str))
  111. {
  112. this.TerminateWizard(Resources.WizardError_Empty_Filename);
  113. }
  114. if (string.IsNullOrEmpty(Path.GetFileNameWithoutExtension(str)))
  115. {
  116. this.TerminateWizard(Resources.WizardError_Empty_Filename);
  117. }
  118. }
  119. public bool ShouldAddProjectItem(string filePath)
  120. {
  121. return true;
  122. }
  123. private void ShowError(string errorMessage)
  124. {
  125. IUIService service = (IUIService) this.GetService(typeof(IUIService));
  126. if (service != null)
  127. {
  128. MessageBoxOptions options = 0;
  129. IWin32Window dialogOwnerWindow = service.GetDialogOwnerWindow();
  130. if (System.Threading.Thread.CurrentThread.CurrentUICulture.TextInfo.IsRightToLeft)
  131. {
  132. options |= MessageBoxOptions.RightAlign;
  133. options |= MessageBoxOptions.RtlReading;
  134. }
  135. MessageBox.Show(dialogOwnerWindow, errorMessage, Resources.WizardError_Caption, MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1, options);
  136. }
  137. }
  138. private void TerminateWizard(string errorMessage)
  139. {
  140. if (!string.IsNullOrEmpty(errorMessage))
  141. {
  142. this.ShowError(errorMessage);
  143. throw new WizardCancelledException(errorMessage);
  144. }
  145. throw new WizardCancelledException();
  146. }
  147. private DTE2 Dte2
  148. {
  149. get
  150. {
  151. if (this._dte2 == null)
  152. {
  153. this.TerminateWizard(Resources.WizardError_No_DTE);
  154. }
  155. return this._dte2;
  156. }
  157. }
  158. }
  159. }