##// END OF EJS Templates
Added Trace<T>.Debug(...) method for debug messages...
cin -
r280:f07be402ab02 v3
parent child
Show More
@@ -89,6 +89,17 namespace Implab.Playground {
89 89 public class Program {
90 90
91 91 static void Main(string[] args) {
92 var u1 = new Uri("/some/one");
93
94 Console.WriteLine($"{u1.IsAbsoluteUri}: {u1}");
95
96 var u2 = new Uri(u1, "../../two");
97
98 Console.WriteLine($"{u2.IsAbsoluteUri}: {u2}");
99
100 }
101
102 static void Main2(string[] args) {
92 103 var listener = new SimpleTraceListener(Console.Out);
93 104 var source = Trace<TypeResolver>.TraceSource;
94 105 source.Switch.Level = SourceLevels.All;
@@ -1,8 +1,12
1 1 using System;
2 using System.IO;
2 3 using System.Reflection;
4 using Implab.Diagnostics;
3 5 using Unity;
4 6
5 7 namespace Implab.ServiceHost.Unity {
8 using static Trace<ContainerBuilder>;
9
6 10 public class ContainerBuilder {
7 11
8 12 readonly TypeResolver m_resolver;
@@ -11,6 +15,8 namespace Implab.ServiceHost.Unity {
11 15
12 16 readonly ContainerConfigurationSchema m_schema;
13 17
18 Uri m_location;
19
14 20 public IUnityContainer Container {
15 21 get {
16 22 return m_container;
@@ -97,13 +103,39 namespace Implab.ServiceHost.Unity {
97 103
98 104 }
99 105
106 /// <summary>
107 /// Includes the confguration. Creates a new <see cref="ContainerBuilder"/>,
108 /// and loads the configuration to it. The created builder will share the
109 /// container and will have its own isolated type resolver.
110 /// </summary>
111 /// <param name="file">A path to configuration relative to the current configuration.</param>
100 112 public void Include(string file) {
101 113 var includeContext = new ContainerBuilder(m_container, m_schema);
114
115 if (m_location != null) {
116 var uri = new Uri(m_location, file);
117 includeContext.LoadConfig(uri);
118 } else {
102 119 includeContext.LoadConfig(file);
103 120 }
121 }
104 122
123 /// <summary>
124 /// Loads a configuration from the specified local file.
125 /// </summary>
126 /// <param name="file">The path to the configuration file.</param>
105 127 public void LoadConfig(string file) {
106 var config = m_schema.LoadFile(file);
128 Safe.ArgumentNotEmpty(file, nameof(file));
129
130 LoadConfig(new Uri(Path.GetFullPath(file)));
131 }
132
133 public void LoadConfig(Uri location) {
134 Safe.ArgumentNotNull(location, nameof(location));
135
136 m_location = location;
137
138 var config = m_schema.LoadConfig(location.ToString());
107 139 config.Visit(this);
108 140 }
109 141
@@ -45,8 +45,8 namespace Implab.ServiceHost.Unity {
45 45 RegisterContainerElement(typeof(T), name);
46 46 }
47 47
48 public ContainerElement LoadFile(string file) {
49 using (var reader = XmlReader.Create(file)) {
48 public ContainerElement LoadConfig(string uri) {
49 using (var reader = XmlReader.Create(uri)) {
50 50 return (ContainerElement)Serializer.Deserialize(reader);
51 51 }
52 52 }
@@ -23,21 +23,5 namespace Implab.ServiceHost.Unity {
23 23 protected RegistrationBuilder(Type registrationType) {
24 24 RegistrationType = registrationType;
25 25 }
26
27 internal void Visit(SingletonLifetimeElement simgletonLifetime) {
28 Lifetime = new SingletonLifetimeManager();
29 }
30
31 internal void Visit(ContainerLifetimeElement containerLifetime) {
32 Lifetime = new ContainerControlledLifetimeManager();
33 }
34
35 internal void Visit(HierarchicalLifetimeElement hierarchicalLifetime) {
36 Lifetime = new HierarchicalLifetimeManager();
37 }
38
39 internal void Visist(ContextLifetimeElement contextLifetime) {
40 Lifetime = new PerResolveLifetimeManager();
41 }
42 26 }
43 27 } No newline at end of file
@@ -46,6 +46,16 namespace Implab.Diagnostics {
46 46 }
47 47
48 48 /// <summary>
49 /// Writes a debug message.
50 /// </summary>
51 /// <param name="format">Format.</param>
52 /// <param name="arguments">Arguments.</param>
53 [Conditional("DEBUG")]
54 public static void Debug(string format, params object[] arguments) {
55
56 }
57
58 /// <summary>
49 59 /// Writes an informational message.
50 60 /// </summary>
51 61 /// <param name="format">Format.</param>
@@ -60,17 +70,19 namespace Implab.Diagnostics {
60 70 /// </summary>
61 71 /// <param name="format">Format.</param>
62 72 /// <param name="arguments">Arguments.</param>
63 [Conditional("TRACE")]
64 73 public static void Warn(string format, params object[] arguments) {
65 74 TraceSource.TraceEvent(TraceEventType.Warning, 0, format, arguments);
66 75 }
67 76
68 [Conditional("TRACE")]
77 /// <summary>
78 /// Writes a error message.
79 /// </summary>
80 /// <param name="format">Format.</param>
81 /// <param name="arguments">Arguments.</param>
69 82 public static void Error(string format, params object[] arguments) {
70 83 TraceSource.TraceEvent(TraceEventType.Error, 0, format, arguments);
71 84 }
72 85
73 [Conditional("TRACE")]
74 86 public static void Error(Exception err) {
75 87 TraceSource.TraceData(TraceEventType.Error, 0, err);
76 88 }
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved
author

ok, latest stable version should be in default

You need to be logged in to leave comments. Login now