History

GSF.Services: Added "LOGIN" command to console application to re-query for credentials or force a re-auth for current user.

ritchiecarroll committed 12 years ago

Commit 62f95691 parent 34274733 files · +55 −36Browse files

Showing the changes to Source/Libraries/GSF.ServiceProcess (1 of 3 files). Show all

Unified · Split

Source/Libraries/GSF.ServiceProcess/ClientHelper.cs+36−25
@@ -185,7 +185,7 @@ namespace GSF.ServiceProcess · 184 unmodified lines
185 public ClientHelper(IContainer container)185 public ClientHelper(IContainer container)
186 : this()186 : this()
187 {187 {
188 if (container != null)188 if ((object)container != null)
189 container.Add(this);189 container.Add(this);
190 }190 }
191 191
@@ -206,7 +206,7 @@ namespace GSF.ServiceProcess · 14 unmodified lines
206 }206 }
207 set207 set
208 {208 {
209 if (m_remotingClient != null)209 if ((object)m_remotingClient != null)
210 {210 {
211 // Detach events from any existing instance211 // Detach events from any existing instance
212 m_remotingClient.ConnectionEstablished -= RemotingClient_ConnectionEstablished;212 m_remotingClient.ConnectionEstablished -= RemotingClient_ConnectionEstablished;
@@ -218,7 +218,7 @@ namespace GSF.ServiceProcess · 5 unmodified lines
218 218
219 m_remotingClient = value;219 m_remotingClient = value;
220 220
221 if (m_remotingClient != null)221 if ((object)m_remotingClient != null)
222 {222 {
223 // Attach events to new instance223 // Attach events to new instance
224 m_remotingClient.ConnectionEstablished += RemotingClient_ConnectionEstablished;224 m_remotingClient.ConnectionEstablished += RemotingClient_ConnectionEstablished;
@@ -245,7 +245,7 @@ namespace GSF.ServiceProcess · 20 unmodified lines
245 }245 }
246 set246 set
247 {247 {
248 if (value == null)248 if ((object)value == null)
249 throw new ArgumentNullException("value");249 throw new ArgumentNullException("value");
250 250
251 m_username = value;251 m_username = value;
@@ -267,7 +267,7 @@ namespace GSF.ServiceProcess · 15 unmodified lines
267 }267 }
268 set268 set
269 {269 {
270 if (value == null)270 if ((object)value == null)
271 throw new ArgumentNullException("value");271 throw new ArgumentNullException("value");
272 272
273 m_password = value;273 m_password = value;
@@ -327,14 +327,14 @@ namespace GSF.ServiceProcess · 53 unmodified lines
327 {327 {
328 get328 get
329 {329 {
330 if (m_remotingClient == null)330 if ((object)m_remotingClient == null)
331 return false;331 return false;
332 332
333 return m_remotingClient.Enabled;333 return m_remotingClient.Enabled;
334 }334 }
335 set335 set
336 {336 {
337 if (m_remotingClient != null)337 if ((object)m_remotingClient != null)
338 m_remotingClient.Enabled = value;338 m_remotingClient.Enabled = value;
339 }339 }
340 }340 }
@@ -420,8 +420,14 @@ namespace GSF.ServiceProcess · 79 unmodified lines
420 // Save settings under the specified category.420 // Save settings under the specified category.
421 ConfigurationFile config = ConfigurationFile.Current;421 ConfigurationFile config = ConfigurationFile.Current;
422 CategorizedSettingsElementCollection settings = config.Settings[m_settingsCategory];422 CategorizedSettingsElementCollection settings = config.Settings[m_settingsCategory];
423
423 settings["Username", true].Update(m_username);424 settings["Username", true].Update(m_username);
424 settings["Password", true].Update(m_password);425 settings["Password", true].Update(m_password);
426
427 settings["Username"].Scope = SettingScope.User;
428 settings["Password"].Scope = SettingScope.User;
429 settings["Password"].Encrypted = true;
430
425 config.Save();431 config.Save();
426 }432 }
427 }433 }
@@ -441,8 +447,10 @@ namespace GSF.ServiceProcess · 13 unmodified lines
441 // Load settings from the specified category.447 // Load settings from the specified category.
442 ConfigurationFile config = ConfigurationFile.Current;448 ConfigurationFile config = ConfigurationFile.Current;
443 CategorizedSettingsElementCollection settings = config.Settings[m_settingsCategory];449 CategorizedSettingsElementCollection settings = config.Settings[m_settingsCategory];
444 settings.Add("Username", m_username, "Username to be used for authentication with the service.");450
445 settings.Add("Password", m_password, "Password to be used for authentication with the service.", true);451 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);
453
446 Username = settings["Username"].ValueAs(m_username);454 Username = settings["Username"].ValueAs(m_username);
447 Password = settings["Password"].ValueAs(m_password);455 Password = settings["Password"].ValueAs(m_password);
448 }456 }
@@ -453,17 +461,20 @@ namespace GSF.ServiceProcess · 4 unmodified lines
453 /// </summary>461 /// </summary>
454 public void Connect()462 public void Connect()
455 {463 {
456 if (m_remotingClient == null)464 if ((object)m_remotingClient == null)
457 throw new InvalidOperationException("RemotingClient property of ClientHelper component is not set");465 throw new InvalidOperationException("RemotingClient property of ClientHelper component is not set");
458 466
459 m_attemptReconnection = true;467 m_attemptReconnection = true;
460 m_authenticationComplete = false;468 m_authenticationComplete = false;
461 m_remotingClient.Connect(); // Wait for connection.469
470 // Wait for connection.
471 m_remotingClient.Connect();
462 472
463 while (!m_authenticationComplete && m_remotingClient.Enabled)473 while (!m_authenticationComplete && m_remotingClient.Enabled)
464 {474 {
475 // Wait for authentication.
465 Thread.Sleep(100);476 Thread.Sleep(100);
466 } // Wait for authentication.477 }
467 }478 }
468 479
469 /// <summary>480 /// <summary>
@@ -473,7 +484,7 @@ namespace GSF.ServiceProcess · 3 unmodified lines
473 {484 {
474 m_attemptReconnection = false;485 m_attemptReconnection = false;
475 486
476 if (m_remotingClient != null)487 if ((object)m_remotingClient != null)
477 m_remotingClient.Disconnect();488 m_remotingClient.Disconnect();
478 }489 }
479 490
@@ -485,7 +496,7 @@ namespace GSF.ServiceProcess · 5 unmodified lines
485 {496 {
486 ClientRequest requestInstance = ClientRequest.Parse(request);497 ClientRequest requestInstance = ClientRequest.Parse(request);
487 498
488 if (requestInstance != null)499 if ((object)requestInstance != null)
489 SendRequest(requestInstance);500 SendRequest(requestInstance);
490 else501 else
491 UpdateStatus(UpdateType.Warning, string.Format("Request command \"{0}\" is invalid\r\n\r\n", request));502 UpdateStatus(UpdateType.Warning, string.Format("Request command \"{0}\" is invalid\r\n\r\n", request));
@@ -507,7 +518,7 @@ namespace GSF.ServiceProcess · 15 unmodified lines
507 /// <param name="update">Update message received.</param>518 /// <param name="update">Update message received.</param>
508 protected virtual void OnReceivedServiceUpdate(UpdateType type, string update)519 protected virtual void OnReceivedServiceUpdate(UpdateType type, string update)
509 {520 {
510 if (ReceivedServiceUpdate != null)521 if ((object)ReceivedServiceUpdate != null)
511 ReceivedServiceUpdate(this, new EventArgs<UpdateType, string>(type, update));522 ReceivedServiceUpdate(this, new EventArgs<UpdateType, string>(type, update));
512 }523 }
513 524
@@ -517,7 +528,7 @@ namespace GSF.ServiceProcess · 3 unmodified lines
517 /// <param name="response"><see cref="ServiceResponse"/> received.</param>528 /// <param name="response"><see cref="ServiceResponse"/> received.</param>
518 protected virtual void OnReceivedServiceResponse(ServiceResponse response)529 protected virtual void OnReceivedServiceResponse(ServiceResponse response)
519 {530 {
520 if (ReceivedServiceResponse != null)531 if ((object)ReceivedServiceResponse != null)
521 ReceivedServiceResponse(this, new EventArgs<ServiceResponse>(response));532 ReceivedServiceResponse(this, new EventArgs<ServiceResponse>(response));
522 }533 }
523 534
@@ -527,7 +538,7 @@ namespace GSF.ServiceProcess · 3 unmodified lines
527 /// <param name="state">New <see cref="ServiceState"/>.</param>538 /// <param name="state">New <see cref="ServiceState"/>.</param>
528 protected virtual void OnServiceStateChanged(ObjectState<ServiceState> state)539 protected virtual void OnServiceStateChanged(ObjectState<ServiceState> state)
529 {540 {
530 if (ServiceStateChanged != null)541 if ((object)ServiceStateChanged != null)
531 ServiceStateChanged(this, new EventArgs<ObjectState<ServiceState>>(state));542 ServiceStateChanged(this, new EventArgs<ObjectState<ServiceState>>(state));
532 }543 }
533 544
@@ -537,7 +548,7 @@ namespace GSF.ServiceProcess · 3 unmodified lines
537 /// <param name="state">New <see cref="ServiceProcessState"/>.</param>548 /// <param name="state">New <see cref="ServiceProcessState"/>.</param>
538 protected virtual void OnProcessStateChanged(ObjectState<ServiceProcessState> state)549 protected virtual void OnProcessStateChanged(ObjectState<ServiceProcessState> state)
539 {550 {
540 if (ProcessStateChanged != null)551 if ((object)ProcessStateChanged != null)
541 ProcessStateChanged(this, new EventArgs<ObjectState<ServiceProcessState>>(state));552 ProcessStateChanged(this, new EventArgs<ObjectState<ServiceProcessState>>(state));
542 }553 }
543 554
@@ -546,7 +557,7 @@ namespace GSF.ServiceProcess · 2 unmodified lines
546 /// </summary>557 /// </summary>
547 protected virtual void OnAuthenticationSuccess()558 protected virtual void OnAuthenticationSuccess()
548 {559 {
549 if (AuthenticationSuccess != null)560 if ((object)AuthenticationSuccess != null)
550 AuthenticationSuccess(this, EventArgs.Empty);561 AuthenticationSuccess(this, EventArgs.Empty);
551 562
552 m_authenticationComplete = true;563 m_authenticationComplete = true;
@@ -559,7 +570,7 @@ namespace GSF.ServiceProcess · 6 unmodified lines
559 {570 {
560 CancelEventArgs args = new CancelEventArgs(true);571 CancelEventArgs args = new CancelEventArgs(true);
561 572
562 if (AuthenticationFailure != null)573 if ((object)AuthenticationFailure != null)
563 AuthenticationFailure(this, args);574 AuthenticationFailure(this, args);
564 575
565 // Continue connection attempts if requested.576 // Continue connection attempts if requested.
@@ -575,7 +586,7 @@ namespace GSF.ServiceProcess · 9 unmodified lines
575 /// </summary>586 /// </summary>
576 protected virtual void OnTelnetSessionEstablished()587 protected virtual void OnTelnetSessionEstablished()
577 {588 {
578 if (TelnetSessionEstablished != null)589 if ((object)TelnetSessionEstablished != null)
579 TelnetSessionEstablished(this, EventArgs.Empty);590 TelnetSessionEstablished(this, EventArgs.Empty);
580 }591 }
581 592
@@ -584,7 +595,7 @@ namespace GSF.ServiceProcess · 2 unmodified lines
584 /// </summary>595 /// </summary>
585 protected virtual void OnTelnetSessionTerminated()596 protected virtual void OnTelnetSessionTerminated()
586 {597 {
587 if (TelnetSessionTerminated != null)598 if ((object)TelnetSessionTerminated != null)
588 TelnetSessionTerminated(this, EventArgs.Empty);599 TelnetSessionTerminated(this, EventArgs.Empty);
589 }600 }
590 601
@@ -701,7 +712,7 @@ namespace GSF.ServiceProcess · 110 unmodified lines
701 {712 {
702 ObjectState<ServiceState> state = response.Attachments[0] as ObjectState<ServiceState>;713 ObjectState<ServiceState> state = response.Attachments[0] as ObjectState<ServiceState>;
703 714
704 if (state != null)715 if ((object)state != null)
705 {716 {
706 // Notify change in service state by raising an event.717 // Notify change in service state by raising an event.
707 OnServiceStateChanged(state);718 OnServiceStateChanged(state);
@@ -725,7 +736,7 @@ namespace GSF.ServiceProcess · 17 unmodified lines
725 {736 {
726 ObjectState<ServiceProcessState> state = response.Attachments[0] as ObjectState<ServiceProcessState>;737 ObjectState<ServiceProcessState> state = response.Attachments[0] as ObjectState<ServiceProcessState>;
727 738
728 if (state != null)739 if ((object)state != null)
729 {740 {
730 // Notify change in process state by raising an event.741 // Notify change in process state by raising an event.
731 OnProcessStateChanged(state);742 OnProcessStateChanged(state);
@@ -807,7 +818,7 @@ namespace GSF.ServiceProcess · 75 unmodified lines
807 if (parts.Length > 1)818 if (parts.Length > 1)
808 {819 {
809 sourceCommand = parts[0].Trim().ToTitleCase();820 sourceCommand = parts[0].Trim().ToTitleCase();
810 responseSuccess = (string.Compare(parts[1].Trim(), "Success", true) == 0);821 responseSuccess = (string.Compare(parts[1].Trim(), "Success", StringComparison.OrdinalIgnoreCase) == 0);
811 parseSucceeded = true;822 parseSucceeded = true;
812 }823 }
813 }824 }

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