Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/24/11 16:15:23 (13 years ago)
Author:
ascheibe
Message:

#1233 slave ui now receives status information and displays it in doughnut chart

Location:
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Views/3.4
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Views/3.4/SlaveItem.cs

    r5795 r5826  
    6262
    6363    public void Open() {
    64       pipeFactory = new DuplexChannelFactory<ISlaveCommunication>(this, "SlaveCommunicationServiceEndpoint");
    65       RegisterEvents();
     64      try {
     65        pipeFactory = new DuplexChannelFactory<ISlaveCommunication>(this, "SlaveCommunicationServiceEndpoint");
     66        RegisterEvents();
     67      }
     68      catch (Exception ex) {
     69        OnMessageLogged("Error establishing connection to Core. Are you missing a configuration file?\n" + ex.ToString());
     70      }
    6671    }
    6772
     
    7277        return true;
    7378      }
    74       catch (Exception e) {
    75         OnMessageLogged("Couldn't connect to Slave core. Is it possible that the Slave Core isn't running?\nException is: " + e.ToString());
     79      catch (Exception) {
     80        OnMessageLogged("Couldn't connect to Slave core. Is it possible that the Slave Core isn't running?\n");
    7681        return false;
    7782      }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Views/3.4/SlaveView.Designer.cs

    r5789 r5826  
    5555      this.btnAbout = new System.Windows.Forms.Button();
    5656      this.jobChart = new System.Windows.Forms.DataVisualization.Charting.Chart();
     57      this.btnRestartService = new System.Windows.Forms.Button();
    5758      ((System.ComponentModel.ISupportInitialize)(this.jobChart)).BeginInit();
    5859      this.SuspendLayout();
     
    6162      //
    6263      this.txtLog.BackColor = System.Drawing.Color.White;
    63       this.txtLog.Location = new System.Drawing.Point(3, 150);
     64      this.txtLog.Location = new System.Drawing.Point(3, 184);
    6465      this.txtLog.Multiline = true;
    6566      this.txtLog.Name = "txtLog";
    6667      this.txtLog.ReadOnly = true;
    6768      this.txtLog.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
    68       this.txtLog.Size = new System.Drawing.Size(584, 273);
     69      this.txtLog.Size = new System.Drawing.Size(584, 239);
    6970      this.txtLog.TabIndex = 1;
    7071      //
     
    111112      // btnAbout
    112113      //
    113       this.btnAbout.Location = new System.Drawing.Point(476, 119);
     114      this.btnAbout.Location = new System.Drawing.Point(476, 149);
    114115      this.btnAbout.Name = "btnAbout";
    115116      this.btnAbout.Size = new System.Drawing.Size(111, 28);
     
    132133      series1.Name = "Series1";
    133134      this.jobChart.Series.Add(series1);
    134       this.jobChart.Size = new System.Drawing.Size(272, 138);
     135      this.jobChart.Size = new System.Drawing.Size(293, 174);
    135136      this.jobChart.TabIndex = 7;
     137      //
     138      // btnRestartService
     139      //
     140      this.btnRestartService.Location = new System.Drawing.Point(476, 119);
     141      this.btnRestartService.Name = "btnRestartService";
     142      this.btnRestartService.Size = new System.Drawing.Size(111, 28);
     143      this.btnRestartService.TabIndex = 8;
     144      this.btnRestartService.Text = "RestartService";
     145      this.btnRestartService.UseVisualStyleBackColor = true;
     146      this.btnRestartService.Click += new System.EventHandler(this.btnRestartService_Click);
    136147      //
    137148      // SlaveView
     
    139150      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    140151      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     152      this.Controls.Add(this.btnRestartService);
    141153      this.Controls.Add(this.jobChart);
    142154      this.Controls.Add(this.btnAbout);
     
    163175    private System.Windows.Forms.Button btnAbout;
    164176    private System.Windows.Forms.DataVisualization.Charting.Chart jobChart;
     177    private System.Windows.Forms.Button btnRestartService;
    165178  }
    166179}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Views/3.4/SlaveView.cs

    r5795 r5826  
    2121
    2222using System;
     23using System.Security.Principal;
     24using System.ServiceProcess;
    2325using System.Threading;
    2426using System.Threading.Tasks;
     
    4749    public SlaveView() {
    4850      InitializeComponent();
     51
     52      if (!CheckRunAsAdmin())
     53        btnRestartService.Enabled = false;
     54      btnRestart.Enabled = false;
     55
    4956    }
    5057
     
    99106    #region Event Handlers
    100107    void Content_SlaveStatusChanged(object sender, EventArgs<StatusCommons> e) {
    101       txtLog.AppendText("got a status changed object from slave\n");
    102108      RenderChart(e.Value);
    103109    }
     
    114120
    115121    private void RenderChart(StatusCommons status) {
     122      jobChart.Series[0].Points.Clear();
    116123
    117124      DataPoint pJobs = new DataPoint(status.Jobs.Count, status.Jobs.Count);
     
    120127      DataPoint pJobsFetched = new DataPoint(status.JobsFetched, status.JobsFetched);
    121128
     129      pJobs.LegendText = "Current jobs: " + status.Jobs.Count;
     130      pJobs.Color = System.Drawing.Color.Orange;
     131      pJobsAborted.LegendText = "Aborted jobs: " + status.JobsAborted;
     132      pJobsAborted.Color = System.Drawing.Color.Red;
     133      pJobsDone.LegendText = "Finished jobs: " + status.JobsDone;
     134      pJobsDone.Color = System.Drawing.Color.Green;
     135      pJobsFetched.LegendText = "Fetched jobs: " + status.JobsFetched;
     136      pJobsFetched.Color = System.Drawing.Color.Blue;
     137
    122138      jobChart.Series[0].Points.Add(pJobs);
    123139      jobChart.Series[0].Points.Add(pJobsAborted);
     
    137153
    138154    private void btnRestart_Click(object sender, System.EventArgs e) {
    139       if (Content != null)
     155      if (Content != null) {
    140156        Content.RestartCore();
     157        btnRestart.Enabled = false;
     158        btnSleep.Enabled = true;
     159      }
    141160    }
    142161
    143162    private void btnSleep_Click(object sender, System.EventArgs e) {
    144       if (Content != null)
     163      if (Content != null) {
    145164        Content.Sleep();
     165        btnRestart.Enabled = true;
     166        btnSleep.Enabled = false;
     167      }
    146168    }
    147169
     
    150172      diag.ShowDialog();
    151173    }
     174
     175    private void btnRestartService_Click(object sender, EventArgs e) {
     176      if (CheckRunAsAdmin()) {
     177        RestartService();
     178      } else {
     179        MessageBox.Show("You need to run this application as Administrator to restart the service");
     180      }
     181    }
     182
     183    private bool CheckRunAsAdmin() {
     184      bool isRunAsAdmin = false;
     185      WindowsIdentity user = WindowsIdentity.GetCurrent();
     186      WindowsPrincipal principal = new WindowsPrincipal(user);
     187
     188      try {
     189        isRunAsAdmin = principal.IsInRole(WindowsBuiltInRole.Administrator);
     190      }
     191      catch { }
     192      return isRunAsAdmin;
     193    }
     194
     195    private void RestartService() {
     196      string serviceName = "HeuristicLab.Clients.Hive.SlaveCore.SlaveWindowsService";
     197      TimeSpan timeout = TimeSpan.FromMilliseconds(5000);
     198
     199      ServiceController service = new ServiceController(serviceName);
     200      try {
     201        if (service.Status == ServiceControllerStatus.Running) {
     202          service.Stop();
     203          service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
     204        }
     205
     206        service.Start();
     207        service.WaitForStatus(ServiceControllerStatus.Running, timeout);
     208      }
     209      catch (InvalidOperationException ex) {
     210        MessageBox.Show("Error starting service: Hive Slave Service not found!\n" + ex.ToString());
     211      }
     212      catch (Exception ex) {
     213        MessageBox.Show("Error starting service, exception is: \n" + ex.ToString());
     214      }
     215    }
    152216  }
    153217}
Note: See TracChangeset for help on using the changeset viewer.