示例#1
0
		void AddFeatureBlock (XmlDocument doc, FeatureBlock block, FeatureTarget target, IDefaultContainer[] defaults,
				      IConfigBlockContainer[] configBlocks)
		{
			if (target != FeatureTarget.Any && block.Target != target)
				return;

			ConfigBlockBlock configBlock = Helpers.FindConfigBlock (configBlocks, block.Name);
			if (configBlock == null)
				throw new ApplicationException (String.Format ("Config block '{0}' cannot be found", block.Name));

			XmlNode attachPoint = null;

			ProcessSections (doc, doc, "/", configBlock.Requires, defaults, configBlock.Name, ref attachPoint);
			if (attachPoint == null)
				attachPoint = FindDefaultAttachPoint (doc, configBlock.Requires);
			if (attachPoint == null)
				throw new ApplicationException (
					String.Format ("Missing attachment point for block '{0}'", configBlock.Name));
			
			XmlDocument contents = new XmlDocument ();
			contents.LoadXml (String.Format ("<{0}>{1}</{0}>", Helpers.FakeRootName, configBlock.Contents));
			AddFeatureRecursively (doc, attachPoint, contents.DocumentElement);
		}
示例#2
0
		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);
		}