[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 |
|
---|
| 22 | using System;
|
---|
[4424] | 23 | using System.Net;
|
---|
| 24 | using System.ServiceModel;
|
---|
| 25 | using System.Threading;
|
---|
[778] | 26 | using System.Windows.Forms;
|
---|
[4424] | 27 | using HeuristicLab.Hive.Contracts;
|
---|
[799] | 28 | using HeuristicLab.Hive.Contracts.Interfaces;
|
---|
[4263] | 29 | using HeuristicLab.Hive.Contracts.ResponseObjects;
|
---|
[778] | 30 |
|
---|
[1089] | 31 | namespace 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;
|
---|
[978] | 56 |
|
---|
[1832] | 57 | if (IsValid()) {
|
---|
| 58 | this.Visible = false;
|
---|
| 59 | information = new HiveServerManagementConsole();
|
---|
| 60 | information.closeFormEvent += new closeForm(EnableForm);
|
---|
| 61 | information.Show();
|
---|
[2065] | 62 | }
|
---|
[778] | 63 | }
|
---|
| 64 |
|
---|
[1148] | 65 | /// <summary>
|
---|
| 66 | /// if the input is correct and the login-method returns a
|
---|
| 67 | /// valid response
|
---|
| 68 | /// </summary>
|
---|
| 69 | /// <returns></returns>
|
---|
[1037] | 70 | private bool IsValid() {
|
---|
[2065] | 71 | Thread t = new Thread(new ThreadStart(ShowWaitDlg));
|
---|
| 72 | if (IsFormValidated()) {
|
---|
| 73 | IPAddress ipAdress = IPAddress.Parse(tbIp.Text);
|
---|
[4296] | 74 | IServerConsoleFacade scf;
|
---|
[2109] | 75 | Response resp;
|
---|
[912] | 76 | try {
|
---|
[2065] | 77 | lblError.Text = "Trying to logon...";
|
---|
[2109] | 78 | this.Cursor = Cursors.WaitCursor;
|
---|
[2065] | 79 | t.Start();
|
---|
[4296] | 80 |
|
---|
| 81 | ServiceLocator.Address = tbIp.Text.Replace(" ", "");
|
---|
| 82 | ServiceLocator.Username = tbUserName.Text;
|
---|
| 83 | ServiceLocator.Password = tbPwd.Text;
|
---|
| 84 | scf = ServiceLocator.GetServerConsoleFacade();
|
---|
| 85 |
|
---|
| 86 | resp = scf.Login();
|
---|
[2065] | 87 | t.Abort();
|
---|
[2109] | 88 | this.Cursor = Cursors.Default;
|
---|
[4263] | 89 | if (resp.StatusMessage == ResponseStatus.Ok) return true;
|
---|
| 90 | lblError.Text = resp.StatusMessage.ToString();
|
---|
[2109] | 91 | MessageBox.Show("Wrong username or password");
|
---|
[912] | 92 | }
|
---|
[2103] | 93 | catch (EndpointNotFoundException ene) {
|
---|
[2109] | 94 | t.Abort();
|
---|
| 95 | this.Cursor = Cursors.Default;
|
---|
| 96 | MessageBox.Show(ene.Message);
|
---|
[2103] | 97 | lblError.Text = "No Service at this address!";
|
---|
[2109] | 98 | scf = null;
|
---|
[2103] | 99 | }
|
---|
[2109] | 100 | catch (Exception ex) {
|
---|
[2065] | 101 | //login failed
|
---|
| 102 | t.Abort();
|
---|
[2109] | 103 | this.Cursor = Cursors.Default;
|
---|
| 104 | MessageBox.Show(ex.Message);
|
---|
| 105 | lblError.Text = "Logon failed! Please restart console";
|
---|
[912] | 106 | }
|
---|
| 107 | }
|
---|
[2109] | 108 | return false;
|
---|
[778] | 109 | }
|
---|
[785] | 110 |
|
---|
[2109] | 111 |
|
---|
[2065] | 112 | private void ShowWaitDlg() {
|
---|
| 113 | LogonDlg dlg = new LogonDlg();
|
---|
| 114 | dlg.ShowDialog();
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | /// <summary>
|
---|
| 118 | /// Validates the form.
|
---|
| 119 | /// </summary>
|
---|
| 120 | /// <returns></returns>
|
---|
| 121 | private bool IsFormValidated() {
|
---|
| 122 | bool isValid = true;
|
---|
| 123 | if (String.IsNullOrEmpty(tbUserName.Text)) {
|
---|
| 124 | lblError.Text = "Please type in Username.";
|
---|
| 125 | isValid = false;
|
---|
| 126 | }
|
---|
| 127 | if (String.IsNullOrEmpty(tbPwd.Text)) {
|
---|
| 128 | lblError.Text = "Please type in Password.";
|
---|
| 129 | isValid = false;
|
---|
| 130 | }
|
---|
| 131 | if (String.IsNullOrEmpty(tbIp.Text)) {
|
---|
| 132 | lblError.Text = "Please type in Port.";
|
---|
| 133 | isValid = false;
|
---|
| 134 | }
|
---|
| 135 | try {
|
---|
| 136 | IPAddress.Parse(tbIp.Text);
|
---|
| 137 | }
|
---|
| 138 | catch (Exception ex) {
|
---|
| 139 | isValid = false;
|
---|
| 140 | lblError.Text = "Please verify entered IP address.";
|
---|
| 141 | }
|
---|
| 142 | return isValid;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
[1037] | 145 | private void EnableForm(bool cf, bool error) {
|
---|
[785] | 146 | if (cf) {
|
---|
| 147 | this.Visible = true;
|
---|
[1723] | 148 | ServiceLocator.ShutDownFacade();
|
---|
[2109] | 149 | lblError.Text = "";
|
---|
[1030] | 150 | if (error == true) {
|
---|
[2065] | 151 | lblError.Text = "Establishing server connection failed.";
|
---|
[1030] | 152 | }
|
---|
[785] | 153 | }
|
---|
| 154 | }
|
---|
[1164] | 155 |
|
---|
| 156 | private void HiveServerConsole_KeyPress(object sender, KeyPressEventArgs e) {
|
---|
| 157 | if (e.KeyChar == (char)Keys.Return) {
|
---|
| 158 | BtnLogin_Click(sender, e);
|
---|
| 159 | }
|
---|
| 160 | }
|
---|
[2065] | 161 |
|
---|
| 162 | private void btnCancel_Click(object sender, EventArgs e) {
|
---|
| 163 | Dispose();
|
---|
| 164 | }
|
---|
[778] | 165 | }
|
---|
[2109] | 166 | }
|
---|