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 @ 4424

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