|
11 | 11 | using System.ComponentModel.Design; |
12 | 12 | using ICSharpCode.Core; |
13 | 13 |
|
14 | | -internal class DefaultServiceContainer : IServiceContainer, IDisposable |
15 | | -{ |
16 | | - IServiceContainer serviceContainer; |
17 | | - Hashtable services = new Hashtable(); |
18 | | - bool inDispose; |
| 14 | +namespace ICSharpCode.Reporting.Addin.Services{ |
19 | 15 |
|
20 | | - public DefaultServiceContainer () { |
21 | | - serviceContainer = new ServiceContainer(); |
22 | | - LoggingService.Info("Init ServiceContaier"); |
23 | | - } |
24 | 16 |
|
25 | | - #region IServiceContainer implementation |
26 | | - public void AddService(Type serviceType, object serviceInstance) |
| 17 | + class DefaultServiceContainer : IServiceContainer, IDisposable |
27 | 18 | { |
28 | | - if (IsServiceMissing(serviceType)) { |
29 | | - serviceContainer.AddService(serviceType, serviceInstance); |
30 | | - services.Add(serviceType, serviceInstance); |
| 19 | + IServiceContainer serviceContainer; |
| 20 | + Hashtable services = new Hashtable(); |
| 21 | + bool inDispose; |
| 22 | + |
| 23 | + public DefaultServiceContainer () { |
| 24 | + serviceContainer = new ServiceContainer(); |
| 25 | + LoggingService.Info("Init ServiceContaier"); |
31 | 26 | } |
32 | | - } |
33 | | - public void AddService(Type serviceType, object serviceInstance, bool promote) |
34 | | - { |
35 | | - throw new NotImplementedException(); |
36 | | - } |
37 | | - public void AddService(Type serviceType, ServiceCreatorCallback callback) |
38 | | - { |
39 | | - throw new NotImplementedException(); |
40 | | - } |
41 | 27 |
|
42 | | - public void AddService(Type serviceType, ServiceCreatorCallback callback, bool promote) |
43 | | - { |
44 | | - throw new NotImplementedException(); |
45 | | - } |
| 28 | + #region IServiceContainer implementation |
| 29 | + public void AddService(Type serviceType, object serviceInstance) |
| 30 | + { |
| 31 | + if (IsServiceMissing(serviceType)) { |
| 32 | + serviceContainer.AddService(serviceType, serviceInstance); |
| 33 | + services.Add(serviceType, serviceInstance); |
| 34 | + } |
| 35 | + } |
| 36 | + public void AddService(Type serviceType, object serviceInstance, bool promote) |
| 37 | + { |
| 38 | + throw new NotImplementedException(); |
| 39 | + } |
| 40 | + public void AddService(Type serviceType, ServiceCreatorCallback callback) |
| 41 | + { |
| 42 | + throw new NotImplementedException(); |
| 43 | + } |
46 | 44 |
|
| 45 | + public void AddService(Type serviceType, ServiceCreatorCallback callback, bool promote) |
| 46 | + { |
| 47 | + throw new NotImplementedException(); |
| 48 | + } |
47 | 49 |
|
48 | | - public void RemoveService(System.Type serviceType, bool promote) |
49 | | - { |
50 | | - if (inDispose) |
51 | | - return; |
52 | | - serviceContainer.RemoveService(serviceType, promote); |
53 | | - if (services.Contains(serviceType)) |
54 | | - services.Remove(serviceType); |
55 | | - } |
| 50 | + |
| 51 | + public void RemoveService(System.Type serviceType, bool promote) |
| 52 | + { |
| 53 | + if (inDispose) |
| 54 | + return; |
| 55 | + serviceContainer.RemoveService(serviceType, promote); |
| 56 | + if (services.Contains(serviceType)) |
| 57 | + services.Remove(serviceType); |
| 58 | + } |
56 | 59 |
|
57 | | - public void RemoveService(System.Type serviceType) |
58 | | - { |
59 | | - if (inDispose == true) |
60 | | - return; |
61 | | - serviceContainer.RemoveService(serviceType); |
62 | | - if (services.Contains(serviceType)) |
63 | | - services.Remove(serviceType); |
64 | | - } |
65 | | - #endregion |
| 60 | + public void RemoveService(System.Type serviceType) |
| 61 | + { |
| 62 | + if (inDispose == true) |
| 63 | + return; |
| 64 | + serviceContainer.RemoveService(serviceType); |
| 65 | + if (services.Contains(serviceType)) |
| 66 | + services.Remove(serviceType); |
| 67 | + } |
| 68 | + #endregion |
66 | 69 |
|
67 | | - #region IServiceProvider implementation |
68 | | - public object GetService(Type serviceType) |
69 | | - { |
70 | | - // System.Console.WriteLine("calling <{0}>",serviceType.ToString()); |
71 | | - if (LoggingService.IsInfoEnabled && IsServiceMissing(serviceType)) { |
72 | | - // LoggingService.InfoFormatted("request missing service : {0} from Assembly {1} is not aviable.", serviceType, serviceType.Assembly.FullName); |
73 | | - // System.Console.WriteLine("Missing <{0}>",serviceType); |
74 | | - // System.Console.WriteLine("\t found"); |
75 | | - } else { |
76 | | - // System.Console.WriteLine("\tmissing"); |
77 | | - // LoggingService.DebugFormatted("get service : {0} from Assembly {1}.", serviceType, serviceType.Assembly.FullName); |
78 | | - // System.Console.WriteLine("Missing <{0}>",serviceType); |
| 70 | + #region IServiceProvider implementation |
| 71 | + public object GetService(Type serviceType) |
| 72 | + { |
| 73 | + // System.Console.WriteLine("calling <{0}>",serviceType.ToString()); |
| 74 | + if (LoggingService.IsInfoEnabled && IsServiceMissing(serviceType)) { |
| 75 | + // LoggingService.InfoFormatted("request missing service : {0} from Assembly {1} is not aviable.", serviceType, serviceType.Assembly.FullName); |
| 76 | + // System.Console.WriteLine("Missing <{0}>",serviceType); |
| 77 | + // System.Console.WriteLine("\t found"); |
| 78 | + } else { |
| 79 | + // System.Console.WriteLine("\tmissing"); |
| 80 | + // LoggingService.DebugFormatted("get service : {0} from Assembly {1}.", serviceType, serviceType.Assembly.FullName); |
| 81 | + // System.Console.WriteLine("Missing <{0}>",serviceType); |
| 82 | + } |
| 83 | + return serviceContainer.GetService(serviceType); |
79 | 84 | } |
80 | | - return serviceContainer.GetService(serviceType); |
81 | | - } |
82 | | - #endregion |
| 85 | + #endregion |
83 | 86 |
|
84 | | - bool IsServiceMissing(Type serviceType) |
85 | | - { |
86 | | - return serviceContainer.GetService(serviceType) == null; |
87 | | - } |
| 87 | + bool IsServiceMissing(Type serviceType) |
| 88 | + { |
| 89 | + return serviceContainer.GetService(serviceType) == null; |
| 90 | + } |
88 | 91 |
|
89 | | - #region IDisposable implementation |
90 | | - public void Dispose() |
91 | | - { |
92 | | - inDispose = true; |
93 | | - foreach (DictionaryEntry o in services) { |
94 | | - if (o.Value == this) { |
95 | | - continue; |
96 | | - } |
97 | | - // || o.GetType().Assembly != Assembly.GetCallingAssembly() |
98 | | - IDisposable disposeMe = o.Value as IDisposable; |
99 | | - if (disposeMe != null) { |
100 | | - try { |
101 | | - disposeMe.Dispose(); |
102 | | - } catch (Exception e) { |
103 | | - ICSharpCode.Core.MessageService.ShowException(e, "Exception while disposing " + disposeMe); |
| 92 | + #region IDisposable implementation |
| 93 | + public void Dispose() |
| 94 | + { |
| 95 | + inDispose = true; |
| 96 | + foreach (DictionaryEntry o in services) { |
| 97 | + if (o.Value == this) { |
| 98 | + continue; |
| 99 | + } |
| 100 | + // || o.GetType().Assembly != Assembly.GetCallingAssembly() |
| 101 | + IDisposable disposeMe = o.Value as IDisposable; |
| 102 | + if (disposeMe != null) { |
| 103 | + try { |
| 104 | + disposeMe.Dispose(); |
| 105 | + } catch (Exception e) { |
| 106 | + ICSharpCode.Core.MessageService.ShowException(e, "Exception while disposing " + disposeMe); |
| 107 | + } |
104 | 108 | } |
105 | 109 | } |
| 110 | + services.Clear(); |
| 111 | + services = null; |
| 112 | + inDispose = false; |
106 | 113 | } |
107 | | - services.Clear(); |
108 | | - services = null; |
109 | | - inDispose = false; |
110 | | - } |
111 | | - #endregion |
| 114 | + #endregion |
| 115 | + } |
112 | 116 | } |
0 commit comments