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

/Portal/CSP Portal Code/CSP.Package/Controls/CreateInternetWebApplication.cs

#
C# | 269 lines | 235 code | 34 blank | 0 comment | 22 complexity | 9a6d2b1374aae335e8de14096394827a MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Diagnostics;
  10. using Microsoft.Win32;
  11. namespace CSP.Package.Controls
  12. {
  13. public partial class CreateInternetWebApplication : UserControl, IInstallationControl
  14. {
  15. private const string _executionPath = @"InternetPortal\CreateWebApplication.bat";
  16. public CreateInternetWebApplication()
  17. {
  18. InitializeComponent();
  19. }
  20. #region IInstallationControl Members
  21. private Installer _form;
  22. public Installer GetForm()
  23. {
  24. return _form;
  25. }
  26. public void SetForm(Installer installer)
  27. {
  28. _form = installer;
  29. }
  30. private bool ValidateInputs()
  31. {
  32. if (checkBox1.Checked)
  33. {
  34. if (txbUrl.Text.Length == 0)
  35. {
  36. MessageBox.Show(CSP.Package.labels.CspInstallError_UrlNoEmpty, CSP.Package.labels.CspInstallError_Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
  37. txbUrl.Focus();
  38. txbUrl.Select();
  39. return false;
  40. }
  41. return true;
  42. }
  43. else
  44. {
  45. if (txbPort.Text.Length > 0)
  46. {
  47. try
  48. {
  49. int i = Convert.ToInt32(txbPort.Text);
  50. }
  51. catch
  52. {
  53. MessageBox.Show(CSP.Package.labels.CspInstallError_PortInteger, CSP.Package.labels.CspInstallError_Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
  54. txbPort.Focus();
  55. txbPort.Select();
  56. return false;
  57. }
  58. }
  59. if (txbLogin.Text.Length == 0)
  60. {
  61. MessageBox.Show(CSP.Package.labels.CspInstallError_LoginNoEmpty, CSP.Package.labels.CspInstallError_Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
  62. txbLogin.Focus();
  63. txbLogin.Select();
  64. return false;
  65. }
  66. if (txbEmail.Text.Length == 0)
  67. {
  68. MessageBox.Show(CSP.Package.labels.CspInstallError_EmailNoEmpty, CSP.Package.labels.CspInstallError_Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
  69. txbEmail.Focus();
  70. txbEmail.Select();
  71. return false;
  72. }
  73. if (chkApid.Checked)
  74. {
  75. if (txbApiduser.Text.Length == 0)
  76. {
  77. MessageBox.Show(CSP.Package.labels.CspInstallError_UsernameNoEmpty, CSP.Package.labels.CspInstallError_Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
  78. txbApiduser.Focus();
  79. txbApiduser.Select();
  80. return false;
  81. }
  82. if (txbApidpwd.Text.Length == 0)
  83. {
  84. MessageBox.Show(CSP.Package.labels.CspInstallError_PasswordNoEmpty, CSP.Package.labels.CspInstallError_Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
  85. txbApidpwd.Focus();
  86. txbApidpwd.Select();
  87. return false;
  88. }
  89. if (!txbApidpwd.Text.Equals(txbApidpwd2.Text))
  90. {
  91. MessageBox.Show(CSP.Package.labels.CspInstallError_PasswordNoMatch, CSP.Package.labels.CspInstallError_Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
  92. txbApidpwd.Focus();
  93. txbApidpwd.Select();
  94. return false;
  95. }
  96. }
  97. return true;
  98. }
  99. }
  100. public bool Next()
  101. {
  102. try
  103. {
  104. if (ValidateInputs())
  105. {
  106. GetForm().AddToLog("----------------------------------------------");
  107. GetForm().AddToLog(CSP.Package.labels.CspInstallLog_InternetWebApplicationStart);
  108. if (!checkBox1.Checked)
  109. {
  110. Process proces = new Process();
  111. proces.StartInfo.CreateNoWindow = false;
  112. proces.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
  113. proces.StartInfo.FileName = _executionPath;
  114. string arguments = string.Format(@"{0} ""{1}"" {2} {3} {4} {5}", new string[] { GetWebApplicationUrl(), GetWebApplicationDescription(), txbLogin.Text, txbEmail.Text, chkApid.Checked ? txbApiduser.Text : string.Empty, chkApid.Checked ? txbApidpwd.Text : string.Empty });
  115. GetForm().AddToLog(" " + labels.CspInstallLog_Arguments + ": " + arguments);
  116. proces.StartInfo.Arguments = arguments;
  117. proces.StartInfo.UseShellExecute = false;
  118. proces.StartInfo.RedirectStandardOutput = true;
  119. proces.StartInfo.RedirectStandardError = true;
  120. proces.Start();
  121. string error = proces.StandardError.ReadToEnd();
  122. string output = proces.StandardOutput.ReadToEnd();
  123. proces.WaitForExit();
  124. if (error != string.Empty)
  125. {
  126. throw new ApplicationException(error);
  127. }
  128. GetForm().AddToLog(output);
  129. }
  130. RegistryAccess.CreateStringProperty(Registry.LocalMachine, Constants.CspRegistryKey, "CSPInternetWebApplication", GetWebApplicationUrl());
  131. RegistryAccess.CreateStringProperty(Registry.LocalMachine, Constants.CspRegistryKey, "CSPInternetIdentity", chkApid.Checked?txbApiduser.Text : "NT Authority\\NetworkService");
  132. return true;
  133. }
  134. else
  135. {
  136. return false;
  137. }
  138. }
  139. catch (Exception ex)
  140. {
  141. this.GetForm().ShowException(ex);
  142. throw ex;
  143. }
  144. }
  145. public void Previous()
  146. {
  147. }
  148. public void Skip()
  149. {
  150. }
  151. #endregion
  152. private void TranslateLiterals()
  153. {
  154. richTextBox1.Text = CSP.Package.labels.CreateInternetWebApplication_Intro;
  155. groupBox1.Text = CSP.Package.labels.IISWebSite_GroupBox;
  156. groupBox2.Text = CSP.Package.labels.ApplicationPoolCredentials_GroupBox;
  157. groupBox3.Text = CSP.Package.labels.OwnerInformation_GroupBox;
  158. groupBox4.Text = CSP.Package.labels.ExistingWebApplication_GroupBox;
  159. label5.Text = CSP.Package.labels.Port_Label;
  160. label6.Text = CSP.Package.labels.HostHeader_Label;
  161. label2.Text = CSP.Package.labels.Description_Label;
  162. label9.Text = CSP.Package.labels.Email_Label;
  163. label10.Text = CSP.Package.labels.Login_Label;
  164. label7.Text = CSP.Package.labels.Username_Label;
  165. label4.Text = CSP.Package.labels.Password_Label;
  166. label3.Text = CSP.Package.labels.PasswordReType_Label;
  167. label11.Text = CSP.Package.labels.Url_Label;
  168. label1.Text = CSP.Package.labels.Identity_Label;
  169. checkBox1.Text = CSP.Package.labels.WebApplicationAlreadyCreatedInternet_Label;
  170. chkSSL.Text = CSP.Package.labels.UseSSL_Label;
  171. chkApid.Text = CSP.Package.labels.Configurable_Label;
  172. }
  173. private string GetWebApplicationIdentity()
  174. {
  175. if (checkBox1.Checked)
  176. {
  177. return txbIdentity.Text;
  178. }
  179. else
  180. {
  181. return chkApid.Checked ? txbApiduser.Text : "NT Authority\\NetworkService";
  182. }
  183. }
  184. private string GetWebApplicationUrl()
  185. {
  186. if (checkBox1.Checked)
  187. {
  188. return txbUrl.Text;
  189. }
  190. else
  191. {
  192. string result = chkSSL.Checked ? "https://" : "http://";
  193. result += txbHostHeader.Text.Length == 0 ? "localhost" : txbHostHeader.Text;
  194. result += txbPort.Text.Length == 0 ? string.Empty : ":" + txbPort.Text;
  195. return result;
  196. }
  197. }
  198. private string GetWebApplicationDescription()
  199. {
  200. return string.Format("Sharepoint - {0}{1}", txbHostHeader.Text, txbPort.Text);
  201. }
  202. private void CreateInternetWebApplication_Load(object sender, EventArgs e)
  203. {
  204. TranslateLiterals();
  205. txbLogin.Text = Environment.UserDomainName + "\\" + Environment.UserName;
  206. }
  207. private void txbPort_TextChanged_1(object sender, EventArgs e)
  208. {
  209. txbDescription.Text = GetWebApplicationDescription();
  210. }
  211. private void txbHostHeader_TextChanged_1(object sender, EventArgs e)
  212. {
  213. txbDescription.Text = GetWebApplicationDescription();
  214. }
  215. private void chkApid_CheckedChanged_1(object sender, EventArgs e)
  216. {
  217. txbApidpwd.ReadOnly = !chkApid.Checked;
  218. txbApidpwd2.ReadOnly = !chkApid.Checked;
  219. txbApiduser.ReadOnly = !chkApid.Checked;
  220. }
  221. private void checkBox1_CheckedChanged(object sender, EventArgs e)
  222. {
  223. txbUrl.ReadOnly = !checkBox1.Checked;
  224. txbIdentity.ReadOnly = !checkBox1.Checked;
  225. }
  226. }
  227. }