using System; using System.IO; using System.Linq; using System.Xml; using Chernobyl.Collections.Generic.Event; using Chernobyl.Reflection.Template; using Chernobyl.Reflection.Template.Xml; using Chernobyl.Resources; namespace Chernobyl.Reflection.Resources { /// /// Loads declarative XML components that describes how .NET types should be /// configured and initialized. /// public class XmlContentResourceProcessor : ResourceProcessor { /// /// Constructor. /// /// The services instance to use when injecting /// or receiving dependencies from created instances. public XmlContentResourceProcessor(IEventCollection services) { Services = services; } /// /// Reads in the declarative instance content to the stream specified. /// /// The callback that will be invoked when the /// resource has been loaded. /// The stream to load the resource from. /// Options for the loading or processing of the /// resource. public override void From(ResourceProcessCallback callback, Stream readFrom, params IOption[] options) { // create a reader and move to the first bit of content using(XmlReader xmlr = XmlReader.Create(readFrom)) { if (xmlr.MoveToContent() != XmlNodeType.None) callback(new ResourceProcessResult(XmlInstance.Create(Services, xmlr).First(), null, true, true)); else CheckedNextFrom(callback, readFrom, options); } } /// /// Writes out the declarative instance content to the stream specified. /// /// The instance to /// write out to the stream specified. /// The stream to write the instances to. /// Options for controlling the writing out of the /// instance data. This resource processor does currently use any options. public override void To(IComponent resource, Stream writeTo, params IOption[] options) { throw new NotImplementedException(); } /// /// The services instance to use when injecting or receiving /// dependencies from created instances. /// IEventCollection Services { get; set; } } }