This repository has been archived by the owner on Nov 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExternalProcessTab.cs
115 lines (99 loc) · 2.44 KB
/
ExternalProcessTab.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SDA_DonationTracker
{
public partial class ExternalProcessTab : UserControl, ITab
{
public Func<ExternalProcessContext> ProcessFactory
{
get;
set;
}
public String TaskName
{
get;
set;
}
private ExternalProcessContext Process;
public ExternalProcessTab()
{
InitializeComponent();
this.EndProcess();
}
public void StartProcess()
{
this.ControlButton.Text = "Abort";
this.ControlButton.Click -= this.StartProcessEvent;
this.ControlButton.Click += this.AbortProcessEvent;
this.StatusLabel.Text = "Running...";
this.Process = this.ProcessFactory();
this.Process.OnComplete += this.OnComplete;
this.Process.OnError += this.OnError;
this.Process.Begin();
this.ProgressBar.Style = ProgressBarStyle.Marquee;
this.ProgressBar.Value = 100;
}
private void StartProcessEvent(object o, EventArgs e)
{
this.StartProcess();
}
private void EndProcess()
{
if (this.Process != null)
{
this.Process.OnComplete -= this.OnComplete;
this.Process.OnError -= this.OnError;
}
this.ControlButton.InvokeEx(() =>
{
this.ControlButton.Click -= this.AbortProcessEvent;
this.ControlButton.Click += this.StartProcessEvent;
this.ControlButton.Text = "Begin";
this.ProgressBar.Style = ProgressBarStyle.Continuous;
this.ProgressBar.Value = 0;
});
}
private void AbortProcessEvent(object o, EventArgs e)
{
this.AbortProcess();
}
public void AbortProcess()
{
if (this.Process != null)
{
this.Process.Abort();
}
this.EndProcess();
}
private void OnComplete(string results)
{
this.ResultsText.InvokeEx(() => this.ResultsText.Text = results);
this.StatusLabel.InvokeEx(() => this.StatusLabel.Text = "Completed");
this.EndProcess();
}
private void OnError(TrackerErrorType error, string message)
{
this.ResultsText.InvokeEx(() => this.ResultsText.Text = message);
this.StatusLabel.InvokeEx(() => this.StatusLabel.Text = "Error");
this.EndProcess();
}
public bool ConfirmClose()
{
if (Process != null && Process.Busy)
{
return false;
}
else
{
this.EndProcess();
return true;
}
}
}
}