# HG changeset patch # User cin # Date 1527264926 -10800 # Node ID f07be402ab0265b61f768a329ba6eef5fdbda66b # Parent 8714471e8d789d9c2fa1ce85cfe81832c451f99c Added Trace.Debug(...) method for debug messages Added ContainerBuilde.LoadConfig(Uri) method diff -r 8714471e8d78 -r f07be402ab02 Implab.Playground/Program.cs --- a/Implab.Playground/Program.cs Fri May 04 18:12:42 2018 +0300 +++ b/Implab.Playground/Program.cs Fri May 25 19:15:26 2018 +0300 @@ -89,6 +89,17 @@ public class Program { static void Main(string[] args) { + var u1 = new Uri("/some/one"); + + Console.WriteLine($"{u1.IsAbsoluteUri}: {u1}"); + + var u2 = new Uri(u1, "../../two"); + + Console.WriteLine($"{u2.IsAbsoluteUri}: {u2}"); + + } + + static void Main2(string[] args) { var listener = new SimpleTraceListener(Console.Out); var source = Trace.TraceSource; source.Switch.Level = SourceLevels.All; diff -r 8714471e8d78 -r f07be402ab02 Implab.ServiceHost/Unity/ContainerBuilder.cs --- a/Implab.ServiceHost/Unity/ContainerBuilder.cs Fri May 04 18:12:42 2018 +0300 +++ b/Implab.ServiceHost/Unity/ContainerBuilder.cs Fri May 25 19:15:26 2018 +0300 @@ -1,8 +1,12 @@ using System; +using System.IO; using System.Reflection; +using Implab.Diagnostics; using Unity; namespace Implab.ServiceHost.Unity { + using static Trace; + public class ContainerBuilder { readonly TypeResolver m_resolver; @@ -11,6 +15,8 @@ readonly ContainerConfigurationSchema m_schema; + Uri m_location; + public IUnityContainer Container { get { return m_container; @@ -97,13 +103,39 @@ } + /// + /// Includes the confguration. Creates a new , + /// and loads the configuration to it. The created builder will share the + /// container and will have its own isolated type resolver. + /// + /// A path to configuration relative to the current configuration. public void Include(string file) { var includeContext = new ContainerBuilder(m_container, m_schema); - includeContext.LoadConfig(file); + + if (m_location != null) { + var uri = new Uri(m_location, file); + includeContext.LoadConfig(uri); + } else { + includeContext.LoadConfig(file); + } } + /// + /// Loads a configuration from the specified local file. + /// + /// The path to the configuration file. public void LoadConfig(string file) { - var config = m_schema.LoadFile(file); + Safe.ArgumentNotEmpty(file, nameof(file)); + + LoadConfig(new Uri(Path.GetFullPath(file))); + } + + public void LoadConfig(Uri location) { + Safe.ArgumentNotNull(location, nameof(location)); + + m_location = location; + + var config = m_schema.LoadConfig(location.ToString()); config.Visit(this); } diff -r 8714471e8d78 -r f07be402ab02 Implab.ServiceHost/Unity/ContainerConfigurationSchema.cs --- a/Implab.ServiceHost/Unity/ContainerConfigurationSchema.cs Fri May 04 18:12:42 2018 +0300 +++ b/Implab.ServiceHost/Unity/ContainerConfigurationSchema.cs Fri May 25 19:15:26 2018 +0300 @@ -45,8 +45,8 @@ RegisterContainerElement(typeof(T), name); } - public ContainerElement LoadFile(string file) { - using (var reader = XmlReader.Create(file)) { + public ContainerElement LoadConfig(string uri) { + using (var reader = XmlReader.Create(uri)) { return (ContainerElement)Serializer.Deserialize(reader); } } diff -r 8714471e8d78 -r f07be402ab02 Implab.ServiceHost/Unity/RegistrationBuilder.cs --- a/Implab.ServiceHost/Unity/RegistrationBuilder.cs Fri May 04 18:12:42 2018 +0300 +++ b/Implab.ServiceHost/Unity/RegistrationBuilder.cs Fri May 25 19:15:26 2018 +0300 @@ -23,21 +23,5 @@ protected RegistrationBuilder(Type registrationType) { RegistrationType = registrationType; } - - internal void Visit(SingletonLifetimeElement simgletonLifetime) { - Lifetime = new SingletonLifetimeManager(); - } - - internal void Visit(ContainerLifetimeElement containerLifetime) { - Lifetime = new ContainerControlledLifetimeManager(); - } - - internal void Visit(HierarchicalLifetimeElement hierarchicalLifetime) { - Lifetime = new HierarchicalLifetimeManager(); - } - - internal void Visist(ContextLifetimeElement contextLifetime) { - Lifetime = new PerResolveLifetimeManager(); - } } } \ No newline at end of file diff -r 8714471e8d78 -r f07be402ab02 Implab/Diagnostics/Trace.cs --- a/Implab/Diagnostics/Trace.cs Fri May 04 18:12:42 2018 +0300 +++ b/Implab/Diagnostics/Trace.cs Fri May 25 19:15:26 2018 +0300 @@ -46,6 +46,16 @@ } /// + /// Writes a debug message. + /// + /// Format. + /// Arguments. + [Conditional("DEBUG")] + public static void Debug(string format, params object[] arguments) { + + } + + /// /// Writes an informational message. /// /// Format. @@ -60,17 +70,19 @@ /// /// Format. /// Arguments. - [Conditional("TRACE")] public static void Warn(string format, params object[] arguments) { TraceSource.TraceEvent(TraceEventType.Warning, 0, format, arguments); } - [Conditional("TRACE")] + /// + /// Writes a error message. + /// + /// Format. + /// Arguments. public static void Error(string format, params object[] arguments) { TraceSource.TraceEvent(TraceEventType.Error, 0, format, arguments); } - [Conditional("TRACE")] public static void Error(Exception err) { TraceSource.TraceData(TraceEventType.Error, 0, err); }