6using System.Windows.Forms;
10 public partial class Recordings : Form
14 InitializeComponent();
15 if (!Directory.Exists(
"Recordings"))
16 Directory.CreateDirectory(
"Recordings");
17 foreach (
string file
in Directory.GetFiles(
"Recordings"))
19 if (file.EndsWith(
"reco"))
21 else if (file.EndsWith(
"pro"))
24 foreach (Automation.Action.ValueType val in (Automation.Action.ValueType[])Enum.GetValues(typeof(Automation.Action.ValueType)))
26 propBox.Items.Add(val);
30 public void InitElements()
33 foreach (Automation.Recording rec in Automation.Recordings.Values)
35 TreeNode tr =
new TreeNode();
36 Node n =
new Node(rec, tr, Node.Type.recording);
39 foreach (Automation.Action item in rec.List)
43 TreeNode tn =
new TreeNode();
44 tn.Text = item.ToString();
45 Node no =
new Node(item, tn, Node.Type.action);
58 propView.Nodes.Clear();
59 foreach (Automation.Recording rec in Automation.Properties.Values)
61 TreeNode tr =
new TreeNode();
62 Node n =
new Node(rec, tr, Node.Type.recording);
65 foreach (Automation.Action item in rec.List)
69 TreeNode tn =
new TreeNode();
70 tn.Text = item.ToString();
72 Node no =
new Node(item, tn, Node.Type.action);
82 propView.Nodes.Add(tr);
85 public void UpdateElements()
87 foreach (TreeNode rec
in view.Nodes)
90 Node n = (Node)rec.Tag;
91 foreach (Automation.Action item in n.recording.List)
95 TreeNode tr =
new TreeNode();
96 tr.Text = item.ToString();
97 Node no =
new Node(item, rec, Node.Type.action);
98 no.recording = n.recording;
108 foreach (TreeNode rec
in propView.Nodes)
111 Node n = (Node)rec.Tag;
112 foreach (Automation.Action item in n.recording.List)
116 TreeNode tr =
new TreeNode();
117 tr.Text = item.ToString();
118 Node no =
new Node(item, rec, Node.Type.action);
119 no.recording = n.recording;
141 public TreeNode node;
148 recording.List.Add(el);
158 public override string ToString()
160 return action.Name +
", " + action.AutomationID +
", " + action.ClassName.ToString() +
", " + action.ActionType;
164 public static void Perform(
string act)
168 Recorder.AddLine(
"Recordings.Perform(" + rec.Name +
");");
170 public static object GetProperty(
Automation.
Action.ValueType automation,
string pro)
177 Recorder.AddLine(
"Recordings.Get(" + rec.Name +
");");
181 private void view_AfterSelect(
object sender, TreeViewEventArgs e)
186 private void startBut_Click(
object sender, EventArgs e)
188 TextInput ti =
new TextInput(
"Property" + propBox.Items.Count);
189 ti.Text =
"Set Property Name";
190 if (ti.ShowDialog() != DialogResult.OK)
192 recordStatusLabel.Text =
"Recording: Started";
193 if (Automation.IsRecording)
195 Automation.StartRecording();
198 private void stopBut_Click(
object sender, EventArgs e)
200 recordStatusLabel.Text =
"Recording: Stopped";
201 if (!Automation.IsRecording)
203 Automation.StopRecording();
204 if (Automation.Recordings.Count > 0)
211 private void playBut_Click(
object sender, EventArgs e)
213 if (view.SelectedNode ==
null)
215 Node n = (Node)view.SelectedNode.Tag;
216 if (n.type == Node.Type.action)
221 private void view_BeforeExpand(
object sender, TreeViewCancelEventArgs e)
226 private void Elements_FormClosing(
object sender, FormClosingEventArgs e)
231 private void performToolStripMenuItem_Click(
object sender, EventArgs e)
233 TreeNode tr = view.SelectedNode;
234 Node no = (Node)tr.Tag;
235 if (no.type == Node.Type.action)
240 private void saveToolStripMenuItem_Click(
object sender, EventArgs e)
242 if (saveRecDialog.ShowDialog() != DialogResult.OK)
244 SaveRecording(saveRecDialog.FileName);
246 private void SaveRecording(
string file)
248 Automation.Recording n;
249 if (view.SelectedNode ==
null)
253 n = ((Node)view.SelectedNode.Tag).recording;
255 string s = Path.GetFileNameWithoutExtension(saveRecDialog.FileName);
257 string j = JsonConvert.SerializeObject(n.List, Formatting.None);
258 File.WriteAllText(file, j);
261 private void SaveProperty(
string file)
263 Automation.Recording n;
264 if (propView.SelectedNode ==
null)
268 n = ((Node)propView.SelectedNode.Tag).recording;
270 string s = Path.GetFileNameWithoutExtension(savePropDialog.FileName);
273 string j = JsonConvert.SerializeObject(n.List, Formatting.None);
274 File.WriteAllText(file, j);
277 private Automation.Recording OpenRec(
string file)
279 string st = File.ReadAllText(file);
280 Automation.Recording rec =
new Automation.Recording();
281 rec.Name = Path.GetFileNameWithoutExtension(file);
283 Newtonsoft.Json.Linq.JArray ar = (Newtonsoft.Json.Linq.JArray)JsonConvert.DeserializeObject(st);
284 for (
int i = 0; i < ar.Count; i++)
286 Automation.Action.Type t = (Automation.Action.Type)Enum.Parse(typeof(Automation.Action.Type), ar[i].ElementAt(0).First.ToString());
287 if (t == Automation.Action.Type.keydown || t == Automation.Action.Type.keyup)
289 Keys k = (Keys)
int.Parse(ar[i].ElementAt(2).First.ToString());
290 KeyEventArgs kea =
new KeyEventArgs(k);
291 int ind =
int.Parse(ar[i].ElementAt(9).First.ToString());
292 Automation.Action ac =
new Automation.Action(t, ar[i].ElementAt(8).First.ToString(), ar[i].ElementAt(9).First.ToString(), ind, ar[i].ElementAt(3).First.ToString(), ar[i].ElementAt(4).First.ToString(), ar[i].ElementAt(5).First.ToString(), kea);
295 if (t == Automation.Action.Type.mousedown || t == Automation.Action.Type.mouseup)
297 MouseButtons mb = (MouseButtons)
int.Parse(ar[i].ElementAt(2).First.ToString());
298 string ps = ar[i].ElementAt(3).First.ToString();
299 string xs = ps.Substring(0, ps.IndexOf(
','));
300 string ys = ps.Substring(ps.IndexOf(
',') + 1, ps.Length - (ps.IndexOf(
',') + 1));
301 int ind =
int.Parse(ar[i].ElementAt(9).First.ToString());
302 System.Drawing.Point po =
new Point(
int.Parse(xs),
int.Parse(ys));
303 MouseEventArgs mo =
new MouseEventArgs(mb, 1, po.X, po.Y, 0);
304 Automation.Action ac =
new Automation.Action(t, ar[i].ElementAt(7).First.ToString(), ar[i].ElementAt(8).First.ToString(), ind, ar[i].ElementAt(4).First.ToString(), ar[i].ElementAt(5).First.ToString(), ar[i].ElementAt(6).First.ToString(), mo);
310 public void OpenRecording(
string file)
312 Automation.Recording rec = OpenRec(file);
313 Automation.Recordings.Add(rec.Name, rec);
316 public void OpenProperty(
string file)
318 Automation.Recording rec = OpenRec(file);
319 Automation.Properties.Add(rec.Name, rec);
323 private void openToolStripMenuItem_Click(
object sender, EventArgs e)
325 openRecDialog.InitialDirectory = Application.StartupPath +
"\\Recordings";
326 if (openRecDialog.ShowDialog() != DialogResult.OK)
328 OpenRecording(openRecDialog.FileName);
331 private void deleteToolStripMenuItem_Click(
object sender, EventArgs e)
333 Node n = (Node)view.SelectedNode.Tag;
334 if (n.type == Node.Type.recording)
336 Automation.Recordings.Remove(n.recording.Name);
337 File.Delete(n.recording.File);
340 else if (n.type == Node.Type.action)
342 n.recording.List.Remove(n.action);
347 private void refreshToolStripMenuItem_Click(
object sender, EventArgs e)
352 private void startPropBut_Click(
object sender, EventArgs e)
354 TextInput ti =
new TextInput(
"Property" + propBox.Items.Count);
355 ti.Text =
"Set Property Name";
357 if (ti.ShowDialog() != DialogResult.OK)
359 propRecStatusLabel.Text =
"Property Recording: Started";
360 Automation.StartPropertyRecording(ti.TextValue);
363 private void stopPropBut_Click(
object sender, EventArgs e)
365 propRecStatusLabel.Text =
"Property Recording: Stopped";
366 if (!Automation.IsRecording)
368 Automation.StopPropertyRecording();
369 if (Automation.Properties.Count > 0)
376 private void getPropBut_Click(
object sender, EventArgs e)
378 if (propView.SelectedNode ==
null)
380 Node n = (Node)propView.SelectedNode.Tag;
381 if (n.type == Node.Type.action)
383 if (n.recording.List.Last().Value == Automation.Action.ValueType.Image)
384 Clipboard.SetImage((Bitmap)Automation.GetProperty(n.recording.Name));
387 if (n.recording.List.Last().Value == Automation.Action.ValueType.TogglePattern)
389 bool b = (bool)Automation.GetProperty(n.recording.Name);
390 MessageBox.Show(b.ToString());
394 string s = (string)Automation.GetProperty(n.recording.Name);
399 private void setPropBut_Click(
object sender, EventArgs e)
401 TextInput ti =
new TextInput(
"Property" + propBox.Items.Count);
402 ti.Text =
"Set Text To Set";
404 if (propView.SelectedNode ==
null)
406 Node n = (Node)propView.SelectedNode.Tag;
407 if (n.type == Node.Type.action)
409 Automation.SetProperty(n.recording.Name, ti.TextValue);
411 private void saveSelectedValueToolStripMenuItem_Click(
object sender, EventArgs e)
413 savePropDialog.InitialDirectory = Application.StartupPath +
"\\Recordings";
414 if (savePropDialog.ShowDialog() != DialogResult.OK)
416 SaveProperty(savePropDialog.FileName);
419 private void openPropertyToolStripMenuItem_Click(
object sender, EventArgs e)
421 openPropDialog.InitialDirectory = Application.StartupPath +
"\\Recordings";
422 if (openPropDialog.ShowDialog() != DialogResult.OK)
424 OpenProperty(openPropDialog.FileName);
427 private void getMenuItem_Click(
object sender, EventArgs e)
429 getPropBut.PerformClick();
432 private void deletePropMenuItem_Click(
object sender, EventArgs e)
434 Node n = (Node)propView.SelectedNode.Tag;
435 if (n.type == Node.Type.recording)
437 Automation.Properties.Remove(n.recording.Name);
438 if (n.recording.File !=
null)
439 File.Delete(n.recording.File);
442 else if (n.type == Node.Type.action)
444 n.recording.List.Remove(n.action);
450 private void propView_AfterSelect(
object sender, TreeViewEventArgs e)
452 if (propView.SelectedNode ==
null)
454 Node n = (Node)propView.SelectedNode.Tag;
455 if (n.type == Node.Type.recording)
457 propBox.SelectedIndex = (int)n.action.Value;
460 private void propBox_SelectedIndexChanged(
object sender, EventArgs e)
462 if (propView.SelectedNode ==
null)
464 Node n = (Node)propView.SelectedNode.Tag;
465 if (n.type == Node.Type.recording)
467 n.action.Value = (Automation.Action.ValueType)propBox.SelectedItem;
470 private void moveUpToolStripMenuItem_Click(
object sender, EventArgs e)
472 if (view.SelectedNode ==
null)
474 Node n = (Node)view.SelectedNode.Tag;
475 if (n.type == Node.Type.recording)
477 int oldindex = n.recording.List.IndexOf(n.action);
478 n.recording.List.RemoveAt(oldindex);
479 int newindex = oldindex - 1;
480 if (newindex > oldindex) newindex--;
482 n.recording.List.Insert(newindex, n.action);
486 private void moveDownToolStripMenuItem_Click(
object sender, EventArgs e)
488 if (view.SelectedNode ==
null)
490 Node n = (Node)view.SelectedNode.Tag;
491 if (n.type == Node.Type.recording)
493 int oldindex = n.recording.List.IndexOf(n.action);
494 n.recording.List.RemoveAt(oldindex);
495 int newindex = oldindex - 1;
497 n.recording.List.Insert(newindex, n.action);
501 private void moveUpToolStripMenuItem1_Click(
object sender, EventArgs e)
503 if (propView.SelectedNode ==
null)
505 Node n = (Node)propView.SelectedNode.Tag;
506 if (n.type == Node.Type.recording)
508 int oldindex = n.recording.List.IndexOf(n.action);
509 n.recording.List.RemoveAt(oldindex);
510 int newindex = oldindex - 1;
512 n.recording.List.Insert(newindex, n.action);
516 private void moveDownToolStripMenuItem1_Click(
object sender, EventArgs e)
518 if (propView.SelectedNode ==
null)
520 Node n = (Node)propView.SelectedNode.Tag;
521 if (n.type == Node.Type.recording)
523 int oldindex = n.recording.List.IndexOf(n.action);
524 n.recording.List.RemoveAt(oldindex);
525 int newindex = (oldindex) + 1;
527 n.recording.List.Insert(newindex, n.action);
531 private void renameToolStripMenuItem_Click(
object sender, EventArgs e)
533 if (propView.SelectedNode ==
null)
535 Node n = (Node)propView.SelectedNode.Tag;
536 if (n.type == Node.Type.recording)
538 n.action.Value = (Automation.Action.ValueType)propBox.SelectedItem;
541 private void topMostBox_CheckedChanged(
object sender, EventArgs e)
543 this.TopMost = topMostBox.Checked;
546 private void startPropBut_Click_1(
object sender, EventArgs e)