changeset 280:f07be402ab02 v3

Added Trace<T>.Debug(...) method for debug messages Added ContainerBuilde.LoadConfig(Uri) method
author cin
date Fri, 25 May 2018 19:15:26 +0300
parents 8714471e8d78
children e0916ddc9950
files Implab.Playground/Program.cs Implab.ServiceHost/Unity/ContainerBuilder.cs Implab.ServiceHost/Unity/ContainerConfigurationSchema.cs Implab.ServiceHost/Unity/RegistrationBuilder.cs Implab/Diagnostics/Trace.cs
diffstat 5 files changed, 62 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- 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<TypeResolver>.TraceSource;
             source.Switch.Level = SourceLevels.All;
--- 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<ContainerBuilder>;
+
     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 @@
 
         }
 
+        /// <summary>
+        /// Includes the confguration. Creates a new <see cref="ContainerBuilder"/>,
+        /// and loads the configuration to it. The created builder will share the
+        /// container and will have its own isolated type resolver.
+        /// </summary>
+        /// <param name="file">A path to configuration relative to the current configuration.</param>
         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);
+            }
         }
 
+        /// <summary>
+        /// Loads a configuration from the specified local file.
+        /// </summary>
+        /// <param name="file">The path to the configuration file.</param>
         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);
         }
 
--- 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);
             }
         }
--- 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
--- 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 @@
         }
 
         /// <summary>
+        /// Writes a debug message.
+        /// </summary>
+        /// <param name="format">Format.</param>
+        /// <param name="arguments">Arguments.</param>
+        [Conditional("DEBUG")]
+        public static void Debug(string format, params object[] arguments) {
+
+        }
+
+        /// <summary>
         /// Writes an informational message.
         /// </summary>
         /// <param name="format">Format.</param>
@@ -60,17 +70,19 @@
         /// </summary>
         /// <param name="format">Format.</param>
         /// <param name="arguments">Arguments.</param>
-        [Conditional("TRACE")]
         public static void Warn(string format, params object[] arguments) {
             TraceSource.TraceEvent(TraceEventType.Warning, 0, format, arguments);
         }
 
-        [Conditional("TRACE")]
+        /// <summary>
+        /// Writes a error message.
+        /// </summary>
+        /// <param name="format">Format.</param>
+        /// <param name="arguments">Arguments.</param>
         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);
         }