SimpleLoginManager /Controllers/RuleController.cs

Language C# Lines 97
MD5 Hash f2a27bf8d3033af0207b5e22fab565d4
Repository https://github.com/cmath/SimpleLoginManager.git View Raw File
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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 ( )
        {

        }
    }
}
Back to Top