PageRenderTime 57ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/Install/InstallWizard.aspx.cs

https://github.com/mailekah/AgapeConnect1
C# | 1973 lines | 1751 code | 66 blank | 156 comment | 79 complexity | fc9950f780b7efeb4eca08b6e1720603 MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0

Large files files are truncated, but you can click here to view the full file

  1. #region Copyright
  2. //
  3. // DotNetNukeŽ - http://www.dotnetnuke.com
  4. // Copyright (c) 2002-2012
  5. // by DotNetNuke Corporation
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  8. // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
  9. // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
  10. // to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in all copies or substantial portions
  13. // of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  16. // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  18. // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  19. // DEALINGS IN THE SOFTWARE.
  20. #endregion
  21. #region Usings
  22. using System;
  23. using System.Collections;
  24. using System.Collections.Generic;
  25. using System.Data.Common;
  26. using System.Globalization;
  27. using System.IO;
  28. using System.Linq;
  29. using System.Net;
  30. using System.Net.Mail;
  31. using System.Text.RegularExpressions;
  32. using System.Threading;
  33. using System.Web;
  34. using System.Web.UI;
  35. using System.Web.UI.WebControls;
  36. using System.Xml;
  37. using System.Xml.XPath;
  38. using ASP;
  39. using DotNetNuke.Application;
  40. using DotNetNuke.Common;
  41. using DotNetNuke.Common.Internal;
  42. using DotNetNuke.Common.Utilities;
  43. using DotNetNuke.Data;
  44. using DotNetNuke.Entities.Controllers;
  45. using DotNetNuke.Entities.Portals;
  46. using DotNetNuke.Entities.Portals.Internal;
  47. using DotNetNuke.Entities.Users;
  48. using DotNetNuke.Framework;
  49. using DotNetNuke.Instrumentation;
  50. using DotNetNuke.Security.Membership;
  51. using DotNetNuke.Services.Localization;
  52. using DotNetNuke.Services.Localization.Internal;
  53. using DotNetNuke.UI.Skins.Controls;
  54. using DotNetNuke.UI.Utilities;
  55. using DotNetNuke.Web.Client.ClientResourceManagement;
  56. using DataCache = DotNetNuke.Common.Utilities.DataCache;
  57. using Globals = DotNetNuke.Common.Globals;
  58. #endregion
  59. namespace DotNetNuke.Services.Install
  60. {
  61. /// -----------------------------------------------------------------------------
  62. /// <summary>
  63. /// The InstallWizard class provides the Installation Wizard for DotNetNuke
  64. /// </summary>
  65. /// <remarks>
  66. /// </remarks>
  67. /// <history>
  68. /// [cnurse] 01/23/2007 Created
  69. /// </history>
  70. /// -----------------------------------------------------------------------------
  71. public partial class InstallWizard : PageBase, IClientAPICallbackEventHandler
  72. {
  73. #region Private Members
  74. private readonly DataProvider _dataProvider = DataProvider.Instance();
  75. protected new string LocalResourceFile = "~/Install/App_LocalResources/InstallWizard.aspx.resx";
  76. private Version _dataBaseVersion;
  77. private XmlDocument _installTemplate;
  78. private const string LocalesFile = "/Install/App_LocalResources/Locales.xml";
  79. private string _connectionString = Null.NullString;
  80. #endregion
  81. #region Private Properties
  82. private bool PortalBinded
  83. {
  84. get
  85. {
  86. if(ViewState["PortalBinded"] == null)
  87. {
  88. return false;
  89. }
  90. return Convert.ToBoolean(ViewState["PortalBinded"]);
  91. }
  92. set
  93. {
  94. ViewState["PortalBinded"] = value;
  95. }
  96. }
  97. #endregion
  98. #region Protected Members
  99. protected Version ApplicationVersion
  100. {
  101. get
  102. {
  103. return DotNetNukeContext.Current.Application.Version;
  104. }
  105. }
  106. protected Version DatabaseVersion
  107. {
  108. get
  109. {
  110. return _dataBaseVersion ?? (_dataBaseVersion = DataProvider.Instance().GetVersion());
  111. }
  112. }
  113. protected Version BaseVersion
  114. {
  115. get
  116. {
  117. return Upgrade.Upgrade.GetInstallVersion(InstallTemplate);
  118. }
  119. }
  120. protected XmlDocument InstallTemplate
  121. {
  122. get
  123. {
  124. if (_installTemplate == null)
  125. {
  126. _installTemplate = new XmlDocument();
  127. Upgrade.Upgrade.GetInstallTemplate(_installTemplate);
  128. }
  129. return _installTemplate;
  130. }
  131. }
  132. protected bool PermissionsValid
  133. {
  134. get
  135. {
  136. bool valid = false;
  137. if (ViewState["PermissionsValid"] != null)
  138. {
  139. valid = Convert.ToBoolean(ViewState["PermissionsValid"]);
  140. }
  141. return valid;
  142. }
  143. set
  144. {
  145. ViewState["PermissionsValid"] = value;
  146. }
  147. }
  148. protected int PortalId
  149. {
  150. get
  151. {
  152. int portalId = Null.NullInteger;
  153. if (ViewState["PortalId"] != null)
  154. {
  155. portalId = Convert.ToInt32(ViewState["PortalId"]);
  156. }
  157. return portalId;
  158. }
  159. set
  160. {
  161. ViewState["PortalId"] = value;
  162. }
  163. }
  164. protected string Versions
  165. {
  166. get
  167. {
  168. string versions = Null.NullString;
  169. if (ViewState["Versions"] != null)
  170. {
  171. versions = Convert.ToString(ViewState["Versions"]);
  172. }
  173. return versions;
  174. }
  175. set
  176. {
  177. ViewState["Versions"] = value;
  178. }
  179. }
  180. #endregion
  181. #region IClientAPICallbackEventHandler Members
  182. public string RaiseClientAPICallbackEvent(string eventArgument)
  183. {
  184. return ProcessAction(eventArgument);
  185. }
  186. #endregion
  187. #region Private Methods
  188. /// -----------------------------------------------------------------------------
  189. /// <summary>
  190. /// BindAuthSystems binds the Authentication Systems checkbox list
  191. /// </summary>
  192. /// <remarks>
  193. /// </remarks>
  194. /// <history>
  195. /// [cnurse] 02/28/2008 Created
  196. /// </history>
  197. /// -----------------------------------------------------------------------------
  198. private void BindAuthSystems()
  199. {
  200. BindPackageItems("AuthSystem", lstAuthSystems, lblNoAuthSystems, "NoAuthSystems", AuthSystemsErrorLabel);
  201. }
  202. /// -----------------------------------------------------------------------------
  203. /// <summary>
  204. /// BindConnectionString binds the connection String info
  205. /// </summary>
  206. /// <remarks>
  207. /// </remarks>
  208. /// <history>
  209. /// [cnurse] 01/23/2007 Created
  210. /// </history>
  211. /// -----------------------------------------------------------------------------
  212. private void BindConnectionString()
  213. {
  214. string connection = Config.GetConnectionString();
  215. foreach (string connectionParam in connection.Split(';'))
  216. {
  217. int index = connectionParam.IndexOf("=");
  218. if (index > 0)
  219. {
  220. string key = connectionParam.Substring(0, index);
  221. string value = connectionParam.Substring(index + 1);
  222. switch (key.ToLower())
  223. {
  224. case "server":
  225. case "data source":
  226. case "address":
  227. case "addr":
  228. case "network address":
  229. txtServer.Text = value;
  230. break;
  231. case "database":
  232. case "initial catalog":
  233. txtDatabase.Text = value;
  234. break;
  235. case "uid":
  236. case "user id":
  237. case "user":
  238. txtUserId.Text = value;
  239. break;
  240. case "pwd":
  241. case "password":
  242. txtPassword.Text = value;
  243. break;
  244. case "integrated security":
  245. chkIntegrated.Checked = (value.ToLower() == "true");
  246. break;
  247. case "attachdbfilename":
  248. txtFile.Text = value.Replace("|DataDirectory|", "");
  249. break;
  250. }
  251. }
  252. }
  253. if (chkIntegrated.Checked)
  254. {
  255. chkOwner.Checked = true;
  256. }
  257. chkOwner.Enabled = !chkIntegrated.Checked;
  258. }
  259. /// -----------------------------------------------------------------------------
  260. /// <summary>
  261. /// Gets the userid for the upgradeConnectionString
  262. /// </summary>
  263. /// <remarks>
  264. /// </remarks>
  265. /// <history>
  266. /// [smehaffie] 07/13/2008 Created
  267. /// </history>
  268. /// -----------------------------------------------------------------------------
  269. private static string GetUpgradeConnectionStringUserID()
  270. {
  271. string dbUser = "";
  272. string connection = Config.GetUpgradeConnectionString();
  273. //If connection string does not use integrated security, then get user id.
  274. if (connection.ToLower().Contains("user id") || connection.ToLower().Contains("uid") || connection.ToLower().Contains("user"))
  275. {
  276. string[] connectionParams = connection.Split(';');
  277. foreach (string connectionParam in connectionParams)
  278. {
  279. int index = connectionParam.IndexOf("=");
  280. if (index > 0)
  281. {
  282. string key = connectionParam.Substring(0, index);
  283. string value = connectionParam.Substring(index + 1);
  284. if ("user id|uuid|user".Contains(key.Trim().ToLower()))
  285. {
  286. dbUser = value.Trim();
  287. }
  288. }
  289. }
  290. }
  291. return dbUser;
  292. }
  293. /// -----------------------------------------------------------------------------
  294. /// <summary>
  295. /// BindDatabases binds the supported databases
  296. /// </summary>
  297. /// <remarks>
  298. /// </remarks>
  299. /// <history>
  300. /// [cnurse] 02/23/2007 Created
  301. /// </history>
  302. /// -----------------------------------------------------------------------------
  303. private void BindDatabases()
  304. {
  305. if ((Config.GetDefaultProvider("data").Name == "SqlDataProvider"))
  306. {
  307. string connection = Config.GetConnectionString();
  308. if (connection.ToLower().Contains("attachdbfilename"))
  309. {
  310. rblDatabases.Items.FindByValue("SQLFile").Selected = true;
  311. }
  312. else
  313. {
  314. rblDatabases.Items.FindByValue("SQLDatabase").Selected = true;
  315. }
  316. }
  317. if ((Config.GetDefaultProvider("data").Name == "OracleDataProvider"))
  318. {
  319. rblDatabases.Items.Add(new ListItem(LocalizeString("Oracle"), "Oracle"));
  320. rblDatabases.SelectedIndex = 2;
  321. }
  322. }
  323. /// -----------------------------------------------------------------------------
  324. /// <summary>
  325. /// BindLanguages binds the languages checkbox list
  326. /// </summary>
  327. /// <remarks>
  328. /// </remarks>
  329. /// <history>
  330. /// [cnurse] 02/20/2007 Created
  331. /// </history>
  332. /// -----------------------------------------------------------------------------
  333. private void BindLanguages()
  334. {
  335. BindPackageItems("Language", lstLanguages, lblNoLanguages, "NoLanguages", languagesErrorLabel);
  336. }
  337. /// -----------------------------------------------------------------------------
  338. /// <summary>
  339. /// BindModules binds the modules checkbox list
  340. /// </summary>
  341. /// <remarks>
  342. /// </remarks>
  343. /// <history>
  344. /// [cnurse] 02/19/2007 Created
  345. /// </history>
  346. /// -----------------------------------------------------------------------------
  347. private void BindModules()
  348. {
  349. BindPackageItems("Module", lstModules, lblNoModules, "NoModules", modulesErrorLabel);
  350. }
  351. private void BindPackageItems(string packageType, CheckBoxList list, Label noItemsLabel, string noItemsKey, Label errorLabel)
  352. {
  353. string installPath = Globals.ApplicationMapPath + "\\Install\\" + packageType;
  354. list.Items.Clear();
  355. if (Directory.Exists(installPath))
  356. {
  357. string[] arrFiles = Directory.GetFiles(installPath);
  358. foreach (string strFile in arrFiles)
  359. {
  360. string strResource = strFile.Replace(installPath + "\\", "");
  361. if (strResource.ToLower().EndsWith(".zip") || strResource.ToLower().EndsWith(".resources"))
  362. {
  363. var packageItem = new ListItem();
  364. //*.zip packages are installed by default
  365. if (strResource.ToLower().EndsWith(".zip"))
  366. {
  367. packageItem.Selected = true;
  368. packageItem.Enabled = false;
  369. }
  370. else //*.resources packages will be optional
  371. {
  372. packageItem.Selected = false;
  373. packageItem.Enabled = true;
  374. }
  375. packageItem.Value = strResource;
  376. strResource = Regex.Replace(strResource, ".zip", "", RegexOptions.IgnoreCase);
  377. strResource = Regex.Replace(strResource, ".resources", "", RegexOptions.IgnoreCase);
  378. strResource = Regex.Replace(strResource, "_Install", ")", RegexOptions.IgnoreCase);
  379. strResource = Regex.Replace(strResource, "_Source", ")", RegexOptions.IgnoreCase);
  380. strResource = strResource.Replace("_0", " (0");
  381. packageItem.Text = strResource;
  382. list.Items.Add(packageItem);
  383. }
  384. }
  385. }
  386. if (list.Items.Count > 0)
  387. {
  388. noItemsLabel.Visible = false;
  389. }
  390. else
  391. {
  392. noItemsLabel.Visible = true;
  393. noItemsLabel.Text = LocalizeString(noItemsKey);
  394. }
  395. if (errorLabel != null)
  396. {
  397. errorLabel.Text = Null.NullString;
  398. }
  399. }
  400. /// -----------------------------------------------------------------------------
  401. /// <summary>
  402. /// BindPermissions binds the permissions checkbox list
  403. /// </summary>
  404. /// <remarks>
  405. /// </remarks>
  406. /// <history>
  407. /// [cnurse] 01/23/2007 Created
  408. /// </history>
  409. /// -----------------------------------------------------------------------------
  410. private void BindPermissions(bool test)
  411. {
  412. PermissionsValid = true;
  413. lstPermissions.Items.Clear();
  414. var permissionItem = new ListItem();
  415. var verifiers = new List<FileSystemPermissionVerifier>
  416. {
  417. new FileSystemPermissionVerifier(Server.MapPath("~")),
  418. new FileSystemPermissionVerifier(Server.MapPath("~/App_Data"))
  419. };
  420. //FolderCreate
  421. if (test && PermissionsValid)
  422. {
  423. permissionItem.Selected = verifiers.All(v => v.VerifyFolderCreate());
  424. PermissionsValid = PermissionsValid && permissionItem.Selected;
  425. }
  426. permissionItem.Enabled = false;
  427. permissionItem.Text = LocalizeString("FolderCreate");
  428. lstPermissions.Items.Add(permissionItem);
  429. //FileCreate
  430. permissionItem = new ListItem();
  431. if (test && PermissionsValid)
  432. {
  433. permissionItem.Selected = verifiers.All(v => v.VerifyFileCreate());
  434. PermissionsValid = PermissionsValid && permissionItem.Selected;
  435. }
  436. permissionItem.Enabled = false;
  437. permissionItem.Text = LocalizeString("FileCreate");
  438. lstPermissions.Items.Add(permissionItem);
  439. //FileDelete
  440. permissionItem = new ListItem();
  441. if (test && PermissionsValid)
  442. {
  443. permissionItem.Selected = verifiers.All(v => v.VerifyFileDelete());
  444. PermissionsValid = PermissionsValid && permissionItem.Selected;
  445. }
  446. permissionItem.Enabled = false;
  447. permissionItem.Text = LocalizeString("FileDelete");
  448. lstPermissions.Items.Add(permissionItem);
  449. //FolderDelete
  450. permissionItem = new ListItem();
  451. if (test && PermissionsValid)
  452. {
  453. permissionItem.Selected = verifiers.All(v => v.VerifyFolderDelete());
  454. PermissionsValid = PermissionsValid && permissionItem.Selected;
  455. }
  456. permissionItem.Enabled = false;
  457. permissionItem.Text = LocalizeString("FolderDelete");
  458. lstPermissions.Items.Add(permissionItem);
  459. if (test)
  460. {
  461. var paths = string.Join("; ", (from v in verifiers select v.BasePath).ToArray());
  462. permissionsErrorLabel.Text = PermissionsValid ? LocalizeString("PermissionsOk") : LocalizeString("PermissionsError").Replace("{0}", paths);
  463. }
  464. }
  465. /// -----------------------------------------------------------------------------
  466. /// <summary>
  467. /// BindPortal binds the portal information
  468. /// </summary>
  469. /// <remarks>
  470. /// </remarks>
  471. /// <history>
  472. /// [cnurse] 02/19/2007 Created
  473. /// </history>
  474. /// -----------------------------------------------------------------------------
  475. private void BindPortal()
  476. {
  477. if(PortalBinded)
  478. {
  479. return;
  480. }
  481. XmlNode portalNode = InstallTemplate.SelectSingleNode("//dotnetnuke/portals/portal");
  482. XmlNode superUserNode = InstallTemplate.SelectSingleNode("//dotnetnuke/superuser");
  483. if (portalNode != null)
  484. {
  485. if (superUserNode != null)
  486. {
  487. usrAdmin.FirstName = XmlUtils.GetNodeValue(superUserNode.CreateNavigator(), "firstname");
  488. usrAdmin.LastName = XmlUtils.GetNodeValue(superUserNode.CreateNavigator(), "lastname");
  489. usrAdmin.UserName = XmlUtils.GetNodeValue(superUserNode.CreateNavigator(), "username");
  490. usrAdmin.Email = XmlUtils.GetNodeValue(superUserNode.CreateNavigator(), "email");
  491. }
  492. txtPortalTitle.Text = XmlUtils.GetNodeValue(portalNode.CreateNavigator(), "portalname");
  493. string templateName = XmlUtils.GetNodeValue(portalNode.CreateNavigator(), "templatefile");
  494. BindTemplates(templateName);
  495. }
  496. adminUserErrorLabel.Text = Null.NullString;
  497. PortalBinded = true;
  498. }
  499. private class TemplateDisplayComparer : IComparer<PortalController.PortalTemplateInfo>
  500. {
  501. public int Compare(PortalController.PortalTemplateInfo x, PortalController.PortalTemplateInfo y)
  502. {
  503. var cultureCompare = String.Compare(x.CultureCode, y.CultureCode, StringComparison.CurrentCulture);
  504. if (cultureCompare == 0)
  505. {
  506. return String.Compare(x.Name, y.Name, StringComparison.CurrentCulture);
  507. }
  508. //put blank cultures last
  509. if (string.IsNullOrEmpty(x.CultureCode) || string.IsNullOrEmpty(y.CultureCode))
  510. {
  511. cultureCompare *= -1;
  512. }
  513. return cultureCompare;
  514. }
  515. }
  516. private void BindTemplates(string templateName)
  517. {
  518. var templates = TestablePortalController.Instance.GetAvailablePortalTemplates();
  519. templates = templates.OrderBy(x => x, new TemplateDisplayComparer()).ToList();
  520. foreach (var template in templates)
  521. {
  522. cboPortalTemplate.Items.Add(CreateListItem(template));
  523. }
  524. SelectADefaultTemplate(templates, templateName);
  525. if (cboPortalTemplate.Items.Count == 0)
  526. {
  527. UI.Skins.Skin.AddModuleMessage(this, "", Localization.Localization.GetString("PortalMissing", LocalResourceFile),
  528. ModuleMessage.ModuleMessageType.RedError);
  529. }
  530. cboPortalTemplate.Items.Insert(0, new ListItem(Localization.Localization.GetString("None_Specified"), "-1"));
  531. }
  532. private void SelectADefaultTemplate(IList<PortalController.PortalTemplateInfo> templates, string templateName)
  533. {
  534. string currentCulture = Thread.CurrentThread.CurrentUICulture.Name;
  535. var defaultTemplates =
  536. templates.Where(x => Path.GetFileName(x.TemplateFilePath) == templateName).ToList();
  537. var match = defaultTemplates.FirstOrDefault(x => x.CultureCode == currentCulture);
  538. if (match == null)
  539. {
  540. match = defaultTemplates.FirstOrDefault(x => x.CultureCode.StartsWith(currentCulture.Substring(0, 2)));
  541. }
  542. if (match == null)
  543. {
  544. match = defaultTemplates.FirstOrDefault(x => string.IsNullOrEmpty(x.CultureCode));
  545. }
  546. if (match != null)
  547. {
  548. cboPortalTemplate.SelectedIndex = templates.IndexOf(match);
  549. }
  550. }
  551. ListItem CreateListItem(PortalController.PortalTemplateInfo template)
  552. {
  553. string text, value;
  554. if (string.IsNullOrEmpty(template.CultureCode))
  555. {
  556. text = template.Name;
  557. value = Path.GetFileName(template.TemplateFilePath);
  558. }
  559. else
  560. {
  561. text = string.Format("{0} - {1}", template.Name, Localization.Localization.GetLocaleName(template.CultureCode, CultureDropDownTypes.NativeName));
  562. value = string.Format("{0}|{1}", Path.GetFileName(template.TemplateFilePath), template.CultureCode);
  563. }
  564. return new ListItem(text, value);
  565. }
  566. /// -----------------------------------------------------------------------------
  567. /// <summary>
  568. /// BindProviders binds the Providers checkbox list
  569. /// </summary>
  570. /// <remarks>
  571. /// </remarks>
  572. /// <history>
  573. /// [cnurse] 06/24/2008 Created
  574. /// </history>
  575. /// -----------------------------------------------------------------------------
  576. private void BindProviders()
  577. {
  578. BindPackageItems("Provider", lstProviders, lblNoProviders, "NoProviders", providersErrorLabel);
  579. }
  580. /// -----------------------------------------------------------------------------
  581. /// <summary>
  582. /// BindSkins binds the skins checkbox list
  583. /// </summary>
  584. /// <remarks>
  585. /// </remarks>
  586. /// <history>
  587. /// [cnurse] 02/16/2007 Created
  588. /// </history>
  589. /// -----------------------------------------------------------------------------
  590. private void BindSkins()
  591. {
  592. BindPackageItems("Skin", lstSkins, lblNoSkins, "NoSkins", skinsErrorLabel);
  593. BindPackageItems("Container", lstContainers, lblNoContainers, "NoContainers", null);
  594. }
  595. /// -----------------------------------------------------------------------------
  596. /// <summary>
  597. /// EnableButton enables/Disables a Navigation Button
  598. /// </summary>
  599. /// <remarks>
  600. /// </remarks>
  601. /// <history>
  602. /// [cnurse] 02/28/2007 Created
  603. /// </history>
  604. /// -----------------------------------------------------------------------------
  605. private static void EnableButton(LinkButton button, bool enabled)
  606. {
  607. if (button != null)
  608. {
  609. button.OnClientClick = "return !checkDisabled(this);";
  610. button.CssClass = enabled
  611. ? ((button.CommandName == "MoveNext") ? "dnnPrimaryAction" : "dnnSecondaryAction")
  612. : "dnnPrimaryAction dnnDisabledAction";
  613. }
  614. }
  615. /// -----------------------------------------------------------------------------
  616. /// <summary>
  617. /// GetInstallerLocales gets an ArrayList of the Locales
  618. /// </summary>
  619. /// <remarks>
  620. /// </remarks>
  621. /// <history>
  622. /// [cnurse] 01/23/2007 Created
  623. /// </history>
  624. /// -----------------------------------------------------------------------------
  625. private static ArrayList GetInstallerLocales()
  626. {
  627. var supportedLocales = new ArrayList();
  628. string filePath = Globals.ApplicationMapPath + LocalesFile.Replace("/", "\\");
  629. if (File.Exists(filePath))
  630. {
  631. var doc = new XPathDocument(filePath);
  632. foreach (XPathNavigator nav in doc.CreateNavigator().Select("root/language"))
  633. {
  634. if (nav.NodeType != XPathNodeType.Comment)
  635. {
  636. var objLocale = new Locale
  637. {
  638. Text = nav.GetAttribute("name", ""),
  639. Code = nav.GetAttribute("key", ""),
  640. Fallback = nav.GetAttribute("fallback", "")
  641. };
  642. supportedLocales.Add(objLocale);
  643. }
  644. }
  645. }
  646. else
  647. {
  648. var objLocale = new Locale
  649. {
  650. Text = "English",
  651. Code = "en-US",
  652. Fallback = ""
  653. };
  654. supportedLocales.Add(objLocale);
  655. }
  656. return supportedLocales;
  657. }
  658. /// -----------------------------------------------------------------------------
  659. /// <summary>
  660. /// GetNextScriptVersion gets the next script to Install
  661. /// </summary>
  662. /// <remarks>
  663. /// </remarks>
  664. /// <history>
  665. /// [cnurse] 02/15/2007 Created
  666. /// </history>
  667. /// -----------------------------------------------------------------------------
  668. private string GetNextScriptVersion(string strProviderPath, Version currentVersion)
  669. {
  670. string strNextVersion = "Done";
  671. if (currentVersion == null)
  672. {
  673. strNextVersion = GetBaseDatabaseVersion();
  674. }
  675. else
  676. {
  677. string strScriptVersion = Null.NullString;
  678. ArrayList arrScripts = Upgrade.Upgrade.GetUpgradeScripts(strProviderPath, currentVersion);
  679. if (arrScripts.Count > 0)
  680. {
  681. //First Script is next script
  682. strScriptVersion = Path.GetFileNameWithoutExtension(Convert.ToString(arrScripts[0]));
  683. }
  684. if (!string.IsNullOrEmpty(strScriptVersion))
  685. {
  686. strNextVersion = strScriptVersion;
  687. }
  688. }
  689. return strNextVersion;
  690. }
  691. /// -----------------------------------------------------------------------------
  692. /// <summary>
  693. /// GetWizardButton gets a wizard button from the template
  694. /// </summary>
  695. /// <remarks>
  696. /// </remarks>
  697. /// <history>
  698. /// [cnurse] 02/28/2007 Created
  699. /// </history>
  700. /// -----------------------------------------------------------------------------
  701. private LinkButton GetWizardButton(string containerID, string buttonID)
  702. {
  703. Control navContainer = wizInstall.FindControl(containerID);
  704. LinkButton button = null;
  705. if (navContainer != null)
  706. {
  707. button = navContainer.FindControl(buttonID) as LinkButton;
  708. }
  709. return button;
  710. }
  711. private void Initialise()
  712. {
  713. if (TestDataBaseInstalled())
  714. {
  715. //running current version, so redirect to site home page
  716. Response.Redirect("~/Default.aspx", true);
  717. }
  718. else
  719. {
  720. if (DatabaseVersion > new Version(0, 0, 0))
  721. {
  722. //Upgrade
  723. languagePanel.Visible = false;
  724. introTitleLabel.Text = string.Format(LocalizeString("UpgradeTitle"), ApplicationVersion.ToString(3));
  725. introDetailLabel.Text = string.Format(LocalizeString("Upgrade"), Upgrade.Upgrade.GetStringVersion(DatabaseVersion));
  726. }
  727. else
  728. {
  729. //Install
  730. UpdateMachineKey();
  731. }
  732. }
  733. }
  734. private bool InstallAuthSystems()
  735. {
  736. return InstallPackageItems("AuthSystem", lstAuthSystems, lblNoAuthSystems, "InstallAuthSystemError");
  737. }
  738. private string InstallDatabase()
  739. {
  740. string strErrorMessage;
  741. string strProviderPath = _dataProvider.GetProviderPath();
  742. if (!strProviderPath.StartsWith("ERROR:"))
  743. {
  744. //Install Base Version
  745. strErrorMessage = Upgrade.Upgrade.InstallDatabase(BaseVersion, strProviderPath, InstallTemplate, false);
  746. }
  747. else
  748. {
  749. //provider error
  750. strErrorMessage = strProviderPath;
  751. }
  752. if (string.IsNullOrEmpty(strErrorMessage))
  753. {
  754. //Get Next Version
  755. strErrorMessage = GetNextScriptVersion(strProviderPath, BaseVersion);
  756. }
  757. else if (!strErrorMessage.StartsWith("ERROR:"))
  758. {
  759. strErrorMessage = "ERROR: " + string.Format(LocalizeString("ScriptError"), Upgrade.Upgrade.GetLogFile(strProviderPath, BaseVersion));
  760. }
  761. return strErrorMessage;
  762. }
  763. private bool InstallHost()
  764. {
  765. bool success = false;
  766. try
  767. {
  768. //Initialise Host Settings
  769. Upgrade.Upgrade.InitialiseHostSettings(InstallTemplate, false);
  770. Upgrade.Upgrade.InstallFiles(InstallTemplate, false);
  771. if (!string.IsNullOrEmpty(txtSMTPServer.Text))
  772. {
  773. HostController.Instance.Update("SMTPServer", txtSMTPServer.Text);
  774. HostController.Instance.Update("SMTPAuthentication", optSMTPAuthentication.SelectedItem.Value);
  775. HostController.Instance.Update("SMTPUsername", txtSMTPUsername.Text, true);
  776. HostController.Instance.Update("SMTPPassword", txtSMTPPassword.Text, true);
  777. HostController.Instance.Update("SMTPEnableSSL", chkSMTPEnableSSL.Checked ? "Y" : "N");
  778. }
  779. //Clear Host Cache
  780. DataCache.ClearHostCache(false);
  781. success = true;
  782. }
  783. catch (Exception exc)
  784. {
  785. DnnLog.Error(exc);
  786. success = false;
  787. }
  788. return success;
  789. }
  790. private bool InstallLanguages()
  791. {
  792. return InstallPackageItems("Language", lstLanguages, languagesErrorLabel, "InstallLanguageError");
  793. }
  794. private bool InstallModules()
  795. {
  796. return InstallPackageItems("Module", lstModules, modulesErrorLabel, "InstallModuleError");
  797. }
  798. private bool InstallPackageItems(string packageType, CheckBoxList list, Label errorLabel, string errorKey)
  799. {
  800. bool success = false;
  801. string strErrorMessage = Null.NullString;
  802. //Get current Script time-out
  803. int scriptTimeOut = Server.ScriptTimeout;
  804. try
  805. {
  806. //Set Script timeout to MAX value
  807. Server.ScriptTimeout = int.MaxValue;
  808. string installPath = Globals.ApplicationMapPath + "\\Install\\" + packageType;
  809. foreach (ListItem packageItem in list.Items)
  810. {
  811. if (packageItem.Selected)
  812. {
  813. if ((File.Exists(installPath + "\\" + packageItem.Value)))
  814. {
  815. success = Upgrade.Upgrade.InstallPackage(installPath + "\\" + packageItem.Value, packageType, false);
  816. if (!success)
  817. {
  818. strErrorMessage += string.Format(LocalizeString(errorKey), packageItem.Text);
  819. }
  820. }
  821. }
  822. }
  823. success = string.IsNullOrEmpty(strErrorMessage) || packageType == "Language";
  824. }
  825. catch (Exception ex)
  826. {
  827. DnnLog.Error(ex);
  828. strErrorMessage = ex.StackTrace;
  829. }
  830. finally
  831. {
  832. //restore Script timeout
  833. Server.ScriptTimeout = scriptTimeOut;
  834. }
  835. if (!success)
  836. {
  837. errorLabel.Text += strErrorMessage;
  838. }
  839. return success;
  840. }
  841. private bool InstallPortal()
  842. {
  843. string strErrorMessage = usrAdmin.Validate();
  844. if (!string.IsNullOrEmpty(strErrorMessage))
  845. {
  846. string strError = LocalizeString(strErrorMessage);
  847. if (strErrorMessage == "PasswordLength")
  848. {
  849. strError = string.Format(strError, MembershipProviderConfig.MinPasswordLength);
  850. }
  851. adminUserErrorLabel.Text = string.Format(LocalizeString("AdminUserError"), strError);
  852. return false;
  853. }
  854. if(cboPortalTemplate.SelectedIndex == 0)
  855. {
  856. string error = LocalizeString("MustSelecteATemplate");
  857. adminUserErrorLabel.Text = error;
  858. return false;
  859. }
  860. bool success = false;
  861. try
  862. {
  863. string strServerPath = Globals.ApplicationMapPath + "\\";
  864. string strPortalAlias = Globals.GetDomainName(HttpContext.Current.Request, true).Replace("/Install", "");
  865. PortalController.PortalTemplateInfo template = LoadPortalTemplateInfoForSelectedItem();
  866. UserInfo adminUser = CreateUserInfo();
  867. if (template.CultureCode != "en-US")
  868. {
  869. //Check if language is installed
  870. var locale = LocaleController.Instance.GetLocale(template.CultureCode);
  871. //If not installed - install it
  872. if (locale == null)
  873. {
  874. string installPath = Globals.ApplicationMapPath + "\\Install\\Language";
  875. string languagePack = String.Format(installPath + "\\ResourcePack.Full.{0}.{1}.resources", Globals.FormatVersion(ApplicationVersion, "00", 3, "."), template.CultureCode);
  876. if (File.Exists(languagePack))
  877. {
  878. success = Upgrade.Upgrade.InstallPackage(languagePack, "Language", false);
  879. }
  880. }
  881. }
  882. //Create Portal
  883. PortalId = TestablePortalController.Instance.CreatePortal(txtPortalTitle.Text,
  884. adminUser,
  885. "",
  886. "",
  887. template,
  888. "",
  889. strPortalAlias,
  890. strServerPath,
  891. "",
  892. false);
  893. success = (PortalId > Null.NullInteger);
  894. if (template.CultureCode != "en-US")
  895. {
  896. var locale = LocaleController.Instance.GetLocale("en-US");
  897. //remove en-US from portal
  898. Localization.Localization.RemoveLanguageFromPortal(PortalId, locale.LanguageId);
  899. }
  900. //Set admin user to be a superuser
  901. adminUser = UserController.GetUserByName(PortalId, usrAdmin.UserName);
  902. adminUser.IsSuperUser = true;
  903. UserController.UpdateUser(PortalId, adminUser);
  904. //Log user in to site
  905. UserLoginStatus loginStatus = UserLoginStatus.LOGIN_FAILURE;
  906. UserController.UserLogin(PortalId, usrAdmin.UserName, usrAdmin.Password, "", "", "", ref loginStatus, false);
  907. Config.Touch();
  908. Response.Redirect("~/Default.aspx", true);
  909. }
  910. catch (ThreadAbortException)
  911. {
  912. //do nothing - we swallow this exception - becuase of redirect
  913. }
  914. catch (Exception ex)
  915. {
  916. DnnLog.Error(ex);
  917. success = false;
  918. strErrorMessage = ex.Message;
  919. }
  920. if (!success)
  921. {
  922. adminUserErrorLabel.Text = string.Format(LocalizeString("InstallPortalError"), strErrorMessage);
  923. }
  924. return success;
  925. }
  926. private UserInfo CreateUserInfo()
  927. {
  928. var adminUser = new UserInfo();
  929. adminUser.FirstName = usrAdmin.FirstName;
  930. adminUser.LastName = usrAdmin.LastName;
  931. adminUser.Username = usrAdmin.UserName;
  932. adminUser.DisplayName = usrAdmin.FirstName + " " + usrAdmin.LastName;
  933. adminUser.Membership.Password = usrAdmin.Password;
  934. adminUser.Email = usrAdmin.Email;
  935. adminUser.IsSuperUser = false;
  936. adminUser.Membership.Approved = true;
  937. adminUser.Profile.FirstName = usrAdmin.FirstName;
  938. adminUser.Profile.LastName = usrAdmin.LastName;
  939. return adminUser;
  940. }
  941. PortalController.PortalTemplateInfo LoadPortalTemplateInfoForSelectedItem()
  942. {
  943. var values = cboPortalTemplate.SelectedItem.Value.Split('|');
  944. return TestablePortalController.Instance.GetPortalTemplate(Path.Combine(TestableGlobals.Instance.HostMapPath, values[0]), values.Length > 1 ? values[1] : null);
  945. }
  946. private bool InstallProviders()
  947. {
  948. return InstallPackageItems("Provider", lstProviders, providersErrorLabel, "InstallProviderError");
  949. }
  950. private bool InstallSkins()
  951. {
  952. bool skinSuccess = InstallPackageItems("Skin", lstSkins, skinsErrorLabel, "InstallSkinError");
  953. bool containerSuccess = InstallPackageItems("Container", lstContainers, skinsErrorLabel, "InstallContainerError");
  954. return skinSuccess && containerSuccess;
  955. }
  956. private string InstallVersion(string strVersion)
  957. {
  958. string strErrorMessage = Null.NullString;
  959. var version = new Version(strVersion);
  960. string strScriptFile = Null.NullString;
  961. string strProviderPath = _dataProvider.GetProviderPath();
  962. if (!strProviderPath.StartsWith("ERROR:"))
  963. {
  964. //Install Version
  965. strScriptFile = Upgrade.Upgrade.GetScriptFile(strProviderPath, version);
  966. strErrorMessage += Upgrade.Upgrade.UpgradeVersion(strScriptFile, false);
  967. Versions += "," + strVersion;
  968. }
  969. else
  970. {
  971. //provider error
  972. strErrorMessage = strProviderPath;
  973. }
  974. if (string.IsNullOrEmpty(strErrorMessage))
  975. {
  976. //Get Next Version
  977. strErrorMessage = GetNextScriptVersion(strProviderPath, version);
  978. }
  979. else
  980. {
  981. strErrorMessage = "ERROR: (see " + Path.GetFileName(strScriptFile).Replace("." + Upgrade.Upgrade.DefaultProvider, ".log") + " for more information)";
  982. }
  983. return strErrorMessage;
  984. }
  985. /// -----------------------------------------------------------------------------
  986. /// <summary>
  987. /// LocalizePage sets up the Localized Text
  988. /// </summary>
  989. /// <remarks>
  990. /// </remarks>
  991. /// <history>
  992. /// [cnurse] 02/09/2007 Created
  993. /// </history>
  994. /// -----------------------------------------------------------------------------
  995. private void LocalizePage()
  996. {
  997. //Main Title
  998. Title = LocalizeString("Title") + @" - " + LocalizeString("Page" + wizInstall.ActiveStepIndex + ".Title");
  999. //Page Titles
  1000. for (int i = 0; i <= wizInstall.WizardSteps.Count - 1; i++)
  1001. {
  1002. wizInstall.WizardSteps[i].Title = LocalizeString("Page" + i + ".Title");
  1003. }
  1004. //Wizard Buttons
  1005. LinkButton nextButton = GetWizardButton("StepNavigationTemplateContainerID", "StepNextButton");
  1006. nextButton.Text = LocalizeString("Next");
  1007. nextButton = GetWizardButton("StartNavigationTemplateContainerID", "StartNextButton");
  1008. nextButton.Text = LocalizeString("Next");
  1009. LinkButton previousButton = GetWizardButton("StepNavigationTemplateContainerID", "StepPreviousButton");
  1010. previousButton.Text = LocalizeString("Previous");
  1011. switch (wizInstall.ActiveStepIndex)
  1012. {
  1013. case 0: //Page 0 - Welcome
  1014. introTitleLabel.Text = string.Format(LocalizeString("IntroTitle"), Globals.FormatVersion(ApplicationVersion));
  1015. introDetailLabel.Text = LocalizeString("IntroDetail");
  1016. installTypeRadioButton.Items[0].Text = LocalizeString("Typical");
  1017. installTypeRadioButton.Items[1].Text = LocalizeString("Full");
  1018. installTypeRadioButton.Items[2].Text = LocalizeString("Auto");
  1019. break;
  1020. case 1: //Page 1 - File Permissions
  1021. BindPermissions(false);
  1022. LinkButton customButton = GetWizardButton("StepNavigationTemplateContainerID", "CustomButton");
  1023. customButton.Text = LocalizeString("TestPerm");
  1024. break;
  1025. case 2://Page 2 - Database Configuration
  1026. databaseConfigTitleLabel.Text = LocalizeString("DatabaseConfigTitle");
  1027. databaseConfigDetailLabel.Text = LocalizeString("DatabaseConfigDetail");
  1028. rblDatabases.Items[0].Text = LocalizeString("SQLServerXPress");
  1029. rblDatabases.Items[1].Text = LocalizeString("SQLServer");
  1030. break;
  1031. case 3: //Page 3 - Database Installation
  1032. databaseInstallTitleLabel.Text = LocalizeString("DatabaseInstallTitle");
  1033. databaseInstallDetailLabel.Text = LocalizeString("DatabaseInstallDetail");
  1034. break;
  1035. case 4: //Page 4 - Modules
  1036. modulesTitleLabel.Text = LocalizeString("ModulesTitle");
  1037. modulesDetailLabel.Text = LocalizeString("ModulesDetail");
  1038. lblModules.Text = LocalizeString("Modules");
  1039. break;
  1040. case 5: //Page 5 - Skins/Conatiners
  1041. skinsTitleLabel.Text = LocalizeString("SkinsTitle");
  1042. skinsDetailLabel.Text = LocalizeString("SkinsDetail");
  1043. lblSkins.Text = LocalizeString("Skins");
  1044. lblContainers.Text = LocalizeString("Containers");
  1045. break;
  1046. case 6: //Page 6 - Languages
  1047. languagesTitleLabel.Text = LocalizeString("LanguagesTitle");
  1048. languagesDetailLabel.Text = LocalizeString("LanguagesDetail");
  1049. lblLanguages.Text = LocalizeString("Languages");
  1050. break;
  1051. case 7: //Page 7 - Auth Systems
  1052. authSystemsTitleLabel.Text = LocalizeString("AuthSystemsTitle");
  1053. authSystemDetailLabel.Text = LocalizeString("AuthSystemsDetail");
  1054. lblAuthSystems.Text = LocalizeString("AuthSystems");
  1055. break;
  1056. case 8: //Page 8 - Providers
  1057. providersTitleLabel.Text = LocalizeString("ProvidersTitle");
  1058. providersDetailLabel.Text = LocalizeString("ProvidersDetail");
  1059. lblProviders.Text = LocalizeString("Providers");
  1060. break;
  1061. case 9: //Page 9 - User/Portal Configuration
  1062. adminUserTitleLabel.Text = LocalizeString("AdminUserTitle");
  1063. adminUserDetailLabel.Text = LocalizeString("AdminUserDetail");
  1064. usrAdmin.FirstNameLabel = LocalizeString("FirstName");
  1065. usrAdmin.LastNameLabel = LocalizeString("LastName");
  1066. usrAdmin.UserNameLabel = LocalizeString("UserName");
  1067. usrAdmin.PasswordLabel = LocalizeString("Password");
  1068. usrAdmin.ConfirmLabel = LocalizeString("Confirm");
  1069. usrAdmin.EmailLabel = LocalizeString("Email");
  1070. lblAdminUser.Text = LocalizeString("AdminUser");
  1071. lblPortal.Text = LocalizeString("Portal");
  1072. portalDetailLabel.Text = LocalizeString("PortalDetail");
  1073. lblSMTPSettings.Text = LocalizeString("SMTPSettings");
  1074. lblSMTPSettingsHelp.Text = LocalizeString("SMTPSettingsHelp");
  1075. break;
  1076. }
  1077. }
  1078. private void SetupDatabasePage()
  1079. {
  1080. if (rblDatabases.SelectedIndex > Null.NullInteger)
  1081. {
  1082. bool isSQLFile = (rblDatabases.SelectedValue == "SQLFile");
  1083. bool isSQLDb = (rblDatabases.SelectedValue == "SQLDatabase");
  1084. bool isOracle = (rblDatabases.SelectedValue == "Oracle");
  1085. databasePanel.Visible = true;
  1086. fileRow.Visible = isSQLFile;
  1087. databaseRow.Visible = isSQLDb;
  1088. integratedRow.Visible = !isOracle;
  1089. userRow.Visible = !chkIntegrated.Checked || isOracle;
  1090. passwordRow.Visible = !chkIntegrated.Checked || isOracle;
  1091. chkOwner.Enabled = isSQLDb;
  1092. chkOwner.Checked = (Config.GetDataBaseOwner() == "dbo.");
  1093. txtqualifier.Text = Config.GetObjectQualifer();
  1094. }
  1095. else
  1096. {
  1097. databasePanel.Visible = false;
  1098. }
  1099. }
  1100. /// -----------------------------------------------------------------------------
  1101. /// <summary>
  1102. /// SetupPage updates the WizardPage
  1103. /// </summary>
  1104. /// <remarks>
  1105. /// </remarks>
  1106. /// <history>
  1107. /// [cnurse] 01/23/2007 Created
  1108. /// </history>
  1109. /// -----------------------------------------------------------------------------
  1110. private void SetupPage()
  1111. {
  1112. LinkButton nextButton = GetWizardButton("StepNavigationTemplateContainerID", "StepNextButton");
  1113. LinkButton prevButton = GetWizardButton("StepNavigationTemplateContainerID", "StepPreviousButton");
  1114. LinkButton customButton = GetWizardButton("StepNavigationTemplateContainerID", "CustomButton");
  1115. EnableButton(nextButton, true);
  1116. EnableButton(prevButton, true);
  1117. ShowButton(customButton, false);
  1118. switch (wizInstall.ActiveStepIndex)
  1119. {
  1120. case 0: //Page 0 - Welcome
  1121. permissionsErrorLabel.Text = "";
  1122. break;
  1123. case 1:
  1124. databaseErrorLabel.Text = "";
  1125. ShowButton(customButton, true);
  1126. break;
  1127. case 2: //Page 2 - Database Configuration
  1128. permissionsErrorLabel.Text = "";
  1129. SetupDatabasePage();
  1130. break;
  1131. case 3:
  1132. databaseErrorLabel.Text = "";
  1133. install…

Large files files are truncated, but you can click here to view the full file