/// <summary> /// Adds the standard URL configuration. /// </summary> public static void AddStandardUrlConfiguration() { try { string configString = ""; using (var stream = new StreamReader(Path.Combine(HttpContext.Current.Server.MapPath("~"), "DesktopModules/InspectorIT/VanityUrls/Includes/StandardProvider.add.config")) ) { configString = stream.ReadToEnd(); } var targetConfig = new XmlDocument(); targetConfig.Load(Path.Combine(HttpContext.Current.Server.MapPath("~"), "web.config")); var merge = new XmlMerge(new StringReader(configString), "", ""); merge.UpdateConfig(targetConfig); Config.Save(targetConfig, "web.config"); } catch (Exception ex) { DotNetNuke.Services.Exceptions.Exceptions.LogException(ex); } }
public static string UpdateConfig(string providerPath, string configFile, Version version, string reason) { DnnInstallLogger.InstallLogInfo(Localization.Localization.GetString("LogStart", Localization.Localization.GlobalResourceFile) + "UpdateConfig:" + version.ToString(3)); string exceptions = ""; if (File.Exists(configFile)) { //Create XmlMerge instance from config file source StreamReader stream = File.OpenText(configFile); try { var merge = new XmlMerge(stream, version.ToString(3), reason); //Process merge merge.UpdateConfigs(); } catch (Exception ex) { Logger.Error(ex); exceptions += string.Format("Error: {0}{1}", ex.Message + ex.StackTrace, Environment.NewLine); // log the results try { using (StreamWriter streamWriter = File.CreateText(providerPath + Globals.FormatVersion(version) + "_Config.log")) { streamWriter.WriteLine(exceptions); streamWriter.Close(); } } catch (Exception exc) { Logger.Error(exc); } } finally { //Close stream stream.Close(); } } if (string.IsNullOrEmpty(exceptions)) { DnnInstallLogger.InstallLogInfo(Localization.Localization.GetString("LogEnd", Localization.Localization.GlobalResourceFile) + "UpdateConfig:" + version.ToString(3)); } else { DnnInstallLogger.InstallLogError(exceptions); } return exceptions; }
private XmlMerge GetXmlMerge(string fileName) { using (Stream mergeStream = _assembly.GetManifestResourceStream(string.Format("DotNetNuke.Tests.Integration.Services.Installer.MergeFiles.{0}Merge.xml", fileName))) { Debug.Assert(mergeStream != null, string.Format("Unable to location embedded resource for {0}Merge.xml", fileName)); var merge = new XmlMerge(mergeStream, "version", "sender"); return merge; } }
/// <summary> /// /// </summary> public static void AddFriendlyUrlHttpModule() { try { const string configString = "<configuration>" + "<nodes configfile=\"web.config\">" + "<node path=\"/configuration/system.web/httpModules/add[@name='RequestFilter']\" action=\"insertbefore\" key=\"name\" collision=\"ignore\">" + "<add name=\"DNNQAUrlRewrite\" type=\"GB.SlideShow.Components.Modules.UrlModule, DotNetNuke.Modules.DNNQA\" />" + "</node>" + "<node path=\"/configuration/system.webServer/modules/add[@name='RequestFilter']\" action=\"insertbefore\" key=\"name\" collision=\"ignore\">" + "<add name=\"DNNQAUrlRewrite\" type=\"GB.SlideShow.Components.Modules.UrlModule, DotNetNuke.Modules.DNNQA\" preCondition=\"managedHandler\" />" + "</node>" + "</nodes>" + "</configuration>"; var targetConfig = new XmlDocument(); targetConfig.Load(Path.Combine(HttpContext.Current.Server.MapPath("~"), "web.config")); if (targetConfig.SelectSingleNode("/configuration/system.webServer/modules/add[@name='DNNQAUrlRewrite']") == null) { var merge = new XmlMerge(new StringReader(configString), "", ""); merge.UpdateConfig(targetConfig); Config.Save(targetConfig, "web.config"); } } catch (Exception ex) { DotNetNuke.Services.Exceptions.Exceptions.LogException(ex); } }
/// <summary> /// Updates the web.config file to drop emails to a local folder. /// </summary> /// <param name="mailDropPath">The path to the mailDrop.xml file that contains the xml for the mail dump.</param> /// <param name="emailPath">The path that emails will be sent to.</param> public static void UpdateConfigForMailDrop(string mailDropPath, string emailPath) { var physicalPath = GetWebPath(); var mailDropFragment = XDocument.Load(Path.Combine(mailDropPath, "mailDrop.xml")); var specifiedPickupDirectory = mailDropFragment.XPathSelectElement("configuration/nodes/node/system.net/mailSettings/smtp/specifiedPickupDirectory"); specifiedPickupDirectory.Attribute("pickupDirectoryLocation").Value = emailPath; mailDropFragment.Save(Path.Combine(physicalPath, "UpdatedMailDrop.xml")); var mailDrop = new FileStream(Path.Combine(physicalPath, "UpdatedMailDrop.xml"), FileMode.Open, FileAccess.Read); try { var fileName = string.Format("{0}\\web.config", physicalPath); var targetDocument = new XmlDocument(); targetDocument.Load(fileName); var mailNodes = (from mail in targetDocument.DocumentElement.ChildNodes.Cast<XmlNode>() where mail.Name == "system.net" select mail).ToList(); if (mailNodes.Count == 0) { var merge = new XmlMerge(mailDrop, String.Empty, String.Empty); merge.UpdateConfig(targetDocument); targetDocument.Save(fileName); } } finally { mailDrop.Close(); } }
public static string UpdateConfig(string configFile, Version version, string reason) { string exceptions = ""; if (File.Exists(configFile)) { //Create XmlMerge instance from config file source StreamReader stream = File.OpenText(configFile); try { var merge = new XmlMerge(stream, version.ToString(3), reason); //Process merge merge.UpdateConfigs(); } catch (Exception ex) { exceptions += String.Format("Error: {0}{1}", ex.Message + ex.StackTrace, Environment.NewLine); Exceptions.Exceptions.LogException(ex); } finally { //Close stream stream.Close(); } } return exceptions; }