-
Notifications
You must be signed in to change notification settings - Fork 0
/
UIAutomation.cs
95 lines (79 loc) · 2.92 KB
/
UIAutomation.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
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace UCNLUI
{
public class UIAutomation
{
#region Properties
Regex wsRemover = new Regex(@"\s+");
Dictionary<string, Action<string>> uiActions;
public static readonly string LogID = "UI_ACTION";
#endregion
#region Constructor
public UIAutomation()
{
uiActions = new Dictionary<string, Action<string>>();
}
#endregion
#region Methods
public void Clear()
{
uiActions.Clear();
}
public void PerformUIAction(string uiAction)
{
if (uiActions.ContainsKey(uiAction))
uiActions[uiAction](string.Empty);
else
{
var splits = uiAction.Split('=');
if (splits.Length == 2)
{
if (uiActions.ContainsKey(splits[0]))
uiActions[splits[0]](splits[1]);
}
}
}
public void InitIntProperty<T>(object o, string property) where T : class
{
PropertyInfo pInfo = typeof(T).GetProperty(property, BindingFlags.NonPublic | BindingFlags.Instance);
if (pInfo != null)
{
uiActions.Add(property, x => pInfo.SetValue(o, int.Parse(x)));
}
}
public void InitBoolProperty<T>(object o, string property) where T : class
{
PropertyInfo pInfo = typeof(T).GetProperty(property, BindingFlags.NonPublic | BindingFlags.Instance);
if (pInfo != null)
{
uiActions.Add(string.Format("{0}=True", property), delegate { pInfo.SetValue(o, true); });
uiActions.Add(string.Format("{0}=False", property), delegate { pInfo.SetValue(o, false); });
}
}
public string GetBoolPropertyStateLogString<T>(object o, string property) where T : class
{
PropertyInfo pInfo = typeof(T).GetProperty(property, BindingFlags.NonPublic | BindingFlags.Instance);
if (pInfo != null)
{
return string.Format("{0}: {1}={2}", LogID, property, pInfo.GetValue(o));
}
else
throw new KeyNotFoundException();
}
public string GetPropertyStateLogString<T>(object o, string property)
{
PropertyInfo pInfo = typeof(T).GetProperty(property, BindingFlags.NonPublic | BindingFlags.Instance);
if (pInfo != null)
{
return string.Format("{0}: {1}={2}", LogID, property, pInfo.GetValue(o));
}
else
throw new KeyNotFoundException();
}
#endregion
}
}