1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.ComponentModel;
|
---|
25 | using System.Data;
|
---|
26 | using System.Drawing;
|
---|
27 | using System.Linq;
|
---|
28 | using System.Text;
|
---|
29 | using System.Windows.Forms;
|
---|
30 | using HeuristicLab.Hive.Contracts.Interfaces;
|
---|
31 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
32 | using HeuristicLab.Hive.Contracts;
|
---|
33 | using System.Security.Cryptography;
|
---|
34 | using System.Net;
|
---|
35 | using System.Threading;
|
---|
36 | using System.ServiceModel;
|
---|
37 |
|
---|
38 | namespace HeuristicLab.Hive.Server.ServerConsole {
|
---|
39 |
|
---|
40 | public partial class HiveServerConsole : Form {
|
---|
41 |
|
---|
42 | HiveServerManagementConsole information = null;
|
---|
43 |
|
---|
44 | public HiveServerConsole() {
|
---|
45 | InitializeComponent();
|
---|
46 | #if(DEBUG)
|
---|
47 | tbIp.Text = "10.20.53.1";
|
---|
48 | tbPort.Text = WcfSettings.GetDefaultPort().ToString();
|
---|
49 | tbUserName.Text = "admin";
|
---|
50 | tbPwd.Text = "admin";
|
---|
51 | #endif
|
---|
52 | }
|
---|
53 |
|
---|
54 | private void tsmiExit_Click(object sender, EventArgs e) {
|
---|
55 | this.Close();
|
---|
56 | }
|
---|
57 |
|
---|
58 | /// <summary>
|
---|
59 | /// When login button is clicked, the ManagementConsole
|
---|
60 | /// will be opened
|
---|
61 | /// </summary>
|
---|
62 | /// <param name="sender"></param>
|
---|
63 | /// <param name="e"></param>
|
---|
64 | private void BtnLogin_Click(object sender, EventArgs e) {
|
---|
65 | string newIp = tbIp.Text;
|
---|
66 | newIp = newIp.Replace(" ", "");
|
---|
67 |
|
---|
68 | ServiceLocator.Address = newIp;
|
---|
69 | ServiceLocator.Port = this.tbPort.Text;
|
---|
70 |
|
---|
71 | if (IsValid()) {
|
---|
72 | this.Visible = false;
|
---|
73 | information = new HiveServerManagementConsole();
|
---|
74 | information.closeFormEvent += new closeForm(EnableForm);
|
---|
75 | information.Show();
|
---|
76 | }
|
---|
77 | }
|
---|
78 |
|
---|
79 | /// <summary>
|
---|
80 | /// if the input is correct and the login-method returns a
|
---|
81 | /// valid response
|
---|
82 | /// </summary>
|
---|
83 | /// <returns></returns>
|
---|
84 | private bool IsValid() {
|
---|
85 | Thread t = new Thread(new ThreadStart(ShowWaitDlg));
|
---|
86 | if (IsFormValidated()) {
|
---|
87 | IPAddress ipAdress = IPAddress.Parse(tbIp.Text);
|
---|
88 | int port = int.Parse(tbPort.Text);
|
---|
89 | ServiceLocator.Address = tbIp.Text.Replace(" ", "");
|
---|
90 | ServiceLocator.Port = tbPort.Text;
|
---|
91 | IServerConsoleFacade scf = ServiceLocator.GetServerConsoleFacade();
|
---|
92 | Response resp;
|
---|
93 | try {
|
---|
94 | lblError.Text = "Trying to logon...";
|
---|
95 | this.Cursor = Cursors.WaitCursor;
|
---|
96 | t.Start();
|
---|
97 | resp = scf.Login(tbUserName.Text, tbPwd.Text);
|
---|
98 | t.Abort();
|
---|
99 | this.Cursor = Cursors.Default;
|
---|
100 | if (resp.Success == true) return true;
|
---|
101 | lblError.Text = resp.StatusMessage;
|
---|
102 | MessageBox.Show("Wrong username or password");
|
---|
103 | }
|
---|
104 | catch (EndpointNotFoundException ene) {
|
---|
105 | t.Abort();
|
---|
106 | this.Cursor = Cursors.Default;
|
---|
107 | MessageBox.Show(ene.Message);
|
---|
108 | lblError.Text = "No Service at this address!";
|
---|
109 | scf = null;
|
---|
110 | }
|
---|
111 | catch (Exception ex) {
|
---|
112 | //login failed
|
---|
113 | t.Abort();
|
---|
114 | this.Cursor = Cursors.Default;
|
---|
115 | MessageBox.Show(ex.Message);
|
---|
116 | lblError.Text = "Logon failed! Please restart console";
|
---|
117 | }
|
---|
118 | }
|
---|
119 | return false;
|
---|
120 | }
|
---|
121 |
|
---|
122 |
|
---|
123 | private void ShowWaitDlg() {
|
---|
124 | LogonDlg dlg = new LogonDlg();
|
---|
125 | dlg.ShowDialog();
|
---|
126 | }
|
---|
127 |
|
---|
128 | /// <summary>
|
---|
129 | /// Validates the form.
|
---|
130 | /// </summary>
|
---|
131 | /// <returns></returns>
|
---|
132 | private bool IsFormValidated() {
|
---|
133 | bool isValid = true;
|
---|
134 | if (String.IsNullOrEmpty(tbUserName.Text)) {
|
---|
135 | lblError.Text = "Please type in Username.";
|
---|
136 | isValid = false;
|
---|
137 | }
|
---|
138 | if (String.IsNullOrEmpty(tbPwd.Text)) {
|
---|
139 | lblError.Text = "Please type in Password.";
|
---|
140 | isValid = false;
|
---|
141 | }
|
---|
142 | if (String.IsNullOrEmpty(tbIp.Text)) {
|
---|
143 | lblError.Text = "Please type in Port.";
|
---|
144 | isValid = false;
|
---|
145 | }
|
---|
146 | if (String.IsNullOrEmpty(tbPort.Text)) {
|
---|
147 | lblError.Text = "Please type in IP-Address.";
|
---|
148 | isValid = false;
|
---|
149 | }
|
---|
150 | try {
|
---|
151 | int.Parse(tbPort.Text);
|
---|
152 | }
|
---|
153 | catch (Exception ex) {
|
---|
154 | isValid = false;
|
---|
155 | lblError.Text = "Please verify entered Port.";
|
---|
156 | }
|
---|
157 | try {
|
---|
158 | IPAddress.Parse(tbIp.Text);
|
---|
159 | }
|
---|
160 | catch (Exception ex) {
|
---|
161 | isValid = false;
|
---|
162 | lblError.Text = "Please verify entered IP address.";
|
---|
163 | }
|
---|
164 | return isValid;
|
---|
165 | }
|
---|
166 |
|
---|
167 | private void EnableForm(bool cf, bool error) {
|
---|
168 | if (cf) {
|
---|
169 | this.Visible = true;
|
---|
170 | ServiceLocator.ShutDownFacade();
|
---|
171 | lblError.Text = "";
|
---|
172 | if (error == true) {
|
---|
173 | lblError.Text = "Establishing server connection failed.";
|
---|
174 | }
|
---|
175 | }
|
---|
176 | }
|
---|
177 |
|
---|
178 | private void HiveServerConsole_KeyPress(object sender, KeyPressEventArgs e) {
|
---|
179 | if (e.KeyChar == (char)Keys.Return) {
|
---|
180 | BtnLogin_Click(sender, e);
|
---|
181 | }
|
---|
182 | }
|
---|
183 |
|
---|
184 | private void btnCancel_Click(object sender, EventArgs e) {
|
---|
185 | Dispose();
|
---|
186 | }
|
---|
187 | }
|
---|
188 | }
|
---|