/Controllers/RuleController.cs
C# | 96 lines | 84 code | 12 blank | 0 comment | 4 complexity | f2a27bf8d3033af0207b5e22fab565d4 MD5 | raw file
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.Composition;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Xml.Linq;
- using Login.Helpers;
- using Login.Services;
- using Login.View;
- using Login.ViewModel;
- using Login.Database;
- namespace Login.Controllers
- {
- [Export]
- public class RuleController
- {
- private IShellService shellService_;
- private LoginPasswordViewModel loginPasswordViewModel_;
- private IPValidationViewModel ipViewModel_;
- private List<IValidationRule> ruleTree_ = new List<IValidationRule>( );
- private IEnumerator<IValidationRule> iterator_;
- private UserInformation userInformation_;
- private FailedLoginCountViewModel failedLoginCountViewModel_;
- private IDatabase dataBase_;
- [ImportingConstructor]
- RuleController ( IShellService shellService, LoginPasswordViewModel lpViewModel, IPValidationViewModel ipViewModel,
- FailedLoginCountViewModel failedLoginCountViewModel, UserInformation userInformation, IDatabase dataBase )
- {
- shellService_ = shellService;
- userInformation_ = userInformation;
- dataBase_ = dataBase;
- loginPasswordViewModel_ = lpViewModel;
- ipViewModel_ = ipViewModel;
- failedLoginCountViewModel_ = failedLoginCountViewModel;
- loginPasswordViewModel_.LoginCommand = new RelayCommand(( param ) => this.validate( ));
- ipViewModel_.LoginCommand = new RelayCommand(( param ) => this.validate( ));
- failedLoginCountViewModel.LoginCommand = new RelayCommand(( param ) => this.validate( ));
- ruleTree_.Add(loginPasswordViewModel_);
- ruleTree_.Add(ipViewModel_);
- ruleTree_.Add(failedLoginCountViewModel_);
- }
- public void Initialize ( )
- {
- shellService_.CurrentRuleView = loginPasswordViewModel_.View;
- iterator_ = ruleTree_.GetEnumerator( );
- iterator_.Reset( );
- iterator_.MoveNext( );
- }
- public void validate ( )
- {
- bool validation_result = iterator_.Current.validate( );
- if ( validation_result )
- {
- if ( iterator_.MoveNext( ) )
- {
- if ( iterator_.Current.RuleType == ERuleType.NonInteractive )
- {
- validate( );
- }
- else
- {
- shellService_.CurrentRuleView = iterator_.Current.View;
- }
- }
- else
- {
- MessageBox.Show("Login succeed");
- }
- }
- else
- {
- MessageBox.Show( "Login failed.");
- iterator_.Reset( );
- iterator_.MoveNext( );
- dataBase_.UpdateNumberOfLoginTries(userInformation_.UserName);
- }
- }
- public void Run ( )
- {
- }
- }
- }