Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.3-Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Console/3.3/HiveServerConsole.cs @ 4340

Last change on this file since 4340 was 4296, checked in by cneumuel, 14 years ago

corrected assembly reference paths, added some missing files

File size: 5.6 KB
Line 
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
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Data;
26using System.Drawing;
27using System.Linq;
28using System.Text;
29using System.Windows.Forms;
30using HeuristicLab.Hive.Contracts.Interfaces;
31using HeuristicLab.Hive.Contracts.BusinessObjects;
32using HeuristicLab.Hive.Contracts;
33using System.Security.Cryptography;
34using System.Net;
35using System.Threading;
36using System.ServiceModel;
37using HeuristicLab.Hive.Contracts.ResponseObjects;
38
39namespace HeuristicLab.Hive.Server.ServerConsole {
40
41  public partial class HiveServerConsole : Form {
42
43    HiveServerManagementConsole information = null;
44
45    public HiveServerConsole() {
46      InitializeComponent();
47    }
48
49    private void tsmiExit_Click(object sender, EventArgs e) {
50      this.Close();
51    }
52
53    /// <summary>
54    /// When login button is clicked, the ManagementConsole
55    /// will be opened
56    /// </summary>
57    /// <param name="sender"></param>
58    /// <param name="e"></param>
59    private void BtnLogin_Click(object sender, EventArgs e) {
60      string newIp = tbIp.Text;
61      newIp = newIp.Replace(" ", "");
62
63      ServiceLocator.Address = newIp;
64      ServiceLocator.Port = this.tbPort.Text;
65
66      if (IsValid()) {
67        this.Visible = false;
68        information = new HiveServerManagementConsole();
69        information.closeFormEvent += new closeForm(EnableForm);
70        information.Show();
71      }
72    }
73
74    /// <summary>
75    /// if the input is correct and the login-method returns a
76    /// valid response
77    /// </summary>
78    /// <returns></returns>
79    private bool IsValid() {
80      Thread t = new Thread(new ThreadStart(ShowWaitDlg));
81      if (IsFormValidated()) {
82        IPAddress ipAdress = IPAddress.Parse(tbIp.Text);
83        int port = int.Parse(tbPort.Text);
84        IServerConsoleFacade scf;
85        Response resp;
86        try {
87          lblError.Text = "Trying to logon...";
88          this.Cursor = Cursors.WaitCursor;
89          t.Start();
90
91          ServiceLocator.Address = tbIp.Text.Replace(" ", "");
92          ServiceLocator.Port = tbPort.Text;
93          ServiceLocator.Username = tbUserName.Text;
94          ServiceLocator.Password = tbPwd.Text;
95          scf = ServiceLocator.GetServerConsoleFacade();
96
97          resp = scf.Login();
98          t.Abort();
99          this.Cursor = Cursors.Default;
100          if (resp.StatusMessage == ResponseStatus.Ok) return true;
101          lblError.Text = resp.StatusMessage.ToString();
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}
Note: See TracBrowser for help on using the repository browser.