/
AHKProxy.cs
82 lines (73 loc) · 3.12 KB
/
AHKProxy.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace OpenRPA.Script.Activities
{
public class AHKProxy : MarshalByRefObject
{
public static void New_AHKSession(bool NewInstance = false)
{
if (sharpAHK.ahkGlobal.ahkdll == null || NewInstance == true) { sharpAHK.ahkGlobal.ahkdll = new AutoHotkey.Interop.AutoHotkeyEngine(); }
else { sharpAHK.ahkGlobal.ahkdll = null; } // option to start new AHK session (resets variables and previously loaded functions)
sharpAHK.ahkGlobal.LoadedAHK = new List<string>(); // reset loaded ahk list
}
public AHKProxy()
{
New_AHKSession(false);
}
public Assembly GetAssembly(string assemblyPath)
{
try
{
return Assembly.LoadFile(assemblyPath);
}
catch (Exception)
{
return null;
}
}
public static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
//This handler is called only when the common language runtime tries to bind to the assembly and fails.
//Retrieve the list of referenced assemblies in an array of AssemblyName.
Assembly MyAssembly, objExecutingAssemblies;
string strTempAssmbPath = "";
var asmBase = System.IO.Directory.GetCurrentDirectory();
objExecutingAssemblies = Assembly.GetExecutingAssembly();
AssemblyName[] arrReferencedAssmbNames = objExecutingAssemblies.GetReferencedAssemblies();
//Loop through the array of referenced assembly names.
foreach (AssemblyName strAssmbName in arrReferencedAssmbNames)
{
//Check for the assembly names that have raised the "AssemblyResolve" event.
if (strAssmbName.FullName.Substring(0, strAssmbName.FullName.IndexOf(",")) == args.Name.Substring(0, args.Name.IndexOf(",")))
{
//Build the path of the assembly from where it has to be loaded.
//The following line is probably the only line of code in this method you may need to modify:
strTempAssmbPath = asmBase;
if (strTempAssmbPath.EndsWith("\\")) strTempAssmbPath += "\\";
strTempAssmbPath += args.Name.Substring(0, args.Name.IndexOf(",")) + ".dll";
break;
}
}
//Load the assembly from the specified path.
MyAssembly = Assembly.LoadFrom(strTempAssmbPath);
//Return the loaded assembly.
return MyAssembly;
}
internal void SetVar(string key, string v)
{
sharpAHK.ahkGlobal.ahkdll.SetVar(key, v);
}
internal void ExecRaw(string code)
{
sharpAHK.ahkGlobal.ahkdll.ExecRaw(code);
}
internal string GetVar(string displayName)
{
return sharpAHK.ahkGlobal.ahkdll.GetVar(displayName);
}
}
}