[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:
Terry MacDonald
2020-10-05 00:18:22 +13:00
parent 17cc302d17
commit 3847bae972
5 changed files with 68 additions and 73 deletions

View File

@ -353,22 +353,53 @@ namespace HeliosPlus {
try
{
// Set up the UI forms to show
ApplyingProfileForm timeoutForm = new ApplyingProfileForm(3, 0, $"Applying Profile '{profile.Name}'", $"Press ESC to timeout");
ApplyingProfileForm topologyForm = new ApplyingProfileForm(0, 30, $"Applying Profile '{profile.Name}' Topology");
ApplyingProfileForm pathInfoForm = new ApplyingProfileForm(0, 30, $"Applying Profile '{profile.Name}' Path");
topologyForm.ShowDialog();
// Now lets start by changing the display topology
Task applyTopologyTask = Task.Run(() =>
// Now lets prepare changing the display topology task
Task applyTopologyTask = new Task(() =>
{
Console.WriteLine("ProfileRepository/SaveShortcutIconToCache : Applying Profile Topology " + profile.Name);
ProfileRepository.ApplyTopology(profile);
Console.WriteLine("Program/ApplyProfile : Applying Profile Topology " + profile.Name);
if (!ProfileRepository.ApplyTopology(profile))
{
// Somehow return that this profile topology didn't apply
}
});
applyTopologyTask.Wait();
topologyForm.Close();
if (applyTopologyTask.IsCompleted)
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
ApplyingProfileForm timeoutForm = new ApplyingProfileForm(null, 3, $"Applying Profile '{profile.Name}'", "Press ESC to cancel!", Color.Blue, true);
ApplyingProfileForm topologyForm = new ApplyingProfileForm(applyTopologyTask, 30, $"Applying Profile '{profile.Name}' Topology", "Step one of two...", Color.Red);
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();
applyTopologyTask.Wait();
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();
Task applyPathInfoTask = Task.Run(() => {
@ -389,7 +420,7 @@ namespace HeliosPlus {
{
return false;
}
*/
}
catch (Exception ex)