annotate Implab.Playground/Program.cs @ 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
267
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
1 using System;
277
963b17c275be Refactoring
cin
parents: 274
diff changeset
2 using System.Collections.Generic;
268
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
3 using System.Diagnostics;
272
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
4 using System.Linq;
278
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
5 using Implab.Components;
268
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
6 using Implab.Diagnostics;
267
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
7 using Implab.ServiceHost.Unity;
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
8 using Implab.Xml;
267
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
9 using Unity;
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
10 using Unity.Injection;
272
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
11 using Unity.Registration;
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
12
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
13 namespace Implab.Playground {
267
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
14
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
15 public class Foo {
269
ff581cff7003 Working on Unity container xml configuration
cin
parents: 268
diff changeset
16
ff581cff7003 Working on Unity container xml configuration
cin
parents: 268
diff changeset
17 public class Bar {
ff581cff7003 Working on Unity container xml configuration
cin
parents: 268
diff changeset
18
ff581cff7003 Working on Unity container xml configuration
cin
parents: 268
diff changeset
19 }
ff581cff7003 Working on Unity container xml configuration
cin
parents: 268
diff changeset
20
270
ade80d94dfb5 Working on Unity container xml configuration
cin
parents: 269
diff changeset
21 public string Name { get; set; }
ade80d94dfb5 Working on Unity container xml configuration
cin
parents: 269
diff changeset
22
267
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
23 public int IntValue { get; set; }
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
24
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
25 public string StringValue { get; set; }
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
26
277
963b17c275be Refactoring
cin
parents: 274
diff changeset
27 public void AddRange(Foo[] items) {
963b17c275be Refactoring
cin
parents: 274
diff changeset
28 Console.WriteLine($"AddRange: Foo[]");
963b17c275be Refactoring
cin
parents: 274
diff changeset
29 }
963b17c275be Refactoring
cin
parents: 274
diff changeset
30
267
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
31 }
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
32
278
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
33 public class FooFactory : IFactory<Foo>, IFactory<Foo.Bar> {
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
34
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
35 public bool UseSsl { get; set; }
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
36
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
37 public string Connection { get; set; }
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
38
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
39 public Foo Create() {
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
40 return new Foo() {
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
41 Name = "AutoFac"
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
42 };
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
43 }
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
44
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
45 Foo.Bar IFactory<Foo.Bar>.Create() {
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
46 return new Foo.Bar();
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
47 }
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
48 }
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
49
272
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
50 public interface IContainer<T> {
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
51 T Instance { get; set; }
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
52 }
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
53
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
54 public class Container<T> : IContainer<T> {
278
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
55 public class Bar {
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
56
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
57 }
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
58
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
59 public class Bar<T2> {
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
60 public class Baz {
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
61
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
62 }
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
63
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
64 }
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
65
267
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
66 public Container() {
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
67
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
68 }
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
69
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
70 public Container(T instance) {
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
71 Instance = instance;
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
72 }
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
73
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
74 public T Instance { get; set; }
270
ade80d94dfb5 Working on Unity container xml configuration
cin
parents: 269
diff changeset
75
ade80d94dfb5 Working on Unity container xml configuration
cin
parents: 269
diff changeset
76 public void SetInstance(T value) {
ade80d94dfb5 Working on Unity container xml configuration
cin
parents: 269
diff changeset
77 Instance = value;
ade80d94dfb5 Working on Unity container xml configuration
cin
parents: 269
diff changeset
78 }
277
963b17c275be Refactoring
cin
parents: 274
diff changeset
79
963b17c275be Refactoring
cin
parents: 274
diff changeset
80 public void AddRange(List<T> items) {
963b17c275be Refactoring
cin
parents: 274
diff changeset
81 Console.WriteLine($"AddRange: {typeof(List<T>)}");
963b17c275be Refactoring
cin
parents: 274
diff changeset
82 }
963b17c275be Refactoring
cin
parents: 274
diff changeset
83
963b17c275be Refactoring
cin
parents: 274
diff changeset
84 public void AddRange(T[] items) {
963b17c275be Refactoring
cin
parents: 274
diff changeset
85 Console.WriteLine($"AddRange: T[] ofType {typeof(T[])}");
963b17c275be Refactoring
cin
parents: 274
diff changeset
86 }
267
6b3e5c48131b Working on Unity xml configuration
cin
parents: 260
diff changeset
87 }
255
b00441e04738 Adde workaround to the behaviour of the logical operations stack in conjuction
cin
parents: 236
diff changeset
88
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
89 public class Program {
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
90
255
b00441e04738 Adde workaround to the behaviour of the logical operations stack in conjuction
cin
parents: 236
diff changeset
91 static void Main(string[] args) {
280
f07be402ab02 Added Trace<T>.Debug(...) method for debug messages
cin
parents: 279
diff changeset
92 var u1 = new Uri("/some/one");
f07be402ab02 Added Trace<T>.Debug(...) method for debug messages
cin
parents: 279
diff changeset
93
f07be402ab02 Added Trace<T>.Debug(...) method for debug messages
cin
parents: 279
diff changeset
94 Console.WriteLine($"{u1.IsAbsoluteUri}: {u1}");
f07be402ab02 Added Trace<T>.Debug(...) method for debug messages
cin
parents: 279
diff changeset
95
f07be402ab02 Added Trace<T>.Debug(...) method for debug messages
cin
parents: 279
diff changeset
96 var u2 = new Uri(u1, "../../two");
f07be402ab02 Added Trace<T>.Debug(...) method for debug messages
cin
parents: 279
diff changeset
97
f07be402ab02 Added Trace<T>.Debug(...) method for debug messages
cin
parents: 279
diff changeset
98 Console.WriteLine($"{u2.IsAbsoluteUri}: {u2}");
f07be402ab02 Added Trace<T>.Debug(...) method for debug messages
cin
parents: 279
diff changeset
99
f07be402ab02 Added Trace<T>.Debug(...) method for debug messages
cin
parents: 279
diff changeset
100 }
f07be402ab02 Added Trace<T>.Debug(...) method for debug messages
cin
parents: 279
diff changeset
101
f07be402ab02 Added Trace<T>.Debug(...) method for debug messages
cin
parents: 279
diff changeset
102 static void Main2(string[] args) {
277
963b17c275be Refactoring
cin
parents: 274
diff changeset
103 var listener = new SimpleTraceListener(Console.Out);
963b17c275be Refactoring
cin
parents: 274
diff changeset
104 var source = Trace<TypeResolver>.TraceSource;
963b17c275be Refactoring
cin
parents: 274
diff changeset
105 source.Switch.Level = SourceLevels.All;
963b17c275be Refactoring
cin
parents: 274
diff changeset
106 source.Listeners.Add(listener);
963b17c275be Refactoring
cin
parents: 274
diff changeset
107
279
8714471e8d78 Container configuration cleanup, RC2
cin
parents: 278
diff changeset
108 var stopwatch = new Stopwatch();
8714471e8d78 Container configuration cleanup, RC2
cin
parents: 278
diff changeset
109 stopwatch.Start();
8714471e8d78 Container configuration cleanup, RC2
cin
parents: 278
diff changeset
110
8714471e8d78 Container configuration cleanup, RC2
cin
parents: 278
diff changeset
111 var container = new UnityContainer();
8714471e8d78 Container configuration cleanup, RC2
cin
parents: 278
diff changeset
112
8714471e8d78 Container configuration cleanup, RC2
cin
parents: 278
diff changeset
113 Console.WriteLine($"Created: {stopwatch.ElapsedMilliseconds}");
8714471e8d78 Container configuration cleanup, RC2
cin
parents: 278
diff changeset
114 stopwatch.Restart();
8714471e8d78 Container configuration cleanup, RC2
cin
parents: 278
diff changeset
115
8714471e8d78 Container configuration cleanup, RC2
cin
parents: 278
diff changeset
116 container.LoadXmlConfiguration("data/sample.xml");
273
79110a16cab7 Working on Unity xml configuration: Refactoring in progress
cin
parents: 272
diff changeset
117
279
8714471e8d78 Container configuration cleanup, RC2
cin
parents: 278
diff changeset
118 Console.WriteLine($"Loaded: {stopwatch.ElapsedMilliseconds}");
273
79110a16cab7 Working on Unity xml configuration: Refactoring in progress
cin
parents: 272
diff changeset
119
279
8714471e8d78 Container configuration cleanup, RC2
cin
parents: 278
diff changeset
120 stopwatch.Restart();
8714471e8d78 Container configuration cleanup, RC2
cin
parents: 278
diff changeset
121 var instace1 = container.Resolve<IContainer<string>>();
8714471e8d78 Container configuration cleanup, RC2
cin
parents: 278
diff changeset
122 Console.WriteLine($"Resolved1: {stopwatch.ElapsedMilliseconds}");
277
963b17c275be Refactoring
cin
parents: 274
diff changeset
123
279
8714471e8d78 Container configuration cleanup, RC2
cin
parents: 278
diff changeset
124 stopwatch.Restart();
8714471e8d78 Container configuration cleanup, RC2
cin
parents: 278
diff changeset
125 var instace2 = container.Resolve<IContainer<Foo>>();
8714471e8d78 Container configuration cleanup, RC2
cin
parents: 278
diff changeset
126 Console.WriteLine($"Resolved2: {stopwatch.ElapsedMilliseconds}");
8714471e8d78 Container configuration cleanup, RC2
cin
parents: 278
diff changeset
127
8714471e8d78 Container configuration cleanup, RC2
cin
parents: 278
diff changeset
128 DisplayContainerRegistrations(container);
272
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
129 }
268
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
130
272
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
131 static void DisplayContainerRegistrations(IUnityContainer theContainer) {
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
132 string regName, regType, mapTo, lifetime;
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
133 Console.WriteLine("Container has {0} Registrations:",
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
134 theContainer.Registrations.Count());
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
135 foreach (ContainerRegistration item in theContainer.Registrations) {
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
136 regType = item.RegisteredType.FullName;
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
137 mapTo = item.MappedToType.FullName;
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
138 regName = item.Name ?? "[default]";
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
139 lifetime = item.LifetimeManager.LifetimeType.Name;
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
140 if (mapTo != regType) {
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
141 mapTo = " -> " + mapTo;
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
142 } else {
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
143 mapTo = string.Empty;
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
144 }
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
145 lifetime = lifetime.Substring(0, lifetime.Length - "LifetimeManager".Length);
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
146 Console.WriteLine("+ {0}{1} '{2}' {3}", regType, mapTo, regName, lifetime);
9d1cca834b05 preview version of Unity xml configuration
cin
parents: 271
diff changeset
147 }
233
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
148 }
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
149
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
150
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
151 }
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
152 }