Mercurial > silverbladetech
annotate Chronosv2/source/Services/WidgetConfigurationService.cs @ 14:741981715d94
Initial review and translations
author | stevenh7776 stevenhollidge@hotmail.com |
---|---|
date | Tue, 21 Feb 2012 18:59:30 +0700 |
parents | 443821e55f06 |
children |
rev | line source |
---|---|
10
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
1 using System; |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
2 using System.Collections.Generic; |
14
741981715d94
Initial review and translations
stevenh7776 stevenhollidge@hotmail.com
parents:
10
diff
changeset
|
3 using System.Configuration; |
10
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
4 using Chronos.Configuration; |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
5 using Chronos.Presentation.Core.Configuration; |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
6 using Chronos.Presentation.Core.Widgets; |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
7 using NLog; |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
8 using nRoute.Components.Composition; |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
9 using nRoute.Services; |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
10 |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
11 namespace Chronos.Services |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
12 { |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
13 [MapService(typeof(IWidgetConfigurationService), |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
14 InitializationMode = InitializationMode.OnDemand, |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
15 Lifetime = InstanceLifetime.Singleton)] |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
16 public sealed class WidgetConfigurationService |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
17 : IWidgetConfigurationService |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
18 { |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
19 #region · Logger · |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
20 |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
21 private static Logger Logger = LogManager.GetCurrentClassLogger(); |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
22 |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
23 #endregion |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
24 |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
25 #region · SyncObject · |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
26 |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
27 private static readonly object SyncObject = new object(); |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
28 |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
29 #endregion |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
30 |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
31 #region · Constants · |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
32 |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
33 private static readonly string RootConfigFile = "Widgets.config"; |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
34 private static readonly string RootSection = "chronoserp.widgets"; |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
35 |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
36 #endregion |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
37 |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
38 #region · Fields · |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
39 |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
40 private List<IWidget> widgets; |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
41 |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
42 #endregion |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
43 |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
44 #region · Constructors · |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
45 |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
46 public WidgetConfigurationService() |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
47 { |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
48 } |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
49 |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
50 #endregion |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
51 |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
52 #region · Methods · |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
53 |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
54 public IEnumerable<IWidget> GetWidgets() |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
55 { |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
56 lock (SyncObject) |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
57 { |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
58 if (this.widgets == null) |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
59 { |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
60 WidgetsSectionHandler section = ConfigurationManager.GetSection(RootSection) as WidgetsSectionHandler; |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
61 |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
62 if (section != null) |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
63 { |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
64 this.widgets = new List<IWidget>(); |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
65 |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
66 foreach (WidgetConfigurationElement widgetConfig in section.Widgets) |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
67 { |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
68 IWidget widget = this.CreateWidgetDefinition(widgetConfig); |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
69 |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
70 if (widget == null) |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
71 { |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
72 Logger.Debug("Widget not found {0} - {1}", widgetConfig.Id, widgetConfig.Type); |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
73 } |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
74 else |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
75 { |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
76 this.widgets.Add(widget); |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
77 } |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
78 } |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
79 } |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
80 } |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
81 } |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
82 |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
83 return this.widgets; |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
84 } |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
85 |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
86 public T GetWidgetConfigurationSection<T>(string sectionName) |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
87 where T: ConfigurationSection |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
88 { |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
89 throw new NotImplementedException(); |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
90 } |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
91 |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
92 #endregion |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
93 |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
94 #region · Private Methods · |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
95 |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
96 private IWidget CreateWidgetDefinition(WidgetConfigurationElement widgetConfig) |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
97 { |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
98 IWidget widget = null; |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
99 |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
100 try |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
101 { |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
102 widget = Activator.CreateInstance(Type.GetType(widgetConfig.Type)) as IWidget; |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
103 } |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
104 catch (Exception ex) |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
105 { |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
106 Logger.ErrorException |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
107 ( |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
108 String.Format("Widget not found {0} - {1}", widgetConfig.Id, widgetConfig.Type), |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
109 ex |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
110 ); |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
111 } |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
112 |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
113 return widget; |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
114 } |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
115 |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
116 #endregion |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
117 } |
443821e55f06
Initial cleaned up add from Codeplex files
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
118 } |