public void AddFeature(string configFilePath, string featureName, FeatureTarget target, IDefaultContainer[] defaults, IConfigBlockContainer[] configBlocks) { AssertStorage(); FeatureNode fn; if (!storage.ContainsKey(featureName) || (fn = storage [featureName]) == null) { throw new ApplicationException(String.Format("Missing definition of feature '{0}'", featureName)); } List <FeatureBlock> blocks = fn.Blocks; if (blocks == null || blocks.Count == 0) { throw new ApplicationException(String.Format("Definition of feature '{0}' is empty", featureName)); } RunActions(fn.ActionsBefore); XmlDocument doc = new XmlDocument(); if (File.Exists(configFilePath)) { doc.Load(configFilePath); } foreach (FeatureBlock block in blocks) { AddFeatureBlock(doc, block, target, defaults, configBlocks); } Helpers.SaveXml(doc, configFilePath); RunActions(fn.ActionsAfter); }
public void WriteDefaultConfigFile(string name, FeatureTarget target, string path, IDefaultContainer[] defaults) { AssertStorage(); DefaultConfigFile dcf; if (!storage.ContainsKey(name) || (dcf = storage [name]) == null) { throw new ApplicationException( String.Format("Definition of the '{0}' default config file not found.", name)); } if (target != FeatureTarget.Any && dcf.Target != target) { throw new ApplicationException( String.Format("Config file '{0}' can be generated only for the '{1}' target", name, target)); } string targetFile = Path.Combine(path, dcf.FileName); if (File.Exists(targetFile)) { OverwriteFileEventArgs args = new OverwriteFileEventArgs( dcf.FileName, path, target, true ); OnOverwriteFile(args); if (!args.Overwrite) { return; } } try { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } } catch (Exception ex) { throw new ApplicationException( String.Format("Could not create directory '{0}'", path), ex); } XmlDocument doc = new XmlDocument(); PopulateDocument(name, target, doc, dcf, defaults); Helpers.SaveXml(doc, targetFile); }