6using System.Windows.Forms;
10 public partial class Recordings : Form
15 InitializeComponent();
16 if (!Directory.Exists(
"Recordings"))
17 Directory.CreateDirectory(
"Recordings");
18 foreach (
string file
in Directory.GetFiles(
"Recordings"))
20 if (file.EndsWith(
"reco"))
22 else if (file.EndsWith(
"pro"))
27 propBox.Items.Add(val);
41 TreeNode tr =
new TreeNode();
49 TreeNode tn =
new TreeNode();
50 tn.Text = item.ToString();
65 propView.Nodes.Clear();
68 TreeNode tr =
new TreeNode();
76 TreeNode tn =
new TreeNode();
77 tn.Text = item.ToString();
89 propView.Nodes.Add(tr);
95 foreach (TreeNode rec
in view.Nodes)
103 TreeNode tr =
new TreeNode();
104 tr.Text = item.ToString();
116 foreach (TreeNode rec
in propView.Nodes)
124 TreeNode tr =
new TreeNode();
125 tr.Text = item.ToString();
172 return action.Name +
", " + action.AutomationID +
", " +
action.ClassName.ToString() +
", " +
action.ActionType;
206 private void view_AfterSelect(
object sender, TreeViewEventArgs e)
217 private void startBut_Click(
object sender, EventArgs e)
219 TextInput ti =
new TextInput(
"Property" + propBox.Items.Count);
220 ti.Text =
"Set Property Name";
221 if (ti.ShowDialog() != DialogResult.OK)
223 recordStatusLabel.Text =
"Recording: Started";
224 if (Automation.IsRecording)
226 Automation.StartRecording();
235 private void stopBut_Click(
object sender, EventArgs e)
237 recordStatusLabel.Text =
"Recording: Stopped";
238 if (!Automation.IsRecording)
240 Automation.StopRecording();
241 if (Automation.Recordings.Count > 0)
255 private void playBut_Click(
object sender, EventArgs e)
257 if (view.SelectedNode ==
null)
259 Node n = (Node)view.SelectedNode.Tag;
260 if (n.type == Node.Type.action)
265 private void view_BeforeExpand(
object sender, TreeViewCancelEventArgs e)
270 private void Elements_FormClosing(
object sender, FormClosingEventArgs e)
280 private void performToolStripMenuItem_Click(
object sender, EventArgs e)
282 TreeNode tr = view.SelectedNode;
283 Node no = (Node)tr.Tag;
284 if (no.type == Node.Type.action)
295 private void saveToolStripMenuItem_Click(
object sender, EventArgs e)
297 if (saveRecDialog.ShowDialog() != DialogResult.OK)
299 SaveRecording(saveRecDialog.FileName);
306 private void SaveRecording(
string file)
308 Automation.Recording n;
309 if (view.SelectedNode ==
null)
313 n = ((Node)view.SelectedNode.Tag).recording;
315 string s = Path.GetFileNameWithoutExtension(saveRecDialog.FileName);
317 string j = JsonConvert.SerializeObject(n.List, Formatting.None);
318 File.WriteAllText(file, j);
327 private void SaveProperty(
string file)
329 Automation.Recording n;
330 if (propView.SelectedNode ==
null)
334 n = ((Node)propView.SelectedNode.Tag).recording;
336 string s = Path.GetFileNameWithoutExtension(savePropDialog.FileName);
339 string j = JsonConvert.SerializeObject(n.List, Formatting.None);
340 File.WriteAllText(file, j);
348 private Automation.Recording OpenRec(
string file)
350 string st = File.ReadAllText(file);
351 Automation.Recording rec =
new Automation.Recording();
352 rec.Name = Path.GetFileNameWithoutExtension(file);
354 Newtonsoft.Json.Linq.JArray ar = (Newtonsoft.Json.Linq.JArray)JsonConvert.DeserializeObject(st);
355 for (
int i = 0; i < ar.Count; i++)
357 Automation.Action.Type t = (Automation.Action.Type)Enum.Parse(typeof(Automation.Action.Type), ar[i].ElementAt(0).First.ToString());
358 if (t == Automation.Action.Type.keydown || t == Automation.Action.Type.keyup)
360 Keys k = (
Keys)
int.Parse(ar[i].ElementAt(2).First.ToString());
361 KeyEventArgs kea =
new KeyEventArgs(k);
362 int ind =
int.Parse(ar[i].ElementAt(9).First.ToString());
363 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);
366 if (t == Automation.Action.Type.mousedown || t == Automation.Action.Type.mouseup)
368 MouseButtons mb = (MouseButtons)
int.Parse(ar[i].ElementAt(2).First.ToString());
369 string ps = ar[i].ElementAt(3).First.ToString();
370 string xs = ps.Substring(0, ps.IndexOf(
','));
371 string ys = ps.Substring(ps.IndexOf(
',')+1, ps.Length - (ps.IndexOf(
',')+1));
372 int ind =
int.Parse(ar[i].ElementAt(9).First.ToString());
373 System.Drawing.Point po =
new Point(
int.Parse(xs),
int.Parse(ys));
374 MouseEventArgs mo =
new MouseEventArgs(mb, 1, po.X, po.Y, 0);
375 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);
406 private void openToolStripMenuItem_Click(
object sender, EventArgs e)
408 openRecDialog.InitialDirectory = Application.StartupPath +
"\\Recordings";
409 if (openRecDialog.ShowDialog() != DialogResult.OK)
418 private void deleteToolStripMenuItem_Click(
object sender, EventArgs e)
420 Node n = (Node)view.SelectedNode.Tag;
421 if(n.type == Node.Type.recording)
423 Automation.Recordings.Remove(n.recording.Name);
424 File.Delete(n.recording.File);
427 else if (n.type == Node.Type.action)
429 n.recording.List.Remove(n.action);
438 private void refreshToolStripMenuItem_Click(
object sender, EventArgs e)
449 private void startPropBut_Click(
object sender, EventArgs e)
451 TextInput ti =
new TextInput(
"Property" + propBox.Items.Count);
452 ti.Text =
"Set Property Name";
453 if (ti.ShowDialog() != DialogResult.OK)
455 propRecStatusLabel.Text =
"Property Recording: Started";
456 Automation.StartPropertyRecording(ti.Text);
467 private void stopPropBut_Click(
object sender, EventArgs e)
469 propRecStatusLabel.Text =
"Property Recording: Stopped";
470 if (!Automation.IsRecording)
472 Automation.StopPropertyRecording();
473 if (Automation.Properties.Count > 0)
487 private void getPropBut_Click(
object sender, EventArgs e)
489 if (propView.SelectedNode ==
null)
491 Node n = (Node)propView.SelectedNode.Tag;
492 if (n.type == Node.Type.action)
494 if (n.recording.List.Last().Value == Automation.Action.ValueType.Image)
495 Clipboard.SetImage((System.Drawing.Bitmap)Automation.GetProperty(n.recording.Name));
498 string s = (string)Automation.GetProperty(n.recording.Name);
508 private void setPropBut_Click(
object sender, EventArgs e)
510 TextInput ti =
new TextInput(
"Property" + propBox.Items.Count);
511 ti.Text =
"Set Text To Set";
512 if (propView.SelectedNode ==
null)
514 Node n = (Node)propView.SelectedNode.Tag;
515 if (n.type == Node.Type.action)
517 Automation.SetProperty(n.recording.Name, ti.TextValue);
525 private void saveSelectedValueToolStripMenuItem_Click(
object sender, EventArgs e)
527 savePropDialog.InitialDirectory = Application.StartupPath +
"\\Recordings";
528 if (savePropDialog.ShowDialog() != DialogResult.OK)
530 SaveProperty(savePropDialog.FileName);
539 private void openPropertyToolStripMenuItem_Click(
object sender, EventArgs e)
541 openPropDialog.InitialDirectory = Application.StartupPath +
"\\Recordings";
542 if (openPropDialog.ShowDialog() != DialogResult.OK)
551 private void getMenuItem_Click(
object sender, EventArgs e)
553 getPropBut.PerformClick();
560 private void deletePropMenuItem_Click(
object sender, EventArgs e)
562 Node n = (Node)propView.SelectedNode.Tag;
563 if (n.type == Node.Type.recording)
565 Automation.Properties.Remove(n.recording.Name);
566 if(n.recording.File!=
null)
567 File.Delete(n.recording.File);
570 else if (n.type == Node.Type.action)
572 n.recording.List.Remove(n.action);
586 private void propView_AfterSelect(
object sender, TreeViewEventArgs e)
588 if (propView.SelectedNode ==
null)
590 Node n = (Node)propView.SelectedNode.Tag;
591 if (n.type == Node.Type.recording)
593 propBox.SelectedIndex = (int)n.action.Value;
603 private void propBox_SelectedIndexChanged(
object sender, EventArgs e)
605 if (propView.SelectedNode ==
null)
607 Node n = (Node)propView.SelectedNode.Tag;
608 if (n.type == Node.Type.recording)
610 n.action.Value = (Automation.Action.ValueType)propBox.SelectedItem;
619 private void moveUpToolStripMenuItem_Click(
object sender, EventArgs e)
621 if (view.SelectedNode ==
null)
623 Node n = (Node)view.SelectedNode.Tag;
624 if (n.type == Node.Type.recording)
626 int oldindex = n.recording.List.IndexOf(n.action);
627 n.recording.List.RemoveAt(oldindex);
628 int newindex = oldindex - 1;
629 if (newindex > oldindex) newindex--;
631 n.recording.List.Insert(newindex, n.action);
642 private void moveDownToolStripMenuItem_Click(
object sender, EventArgs e)
644 if (view.SelectedNode ==
null)
646 Node n = (Node)view.SelectedNode.Tag;
647 if (n.type == Node.Type.recording)
649 int oldindex = n.recording.List.IndexOf(n.action);
650 n.recording.List.RemoveAt(oldindex);
651 int newindex = oldindex - 1;
653 n.recording.List.Insert(newindex, n.action);
664 private void moveUpToolStripMenuItem1_Click(
object sender, EventArgs e)
666 if (propView.SelectedNode ==
null)
668 Node n = (Node)propView.SelectedNode.Tag;
669 if (n.type == Node.Type.recording)
671 int oldindex = n.recording.List.IndexOf(n.action);
672 n.recording.List.RemoveAt(oldindex);
673 int newindex = oldindex - 1;
675 n.recording.List.Insert(newindex, n.action);
685 private void moveDownToolStripMenuItem1_Click(
object sender, EventArgs e)
687 if (propView.SelectedNode ==
null)
689 Node n = (Node)propView.SelectedNode.Tag;
690 if (n.type == Node.Type.recording)
692 int oldindex = n.recording.List.IndexOf(n.action);
693 n.recording.List.RemoveAt(oldindex);
694 int newindex = (oldindex) + 1;
696 n.recording.List.Insert(newindex, n.action);
707 private void renameToolStripMenuItem_Click(
object sender, EventArgs e)
709 if (propView.SelectedNode ==
null)
711 Node n = (Node)propView.SelectedNode.Tag;
712 if (n.type == Node.Type.recording)
714 n.action.Value = (Automation.Action.ValueType)propBox.SelectedItem;
System.Windows.Forms.Keys Keys
System.Drawing.Point Point
static Dictionary< string, Recording > Recordings
static Dictionary< string, Recording > Properties
static void AddLine(string s)
Automation.Recording recording
Node(Automation.Action el, TreeNode n, Type t)
Node(Automation.Recording rec, TreeNode n, Type t)
override string ToString()
static void Perform(string act)
void OpenRecording(string file)
void UpdateElements()
It clears the nodes of the treeview, then adds the nodes back in.
void InitElements()
It's a function that adds nodes to a treeview.
void OpenProperty(string file)
static object GetProperty(Automation.Action.ValueType automation, string pro)