##// 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 public class Program {
89 public class Program {
90
90
91 static void Main(string[] args) {
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 var listener = new SimpleTraceListener(Console.Out);
103 var listener = new SimpleTraceListener(Console.Out);
93 var source = Trace<TypeResolver>.TraceSource;
104 var source = Trace<TypeResolver>.TraceSource;
94 source.Switch.Level = SourceLevels.All;
105 source.Switch.Level = SourceLevels.All;
@@ -1,8 +1,12
1 using System;
1 using System;
2 using System.IO;
2 using System.Reflection;
3 using System.Reflection;
4 using Implab.Diagnostics;
3 using Unity;
5 using Unity;
4
6
5 namespace Implab.ServiceHost.Unity {
7 namespace Implab.ServiceHost.Unity {
8 using static Trace<ContainerBuilder>;
9
6 public class ContainerBuilder {
10 public class ContainerBuilder {
7
11
8 readonly TypeResolver m_resolver;
12 readonly TypeResolver m_resolver;
@@ -11,6 +15,8 namespace Implab.ServiceHost.Unity {
11
15
12 readonly ContainerConfigurationSchema m_schema;
16 readonly ContainerConfigurationSchema m_schema;
13
17
18 Uri m_location;
19
14 public IUnityContainer Container {
20 public IUnityContainer Container {
15 get {
21 get {
16 return m_container;
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 public void Include(string file) {
112 public void Include(string file) {
101 var includeContext = new ContainerBuilder(m_container, m_schema);
113 var includeContext = new ContainerBuilder(m_container, m_schema);
102 includeContext.LoadConfig(file);
114
115 if (m_location != null) {
116 var uri = new Uri(m_location, file);
117 includeContext.LoadConfig(uri);
118 } else {
119 includeContext.LoadConfig(file);
120 }
103 }
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 public void LoadConfig(string file) {
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 config.Visit(this);
139 config.Visit(this);
108 }
140 }
109
141
@@ -45,8 +45,8 namespace Implab.ServiceHost.Unity {
45 RegisterContainerElement(typeof(T), name);
45 RegisterContainerElement(typeof(T), name);
46 }
46 }
47
47
48 public ContainerElement LoadFile(string file) {
48 public ContainerElement LoadConfig(string uri) {
49 using (var reader = XmlReader.Create(file)) {
49 using (var reader = XmlReader.Create(uri)) {
50 return (ContainerElement)Serializer.Deserialize(reader);
50 return (ContainerElement)Serializer.Deserialize(reader);
51 }
51 }
52 }
52 }
@@ -23,21 +23,5 namespace Implab.ServiceHost.Unity {
23 protected RegistrationBuilder(Type registrationType) {
23 protected RegistrationBuilder(Type registrationType) {
24 RegistrationType = registrationType;
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 } No newline at end of file
27 }
@@ -46,6 +46,16 namespace Implab.Diagnostics {
46 }
46 }
47
47
48 /// <summary>
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 /// Writes an informational message.
59 /// Writes an informational message.
50 /// </summary>
60 /// </summary>
51 /// <param name="format">Format.</param>
61 /// <param name="format">Format.</param>
@@ -60,17 +70,19 namespace Implab.Diagnostics {
60 /// </summary>
70 /// </summary>
61 /// <param name="format">Format.</param>
71 /// <param name="format">Format.</param>
62 /// <param name="arguments">Arguments.</param>
72 /// <param name="arguments">Arguments.</param>
63 [Conditional("TRACE")]
64 public static void Warn(string format, params object[] arguments) {
73 public static void Warn(string format, params object[] arguments) {
65 TraceSource.TraceEvent(TraceEventType.Warning, 0, format, arguments);
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 public static void Error(string format, params object[] arguments) {
82 public static void Error(string format, params object[] arguments) {
70 TraceSource.TraceEvent(TraceEventType.Error, 0, format, arguments);
83 TraceSource.TraceEvent(TraceEventType.Error, 0, format, arguments);
71 }
84 }
72
85
73 [Conditional("TRACE")]
74 public static void Error(Exception err) {
86 public static void Error(Exception err) {
75 TraceSource.TraceData(TraceEventType.Error, 0, err);
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