- Timestamp:
- 05/23/11 21:31:48 (13 years ago)
- 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
r6225 r6257 28 28 namespace HeuristicLab.Clients.Hive.SlaveCore.Views { 29 29 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 30 44 [CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)] 31 45 [Item("SlaveItem", "Represents a slave which receives messages from the core")] … … 33 47 private ISlaveCommunication pipeProxy; 34 48 private DuplexChannelFactory<ISlaveCommunication> pipeFactory; 49 private int lastJobsFetched = 0; 35 50 36 51 public SlaveItem() { … … 51 66 void pipeFactory_Opened(object sender, EventArgs e) { 52 67 OnMessageLogged("Connection to Slave core established"); 68 OnCoreConnectionChanged(CoreConnection.Connected); 53 69 } 54 70 55 71 void pipeFactory_Closed(object sender, EventArgs e) { 56 72 OnMessageLogged("Connection to Slave core closed"); 73 OnCoreConnectionChanged(CoreConnection.Offline); 57 74 } 58 75 59 76 void pipeFactory_Faulted(object sender, EventArgs e) { 60 77 OnMessageLogged("Connection to Slave core faulted"); 78 OnCoreConnectionChanged(CoreConnection.Offline); 61 79 } 62 80 … … 120 138 public void Sleep() { 121 139 try { 122 if (pipeFactory.State != CommunicationState.Faulted && pipeFactory.State != CommunicationState.Closed) 140 if (pipeFactory.State != CommunicationState.Faulted && pipeFactory.State != CommunicationState.Closed) { 123 141 pipeProxy.Sleep(); 142 } 124 143 } 125 144 catch (Exception e) { … … 135 154 } 136 155 137 private int lastJobsFetched = 0; 138 139 public event EventHandler<EventArgs<StatusCommons>> SlaveStatusChanged; 156 public event EventHandler<EventArgs<string>> UserVisibleMessageFired; 140 157 public void OnUserVisibleMessageFired(string msg) { 141 158 var handler = UserVisibleMessageFired; … … 143 160 } 144 161 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; 146 189 public void OnStatusChanged(StatusCommons status) { 147 190 var handler = SlaveStatusChanged; 148 191 if (handler != null) handler(this, new EventArgs<StatusCommons>(status)); 149 192 193 OnSlaveDisplayStateChanged(status); 194 150 195 int diff = status.JobsFetched - lastJobsFetched; 151 196 lastJobsFetched = status.JobsFetched; 152 197 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 } 154 203 } 155 204 } … … 165 214 var handler = SlaveShutdown; 166 215 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)); 167 223 } 168 224 -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Views/3.4/SlaveView.Designer.cs
r6225 r6257 45 45 /// </summary> 46 46 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(); 49 53 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(); 54 60 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(); 56 67 ((System.ComponentModel.ISupportInitialize)(this.jobChart)).BeginInit(); 68 ((System.ComponentModel.ISupportInitialize)(this.coresChart)).BeginInit(); 57 69 this.SuspendLayout(); 58 70 // 59 // btnPauseAll60 //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 // btnStopAll71 //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 // btnRestart82 //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 // btnSleep93 //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 //103 71 // jobChart 104 72 // 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); 110 90 this.jobChart.Name = "jobChart"; 111 91 series6.ChartArea = "ChartArea1"; 112 series6.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Doughnut;113 92 series6.Legend = "Legend1"; 114 93 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"; 115 103 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); 117 108 this.jobChart.TabIndex = 7; 118 109 // 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"; 129 171 // 130 172 // SlaveView … … 132 174 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 133 175 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); 135 182 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);140 183 this.Name = "SlaveView"; 141 this.Size = new System.Drawing.Size(590, 426);184 this.Size = new System.Drawing.Size(590, 313); 142 185 ((System.ComponentModel.ISupportInitialize)(this.jobChart)).EndInit(); 186 ((System.ComponentModel.ISupportInitialize)(this.coresChart)).EndInit(); 143 187 this.ResumeLayout(false); 188 this.PerformLayout(); 144 189 145 190 } … … 147 192 #endregion 148 193 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;153 194 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; 155 201 } 156 202 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Views/3.4/SlaveView.cs
r6225 r6257 21 21 22 22 using System; 23 using System.Diagnostics; 24 using System.Runtime.InteropServices; 23 25 using System.Security.Principal; 24 26 using System.ServiceProcess; … … 47 49 } 48 50 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 49 58 public SlaveView() { 50 59 InitializeComponent(); 51 60 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; 56 68 } 57 69 … … 60 72 Content.SlaveShutdown -= new System.EventHandler(Content_SlaveShutdown); 61 73 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); 62 76 63 77 base.DeregisterContentEvents(); … … 69 83 Content.SlaveShutdown += new System.EventHandler(Content_SlaveShutdown); 70 84 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); 71 87 } 72 88 #endregion … … 74 90 protected override void OnContentChanged() { 75 91 base.OnContentChanged(); 92 btnKill.Enabled = false; 93 btnStart.Enabled = false; 94 btnStop.Enabled = false; 95 76 96 if (Content == null) { 77 //nothing to do... 97 //nothing to do... 78 98 } else { 79 99 //try to establish a connection to the slave service … … 104 124 #region Event Handlers 105 125 void Content_SlaveStatusChanged(object sender, EventArgs<StatusCommons> e) { 106 RenderChart(e.Value); 126 RenderJobChart(e.Value); 127 RenderCoreChart(e.Value); 107 128 } 108 129 … … 110 131 Task.Factory.StartNew(Connector); 111 132 } 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 } 112 158 #endregion 113 159 114 private void Render Chart(StatusCommons status) {160 private void RenderJobChart(StatusCommons status) { 115 161 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); 121 170 122 171 pJobs.LegendText = "Current jobs: " + status.Jobs.Count; 123 172 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 124 177 pJobsAborted.LegendText = "Aborted jobs: " + status.JobsAborted; 125 178 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 126 183 pJobsDone.LegendText = "Finished jobs: " + status.JobsFinished; 127 184 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 128 189 pJobsFetched.LegendText = "Fetched jobs: " + status.JobsFetched; 190 pJobsFetched.ToolTip = pJobsFetched.LegendText; 129 191 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); 169 210 } 170 211 … … 181 222 } 182 223 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() { 184 244 string serviceName = "HeuristicLab.Clients.Hive.SlaveCore.SlaveWindowsService"; 185 245 TimeSpan timeout = TimeSpan.FromMilliseconds(5000); … … 202 262 } 203 263 } 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 } 204 312 } 205 313 }
Note: See TracChangeset
for help on using the changeset viewer.