PageRenderTime 54ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/Controllers/RuleController.cs

https://github.com/cmath/SimpleLoginManager
C# | 96 lines | 84 code | 12 blank | 0 comment | 4 complexity | f2a27bf8d3033af0207b5e22fab565d4 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.Composition;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Xml.Linq;
  9. using Login.Helpers;
  10. using Login.Services;
  11. using Login.View;
  12. using Login.ViewModel;
  13. using Login.Database;
  14. namespace Login.Controllers
  15. {
  16. [Export]
  17. public class RuleController
  18. {
  19. private IShellService shellService_;
  20. private LoginPasswordViewModel loginPasswordViewModel_;
  21. private IPValidationViewModel ipViewModel_;
  22. private List<IValidationRule> ruleTree_ = new List<IValidationRule>( );
  23. private IEnumerator<IValidationRule> iterator_;
  24. private UserInformation userInformation_;
  25. private FailedLoginCountViewModel failedLoginCountViewModel_;
  26. private IDatabase dataBase_;
  27. [ImportingConstructor]
  28. RuleController ( IShellService shellService, LoginPasswordViewModel lpViewModel, IPValidationViewModel ipViewModel,
  29. FailedLoginCountViewModel failedLoginCountViewModel, UserInformation userInformation, IDatabase dataBase )
  30. {
  31. shellService_ = shellService;
  32. userInformation_ = userInformation;
  33. dataBase_ = dataBase;
  34. loginPasswordViewModel_ = lpViewModel;
  35. ipViewModel_ = ipViewModel;
  36. failedLoginCountViewModel_ = failedLoginCountViewModel;
  37. loginPasswordViewModel_.LoginCommand = new RelayCommand(( param ) => this.validate( ));
  38. ipViewModel_.LoginCommand = new RelayCommand(( param ) => this.validate( ));
  39. failedLoginCountViewModel.LoginCommand = new RelayCommand(( param ) => this.validate( ));
  40. ruleTree_.Add(loginPasswordViewModel_);
  41. ruleTree_.Add(ipViewModel_);
  42. ruleTree_.Add(failedLoginCountViewModel_);
  43. }
  44. public void Initialize ( )
  45. {
  46. shellService_.CurrentRuleView = loginPasswordViewModel_.View;
  47. iterator_ = ruleTree_.GetEnumerator( );
  48. iterator_.Reset( );
  49. iterator_.MoveNext( );
  50. }
  51. public void validate ( )
  52. {
  53. bool validation_result = iterator_.Current.validate( );
  54. if ( validation_result )
  55. {
  56. if ( iterator_.MoveNext( ) )
  57. {
  58. if ( iterator_.Current.RuleType == ERuleType.NonInteractive )
  59. {
  60. validate( );
  61. }
  62. else
  63. {
  64. shellService_.CurrentRuleView = iterator_.Current.View;
  65. }
  66. }
  67. else
  68. {
  69. MessageBox.Show("Login succeed");
  70. }
  71. }
  72. else
  73. {
  74. MessageBox.Show( "Login failed.");
  75. iterator_.Reset( );
  76. iterator_.MoveNext( );
  77. dataBase_.UpdateNumberOfLoginTries(userInformation_.UserName);
  78. }
  79. }
  80. public void Run ( )
  81. {
  82. }
  83. }
  84. }