Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Server.Console/3.2/HiveServerConsole.cs @ 2621

Last change on this file since 2621 was 2118, checked in by aleitner, 15 years ago

change comments, delete manual login-data (#569)

File size: 5.5 KB
RevLine 
[778]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;
[799]30using HeuristicLab.Hive.Contracts.Interfaces;
31using HeuristicLab.Hive.Contracts.BusinessObjects;
[912]32using HeuristicLab.Hive.Contracts;
[956]33using System.Security.Cryptography;
[978]34using System.Net;
[2065]35using System.Threading;
[2103]36using System.ServiceModel;
[778]37
[1089]38namespace HeuristicLab.Hive.Server.ServerConsole {
[778]39
40  public partial class HiveServerConsole : Form {
41
[794]42    HiveServerManagementConsole information = null;
[778]43
44    public HiveServerConsole() {
45      InitializeComponent();
46    }
47
48    private void tsmiExit_Click(object sender, EventArgs e) {
49      this.Close();
50    }
51
[794]52    /// <summary>
53    /// When login button is clicked, the ManagementConsole
54    /// will be opened
55    /// </summary>
56    /// <param name="sender"></param>
57    /// <param name="e"></param>
[1037]58    private void BtnLogin_Click(object sender, EventArgs e) {
[935]59      string newIp = tbIp.Text;
60      newIp = newIp.Replace(" ", "");
61
[1832]62      ServiceLocator.Address = newIp;
63      ServiceLocator.Port = this.tbPort.Text;
[978]64
[1832]65      if (IsValid()) {
66        this.Visible = false;
67        information = new HiveServerManagementConsole();
68        information.closeFormEvent += new closeForm(EnableForm);
69        information.Show();
[2065]70      }
[778]71    }
72
[1148]73    /// <summary>
74    /// if the input is correct and the login-method returns a
75    /// valid response
76    /// </summary>
77    /// <returns></returns>
[1037]78    private bool IsValid() {
[2065]79      Thread t = new Thread(new ThreadStart(ShowWaitDlg));
80      if (IsFormValidated()) {
81        IPAddress ipAdress = IPAddress.Parse(tbIp.Text);
82        int port = int.Parse(tbPort.Text);
[2103]83        ServiceLocator.Address = tbIp.Text.Replace(" ", "");
84        ServiceLocator.Port = tbPort.Text;
[2065]85        IServerConsoleFacade scf = ServiceLocator.GetServerConsoleFacade();
[2109]86        Response resp;
[912]87        try {
[2065]88          lblError.Text = "Trying to logon...";
[2109]89          this.Cursor = Cursors.WaitCursor;
[2065]90          t.Start();
[2109]91          resp = scf.Login(tbUserName.Text, tbPwd.Text);
[2065]92          t.Abort();
[2109]93          this.Cursor = Cursors.Default;
94          if (resp.Success == true) return true;
[2065]95          lblError.Text = resp.StatusMessage;
[2109]96          MessageBox.Show("Wrong username or password");
[912]97        }
[2103]98        catch (EndpointNotFoundException ene) {
[2109]99          t.Abort();
100          this.Cursor = Cursors.Default;
101          MessageBox.Show(ene.Message);
[2103]102          lblError.Text = "No Service at this address!";
[2109]103          scf = null;
[2103]104        }
[2109]105        catch (Exception ex) {
[2065]106          //login failed
107          t.Abort();
[2109]108          this.Cursor = Cursors.Default;
109          MessageBox.Show(ex.Message);
110          lblError.Text = "Logon failed! Please restart console";
[912]111        }
112      }
[2109]113        return false;
[778]114    }
[785]115
[2109]116
[2065]117    private void ShowWaitDlg() {
118      LogonDlg dlg = new LogonDlg();
119      dlg.ShowDialog();
120    }
121
122    /// <summary>
123    /// Validates the form.
124    /// </summary>
125    /// <returns></returns>
126    private bool IsFormValidated() {
127      bool isValid = true;
128      if (String.IsNullOrEmpty(tbUserName.Text)) {
129        lblError.Text = "Please type in Username.";
130        isValid = false;
131      }
132      if (String.IsNullOrEmpty(tbPwd.Text)) {
133        lblError.Text = "Please type in Password.";
134        isValid = false;
135      }
136      if (String.IsNullOrEmpty(tbIp.Text)) {
137        lblError.Text = "Please type in Port.";
138        isValid = false;
139      }
140      if (String.IsNullOrEmpty(tbPort.Text)) {
141        lblError.Text = "Please type in IP-Address.";
142        isValid = false;
143      }
144      try {
145        int.Parse(tbPort.Text);
146      }
147      catch (Exception ex) {
148        isValid = false;
149        lblError.Text = "Please verify entered Port.";
150      }
151      try {
152        IPAddress.Parse(tbIp.Text);
153      }
154      catch (Exception ex) {
155        isValid = false;
156        lblError.Text = "Please verify entered IP address.";
157      }
158      return isValid;
159    }
160
[1037]161    private void EnableForm(bool cf, bool error) {
[785]162      if (cf) {
163        this.Visible = true;
[1723]164        ServiceLocator.ShutDownFacade();
[2109]165        lblError.Text = "";
[1030]166        if (error == true) {
[2065]167          lblError.Text = "Establishing server connection failed.";
[1030]168        }
[785]169      }
170    }
[1164]171
172    private void HiveServerConsole_KeyPress(object sender, KeyPressEventArgs e) {
173      if (e.KeyChar == (char)Keys.Return) {
174        BtnLogin_Click(sender, e);
175      }
176    }
[2065]177
178    private void btnCancel_Click(object sender, EventArgs e) {
179      Dispose();
180    }
[778]181  }
[2109]182}
Note: See TracBrowser for help on using the repository browser.