Skip to content

Commit

Permalink
Highlight current operation
Browse files Browse the repository at this point in the history
  • Loading branch information
riuson committed Feb 27, 2020
1 parent bf88e97 commit b419aaa
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Pauser/Logic/Implementations/BatchOperationControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ private void Execute() {
}

private void ExecuteOperation(IBatchOperation operation) {
this.ReportProgress(operation);

switch (operation.Operation) {
case Operation.DisableNetworks: {
this._adaptersControl.Disable();
Expand Down
38 changes: 32 additions & 6 deletions Pauser/UI/ControlCombined.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
using Pauser.Logic.Interfaces;
using System;
using System.Data;
using System.Drawing;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Message = System.Tuple<int, string>;

namespace Pauser.UI {
public partial class ControlCombined : UserControl {
private readonly IBatchOperationControl _batchOperationControl;
private readonly IBatchOperationActual _batchOperationActual;
private IProgress<Message> _progress;
private CommandLink _commandStart;
private TaskScheduler _contextUI;

public ControlCombined(
IBatchOperationControl batchOperationControl,
Expand All @@ -30,22 +33,45 @@ private void CreateUI() {
this._commandStart.Click += this.StartSequence;
this.tableLayoutPanel1.Controls.Add(this._commandStart, 1, 0);

this._progress = new Progress<Message>(this.ProgressHandler);

this.ColumnOperation.DataSource = Enum.GetValues(typeof(Operation));
this.dataGridView1.AutoGenerateColumns = false;
this.dataGridView1.DataSource = this._batchOperationActual.Operations;

this._contextUI = TaskScheduler.FromCurrentSynchronizationContext();
this._batchOperationControl.Progress += BatchOperationControlOnProgress;
}

private async void StartSequence(object sender, EventArgs e) {
this._commandStart.Enabled = false;
await this._batchOperationControl.ExecuteAsync();
this.HighlightOperationRemove();
this._commandStart.Enabled = true;
}

private void ProgressHandler(Message msg) {
//this.progressBar.Value = msg.Item1;
//this.labelStatus.Text = msg.Item2;
private void BatchOperationControlOnProgress(object sender, BatchOperationsProgress e) =>
Task.Factory.StartNew(o => this.HighlightOperation((IBatchOperation)o), e.Operation, CancellationToken.None, TaskCreationOptions.None, this._contextUI);

private void HighlightOperation(IBatchOperation operation) {
foreach (DataGridViewRow dataGridViewRow in this.dataGridView1.Rows) {
if (dataGridViewRow.DataBoundItem is IBatchOperation rowOperation) {
if (rowOperation.Id == operation.Id) {
dataGridViewRow.DefaultCellStyle.BackColor = Color.Blue;
dataGridViewRow.DefaultCellStyle.ForeColor = Color.White;
} else {
dataGridViewRow.DefaultCellStyle.BackColor = Color.White;
dataGridViewRow.DefaultCellStyle.ForeColor = Color.Black;
}
}
}
}

private void HighlightOperationRemove() {
foreach (DataGridViewRow dataGridViewRow in this.dataGridView1.Rows) {
if (dataGridViewRow.DataBoundItem is IBatchOperation rowOperation) {
dataGridViewRow.DefaultCellStyle.BackColor = Color.White;
dataGridViewRow.DefaultCellStyle.ForeColor = Color.Black;
}
}
}
}
}

0 comments on commit b419aaa

Please sign in to comment.