mirror of
https://github.com/terrymacdonald/DisplayMagician.git
synced 2024-08-30 18:32:20 +00:00
[WIP] DisplayUI works but needs error handling
DisplayUI is mostly working but it needs some work fixing the error situations when the PathInfo can't be applied properly. Need a way of setting the Task result from the Task Action. Don't know how to do that so something new to learn!
This commit is contained in:
@ -27,6 +27,7 @@ using System.Net.NetworkInformation;
|
|||||||
using NvAPIWrapper.Mosaic;
|
using NvAPIWrapper.Mosaic;
|
||||||
using NvAPIWrapper.Native.Mosaic;
|
using NvAPIWrapper.Native.Mosaic;
|
||||||
|
|
||||||
|
|
||||||
namespace HeliosPlus.Shared
|
namespace HeliosPlus.Shared
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -353,22 +353,53 @@ namespace HeliosPlus {
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// Now lets prepare changing the display topology task
|
||||||
|
Task applyTopologyTask = new Task(() =>
|
||||||
|
{
|
||||||
|
Console.WriteLine("Program/ApplyProfile : Applying Profile Topology " + profile.Name);
|
||||||
|
if (!ProfileRepository.ApplyTopology(profile))
|
||||||
|
{
|
||||||
|
// Somehow return that this profile topology didn't apply
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Task applyPathInfoTask = new Task(() => {
|
||||||
|
Console.WriteLine("Program/ApplyProfile : Applying Profile Path " + profile.Name);
|
||||||
|
if (!ProfileRepository.ApplyPathInfo(profile))
|
||||||
|
{
|
||||||
|
// Somehow return that this profile path info didn't apply
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
// Set up the UI forms to show
|
// Set up the UI forms to show
|
||||||
ApplyingProfileForm timeoutForm = new ApplyingProfileForm(3, 0, $"Applying Profile '{profile.Name}'", $"Press ESC to timeout");
|
ApplyingProfileForm timeoutForm = new ApplyingProfileForm(null, 3, $"Applying Profile '{profile.Name}'", "Press ESC to cancel!", Color.Blue, true);
|
||||||
ApplyingProfileForm topologyForm = new ApplyingProfileForm(0, 30, $"Applying Profile '{profile.Name}' Topology");
|
ApplyingProfileForm topologyForm = new ApplyingProfileForm(applyTopologyTask, 30, $"Applying Profile '{profile.Name}' Topology", "Step one of two...", Color.Red);
|
||||||
ApplyingProfileForm pathInfoForm = new ApplyingProfileForm(0, 30, $"Applying Profile '{profile.Name}' Path");
|
ApplyingProfileForm pathInfoForm = new ApplyingProfileForm(applyPathInfoTask, 30, $"Applying Profile '{profile.Name}' Path", "Step two of two...", Color.Green);
|
||||||
|
|
||||||
|
if (timeoutForm.ShowDialog() == DialogResult.Cancel)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
topologyForm.ShowDialog();
|
topologyForm.ShowDialog();
|
||||||
// Now lets start by changing the display topology
|
|
||||||
Task applyTopologyTask = Task.Run(() =>
|
|
||||||
{
|
|
||||||
Console.WriteLine("ProfileRepository/SaveShortcutIconToCache : Applying Profile Topology " + profile.Name);
|
|
||||||
ProfileRepository.ApplyTopology(profile);
|
|
||||||
});
|
|
||||||
applyTopologyTask.Wait();
|
applyTopologyTask.Wait();
|
||||||
topologyForm.Close();
|
|
||||||
|
|
||||||
if (applyTopologyTask.IsCompleted)
|
if (applyTopologyTask.IsFaulted)
|
||||||
|
Console.WriteLine("Program/ApplyProfile : Applying Profile Topology stage failed to complete");
|
||||||
|
|
||||||
|
pathInfoForm.ShowDialog();
|
||||||
|
applyPathInfoTask.Wait();
|
||||||
|
|
||||||
|
if (applyPathInfoTask.IsFaulted)
|
||||||
|
Console.WriteLine("Program/ApplyProfile : Applying Profile PathInfo stage failed to complete");
|
||||||
|
|
||||||
|
if (applyTopologyTask.IsCompleted && applyPathInfoTask.IsCompleted)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/* if (applyTopologyTask.IsCompleted)
|
||||||
{
|
{
|
||||||
pathInfoForm.ShowDialog();
|
pathInfoForm.ShowDialog();
|
||||||
Task applyPathInfoTask = Task.Run(() => {
|
Task applyPathInfoTask = Task.Run(() => {
|
||||||
@ -389,7 +420,7 @@ namespace HeliosPlus {
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -34,7 +34,6 @@
|
|||||||
this.progressBar = new CircularProgressBar.CircularProgressBar();
|
this.progressBar = new CircularProgressBar.CircularProgressBar();
|
||||||
this.lbl_message = new System.Windows.Forms.Label();
|
this.lbl_message = new System.Windows.Forms.Label();
|
||||||
this.t_countdown = new System.Windows.Forms.Timer(this.components);
|
this.t_countdown = new System.Windows.Forms.Timer(this.components);
|
||||||
this.t_cancellation = new System.Windows.Forms.Timer(this.components);
|
|
||||||
this.progressPanel.SuspendLayout();
|
this.progressPanel.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -105,11 +104,6 @@
|
|||||||
this.t_countdown.Interval = 1000;
|
this.t_countdown.Interval = 1000;
|
||||||
this.t_countdown.Tick += new System.EventHandler(this.t_countdown_Tick);
|
this.t_countdown.Tick += new System.EventHandler(this.t_countdown_Tick);
|
||||||
//
|
//
|
||||||
// t_cancellation
|
|
||||||
//
|
|
||||||
this.t_cancellation.Interval = 1000;
|
|
||||||
this.t_cancellation.Tick += new System.EventHandler(this.t_cancellation_Tick);
|
|
||||||
//
|
|
||||||
// ApplyingProfileForm
|
// ApplyingProfileForm
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
@ -144,6 +138,5 @@
|
|||||||
private System.Windows.Forms.Label lbl_sub_message;
|
private System.Windows.Forms.Label lbl_sub_message;
|
||||||
private System.Windows.Forms.Label lbl_message;
|
private System.Windows.Forms.Label lbl_message;
|
||||||
private System.Windows.Forms.Timer t_countdown;
|
private System.Windows.Forms.Timer t_countdown;
|
||||||
private System.Windows.Forms.Timer t_cancellation;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -21,7 +21,6 @@ namespace HeliosPlus.UIForms
|
|||||||
private int _displayChangeDelta;
|
private int _displayChangeDelta;
|
||||||
private int _lastCount;
|
private int _lastCount;
|
||||||
private bool _isClosing;
|
private bool _isClosing;
|
||||||
private int _cancellationCounter;
|
|
||||||
|
|
||||||
public ApplyingProfileForm()
|
public ApplyingProfileForm()
|
||||||
{
|
{
|
||||||
@ -34,21 +33,25 @@ namespace HeliosPlus.UIForms
|
|||||||
Reposition();
|
Reposition();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApplyingProfileForm(int cancellationTimeout = 0, int countdown = 0, string title = null, string message = null, int displayChangeMaxDelta = 5) : this()
|
public ApplyingProfileForm(Task taskToRun = null, int countdown = 0, string title = null, string message = null, Color progressColor = default(Color), bool cancellable = false, int displayChangeMaxDelta = 5) : this()
|
||||||
{
|
{
|
||||||
_cancellationCounter = cancellationTimeout;
|
|
||||||
_countdownCounter = countdown;
|
_countdownCounter = countdown;
|
||||||
_lastCount = _countdownCounter;
|
_lastCount = _countdownCounter;
|
||||||
_displayChangeMaxDelta = displayChangeMaxDelta;
|
_displayChangeMaxDelta = displayChangeMaxDelta;
|
||||||
if (!string.IsNullOrEmpty(title)) CountdownTitle = title;
|
Cancellable = cancellable;
|
||||||
if (!string.IsNullOrEmpty(message)) CountdownMessage = message;
|
TaskToRun = taskToRun;
|
||||||
|
if (progressColor.Equals(default(Color)))
|
||||||
|
progressColor = Color.Red;
|
||||||
|
ProgressColor = progressColor;
|
||||||
|
if (!string.IsNullOrEmpty(title)) Title = title;
|
||||||
|
if (!string.IsNullOrEmpty(message)) Message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string CancellationTitle { get; set; } = "Starting in ...";
|
public string Title { get; set; } = "Please wait...";
|
||||||
public string CancellationMessage { get; set; } = "Please press ESC to cancel";
|
public string Message { get; set; } = "It won't be long now!";
|
||||||
|
public Color ProgressColor { get; set; } = Color.OrangeRed;
|
||||||
public string CountdownTitle { get; set; } = "Please wait...";
|
public bool Cancellable{ get; set; } = false;
|
||||||
public string CountdownMessage { get; set; } = "It won't be long now!";
|
public Task TaskToRun { get; set; } = null;
|
||||||
|
|
||||||
protected override void OnKeyDown(KeyEventArgs e)
|
protected override void OnKeyDown(KeyEventArgs e)
|
||||||
{
|
{
|
||||||
@ -77,9 +80,8 @@ namespace HeliosPlus.UIForms
|
|||||||
return base.ProcessCmdKey(ref msg, keyData);
|
return base.ProcessCmdKey(ref msg, keyData);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t_cancellation.Enabled)
|
if (Cancellable)
|
||||||
{
|
{
|
||||||
t_cancellation.Stop();
|
|
||||||
t_countdown.Stop();
|
t_countdown.Stop();
|
||||||
DialogResult = DialogResult.Cancel;
|
DialogResult = DialogResult.Cancel;
|
||||||
Close();
|
Close();
|
||||||
@ -106,11 +108,13 @@ namespace HeliosPlus.UIForms
|
|||||||
{
|
{
|
||||||
if (_countdownCounter > 0)
|
if (_countdownCounter > 0)
|
||||||
{
|
{
|
||||||
lbl_message.Text = CountdownTitle;
|
lbl_message.Text = Title;
|
||||||
lbl_sub_message.Text = CountdownMessage;
|
lbl_sub_message.Text = Message;
|
||||||
progressBar.ProgressColor = Color.OrangeRed;
|
progressBar.ProgressColor = ProgressColor;
|
||||||
progressBar.Text = (progressBar.Value = progressBar.Maximum = _countdownCounter).ToString();
|
progressBar.Text = (progressBar.Value = progressBar.Maximum = _countdownCounter).ToString();
|
||||||
t_countdown.Start();
|
t_countdown.Start();
|
||||||
|
if (TaskToRun is Task)
|
||||||
|
TaskToRun.Start();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -119,6 +123,8 @@ namespace HeliosPlus.UIForms
|
|||||||
progressBar.Maximum = 100;
|
progressBar.Maximum = 100;
|
||||||
progressBar.Value = 50;
|
progressBar.Value = 50;
|
||||||
progressBar.Style = ProgressBarStyle.Marquee;
|
progressBar.Style = ProgressBarStyle.Marquee;
|
||||||
|
if (TaskToRun is Task)
|
||||||
|
TaskToRun.Start();
|
||||||
DialogResult = DialogResult.OK;
|
DialogResult = DialogResult.OK;
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
@ -126,23 +132,6 @@ namespace HeliosPlus.UIForms
|
|||||||
HandleDisplayChangeDelta();
|
HandleDisplayChangeDelta();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DoCancellationTimeout()
|
|
||||||
{
|
|
||||||
if (_cancellationCounter > 0)
|
|
||||||
{
|
|
||||||
lbl_message.Text = CancellationTitle;
|
|
||||||
lbl_sub_message.Text = CancellationMessage;
|
|
||||||
progressBar.ProgressColor = Color.DodgerBlue;
|
|
||||||
progressBar.Text = (progressBar.Value = progressBar.Maximum = _cancellationCounter).ToString();
|
|
||||||
t_cancellation.Start();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DoCountdown();
|
|
||||||
}
|
|
||||||
HandleDisplayChangeDelta();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Reposition()
|
private void Reposition()
|
||||||
{
|
{
|
||||||
lock (_progressPositions)
|
lock (_progressPositions)
|
||||||
@ -213,7 +202,7 @@ namespace HeliosPlus.UIForms
|
|||||||
Console.WriteLine($"ApplyingProfileForm/ApplyingProfileForm_Shown exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
|
Console.WriteLine($"ApplyingProfileForm/ApplyingProfileForm_Shown exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
|
||||||
// ignored
|
// ignored
|
||||||
}
|
}
|
||||||
}, this), new SafeInvoker(DoCancellationTimeout, this));
|
}, this), new SafeInvoker(DoCountdown, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void t_countdown_Tick(object sender, EventArgs e)
|
private void t_countdown_Tick(object sender, EventArgs e)
|
||||||
@ -235,22 +224,6 @@ namespace HeliosPlus.UIForms
|
|||||||
Reposition();
|
Reposition();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void t_cancellation_Tick(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (_cancellationCounter < 0)
|
|
||||||
{
|
|
||||||
t_cancellation.Stop();
|
|
||||||
DoCountdown();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
progressBar.Value = _cancellationCounter;
|
|
||||||
progressBar.Text = progressBar.Value.ToString();
|
|
||||||
_cancellationCounter--;
|
|
||||||
Reposition();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void WndProc(ref Message m)
|
protected override void WndProc(ref Message m)
|
||||||
{
|
{
|
||||||
const int WM_SETTINGCHANGE = 0x001A;
|
const int WM_SETTINGCHANGE = 0x001A;
|
||||||
|
@ -120,7 +120,4 @@
|
|||||||
<metadata name="t_countdown.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
<metadata name="t_countdown.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
<value>143, 17</value>
|
<value>143, 17</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="t_cancellation.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
|
||||||
<value>17, 17</value>
|
|
||||||
</metadata>
|
|
||||||
</root>
|
</root>
|
Reference in New Issue
Block a user