-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomMethods.cs
More file actions
141 lines (130 loc) · 4.84 KB
/
CustomMethods.cs
File metadata and controls
141 lines (130 loc) · 4.84 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using NaturalCommands;
using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Windows.Automation;
using WindowsInput;
namespace NaturalCommends
{
public class CustomMethods
{
IInputSimulator _inputSimulator = new InputSimulator();
public CustomMethods()
{
}
public string EnterTimestamp(string? dictation = null)
{
var value = DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss");
_inputSimulator.Keyboard.TextEntry(value);
return $"{{Entered timestamp}}";
}
public string RestartDragon(string? dictation = null)
{
var processName = "nsbrowse";
KillAllProcesses(processName);
processName = "dragonbar";
KillAllProcesses(processName);
processName = "natspeak";
KillAllProcesses(processName);
processName = "ProcHandler";
KillAllProcesses(processName);
processName = "KBPro";
KillAllProcesses(processName);
processName = "draAgedgonlogger";
KillAllProcesses(processName);
try
{
Process process = new Process();
var filename = "C:\\Program Files(x86)\\KnowBrainer\\KnowBrainer Professional 2017\\KBPro.exe";
if (File.Exists(filename))
{
process.StartInfo.UseShellExecute = true;
process.StartInfo.WorkingDirectory = "C:\\Program Files (x86)\\KnowBrainer\\KnowBrainer Professional 2017\\";
process.StartInfo.FileName = filename;
process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
process.Start();
}
else
{
SendKeys.SendWait("^+k");
}
}
catch (Exception exception)
{
// System.Windows.Forms.MessageBox.Show(exception.Message);
AutoClosingMessageBox.Show(exception.Message, "Error trying to start a process", 3000);
}
return $"{{Dragon Restarted}}";
}
public string ShutdownWindows(string dictation)
{
if (dictation.ToLower() == "shut down windows" || dictation.ToLower() == "shutdown windows")
{
Process.Start("shutdown", "/s /t 10");
}
else if (dictation.ToLower() == "restart windows")
{
Process.Start("shutdown", "/r /t 10");
}
return $"{{Windows has left the building}}";
}
private void KillAllProcesses(string name)
{
var processName = (name);
if (processName.Length > 0)
{
foreach (var process in Process.GetProcessesByName(processName))
{
try
{
process.Kill();
}
catch (Exception)
{
//System.Windows.MessageBox.Show(exception.Message);
}
}
}
}
List<string> phoneticAlphabet = new List<string>() { "Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot", "Golf", "Hotel", "India", "Juliet", "Kilo", "Lima", "Mike", "November", "Oscar", "Paper", "Papa", "Quebec", "Romeo", "Sierra", "Tango", "Uniform", "Victor", "Whiskey", "X-ray", "Yankee", "Zulu" };
public string ProcessCapitalLetters(string dictation)
{
return ProcessLetters(dictation, "Upper");
}
public string ProcessMixedLetters(string dictation)
{
return ProcessLetters(dictation, "Mixed");
}
public string ProcessLowerLetters(string dictation)
{
return ProcessLetters(dictation, "Lower");
}
private string ProcessLetters(string dictation, string caseType)
{
foreach (var item in phoneticAlphabet)
{
if (dictation.ToLower().Contains(item.ToLower()))
{
dictation = dictation.ToLower().Replace(item.ToLower(), item.Substring(0, 1));
}
}
dictation = dictation.Replace(" ", "");
if (caseType == "Upper")
{
dictation = dictation.ToUpper();
}
else if (caseType == "Mixed")
{
dictation = dictation.Substring(0, 1).ToUpper() +
dictation.ToLower().Substring(1);
}
else
{
dictation = dictation.ToLower();
}
_inputSimulator.Keyboard.TextEntry(dictation);
return $"{{Letters Processed: {dictation}}}";
}
}
}