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