Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/11/08 16:53:26 (15 years ago)
Author:
whackl
Message:

added logic to client console (#397)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Client.Console/HiveClientConsole.cs

    r953 r973  
    3131using System.Threading;
    3232using ZedGraph;
    33 //using HeuristicLab.Hive.Client.Console.ClientWCFService;
     33using HeuristicLab.Hive.Client.Console.ClientService;
    3434using System.ServiceModel;
     35using System.Net;
    3536
    3637namespace HeuristicLab.Hive.Client.Console {
     
    4142
    4243    EventLog HiveClientEventLog;
    43     int selectedEventLogId;
     44    ClientConsoleCommunicatorClient cccc;
     45    System.Windows.Forms.Timer refreshTimer;
    4446
    4547    public HiveClientConsole() {
    4648      InitializeComponent();
     49      InitTimer();
     50      ConnectToClient();
     51      RefreshGui();
    4752      GetEventLog();
    48 
    49       //ClientConsoleCommunicatorClient cccc = new ClientConsoleCommunicatorClient(new NetTcpBinding(),
    50       //    new EndpointAddress("net.tcp://127.0.0.1:8000/ClientConsole/ClientConsoleCommunicator"));
    51       //StatusCommons sc = cccc.GetStatusInfos();
     53    }
     54
     55    private void InitTimer() {
     56      refreshTimer = new System.Windows.Forms.Timer();
     57      refreshTimer.Interval = 1000;
     58      refreshTimer.Tick += new EventHandler(refreshTimer_Tick);
     59      refreshTimer.Start();
     60    }
     61
     62    void refreshTimer_Tick(object sender, EventArgs e) {
     63      RefreshGui();
     64    }
     65   
     66    private void RefreshGui() {
     67      StatusCommons sc = new StatusCommons();
     68     
     69      try {
     70        sc = cccc.GetStatusInfos();
     71      }
     72      catch (Exception ex) {
     73        refreshTimer.Stop();
     74        DialogResult res = MessageBox.Show("Connection Error, check if Hive Client is running!", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     75        if (res == DialogResult.OK)
     76          this.Close();
     77      }
     78
     79      lbGuid.Text = sc.ClientGuid.ToString();
     80      lbCs.Text = sc.ConnectedSince.ToString();
     81      lbConnectionStatus.Text = sc.Status.ToString();
     82      lbJobdone.Text = sc.JobsDone.ToString();
     83      lbJobsAborted.Text = sc.JobsAborted.ToString();
     84      lbJobsFetched.Text = sc.JobsFetched.ToString();
     85
     86      this.Text = "Client Console (" + sc.Status.ToString() + ")";
     87      lbStatus.Text = sc.Status.ToString();
     88
     89      ListViewItem curJobStatusItem;
     90
     91      if (sc.Jobs != null) {
     92        lvJobDetail.Items.Clear();
     93        double progress;
     94        foreach (JobStatus curJob in sc.Jobs) {
     95          curJobStatusItem = new ListViewItem(curJob.JobId.ToString());
     96          curJobStatusItem.SubItems.Add(curJob.Since.ToString());
     97          progress = curJob.Progress * 100;
     98          curJobStatusItem.SubItems.Add(progress.ToString());
     99          lvJobDetail.Items.Add(curJobStatusItem);
     100        }
     101      }
     102
     103      UpdateGraph(zGJobs, sc.JobsDone, sc.JobsAborted);
     104 
     105      if (sc.Status == NetworkEnumWcfConnState.Connected) {
     106        btConnect.Enabled = false;
     107        btnDisconnect.Enabled = true;
     108        ConnectionContainer curConnection = cccc.GetCurrentConnection();
     109        tbIPAdress.Text = curConnection.IPAdress;
     110        tbPort.Text = curConnection.Port.ToString();
     111      } else if (sc.Status == NetworkEnumWcfConnState.Disconnected) {
     112        btConnect.Enabled = true;
     113        btnDisconnect.Enabled = false;
     114      } else if (sc.Status == NetworkEnumWcfConnState.Failed) {
     115        btConnect.Enabled = true;
     116        btnDisconnect.Enabled = false;
     117      }
     118    }
     119
     120    private void ConnectToClient() {
     121      try {
     122        cccc = new ClientConsoleCommunicatorClient();
     123      }
     124      catch (Exception) {
     125        refreshTimer.Stop();
     126        DialogResult res = MessageBox.Show("Connection Error, check if Hive Client is running!", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     127        if (res == DialogResult.OK)
     128          this.Close();
     129      }
    52130    }
    53131
     
    72150
    73151    private void HiveClientConsole_Load(object sender, EventArgs e) {
    74       CreateGraph(zGJobs);
    75152      //SetSize();
    76153    }
     
    89166        curEventLogEntry.SubItems.Add(ev.TimeGenerated.Date.ToString());
    90167        curEventLogEntry.SubItems.Add(ev.TimeGenerated.TimeOfDay.ToString());
     168        lvLog.Items.Add(curEventLogEntry);
    91169      }
    92170    }
     
    96174    }
    97175
    98     private void SetSize() {
    99       zGJobs.Location = new Point(10, 10);
    100       // Leave a small margin around the outside of the control
    101 
    102       zGJobs.Size = new Size(ClientRectangle.Width - 20,
    103                               ClientRectangle.Height - 20);
    104     }
    105 
    106 
    107     private void CreateGraph(ZedGraphControl zgc) {
     176    private void UpdateGraph(ZedGraphControl zgc, int jobsDone, int jobsAborted) {
     177      zgc.GraphPane.GraphObjList.Clear();
    108178      GraphPane myPane = zgc.GraphPane;
    109179
     
    113183      myPane.Fill.Type = FillType.None;
    114184
    115       myPane.AddPieSlice(40, Color.Red, 0, "Jobs aborted");
    116       myPane.AddPieSlice(60, Color.Green, 0.1, "Jobs done");
    117 
     185      double sum = jobsDone + jobsAborted;
     186      double perDone = jobsDone / sum * 100;
     187      double perAborted = jobsAborted / sum * 100;
     188
     189      myPane.AddPieSlice(perAborted, Color.Red, 0, "Jobs aborted");
     190      myPane.AddPieSlice(perDone, Color.Green, 0.1, "Jobs done");
    118191      myPane.AxisChange();
    119192    }
     
    130203      EventlogDetails.Show();
    131204    }
     205
     206    private void btConnect_Click(object sender, EventArgs e) {
     207      IPAddress ipAdress;
     208      int port;
     209      ConnectionContainer cc = new ConnectionContainer();
     210      //IPAddress.TryParse(tbIPAdress.Text.ToString(), ipAdress);
     211      if (IPAddress.TryParse(tbIPAdress.Text, out ipAdress) && int.TryParse(tbPort.Text, out port)) {
     212        cc.IPAdress = tbIPAdress.Text;
     213        cc.Port = port;
     214        cccc.SetConnection(cc);
     215      } else {
     216        MessageBox.Show("IP Adress and/or Port Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     217      }
     218     
     219    }
     220
     221    private void btnDisconnect_Click(object sender, EventArgs e) {
     222      cccc.Disconnect();
     223    }
    132224  }
    133225}
Note: See TracChangeset for help on using the changeset viewer.