History

GSF.ServiceProcess: Added customizable message serialization format to ServiceHelper and ClientHelper.

ritchiecarroll committed 12 years ago

Commit bcb45dd1 parent 1b7f0693 files · +64 −8Browse files

Unified · Split

3 files
  1. Source/Libraries/GSF.ServiceProcess/ClientHelper.cs +25 −3
  2. Source/Libraries/GSF.ServiceProcess/ServiceHelper.cs +33 −5
  3. Source/Libraries/GSF.TimeSeries/UI/WindowsServiceClient.cs +6 −0
Source/Libraries/GSF.ServiceProcess/ClientHelper.cs+25−3
@@ -156,6 +156,7 @@ namespace GSF.ServiceProcess · 155 unmodified lines
156 private ClientBase m_remotingClient;156 private ClientBase m_remotingClient;
157 private string m_username;157 private string m_username;
158 private string m_password;158 private string m_password;
159 private SerializationFormat m_serializationFormat;
159 private bool m_persistSettings;160 private bool m_persistSettings;
160 private string m_settingsCategory;161 private string m_settingsCategory;
161 private bool m_attemptReconnection;162 private bool m_attemptReconnection;
@@ -274,6 +275,24 @@ namespace GSF.ServiceProcess · 112 unmodified lines
274 }275 }
275 }276 }
276 277
278 /// <summary>
279 /// Gets or sets a value that indicates the desired message <see cref="GSF.SerializationFormat"/> for interaction with <see cref="ServiceHelper"/>.
280 /// </summary>
281 [Category("Settings"),
282 DefaultValue(ServiceHelper.DefaultSerializationFormat),
283 Description("Indicates messaging serialization format for interactions with ServiceHelper.")]
284 public SerializationFormat SerializationFormat
285 {
286 get
287 {
288 return m_serializationFormat;
289 }
290 set
291 {
292 m_serializationFormat = value;
293 }
294 }
295
277 /// <summary>296 /// <summary>
278 /// Gets or sets a boolean value that indicates whether the settings of <see cref="ClientHelper"/> are to be saved to the config file.297 /// Gets or sets a boolean value that indicates whether the settings of <see cref="ClientHelper"/> are to be saved to the config file.
279 /// </summary>298 /// </summary>
@@ -423,6 +442,7 @@ namespace GSF.ServiceProcess · 143 unmodified lines
423 442
424 settings["Username", true].Update(m_username);443 settings["Username", true].Update(m_username);
425 settings["Password", true].Update(m_password);444 settings["Password", true].Update(m_password);
445 settings["SerializationFormat", true].Update(m_serializationFormat);
426 446
427 settings["Username"].Scope = SettingScope.User;447 settings["Username"].Scope = SettingScope.User;
428 settings["Password"].Scope = SettingScope.User;448 settings["Password"].Scope = SettingScope.User;
@@ -450,9 +470,11 @@ namespace GSF.ServiceProcess · 21 unmodified lines
450 470
451 settings.Add("Username", m_username, "Username to be used for authentication with the service.", false, SettingScope.User);471 settings.Add("Username", m_username, "Username to be used for authentication with the service.", false, SettingScope.User);
452 settings.Add("Password", m_password, "Password to be used for authentication with the service.", true, SettingScope.User);472 settings.Add("Password", m_password, "Password to be used for authentication with the service.", true, SettingScope.User);
473 settings.Add("SerializationFormat", m_password, "Message serialization format for interactions with service, one of: Xml, Json or Binary. Default is Binary.");
453 474
454 Username = settings["Username"].ValueAs(m_username);475 Username = settings["Username"].ValueAs(m_username);
455 Password = settings["Password"].ValueAs(m_password);476 Password = settings["Password"].ValueAs(m_password);
477 SerializationFormat = settings["SerializationFormat"].ValueAs(m_serializationFormat);
456 }478 }
457 }479 }
458 480
@@ -686,7 +708,7 @@ namespace GSF.ServiceProcess · 227 unmodified lines
686 {708 {
687 ServiceResponse response;709 ServiceResponse response;
688 710
689 Serialization.TryDeserialize(e.Argument1.BlockCopy(0, e.Argument2), SerializationFormat.Binary, out response);711 Serialization.TryDeserialize(e.Argument1.BlockCopy(0, e.Argument2), m_serializationFormat, out response);
690 712
691 if ((object)response != null)713 if ((object)response != null)
692 {714 {
@@ -792,7 +814,7 @@ namespace GSF.ServiceProcess · 99 unmodified lines
792 }814 }
793 815
794 /// <summary>816 /// <summary>
795 /// Attempts to parse an actionable reponse sent from the service.817 /// Attempts to parse an actionable response sent from the service.
796 /// </summary>818 /// </summary>
797 /// <param name="serviceResponse"><see cref="ServiceResponse"/> to test for actionable response.</param>819 /// <param name="serviceResponse"><see cref="ServiceResponse"/> to test for actionable response.</param>
798 /// <param name="sourceCommand">Command that invoked <paramref name="serviceResponse"/>.</param>820 /// <param name="sourceCommand">Command that invoked <paramref name="serviceResponse"/>.</param>
@@ -812,7 +834,7 @@ namespace GSF.ServiceProcess · 13 unmodified lines
812 // Attempt to parse response message834 // Attempt to parse response message
813 if (!string.IsNullOrWhiteSpace(response))835 if (!string.IsNullOrWhiteSpace(response))
814 {836 {
815 // Reponse types are formatted as "Command:Success" or "Command:Failure"837 // Response types are formatted as "Command:Success" or "Command:Failure"
816 string[] parts = response.Split(':');838 string[] parts = response.Split(':');
817 839
818 if (parts.Length > 1)840 if (parts.Length > 1)
Source/Libraries/GSF.ServiceProcess/ServiceHelper.cs+33−5
@@ -225,6 +225,11 @@ namespace GSF.ServiceProcess · 224 unmodified lines
225 /// </summary>225 /// </summary>
226 public const bool DefaultSecureRemoteInteractions = false;226 public const bool DefaultSecureRemoteInteractions = false;
227 227
228 /// <summary>
229 /// Specifies the default value for the <see cref="ServiceHelper.SerializationFormat"/> property.
230 /// </summary>
231 public const SerializationFormat DefaultSerializationFormat = SerializationFormat.Binary;
232
228 /// <summary>233 /// <summary>
229 /// Specifies the default value for the <see cref="PersistSettings"/> property.234 /// Specifies the default value for the <see cref="PersistSettings"/> property.
230 /// </summary>235 /// </summary>
@@ -353,6 +358,7 @@ namespace GSF.ServiceProcess · 122 unmodified lines
353 private bool m_supportTelnetSessions;358 private bool m_supportTelnetSessions;
354 private bool m_supportSystemCommands;359 private bool m_supportSystemCommands;
355 private bool m_secureRemoteInteractions;360 private bool m_secureRemoteInteractions;
361 private SerializationFormat m_serializationFormat;
356 private bool m_persistSettings;362 private bool m_persistSettings;
357 private string m_settingsCategory;363 private string m_settingsCategory;
358 private string m_telnetSessionPassword;364 private string m_telnetSessionPassword;
@@ -370,15 +376,15 @@ namespace GSF.ServiceProcess · 11 unmodified lines
370 private readonly Dictionary<ISupportLifecycle, bool> m_componentEnabledStates;376 private readonly Dictionary<ISupportLifecycle, bool> m_componentEnabledStates;
371 private TryGetClientPrincipalFunctionSignature m_tryGetClientPrincipalFunction;377 private TryGetClientPrincipalFunctionSignature m_tryGetClientPrincipalFunction;
372 private readonly ProcessQueue<StatusUpdate> m_statusUpdateQueue;378 private readonly ProcessQueue<StatusUpdate> m_statusUpdateQueue;
373 private bool m_enabled;
374 private bool m_disposed;
375 private bool m_initialized;
376 private bool m_suppressUpdates;379 private bool m_suppressUpdates;
377 private Guid m_remoteCommandClientID;380 private Guid m_remoteCommandClientID;
378 private Process m_remoteCommandProcess;381 private Process m_remoteCommandProcess;
379 private Ticks m_lastStatusUpdateTime;382 private Ticks m_lastStatusUpdateTime;
380 private long m_statusUpdateCount;383 private long m_statusUpdateCount;
381 private bool m_supressStatusUpdates;384 private bool m_supressStatusUpdates;
385 private bool m_enabled;
386 private bool m_initialized;
387 private bool m_disposed;
382 388
383 #endregion389 #endregion
384 390
@@ -399,6 +405,7 @@ namespace GSF.ServiceProcess · 14 unmodified lines
399 m_supportTelnetSessions = DefaultSupportTelnetSessions;405 m_supportTelnetSessions = DefaultSupportTelnetSessions;
400 m_supportSystemCommands = DefaultSupportSystemCommands;406 m_supportSystemCommands = DefaultSupportSystemCommands;
401 m_secureRemoteInteractions = DefaultSecureRemoteInteractions;407 m_secureRemoteInteractions = DefaultSecureRemoteInteractions;
408 m_serializationFormat = DefaultSerializationFormat;
402 m_persistSettings = DefaultPersistSettings;409 m_persistSettings = DefaultPersistSettings;
403 m_settingsCategory = DefaultSettingsCategory;410 m_settingsCategory = DefaultSettingsCategory;
404 m_processes = new List<ServiceProcess>();411 m_processes = new List<ServiceProcess>();
@@ -622,6 +629,24 @@ namespace GSF.ServiceProcess · 217 unmodified lines
622 }629 }
623 }630 }
624 631
632 /// <summary>
633 /// Gets or sets a value that indicates the desired message <see cref="GSF.SerializationFormat"/> for interaction with <see cref="ClientHelper"/>.
634 /// </summary>
635 [Category("Settings"),
636 DefaultValue(DefaultSerializationFormat),
637 Description("Indicates messaging serialization format for interactions with ClientHelper.")]
638 public SerializationFormat SerializationFormat
639 {
640 get
641 {
642 return m_serializationFormat;
643 }
644 set
645 {
646 m_serializationFormat = value;
647 }
648 }
649
625 /// <summary>650 /// <summary>
626 /// Gets or sets a boolean value that indicates whether the settings of <see cref="ServiceHelper"/> are to be saved to the config file.651 /// Gets or sets a boolean value that indicates whether the settings of <see cref="ServiceHelper"/> are to be saved to the config file.
627 /// </summary>652 /// </summary>
@@ -1049,6 +1074,7 @@ namespace GSF.ServiceProcess · 421 unmodified lines
1049 settings["SupportTelnetSessions", true].Update(m_supportTelnetSessions);1074 settings["SupportTelnetSessions", true].Update(m_supportTelnetSessions);
1050 settings["SupportSystemCommands", true].Update(m_supportSystemCommands);1075 settings["SupportSystemCommands", true].Update(m_supportSystemCommands);
1051 settings["SecureRemoteInteractions", true].Update(m_secureRemoteInteractions);1076 settings["SecureRemoteInteractions", true].Update(m_secureRemoteInteractions);
1077 settings["SerializationFormat", true].Update(m_serializationFormat);
1052 config.Save();1078 config.Save();
1053 }1079 }
1054 1080
@@ -1103,6 +1129,7 @@ namespace GSF.ServiceProcess · 48 unmodified lines
1103 settings.Add("SupportTelnetSessions", m_supportTelnetSessions, "True to enable the support for remote telnet-like sessions; otherwise False.");1129 settings.Add("SupportTelnetSessions", m_supportTelnetSessions, "True to enable the support for remote telnet-like sessions; otherwise False.");
1104 settings.Add("SupportSystemCommands", m_supportSystemCommands, "True to enable system-level access (-system switch) via the build-in commands; otherwise False.");1130 settings.Add("SupportSystemCommands", m_supportSystemCommands, "True to enable system-level access (-system switch) via the build-in commands; otherwise False.");
1105 settings.Add("SecureRemoteInteractions", m_secureRemoteInteractions, "True to enable security of remote client interactions; otherwise False.");1131 settings.Add("SecureRemoteInteractions", m_secureRemoteInteractions, "True to enable security of remote client interactions; otherwise False.");
1132 settings.Add("SerializationFormat", m_serializationFormat, "Message serialization format for interactions with clients, one of: Xml, Json or Binary. Default is Binary.");
1106 1133
1107 if ((object)settings["TelnetSessionPassword"] != null)1134 if ((object)settings["TelnetSessionPassword"] != null)
1108 m_telnetSessionPassword = settings["TelnetSessionPassword"].ValueAs(m_telnetSessionPassword);1135 m_telnetSessionPassword = settings["TelnetSessionPassword"].ValueAs(m_telnetSessionPassword);
@@ -1116,6 +1143,7 @@ namespace GSF.ServiceProcess · 7 unmodified lines
1116 SupportTelnetSessions = settings["SupportTelnetSessions"].ValueAs(m_supportTelnetSessions);1143 SupportTelnetSessions = settings["SupportTelnetSessions"].ValueAs(m_supportTelnetSessions);
1117 SupportSystemCommands = settings["SupportSystemCommands"].ValueAs(m_supportSystemCommands);1144 SupportSystemCommands = settings["SupportSystemCommands"].ValueAs(m_supportSystemCommands);
1118 SecureRemoteInteractions = settings["SecureRemoteInteractions"].ValueAs(m_secureRemoteInteractions);1145 SecureRemoteInteractions = settings["SecureRemoteInteractions"].ValueAs(m_secureRemoteInteractions);
1146 SerializationFormat = settings["SerializationFormat"].ValueAs(m_serializationFormat);
1119 }1147 }
1120 1148
1121 /// <summary>1149 /// <summary>
@@ -2146,7 +2174,7 @@ namespace GSF.ServiceProcess · 1024 unmodified lines
2146 if ((object)client == null)2174 if ((object)client == null)
2147 {2175 {
2148 // First message from a remote client should be its info.2176 // First message from a remote client should be its info.
2149 Serialization.TryDeserialize(e.Argument2.BlockCopy(0, e.Argument3), SerializationFormat.Binary, out client);2177 Serialization.TryDeserialize(e.Argument2.BlockCopy(0, e.Argument3), m_serializationFormat, out client);
2150 2178
2151 try2179 try
2152 {2180 {
@@ -2210,7 +2238,7 @@ namespace GSF.ServiceProcess · 57 unmodified lines
2210 ClientRequest request;2238 ClientRequest request;
2211 ClientRequestInfo requestInfo = null;2239 ClientRequestInfo requestInfo = null;
2212 2240
2213 Serialization.TryDeserialize(e.Argument2.BlockCopy(0, e.Argument3), SerializationFormat.Binary, out request);2241 Serialization.TryDeserialize(e.Argument2.BlockCopy(0, e.Argument3), m_serializationFormat, out request);
2214 2242
2215 if ((object)request != null)2243 if ((object)request != null)
2216 {2244 {
Source/Libraries/GSF.TimeSeries/UI/WindowsServiceClient.cs+6−0
@@ -62,6 +62,7 @@ namespace GSF.TimeSeries.UI · 61 unmodified lines
62 {62 {
63 // Initialize status cache members.63 // Initialize status cache members.
64 Dictionary<string, string> settings = connectionString.ParseKeyValuePairs();64 Dictionary<string, string> settings = connectionString.ParseKeyValuePairs();
65 SerializationFormat serializationFormat;
65 string setting;66 string setting;
66 67
67 if (settings.TryGetValue("statusBufferSize", out setting) && !string.IsNullOrWhiteSpace(setting))68 if (settings.TryGetValue("statusBufferSize", out setting) && !string.IsNullOrWhiteSpace(setting))
@@ -77,8 +78,13 @@ namespace GSF.TimeSeries.UI · 9 unmodified lines
77 else78 else
78 m_remotingClient = InitializeTcpClient(connectionString);79 m_remotingClient = InitializeTcpClient(connectionString);
79 80
81 // Parse out desired message serialization format, if specified
82 if (!settings.TryGetValue("serializationFormat", out setting) || !Enum.TryParse(setting, true, out serializationFormat))
83 serializationFormat = SerializationFormat.Binary;
84
80 // Initialize windows service client.85 // Initialize windows service client.
81 m_clientHelper = new ClientHelper();86 m_clientHelper = new ClientHelper();
87 m_clientHelper.SerializationFormat = serializationFormat;
82 m_clientHelper.RemotingClient = m_remotingClient;88 m_clientHelper.RemotingClient = m_remotingClient;
83 m_clientHelper.ReceivedServiceUpdate += ClientHelper_ReceivedServiceUpdate;89 m_clientHelper.ReceivedServiceUpdate += ClientHelper_ReceivedServiceUpdate;
84 }90 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t