Я разрабатываю пакет umbraco, который использует настраиваемую конфигурацию.Umbraco - Создайте раздел конфигурации во время выполнения с источником конфигурации
Моей задачей является создание раздела конфигурации во время процесса intall.
С packageActionsContrib он работает отлично, код добавить configSection по мере необходимости и создает узел:
<section name="LogServiceConfiguration" type="Utils.LogServiceConfiguration, Utils, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" allowLocation="true" allowDefinition="Everywhere" allowExeDefinition="MachineToApplication" overrideModeDefault="Allow" restartOnExternalChanges="true" requirePermission="true" />
...
<LogServiceConfiguration>
<Error EmailNodeId="0" PageUrl="" DoRedirect="false" />
</LogServiceConfiguration>
Что мне нужно изменить вторую часть с
<LogServiceConfiguration configSource="config\LogService.config" />
я, уже предоставляют файл с установкой, поэтому я создал только строку, а не файл.
Код этого
public class AddConfigurationSection : IPackageAction
{
#region IPackageAction Members
public bool Execute(string packageName, XmlNode xmlData)
{
try
{
var config = WebConfigurationManager.OpenWebConfiguration("~");
var sectionName = xmlData.SelectSingleNode("//Section").Attributes["name"].Value;
if (config.Sections[sectionName] == null)
{
var assemblyName = xmlData.SelectSingleNode("//Section").Attributes["assembly"].Value;
var typeName = xmlData.SelectSingleNode("//Section").Attributes["type"].Value;
var assembly = Assembly.Load(assemblyName);
if (assembly == null) return false;
var configSection = assembly.CreateInstance(typeName) as ConfigurationSection;
if (configSection == null) return false;
config.Sections.Add(sectionName, configSection);
configSection.SectionInformation.ForceSave = true;
config.Save(ConfigurationSaveMode.Full);
}
return true;
}
catch (Exception e)
{
string message = "Error at execute AddConfigurationSection package action: " + e.Message;
Log.LogException(message, e);
return false;
}
}
public string Alias()
{
return "AddConfigurationSection";
}
public bool Undo(string packageName, XmlNode xmlData)
{
try
{
var config = WebConfigurationManager.OpenWebConfiguration("~");
var sectionName = xmlData.SelectSingleNode("//Section").Attributes["name"].Value;
if (config.Sections[sectionName] != null)
{
config.Sections.Remove(sectionName);
config.Save(ConfigurationSaveMode.Full);
}
return true;
}
catch
{
return false;
}
}
public XmlNode SampleXml()
{
var sample = "<Action runat=\"install\" undo=\"true\" alias=\"AddConfigurationSection\"><Section name=\"\" assembly=\"\" type=\"\" /></Action>";
return helper.parseStringToXmlNode(sample);
}
#endregion
}
Первая ссылка нарушена. – TombMedia