Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/23/11 21:31:48 (14 years ago)
Author:
ascheibe
Message:

#1233

  • added UAC self elevation for start/stop of windows service
  • added slave states and simplified ui commands
Location:
branches/HeuristicLab.Hive-3.4/sources
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.SlaveTrayIcon/HeuristicLab.Clients.Hive.Slave.SlaveTrayIcon.csproj

    r6225 r6257  
    7979      <SubType>Form</SubType>
    8080    </Compile>
    81     <Compile Include="MainWindow.Designer.cs">
     81    <Compile Include="MainWindow.designer.cs">
    8282      <DependentUpon>MainWindow.cs</DependentUpon>
    8383    </Compile>
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.SlaveTrayIcon/MainWindow.Designer.cs

    r6225 r6257  
    2929      this.notifyIcon = new System.Windows.Forms.NotifyIcon(this.components);
    3030      this.contextMenuNotifyIcon = new System.Windows.Forms.ContextMenuStrip(this.components);
     31      this.homepageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     32      this.toolStripSeparator = new System.Windows.Forms.ToolStripSeparator();
    3133      this.showToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    3234      this.closeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    33       this.toolStripSeparator = new System.Windows.Forms.ToolStripSeparator();
    34       this.homepageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    3535      this.mainTabControl = new System.Windows.Forms.TabControl();
    3636      this.tabSlaveView = new System.Windows.Forms.TabPage();
     
    6969      this.contextMenuNotifyIcon.Size = new System.Drawing.Size(210, 98);
    7070      //
    71       // showToolStripMenuItem
    72       //
    73       this.showToolStripMenuItem.Name = "showToolStripMenuItem";
    74       this.showToolStripMenuItem.Size = new System.Drawing.Size(209, 22);
    75       this.showToolStripMenuItem.Text = "Show";
    76       this.showToolStripMenuItem.Click += new System.EventHandler(this.showToolStripMenuItem_Click);
    77       //
    78       // closeToolStripMenuItem
    79       //
    80       this.closeToolStripMenuItem.Name = "closeToolStripMenuItem";
    81       this.closeToolStripMenuItem.Size = new System.Drawing.Size(209, 22);
    82       this.closeToolStripMenuItem.Text = "Close";
    83       this.closeToolStripMenuItem.Click += new System.EventHandler(this.closeToolStripMenuItem_Click);
    84       //
    85       // toolStripSeparator
    86       //
    87       this.toolStripSeparator.Name = "toolStripSeparator";
    88       this.toolStripSeparator.Size = new System.Drawing.Size(206, 6);
    89       //
    9071      // homepageToolStripMenuItem
    9172      //
     
    9576      this.homepageToolStripMenuItem.Text = "Visit dev.heuristiclab.com";
    9677      this.homepageToolStripMenuItem.Click += new System.EventHandler(this.homepageToolStripMenuItem_Click);
     78      //
     79      // toolStripSeparator
     80      //
     81      this.toolStripSeparator.Name = "toolStripSeparator";
     82      this.toolStripSeparator.Size = new System.Drawing.Size(206, 6);
     83      //
     84      // showToolStripMenuItem
     85      //
     86      this.showToolStripMenuItem.Name = "showToolStripMenuItem";
     87      this.showToolStripMenuItem.Size = new System.Drawing.Size(209, 22);
     88      this.showToolStripMenuItem.Text = "Show";
     89      this.showToolStripMenuItem.Click += new System.EventHandler(this.showToolStripMenuItem_Click);
     90      //
     91      // closeToolStripMenuItem
     92      //
     93      this.closeToolStripMenuItem.Name = "closeToolStripMenuItem";
     94      this.closeToolStripMenuItem.Size = new System.Drawing.Size(209, 22);
     95      this.closeToolStripMenuItem.Text = "Close";
     96      this.closeToolStripMenuItem.Click += new System.EventHandler(this.closeToolStripMenuItem_Click);
    9797      //
    9898      // mainTabControl
     
    107107      this.mainTabControl.Name = "mainTabControl";
    108108      this.mainTabControl.SelectedIndex = 0;
    109       this.mainTabControl.Size = new System.Drawing.Size(581, 303);
     109      this.mainTabControl.Size = new System.Drawing.Size(581, 369);
    110110      this.mainTabControl.TabIndex = 1;
    111111      //
     
    116116      this.tabSlaveView.Name = "tabSlaveView";
    117117      this.tabSlaveView.Padding = new System.Windows.Forms.Padding(3);
    118       this.tabSlaveView.Size = new System.Drawing.Size(573, 277);
     118      this.tabSlaveView.Size = new System.Drawing.Size(573, 343);
    119119      this.tabSlaveView.TabIndex = 0;
    120120      this.tabSlaveView.Text = "Overview";
     
    131131      this.slaveView.Name = "slaveView";
    132132      this.slaveView.ReadOnly = false;
    133       this.slaveView.Size = new System.Drawing.Size(561, 265);
     133      this.slaveView.Size = new System.Drawing.Size(561, 331);
    134134      this.slaveView.TabIndex = 0;
    135135      //
     
    185185      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    186186      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    187       this.ClientSize = new System.Drawing.Size(605, 327);
     187      this.ClientSize = new System.Drawing.Size(605, 393);
    188188      this.Controls.Add(this.mainTabControl);
    189189      this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.SlaveTrayIcon/MainWindow.cs

    r6225 r6257  
    4949    }
    5050
    51     private void RestoreFromTray() {
     51    public void RestoreFromTray() {
    5252      Show();
    5353      WindowState = FormWindowState.Normal;
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.SlaveTrayIcon/Program.cs

    r6116 r6257  
    1212    /// </summary>
    1313    [STAThread]
    14     static void Main() {
    15       KillOtherInstances();
     14    static void Main(string[] args) {
     15      if (args.Length < 1 || (args.Length > 0 && args[0] != "showui")) {
     16        KillOtherInstances();
     17      }
    1618
    1719      Application.EnableVisualStyles();
    1820      Application.SetCompatibleTextRenderingDefault(false);
    1921      MainWindow mw = new MainWindow();
    20       mw.MinimizeToTray();
     22      if (args.Length < 1 || (args.Length > 0 && args[0] != "showui")) {
     23        mw.MinimizeToTray();
     24      } else if (args.Length > 0 && args[0] == "showui") {
     25        mw.RestoreFromTray();
     26      }
     27     
     28
    2129      mw.Content = new SlaveItem();
    2230
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Views/3.4/SlaveItem.cs

    r6225 r6257  
    2828namespace HeuristicLab.Clients.Hive.SlaveCore.Views {
    2929
     30
     31  public enum SlaveDisplayStat {
     32    Offline,  // not connected to Hive
     33    Idle,     // slave has no jobs to calculate
     34    Busy,     // jobs are currently running on slave
     35    Asleep,   // we are not accepting jobs at the moment
     36    NoService // the slave windows service is currently not running
     37  }
     38
     39  public enum CoreConnection {
     40    Connected,
     41    Offline
     42  }
     43
    3044  [CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)]
    3145  [Item("SlaveItem", "Represents a slave which receives messages from the core")]
     
    3347    private ISlaveCommunication pipeProxy;
    3448    private DuplexChannelFactory<ISlaveCommunication> pipeFactory;
     49    private int lastJobsFetched = 0;
    3550
    3651    public SlaveItem() {
     
    5166    void pipeFactory_Opened(object sender, EventArgs e) {
    5267      OnMessageLogged("Connection to Slave core established");
     68      OnCoreConnectionChanged(CoreConnection.Connected);
    5369    }
    5470
    5571    void pipeFactory_Closed(object sender, EventArgs e) {
    5672      OnMessageLogged("Connection to Slave core closed");
     73      OnCoreConnectionChanged(CoreConnection.Offline);
    5774    }
    5875
    5976    void pipeFactory_Faulted(object sender, EventArgs e) {
    6077      OnMessageLogged("Connection to Slave core faulted");
     78      OnCoreConnectionChanged(CoreConnection.Offline);
    6179    }
    6280
     
    120138    public void Sleep() {
    121139      try {
    122         if (pipeFactory.State != CommunicationState.Faulted && pipeFactory.State != CommunicationState.Closed)
     140        if (pipeFactory.State != CommunicationState.Faulted && pipeFactory.State != CommunicationState.Closed) {
    123141          pipeProxy.Sleep();
     142        }
    124143      }
    125144      catch (Exception e) {
     
    135154    }
    136155
    137     private int lastJobsFetched = 0;
    138 
    139     public event EventHandler<EventArgs<StatusCommons>> SlaveStatusChanged;
     156    public event EventHandler<EventArgs<string>> UserVisibleMessageFired;
    140157    public void OnUserVisibleMessageFired(string msg) {
    141158      var handler = UserVisibleMessageFired;
     
    143160    }
    144161
    145     public event EventHandler<EventArgs<string>> UserVisibleMessageFired;
     162    public event EventHandler<EventArgs<SlaveDisplayStat>> SlaveDisplayStateChanged;
     163    public void OnSlaveDisplayStateChanged(StatusCommons status) {
     164      SlaveDisplayStat stat;
     165
     166      if (status.Jobs.Count > 0) {
     167        stat = SlaveDisplayStat.Busy;
     168      } else {
     169        stat = SlaveDisplayStat.Idle;
     170      }
     171      if (status.Asleep) {
     172        stat = SlaveDisplayStat.Asleep;
     173      }
     174      if (status.Status == NetworkEnum.WcfConnState.Disconnected || status.Status == NetworkEnum.WcfConnState.Failed) {
     175        stat = SlaveDisplayStat.Offline;
     176      }
     177
     178      var handler = SlaveDisplayStateChanged;
     179      if (handler != null) handler(this, new EventArgs<SlaveDisplayStat>(stat));
     180    }
     181
     182    public void OnSlaveDisplayStateChanged(SlaveDisplayStat stat) {
     183      var handler = SlaveDisplayStateChanged;
     184      if (handler != null) handler(this, new EventArgs<SlaveDisplayStat>(stat));
     185
     186    }
     187
     188    public event EventHandler<EventArgs<StatusCommons>> SlaveStatusChanged;
    146189    public void OnStatusChanged(StatusCommons status) {
    147190      var handler = SlaveStatusChanged;
    148191      if (handler != null) handler(this, new EventArgs<StatusCommons>(status));
    149192
     193      OnSlaveDisplayStateChanged(status);
     194
    150195      int diff = status.JobsFetched - lastJobsFetched;
    151196      lastJobsFetched = status.JobsFetched;
    152197      if (diff > 0) {
    153         OnUserVisibleMessageFired(string.Format("HeuristicLab Hive received {0} new jobs!", diff));
     198        if (diff == 1) {
     199          OnUserVisibleMessageFired("HeuristicLab Hive received 1 new job!");
     200        } else {
     201          OnUserVisibleMessageFired(string.Format("HeuristicLab Hive received {0} new jobs!", diff));
     202        }
    154203      }
    155204    }
     
    165214      var handler = SlaveShutdown;
    166215      if (handler != null) handler(this, EventArgs.Empty);
     216      OnSlaveDisplayStateChanged(SlaveDisplayStat.NoService);
     217    }
     218
     219    public event EventHandler<EventArgs<CoreConnection>> CoreConnectionChanged;
     220    public void OnCoreConnectionChanged(CoreConnection conn) {
     221      var handler = CoreConnectionChanged;
     222      if (handler != null) handler(this, new EventArgs<CoreConnection>(conn));
    167223    }
    168224
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Views/3.4/SlaveView.Designer.cs

    r6225 r6257  
    4545    /// </summary>
    4646    private void InitializeComponent() {
    47       System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea6 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
    48       System.Windows.Forms.DataVisualization.Charting.Legend legend6 = new System.Windows.Forms.DataVisualization.Charting.Legend();
     47      System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea3 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
     48      System.Windows.Forms.DataVisualization.Charting.CustomLabel customLabel5 = new System.Windows.Forms.DataVisualization.Charting.CustomLabel();
     49      System.Windows.Forms.DataVisualization.Charting.CustomLabel customLabel6 = new System.Windows.Forms.DataVisualization.Charting.CustomLabel();
     50      System.Windows.Forms.DataVisualization.Charting.CustomLabel customLabel7 = new System.Windows.Forms.DataVisualization.Charting.CustomLabel();
     51      System.Windows.Forms.DataVisualization.Charting.CustomLabel customLabel8 = new System.Windows.Forms.DataVisualization.Charting.CustomLabel();
     52      System.Windows.Forms.DataVisualization.Charting.Legend legend3 = new System.Windows.Forms.DataVisualization.Charting.Legend();
    4953      System.Windows.Forms.DataVisualization.Charting.Series series6 = new System.Windows.Forms.DataVisualization.Charting.Series();
    50       this.btnPauseAll = new System.Windows.Forms.Button();
    51       this.btnStopAll = new System.Windows.Forms.Button();
    52       this.btnRestart = new System.Windows.Forms.Button();
    53       this.btnSleep = new System.Windows.Forms.Button();
     54      System.Windows.Forms.DataVisualization.Charting.Series series7 = new System.Windows.Forms.DataVisualization.Charting.Series();
     55      System.Windows.Forms.DataVisualization.Charting.Series series8 = new System.Windows.Forms.DataVisualization.Charting.Series();
     56      System.Windows.Forms.DataVisualization.Charting.Series series9 = new System.Windows.Forms.DataVisualization.Charting.Series();
     57      System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea4 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
     58      System.Windows.Forms.DataVisualization.Charting.Legend legend4 = new System.Windows.Forms.DataVisualization.Charting.Legend();
     59      System.Windows.Forms.DataVisualization.Charting.Series series10 = new System.Windows.Forms.DataVisualization.Charting.Series();
    5460      this.jobChart = new System.Windows.Forms.DataVisualization.Charting.Chart();
    55       this.btnRestartService = new System.Windows.Forms.Button();
     61      this.coresChart = new System.Windows.Forms.DataVisualization.Charting.Chart();
     62      this.btnStart = new System.Windows.Forms.Button();
     63      this.btnStop = new System.Windows.Forms.Button();
     64      this.btnKill = new System.Windows.Forms.Button();
     65      this.lblSlaveState = new System.Windows.Forms.Label();
     66      this.label1 = new System.Windows.Forms.Label();
    5667      ((System.ComponentModel.ISupportInitialize)(this.jobChart)).BeginInit();
     68      ((System.ComponentModel.ISupportInitialize)(this.coresChart)).BeginInit();
    5769      this.SuspendLayout();
    5870      //
    59       // btnPauseAll
    60       //
    61       this.btnPauseAll.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
    62       this.btnPauseAll.Location = new System.Drawing.Point(476, 3);
    63       this.btnPauseAll.Name = "btnPauseAll";
    64       this.btnPauseAll.Size = new System.Drawing.Size(111, 28);
    65       this.btnPauseAll.TabIndex = 2;
    66       this.btnPauseAll.Text = "Pause all jobs";
    67       this.btnPauseAll.UseVisualStyleBackColor = true;
    68       this.btnPauseAll.Click += new System.EventHandler(this.btnSoftPause_Click);
    69       //
    70       // btnStopAll
    71       //
    72       this.btnStopAll.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
    73       this.btnStopAll.Location = new System.Drawing.Point(476, 32);
    74       this.btnStopAll.Name = "btnStopAll";
    75       this.btnStopAll.Size = new System.Drawing.Size(111, 28);
    76       this.btnStopAll.TabIndex = 3;
    77       this.btnStopAll.Text = "Stop all jobs";
    78       this.btnStopAll.UseVisualStyleBackColor = true;
    79       this.btnStopAll.Click += new System.EventHandler(this.btnHardPause_Click);
    80       //
    81       // btnRestart
    82       //
    83       this.btnRestart.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
    84       this.btnRestart.Location = new System.Drawing.Point(476, 90);
    85       this.btnRestart.Name = "btnRestart";
    86       this.btnRestart.Size = new System.Drawing.Size(111, 28);
    87       this.btnRestart.TabIndex = 4;
    88       this.btnRestart.Text = "Restart Core";
    89       this.btnRestart.UseVisualStyleBackColor = true;
    90       this.btnRestart.Click += new System.EventHandler(this.btnRestart_Click);
    91       //
    92       // btnSleep
    93       //
    94       this.btnSleep.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
    95       this.btnSleep.Location = new System.Drawing.Point(476, 61);
    96       this.btnSleep.Name = "btnSleep";
    97       this.btnSleep.Size = new System.Drawing.Size(111, 28);
    98       this.btnSleep.TabIndex = 5;
    99       this.btnSleep.Text = "Send slave to sleep";
    100       this.btnSleep.UseVisualStyleBackColor = true;
    101       this.btnSleep.Click += new System.EventHandler(this.btnSleep_Click);
    102       //
    10371      // jobChart
    10472      //
    105       chartArea6.Name = "ChartArea1";
    106       this.jobChart.ChartAreas.Add(chartArea6);
    107       legend6.Name = "Legend1";
    108       this.jobChart.Legends.Add(legend6);
    109       this.jobChart.Location = new System.Drawing.Point(3, 3);
     73      this.jobChart.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
     74      customLabel5.Text = "Jobs";
     75      customLabel6.Text = "Aborted Jobs";
     76      customLabel7.Text = "Finished Jobs";
     77      customLabel8.Text = "Fetched Jobs";
     78      chartArea3.AxisX.CustomLabels.Add(customLabel5);
     79      chartArea3.AxisX.CustomLabels.Add(customLabel6);
     80      chartArea3.AxisX.CustomLabels.Add(customLabel7);
     81      chartArea3.AxisX.CustomLabels.Add(customLabel8);
     82      chartArea3.AxisX.Enabled = System.Windows.Forms.DataVisualization.Charting.AxisEnabled.True;
     83      chartArea3.AxisX.MajorGrid.Enabled = false;
     84      chartArea3.AxisX.MajorTickMark.Enabled = false;
     85      chartArea3.Name = "ChartArea1";
     86      this.jobChart.ChartAreas.Add(chartArea3);
     87      legend3.Name = "Legend1";
     88      this.jobChart.Legends.Add(legend3);
     89      this.jobChart.Location = new System.Drawing.Point(0, 3);
    11090      this.jobChart.Name = "jobChart";
    11191      series6.ChartArea = "ChartArea1";
    112       series6.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Doughnut;
    11392      series6.Legend = "Legend1";
    11493      series6.Name = "Series1";
     94      series7.ChartArea = "ChartArea1";
     95      series7.Legend = "Legend1";
     96      series7.Name = "Series2";
     97      series8.ChartArea = "ChartArea1";
     98      series8.Legend = "Legend1";
     99      series8.Name = "Series3";
     100      series9.ChartArea = "ChartArea1";
     101      series9.Legend = "Legend1";
     102      series9.Name = "Series4";
    115103      this.jobChart.Series.Add(series6);
    116       this.jobChart.Size = new System.Drawing.Size(293, 174);
     104      this.jobChart.Series.Add(series7);
     105      this.jobChart.Series.Add(series8);
     106      this.jobChart.Series.Add(series9);
     107      this.jobChart.Size = new System.Drawing.Size(280, 156);
    117108      this.jobChart.TabIndex = 7;
    118109      //
    119       // btnRestartService
    120       //
    121       this.btnRestartService.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
    122       this.btnRestartService.Location = new System.Drawing.Point(476, 119);
    123       this.btnRestartService.Name = "btnRestartService";
    124       this.btnRestartService.Size = new System.Drawing.Size(111, 28);
    125       this.btnRestartService.TabIndex = 8;
    126       this.btnRestartService.Text = "RestartService";
    127       this.btnRestartService.UseVisualStyleBackColor = true;
    128       this.btnRestartService.Click += new System.EventHandler(this.btnRestartService_Click);
     110      // coresChart
     111      //
     112      chartArea4.Name = "ChartArea1";
     113      this.coresChart.ChartAreas.Add(chartArea4);
     114      legend4.Name = "Legend1";
     115      this.coresChart.Legends.Add(legend4);
     116      this.coresChart.Location = new System.Drawing.Point(3, 165);
     117      this.coresChart.Name = "coresChart";
     118      series10.ChartArea = "ChartArea1";
     119      series10.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie;
     120      series10.Legend = "Legend1";
     121      series10.Name = "Series1";
     122      this.coresChart.Series.Add(series10);
     123      this.coresChart.Size = new System.Drawing.Size(277, 135);
     124      this.coresChart.TabIndex = 9;
     125      //
     126      // btnStart
     127      //
     128      this.btnStart.Location = new System.Drawing.Point(467, 111);
     129      this.btnStart.Name = "btnStart";
     130      this.btnStart.Size = new System.Drawing.Size(75, 23);
     131      this.btnStart.TabIndex = 10;
     132      this.btnStart.Text = "Start";
     133      this.btnStart.UseVisualStyleBackColor = true;
     134      this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
     135      //
     136      // btnStop
     137      //
     138      this.btnStop.Location = new System.Drawing.Point(467, 82);
     139      this.btnStop.Name = "btnStop";
     140      this.btnStop.Size = new System.Drawing.Size(75, 23);
     141      this.btnStop.TabIndex = 11;
     142      this.btnStop.Text = "Stop";
     143      this.btnStop.UseVisualStyleBackColor = true;
     144      this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
     145      //
     146      // btnKill
     147      //
     148      this.btnKill.Location = new System.Drawing.Point(467, 53);
     149      this.btnKill.Name = "btnKill";
     150      this.btnKill.Size = new System.Drawing.Size(75, 23);
     151      this.btnKill.TabIndex = 12;
     152      this.btnKill.Text = "Kill";
     153      this.btnKill.UseVisualStyleBackColor = true;
     154      this.btnKill.Click += new System.EventHandler(this.btnKill_Click);
     155      //
     156      // lblSlaveState
     157      //
     158      this.lblSlaveState.Location = new System.Drawing.Point(370, 3);
     159      this.lblSlaveState.Name = "lblSlaveState";
     160      this.lblSlaveState.Size = new System.Drawing.Size(100, 23);
     161      this.lblSlaveState.TabIndex = 13;
     162      //
     163      // label1
     164      //
     165      this.label1.AutoSize = true;
     166      this.label1.Location = new System.Drawing.Point(286, 3);
     167      this.label1.Name = "label1";
     168      this.label1.Size = new System.Drawing.Size(62, 13);
     169      this.label1.TabIndex = 14;
     170      this.label1.Text = "Slave State";
    129171      //
    130172      // SlaveView
     
    132174      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    133175      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    134       this.Controls.Add(this.btnRestartService);
     176      this.Controls.Add(this.label1);
     177      this.Controls.Add(this.lblSlaveState);
     178      this.Controls.Add(this.btnKill);
     179      this.Controls.Add(this.btnStop);
     180      this.Controls.Add(this.btnStart);
     181      this.Controls.Add(this.coresChart);
    135182      this.Controls.Add(this.jobChart);
    136       this.Controls.Add(this.btnSleep);
    137       this.Controls.Add(this.btnRestart);
    138       this.Controls.Add(this.btnStopAll);
    139       this.Controls.Add(this.btnPauseAll);
    140183      this.Name = "SlaveView";
    141       this.Size = new System.Drawing.Size(590, 426);
     184      this.Size = new System.Drawing.Size(590, 313);
    142185      ((System.ComponentModel.ISupportInitialize)(this.jobChart)).EndInit();
     186      ((System.ComponentModel.ISupportInitialize)(this.coresChart)).EndInit();
    143187      this.ResumeLayout(false);
     188      this.PerformLayout();
    144189
    145190    }
     
    147192    #endregion
    148193
    149     private System.Windows.Forms.Button btnPauseAll;
    150     private System.Windows.Forms.Button btnStopAll;
    151     private System.Windows.Forms.Button btnRestart;
    152     private System.Windows.Forms.Button btnSleep;
    153194    private System.Windows.Forms.DataVisualization.Charting.Chart jobChart;
    154     private System.Windows.Forms.Button btnRestartService;
     195    private System.Windows.Forms.DataVisualization.Charting.Chart coresChart;
     196    private System.Windows.Forms.Button btnStart;
     197    private System.Windows.Forms.Button btnStop;
     198    private System.Windows.Forms.Button btnKill;
     199    private System.Windows.Forms.Label lblSlaveState;
     200    private System.Windows.Forms.Label label1;
    155201  }
    156202}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Views/3.4/SlaveView.cs

    r6225 r6257  
    2121
    2222using System;
     23using System.Diagnostics;
     24using System.Runtime.InteropServices;
    2325using System.Security.Principal;
    2426using System.ServiceProcess;
     
    4749    }
    4850
     51    private SlaveDisplayStat lastSlaveDisplayStat;
     52
     53    [DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)]
     54    static extern int SendMessage(IntPtr hWnd, UInt32 Msg, int wParam, IntPtr lParam);
     55
     56    const UInt32 BCM_SETSHIELD = 0x160C;
     57
    4958    public SlaveView() {
    5059      InitializeComponent();
    5160
    52       if (!CheckRunAsAdmin())
    53         btnRestartService.Enabled = false;
    54       btnRestart.Enabled = false;
    55 
     61      this.btnKill.FlatStyle = FlatStyle.System;
     62      SendMessage(btnKill.Handle, BCM_SETSHIELD, 0, (IntPtr)1);
     63
     64      lblSlaveState.Text = SlaveDisplayStat.NoService.ToString();
     65      btnKill.Enabled = false;
     66      btnStart.Enabled = false;
     67      btnStop.Enabled = false;
    5668    }
    5769
     
    6072      Content.SlaveShutdown -= new System.EventHandler(Content_SlaveShutdown);
    6173      Content.SlaveStatusChanged -= new System.EventHandler<EventArgs<StatusCommons>>(Content_SlaveStatusChanged);
     74      Content.SlaveDisplayStateChanged -= new EventHandler<EventArgs<SlaveDisplayStat>>(Content_SlaveDisplayStateChanged);
     75      Content.CoreConnectionChanged -= new EventHandler<EventArgs<CoreConnection>>(Content_CoreConnectionChanged);
    6276
    6377      base.DeregisterContentEvents();
     
    6983      Content.SlaveShutdown += new System.EventHandler(Content_SlaveShutdown);
    7084      Content.SlaveStatusChanged += new System.EventHandler<EventArgs<StatusCommons>>(Content_SlaveStatusChanged);
     85      Content.SlaveDisplayStateChanged += new EventHandler<EventArgs<SlaveDisplayStat>>(Content_SlaveDisplayStateChanged);
     86      Content.CoreConnectionChanged += new EventHandler<EventArgs<CoreConnection>>(Content_CoreConnectionChanged);
    7187    }
    7288    #endregion
     
    7490    protected override void OnContentChanged() {
    7591      base.OnContentChanged();
     92      btnKill.Enabled = false;
     93      btnStart.Enabled = false;
     94      btnStop.Enabled = false;
     95
    7696      if (Content == null) {
    77         //nothing to do...       
     97        //nothing to do...         
    7898      } else {
    7999        //try to establish a connection to the slave service
     
    104124    #region Event Handlers
    105125    void Content_SlaveStatusChanged(object sender, EventArgs<StatusCommons> e) {
    106       RenderChart(e.Value);
     126      RenderJobChart(e.Value);
     127      RenderCoreChart(e.Value);
    107128    }
    108129
     
    110131      Task.Factory.StartNew(Connector);
    111132    }
     133
     134    void Content_SlaveDisplayStateChanged(object sender, EventArgs<SlaveDisplayStat> e) {
     135      lblSlaveState.Text = e.Value.ToString();
     136      lastSlaveDisplayStat = e.Value;
     137
     138      if (e.Value == SlaveDisplayStat.Asleep || e.Value == SlaveDisplayStat.NoService) {
     139        btnKill.Enabled = false;
     140        btnStart.Enabled = true;
     141        btnStop.Enabled = false;
     142      }
     143
     144      if (e.Value == SlaveDisplayStat.Busy || e.Value == SlaveDisplayStat.Idle || e.Value == SlaveDisplayStat.Offline) {
     145        btnKill.Enabled = true;
     146        btnStart.Enabled = false;
     147        btnStop.Enabled = true;
     148      }
     149    }
     150
     151    void Content_CoreConnectionChanged(object sender, EventArgs<CoreConnection> e) {
     152      if (e.Value == CoreConnection.Offline) {
     153        btnKill.Enabled = false;
     154        btnStart.Enabled = false;
     155        btnStop.Enabled = false;
     156      }
     157    }
    112158    #endregion
    113159
    114     private void RenderChart(StatusCommons status) {
     160    private void RenderJobChart(StatusCommons status) {
    115161      jobChart.Series[0].Points.Clear();
    116 
    117       DataPoint pJobs = new DataPoint(status.Jobs.Count, status.Jobs.Count);
    118       DataPoint pJobsAborted = new DataPoint(status.JobsAborted, status.JobsAborted);
    119       DataPoint pJobsDone = new DataPoint(status.JobsFinished, status.JobsFinished);
    120       DataPoint pJobsFetched = new DataPoint(status.JobsFetched, status.JobsFetched);
     162      jobChart.Series[1].Points.Clear();
     163      jobChart.Series[2].Points.Clear();
     164      jobChart.Series[3].Points.Clear();
     165
     166      DataPoint pJobs = new DataPoint(1, status.Jobs.Count);
     167      DataPoint pJobsAborted = new DataPoint(2, status.JobsAborted);
     168      DataPoint pJobsDone = new DataPoint(3, status.JobsFinished);
     169      DataPoint pJobsFetched = new DataPoint(4, status.JobsFetched);
    121170
    122171      pJobs.LegendText = "Current jobs: " + status.Jobs.Count;
    123172      pJobs.Color = System.Drawing.Color.Orange;
     173      pJobs.ToolTip = pJobs.LegendText;
     174      jobChart.Series[0].LegendText = pJobs.LegendText;
     175      jobChart.Series[0].Points.Add(pJobs);
     176
    124177      pJobsAborted.LegendText = "Aborted jobs: " + status.JobsAborted;
    125178      pJobsAborted.Color = System.Drawing.Color.Red;
     179      pJobsAborted.ToolTip = pJobsAborted.LegendText;
     180      jobChart.Series[1].LegendText = pJobsAborted.LegendText;
     181      jobChart.Series[1].Points.Add(pJobsAborted);
     182
    126183      pJobsDone.LegendText = "Finished jobs: " + status.JobsFinished;
    127184      pJobsDone.Color = System.Drawing.Color.Green;
     185      pJobsDone.ToolTip = pJobsDone.LegendText;
     186      jobChart.Series[2].LegendText = pJobsDone.LegendText;
     187      jobChart.Series[2].Points.Add(pJobsDone);
     188
    128189      pJobsFetched.LegendText = "Fetched jobs: " + status.JobsFetched;
     190      pJobsFetched.ToolTip = pJobsFetched.LegendText;
    129191      pJobsFetched.Color = System.Drawing.Color.Blue;
    130 
    131       jobChart.Series[0].Points.Add(pJobs);
    132       jobChart.Series[0].Points.Add(pJobsAborted);
    133       jobChart.Series[0].Points.Add(pJobsDone);
    134       jobChart.Series[0].Points.Add(pJobsFetched);
    135     }
    136 
    137     private void btnSoftPause_Click(object sender, System.EventArgs e) {
    138       if (Content != null)
    139         Content.PauseAll();
    140     }
    141 
    142     private void btnHardPause_Click(object sender, System.EventArgs e) {
    143       if (Content != null)
    144         Content.StopAll();
    145     }
    146 
    147     private void btnRestart_Click(object sender, System.EventArgs e) {
    148       if (Content != null) {
    149         Content.RestartCore();
    150         btnRestart.Enabled = false;
    151         btnSleep.Enabled = true;
    152       }
    153     }
    154 
    155     private void btnSleep_Click(object sender, System.EventArgs e) {
    156       if (Content != null) {
    157         Content.Sleep();
    158         btnRestart.Enabled = true;
    159         btnSleep.Enabled = false;
    160       }
    161     }
    162 
    163     private void btnRestartService_Click(object sender, EventArgs e) {
    164       if (CheckRunAsAdmin()) {
    165         RestartService();
    166       } else {
    167         MessageBox.Show("You need to run this application as Administrator to restart the service");
    168       }
     192      jobChart.Series[3].LegendText = pJobsFetched.LegendText;
     193      jobChart.Series[3].Points.Add(pJobsFetched);
     194    }
     195
     196    private void RenderCoreChart(StatusCommons statusCommons) {
     197      int usedCores = statusCommons.TotalCores - statusCommons.FreeCores;
     198      DataPoint pFreeCores = new DataPoint(statusCommons.FreeCores, statusCommons.FreeCores);
     199      DataPoint pUsedCores = new DataPoint(usedCores, usedCores);
     200
     201      coresChart.Series[0].Points.Clear();
     202
     203      pFreeCores.LegendText = "Free cores: " + statusCommons.FreeCores;
     204      pFreeCores.Color = System.Drawing.Color.Green;
     205      pUsedCores.LegendText = "Used cores: " + usedCores;
     206      pUsedCores.Color = System.Drawing.Color.Red;
     207
     208      coresChart.Series[0].Points.Add(pFreeCores);
     209      coresChart.Series[0].Points.Add(pUsedCores);
    169210    }
    170211
     
    181222    }
    182223
    183     private void RestartService() {
     224    private void ElevateApplication() {
     225      // Launch itself as administrator
     226      ProcessStartInfo proc = new ProcessStartInfo(Application.ExecutablePath, "showui");
     227      proc.UseShellExecute = true;
     228      proc.WorkingDirectory = Environment.CurrentDirectory;
     229      proc.FileName = Application.ExecutablePath;
     230      proc.Verb = "runas";
     231
     232      try {
     233        Process.Start(proc);
     234      }
     235      catch {
     236        // The user refused to allow privileges elevation.
     237        // Do nothing and return directly ...
     238        return;
     239      }
     240      Application.Exit();  // Quit itself
     241    }
     242
     243    private void StartService() {
    184244      string serviceName = "HeuristicLab.Clients.Hive.SlaveCore.SlaveWindowsService";
    185245      TimeSpan timeout = TimeSpan.FromMilliseconds(5000);
     
    202262      }
    203263    }
     264
     265    private void StopService() {
     266      string serviceName = "HeuristicLab.Clients.Hive.SlaveCore.SlaveWindowsService";
     267      TimeSpan timeout = TimeSpan.FromMilliseconds(5000);
     268
     269      ServiceController service = new ServiceController(serviceName);
     270      try {
     271        if (service.Status == ServiceControllerStatus.Running) {
     272          service.Stop();
     273          service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
     274        }
     275      }
     276      catch (InvalidOperationException ex) {
     277        MessageBox.Show("Error starting service: Hive Slave Service not found!" + Environment.NewLine + ex.ToString());
     278      }
     279      catch (Exception ex) {
     280        MessageBox.Show("Error starting service, exception is: " + Environment.NewLine + ex.ToString());
     281      }
     282    }
     283
     284    private void btnKill_Click(object sender, EventArgs e) {
     285      if (CheckRunAsAdmin()) {
     286        StopService();
     287      } else {
     288        ElevateApplication();
     289      }
     290
     291    }
     292
     293    private void btnStop_Click(object sender, EventArgs e) {
     294      if (Content != null) {
     295        Content.Sleep();
     296      }
     297    }
     298
     299    private void btnStart_Click(object sender, EventArgs e) {
     300      if (Content != null) {
     301        if (lastSlaveDisplayStat == SlaveDisplayStat.Asleep) {
     302          Content.RestartCore();
     303        } else if (lastSlaveDisplayStat == SlaveDisplayStat.NoService) {
     304          if (CheckRunAsAdmin()) {
     305            StartService();
     306          } else {
     307            ElevateApplication();
     308          }
     309        }
     310      }
     311    }
    204312  }
    205313}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/ConfigManager.cs

    r6216 r6257  
    4141    }
    4242
     43    /// <summary>
     44    /// if the Sleeping is true, the Slave won't accept any new jobs
     45    /// </summary>
     46    public bool Asleep { get; set; }
     47
    4348    public Core Core { get; set; }
    4449    private Slave slave;
     
    4853    /// </summary>
    4954    private ConfigManager() {
     55      Asleep = false;
    5056      slave = new Slave();
    5157      slave.Id = GetUniqueMachineId();
     
    8490      st.TotalCores = slave.Cores.HasValue ? slave.Cores.Value : 0;
    8591      st.FreeCores = GetFreeCores();
     92      st.Asleep = ConfigManager.Instance.Asleep;
    8693
    8794      st.JobsAborted = SlaveStatusInfo.JobsAborted;
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Core.cs

    r6248 r6257  
    365365    private void DoStartSlave() {
    366366      clientCom.LogMessage("Restart received");
    367       StartHeartbeats();
     367      ConfigManager.Instance.Asleep = false;
    368368      clientCom.LogMessage("Restart done");
    369369    }
     
    374374    /// </summary>   
    375375    private void Sleep() {
    376       clientCom.LogMessage("Sleep received");
    377       heartbeatManager.StopHeartBeat();
    378       heartbeatManager = null;
    379       DoStopAll();
    380       WcfService.Instance.Disconnect();
    381       clientCom.LogMessage("Sleep done");
     376      clientCom.LogMessage("Sleep received - not accepting any new jobs");
     377      ConfigManager.Instance.Asleep = true;
     378      DoPauseAll(); //TODO: or stop? can't decide...     
    382379    }
    383380
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/HeartbeatManager.cs

    r6203 r6257  
    9292                FreeMemory = ConfigManager.GetFreeMemory(),
    9393                JobProgress = ConfigManager.Instance.GetExecutionTimeOfAllJobs(),
    94                 AssignJob = true //TODO: check if we want another job
     94                AssignJob = !ConfigManager.Instance.Asleep
    9595              };
    9696
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/StatusCommons.cs

    r6203 r6257  
    5050    [DataMember]
    5151    public List<JobStatus> Jobs { get; set; }
     52    [DataMember]
     53    public bool Asleep { get; set; }
    5254
    5355    public override string ToString() {
Note: See TracChangeset for help on using the changeset viewer.