-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIPlugin.cs
69 lines (62 loc) · 2.69 KB
/
IPlugin.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
using System;
namespace SoftwareTelephone
{
public interface IPlugin
{
string Input { get; set; }
string Output { get; }
string ToString();
string getInputType();
string getOutputType();
void configure(IConfig Config);
void configure(IConfig Config, bool forceReconfigure);
}
abstract public class PluginApplication : IPlugin
{
protected string mInput;
protected string mOutput;
protected string mApplicationLocation;
public string Input { get { return mInput; } set { mInput = value; runApplication(); } }
public string Output { get { return mOutput; } }
public override abstract string ToString();
public abstract string DefaultApplicationFileName();
public abstract string getInputType();
public abstract string getOutputType();
public void configure(IConfig Config)
{
configure(Config, false);
}
public virtual void configure(IConfig Config, bool forceReconfigure)
{
mApplicationLocation = Config.getSavedConfigurationInformation(ToString() + ".Location");
if (forceReconfigure || mApplicationLocation.Length == 0 || !System.IO.File.Exists( mApplicationLocation ))
{
System.Windows.Forms.OpenFileDialog selecteSpeak = new System.Windows.Forms.OpenFileDialog();
selecteSpeak.DefaultExt = "exe";
selecteSpeak.Filter = ToString() + "|" + DefaultApplicationFileName() + "|All files|*.*";
selecteSpeak.Title = "Select " + ToString() + " executable...";
if (selecteSpeak.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Config.setSavedConfigurationInformation(ToString() + ".Location", selecteSpeak.FileName);
mApplicationLocation = selecteSpeak.FileName;
}
}
}
protected virtual void runApplication()
{
System.Diagnostics.Process runApplication = new System.Diagnostics.Process();
runApplication.StartInfo = new System.Diagnostics.ProcessStartInfo(mApplicationLocation, buildParameters(Input));
runApplication.StartInfo.UseShellExecute = false;
try
{
runApplication.Start();
runApplication.WaitForExit();
}
catch (Exception E)
{
System.Windows.Forms.MessageBox.Show(E.Message, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
}
}
abstract protected string buildParameters(string Input);
}
}