/// <summary>If the <paramref name="file"/> is a strong-named assembly, applies the XML merge.</summary> /// <param name="file">The assembly file.</param> /// <param name="xmlMergeFile">The XML merge file name.</param> /// <returns><c>true</c> if the XML Merge was applied successfully, <c>false</c> if the file was not a strong-named assembly or could not be read.</returns> private bool ApplyXmlMerge(InstallFile file, string xmlMergeFile) { var assemblyFileFullPath = Path.Combine(this.PhysicalBasePath, file.FullName); if (!File.Exists(assemblyFileFullPath)) { return(false); } var assemblyName = ReadAssemblyName(assemblyFileFullPath); var publicKeyToken = ReadPublicKey(assemblyName); if (string.IsNullOrEmpty(publicKeyToken)) { return(false); } var name = assemblyName.Name; var assemblyVersion = assemblyName.Version; var newVersion = assemblyVersion.ToString(); var xmlMergePath = Path.Combine(Globals.InstallMapPath, "Config", xmlMergeFile); var xmlMergeDoc = GetXmlMergeDoc(xmlMergePath, name, publicKeyToken, OldVersion, newVersion); var xmlMerge = new XmlMerge(xmlMergeDoc, this.Package.Version.ToString(), this.Package.Name); xmlMerge.UpdateConfigs(); return(true); }
/// ----------------------------------------------------------------------------- /// <summary> /// The UnInstall method uninstalls the config component /// </summary> /// <history> /// [cnurse] 08/04/2007 created /// </history> /// ----------------------------------------------------------------------------- public override void UnInstall() { if (string.IsNullOrEmpty(_UninstallFileName)) { //Create an XmlDocument for the config file _TargetConfig = new XmlDocument(); TargetConfig.Load(Path.Combine(PhysicalSitePath, TargetFile.FullName)); //Create XmlMerge instance from UnInstallConfig source var merge = new XmlMerge(new StringReader(UnInstallConfig), Package.Version.ToString(), Package.Name); //Update the Config file - Note that this method does save the file merge.UpdateConfig(TargetConfig, TargetFile.FullName); } else { //Process external file string strConfigFile = Path.Combine(Package.InstallerInfo.TempInstallFolder, _UninstallFileName); if (File.Exists(strConfigFile)) { //Create XmlMerge instance from config file source StreamReader stream = File.OpenText(strConfigFile); var merge = new XmlMerge(stream, Package.Version.ToString(3), Package.Name + " UnInstall"); //Process merge merge.UpdateConfigs(); //Close stream stream.Close(); } } }
public override void Install() { try { if (string.IsNullOrEmpty(_FileName)) { Util.BackupFile(TargetFile, PhysicalSitePath, Log); _TargetConfig = new XmlDocument(); TargetConfig.Load(Path.Combine(PhysicalSitePath, TargetFile.FullName)); XmlMerge merge = new XmlMerge(new StringReader(InstallConfig), this.Package.Version.ToString(), this.Package.Name); merge.UpdateConfig(TargetConfig); Completed = true; Log.AddInfo(Util.CONFIG_Updated + " - " + TargetFile.Name); } else { string strConfigFile = Path.Combine(this.Package.InstallerInfo.TempInstallFolder, _FileName); if (File.Exists(strConfigFile)) { StreamReader stream = File.OpenText(strConfigFile); XmlMerge merge = new XmlMerge(stream, Package.Version.ToString(3), Package.Name + " Install"); merge.UpdateConfigs(); stream.Close(); Completed = true; Log.AddInfo(Util.CONFIG_Updated); } } } catch (Exception ex) { Log.AddFailure(Util.EXCEPTION + " - " + ex.Message); } }
/// <summary> /// Adds the ifinity URL configuration. /// </summary> public static void AddIfinityUrlConfiguration() { try { var targetConfig = new XmlDocument(); targetConfig.Load(Path.Combine(HttpContext.Current.Server.MapPath("~"), "web.config")); string configString = ""; using (var stream = new StreamReader(Path.Combine(HttpContext.Current.Server.MapPath("~"), "DesktopModules/InspectorIT/VanityUrls/Includes/iFinityProvider.add.config")) ) { configString = stream.ReadToEnd(); } var merge = new XmlMerge(new StringReader(configString), "", ""); merge.UpdateConfig(targetConfig); Config.Save(targetConfig, "web.config"); } catch (Exception ex) { DotNetNuke.Services.Exceptions.Exceptions.LogException(ex); } }
//this is not used now. Kept for reference if in future needs to // set config changes by string directly private void MergeFileUpdated() { var AssemblyBinding = @"<configuration> <nodes configfile=""Web.config""> <node path=""/configuration/runtime/ab:assemblyBinding"" action=""update"" collision=""save"" targetpath=""/configuration/runtime/ab:assemblyBinding/ab:dependentAssembly[ab:assemblyIdentity/@name='System.Web.Mvc'][ab:assemblyIdentity/@publicKeyToken='31bf3856ad364e35']"" nameSpace=""urn:schemas-microsoft-com:asm.v1"" nameSpacePrefix=""ab""> <dependentAssembly xmlns=""urn:schemas-microsoft-com:asm.v1""> <assemblyIdentity name=""System.Web.Mvc"" publicKeyToken=""31bf3856ad364e35"" /> <bindingRedirect oldVersion=""1.0.0.0-4.0.0.0"" newVersion=""4.0.0.1""/> </dependentAssembly> </node> </nodes> </configuration>"; using (TextReader sr = new StringReader(AssemblyBinding)) { var app = DotNetNukeContext.Current.Application; var merge = new XmlMerge(sr, Globals.FormatVersion(app.Version), app.Description); merge.UpdateConfigs(); } }
/// <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(); } }
/// <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.Product.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.Product.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> /// Installs support for Telerik Charting in the web.config. /// </summary> private void InstallTelerikCharting() { using (Stream xmlMergeManifest = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Engage.Dnn.Dashboard.01.00.00.xml")) { XmlMerge configMerge = new XmlMerge(xmlMergeManifest, "01.00.00", "Engage: Dashboard"); configMerge.UpdateConfigs(); this.Response.Redirect(Globals.NavigateURL()); } }
private XmlMerge GetXmlMerge(string fileName) { using (Stream mergeStream = _assembly.GetManifestResourceStream(string.Format("DotNetNuke.Tests.Core.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> /// As ExecuteMerge but allows the merge file prefix to be specified /// </summary> private XmlDocument ExecuteMerge(string mergeName) { string testMethodName = GetTestMethodName(); XmlMerge merge = GetXmlMerge(mergeName ?? testMethodName); XmlDocument targetDoc = LoadTargetDoc(testMethodName); merge.UpdateConfig(targetDoc); WriteToDebug(targetDoc); return(targetDoc); }
public void ShouldChangeOnOverwrite() { XmlMerge merge = GetXmlMerge(nameof(ShouldChangeOnOverwrite)); XmlDocument targetDoc = LoadTargetDoc(nameof(ShouldChangeOnOverwrite)); merge.UpdateConfig(targetDoc); WriteToDebug(targetDoc); var nodes = targetDoc.SelectNodes("/configuration/appSettings/add"); Assert.AreEqual(3, nodes.Count); Assert.True(merge.ConfigUpdateChangedNodes); }
public override void Init(SubsystemConfig config) { _config = (ConfigurationManagerConfig)config; var keyAttributeNames = new Dictionary <string, string> { { "subsystem", "name" } }; _mergeUtil = new XmlMerge(_config.PrivateConfigElementXPaths.ToList(), keyAttributeNames); _currentConfig = CoreApplication.Instance.Config; _currentConfigXml = _currentConfig.ToXml(); _fileSystemManager = Application.GetSubsystemOrThrow <IFileSystemManager>(); _electionManager = Application.GetSubsystemOrThrow <IElectionManager>(); WorkingConfigLoaded = false; Application.ConfigUpdated += ApplicationConfigUpdated; }
/// ----------------------------------------------------------------------------- /// <summary> /// The Install method installs the config component /// </summary> /// ----------------------------------------------------------------------------- public override void Install() { try { if (string.IsNullOrEmpty(_FileName)) { //First backup the config file Util.BackupFile(TargetFile, PhysicalSitePath, Log); //Create an XmlDocument for the config file _TargetConfig = new XmlDocument { XmlResolver = null }; TargetConfig.Load(Path.Combine(PhysicalSitePath, TargetFile.FullName)); //Create XmlMerge instance from InstallConfig source _xmlMerge = new XmlMerge(new StringReader(InstallConfig), Package.Version.ToString(), Package.Name); //Update the Config file - Note that this method does not save the file - we will save it in Commit _xmlMerge.UpdateConfig(TargetConfig); Completed = true; Log.AddInfo(Util.CONFIG_Updated + " - " + TargetFile.Name); } else { //Process external file string strConfigFile = Path.Combine(Package.InstallerInfo.TempInstallFolder, _FileName); if (File.Exists(strConfigFile)) { //Create XmlMerge instance from config file source using (var stream = File.OpenText(strConfigFile)) { _xmlMerge = new XmlMerge(stream, Package.Version.ToString(3), Package.Name + " Install"); //Process merge _xmlMerge.UpdateConfigs(false); } Completed = true; Log.AddInfo(Util.CONFIG_Updated); } } } catch (Exception ex) { Log.AddFailure(Util.EXCEPTION + " - " + ex.Message); } }
private void ExecuteXmlMerge(string path) { if (!File.Exists(path)) { return; } var doc = new XmlDocument(); doc.Load(path); var app = DotNetNukeContext.Current.Application; var merge = new XmlMerge(doc, Globals.FormatVersion(app.Version), app.Description); merge.UpdateConfigs(); }
public override void UnInstall() { if (string.IsNullOrEmpty(_UninstallFileName)) { _TargetConfig = new XmlDocument(); TargetConfig.Load(Path.Combine(PhysicalSitePath, TargetFile.FullName)); XmlMerge merge = new XmlMerge(new StringReader(UnInstallConfig), this.Package.Version.ToString(), this.Package.Name); merge.UpdateConfig(TargetConfig, TargetFile.FullName); } else { string strConfigFile = Path.Combine(this.Package.InstallerInfo.TempInstallFolder, _UninstallFileName); if (File.Exists(strConfigFile)) { StreamReader stream = File.OpenText(strConfigFile); XmlMerge merge = new XmlMerge(stream, Package.Version.ToString(3), Package.Name + " UnInstall"); merge.UpdateConfigs(); stream.Close(); } } }
/// <summary>If tyhe <paramref name="file"/> is a strong-named assembly, applies the XML merge.</summary> /// <param name="file">The assembly file.</param> /// <param name="xmlMergeFile">The XML merge file name.</param> /// <returns><c>true</c> if the XML Merge was applied successfully, <c>false</c> if the file was not a strong-named assembly.</returns> private bool ApplyXmlMerge(InstallFile file, string xmlMergeFile) { var assemblyName = AssemblyName.GetAssemblyName(Path.Combine(this.PhysicalBasePath, file.FullName)); if (!assemblyName.Flags.HasFlag(AssemblyNameFlags.PublicKey)) { return(false); } var name = assemblyName.Name; var publicKeyToken = PublicKeyTokenRegex.Match(assemblyName.FullName).Groups[1].Value; var oldVersion = "0.0.0.0-" + new Version(assemblyName.Version.Major, short.MaxValue, short.MaxValue, short.MaxValue); var newVersion = assemblyName.Version.ToString(); var xmlMergePath = Path.Combine(Globals.InstallMapPath, "Config", xmlMergeFile); var xmlMergeDoc = GetXmlMergeDoc(xmlMergePath, name, publicKeyToken, oldVersion, newVersion); var xmlMerge = new XmlMerge(xmlMergeDoc, file.Version.ToString(), this.Package.Name); xmlMerge.UpdateConfigs(); return(true); }
public void MergeTest() { var xml1 = ReadXmlFromStream("Moonlit.TestFixtures.Xml.Xmls.merge1.xml"); var xml2 = ReadXmlFromStream("Moonlit.TestFixtures.Xml.Xmls.merge2.xml"); var ele = XmlMerge.Merge(XElementFinder, xml1, xml2); var book = ele.Elements().FirstOrDefault(x => (string)x.Attribute("name") == "c#"); AssertAttributes(book, true, "1990"); AssertChild(book, "name", "c#"); AssertChild(book, "publish", "1984"); book = ele.Elements().FirstOrDefault(x => (string)x.Attribute("name") == "c++"); AssertAttributes(book, true, "2009"); AssertChild(book, "name", "C++"); AssertChild(book, "publish", "1990"); book = ele.Elements().FirstOrDefault(x => (string)x.Attribute("name") == "c"); AssertAttributes(book, false, "2000"); AssertChild(book, "name", "C Language"); AssertChild(book, "publish", "1980"); }
/// <summary>Applies the XML Merge instructions to the configuration files.</summary> /// <param name="sourceFileName">Path to the XML Merge configuration file.</param> public void ApplyXmlMerge(string sourceFileName) { var xmlMerge = new XmlMerge(sourceFileName, this.Version, this.Sender); xmlMerge.UpdateConfigs(); }
/// <summary>Applies the XML Merge instructions to the configuration files.</summary> /// <param name="sourceDoc">The XML document with the merge instructions.</param> public void ApplyXmlMerge(XDocument sourceDoc) { var xmlMerge = new XmlMerge(sourceDoc.AsXmlDocument(), this.Version, this.Sender); xmlMerge.UpdateConfigs(); }
/// ----------------------------------------------------------------------------- /// <summary> /// The Install method installs the config component /// </summary> /// <history> /// [cnurse] 08/04/2007 created /// </history> /// ----------------------------------------------------------------------------- public override void Install() { try { if (string.IsNullOrEmpty(_FileName)) { //First backup the config file Util.BackupFile(TargetFile, PhysicalSitePath, Log); //Create an XmlDocument for the config file _TargetConfig = new XmlDocument(); TargetConfig.Load(Path.Combine(PhysicalSitePath, TargetFile.FullName)); //Create XmlMerge instance from InstallConfig source var merge = new XmlMerge(new StringReader(InstallConfig), Package.Version.ToString(), Package.Name); //Update the Config file - Note that this method does not save the file - we will save it in Commit merge.UpdateConfig(TargetConfig); Completed = true; Log.AddInfo(Util.CONFIG_Updated + " - " + TargetFile.Name); } else { //Process external file string strConfigFile = Path.Combine(Package.InstallerInfo.TempInstallFolder, _FileName); if (File.Exists(strConfigFile)) { //Create XmlMerge instance from config file source using (var stream = File.OpenText(strConfigFile)) { _xmlMerge = new XmlMerge(stream, Package.Version.ToString(3), Package.Name + " Install"); //Process merge _xmlMerge.UpdateConfigs(false); } Completed = true; Log.AddInfo(Util.CONFIG_Updated); } } } catch (Exception ex) { Log.AddFailure(Util.EXCEPTION + " - " + ex.Message); } }
/// <summary>Applies the XML Merge instructions to the configuration files.</summary> /// <param name="sourceFileName">Path to the XML Merge configuration file.</param> private void ApplyXmlMerge(string sourceFileName) { var xmlMerge = new XmlMerge(sourceFileName, this.ModuleInfo.DesktopModule.Version, this.ModuleInfo.DesktopModule.FriendlyName); xmlMerge.UpdateConfigs(); }
/// <summary>Applies the XML Merge instructions to the configuration files.</summary> /// <param name="sourceDoc">The XML document with the merge instructions.</param> private void ApplyXmlMerge(XDocument sourceDoc) { var xmlMerge = new XmlMerge(sourceDoc.AsXmlDocument(), this.ModuleInfo.DesktopModule.Version, this.ModuleInfo.DesktopModule.FriendlyName); xmlMerge.UpdateConfigs(); }