| | |
| | | /// <summary>
|
| | | /// Name of reusable macro
|
| | | /// </summary>
|
| | | public string Name { get; private set; }
|
| | | private string Name { get; set; }
|
| | |
|
| | | /// <summary>
|
| | | /// True if macro compilation was successful
|
| | |
| | | /// </summary>
|
| | | public bool QuitWhenDone { get; private set; }
|
| | |
|
| | | AsyncPackage Package { get; set; }
|
| | | EnvDTE80.DTE2 Dte { get; set; }
|
| | | AsyncPackage Package { get; }
|
| | | EnvDTE80.DTE2 Dte { get; }
|
| | | IntPtr MainWindowHWnd { get; }
|
| | |
|
| | | AutomationElement UiRoot => AutomationElement.RootElement;
|
| | |
|
| | |
| | | get
|
| | | {
|
| | | if (_UiVsRoot == null)
|
| | | #if VS2022
|
| | | _UiVsRoot = AutomationElement.FromHandle(Dte.MainWindow.HWnd);
|
| | | #else
|
| | | _UiVsRoot = AutomationElement.FromHandle(new IntPtr(Dte.MainWindow.HWnd));
|
| | | #endif
|
| | | _UiVsRoot = AutomationElement.FromHandle(MainWindowHWnd);
|
| | | return _UiVsRoot;
|
| | | }
|
| | | }
|
| | |
|
| | | JoinableTaskFactory JoinableTaskFactory { get; set; }
|
| | | CancellationToken ServerLoop { get; set; }
|
| | | JoinableTaskFactory JoinableTaskFactory { get; }
|
| | | CancellationToken ServerLoop { get; }
|
| | |
|
| | | string Message { get; set; }
|
| | |
|
| | | static MacroParser Parser { get; set; }
|
| | | MacroLines MacroLines { get; set; }
|
| | |
|
| | | List<string> SelectedAssemblies { get { return _SelectedAssemblies; } }
|
| | | List<string> _SelectedAssemblies =
|
| | | new List<string>
|
| | | {
|
| | | "QtVsTest",
|
| | | "System.Core",
|
| | | };
|
| | | private List<string> SelectedAssemblies { get; } = new List<string>
|
| | | {
|
| | | typeof(Macro).Assembly.FullName,
|
| | | typeof(EnvDTE.DTE).Assembly.FullName,
|
| | | typeof(AutomationElement).Assembly.FullName,
|
| | | "System.Core",
|
| | | };
|
| | |
|
| | | IEnumerable<string> RefAssemblies { get; set; }
|
| | |
|
| | | List<string> Namespaces { get { return _Namespaces; } }
|
| | | List<string> _Namespaces =
|
| | | new List<string>
|
| | | {
|
| | | "System",
|
| | | "System.Linq",
|
| | | "System.Reflection",
|
| | | "Task = System.Threading.Tasks.Task",
|
| | | "System.Windows.Automation",
|
| | | "EnvDTE",
|
| | | "EnvDTE80",
|
| | | };
|
| | | private List<string> Namespaces { get; } = new List<string>
|
| | | {
|
| | | "System",
|
| | | "System.Linq",
|
| | | "System.Reflection",
|
| | | "Task = System.Threading.Tasks.Task",
|
| | | "System.Windows.Automation",
|
| | | "EnvDTE",
|
| | | "EnvDTE80",
|
| | | };
|
| | |
|
| | | Dictionary<string, VSServiceRef> ServiceRefs { get { return _ServiceRefs; } }
|
| | | Dictionary<string, VSServiceRef> _ServiceRefs =
|
| | | new Dictionary<string, VSServiceRef>
|
| | | private Dictionary<string, VSServiceRef> ServiceRefs { get; } = new Dictionary<string, VSServiceRef>
|
| | | {
|
| | | {
|
| | | {
|
| | | "Dte", new VSServiceRef
|
| | | "Dte", new VSServiceRef
|
| | | { Name = "Dte", Interface = "DTE2", Type = "DTE" }
|
| | | },
|
| | | };
|
| | | },
|
| | | };
|
| | |
|
| | | Dictionary<string, GlobalVar> GlobalVars { get { return _GlobalVars; } }
|
| | | Dictionary<string, GlobalVar> _GlobalVars =
|
| | | new Dictionary<string, GlobalVar>
|
| | | private Dictionary<string, GlobalVar> GlobalVars { get; } = new Dictionary<string, GlobalVar>
|
| | | {
|
| | | {
|
| | | {
|
| | | "Result", new GlobalVar
|
| | | "Result", new GlobalVar
|
| | | { Type = "string", Name = "Result", InitialValueExpr = "string.Empty" }
|
| | | },
|
| | | };
|
| | | },
|
| | | };
|
| | |
|
| | | string CSharpMethodCode { get; set; }
|
| | | string CSharpClassCode { get; set; }
|
| | |
| | | const BindingFlags PUBLIC_STATIC = BindingFlags.Public | BindingFlags.Static;
|
| | | const StringComparison IGNORE_CASE = StringComparison.InvariantCultureIgnoreCase;
|
| | |
|
| | | static ConcurrentDictionary<string, Macro> Macros
|
| | | static readonly ConcurrentDictionary<string, Macro> Macros
|
| | | = new ConcurrentDictionary<string, Macro>();
|
| | |
|
| | | static ConcurrentDictionary<string, object> Globals
|
| | | static readonly ConcurrentDictionary<string, object> Globals
|
| | | = new ConcurrentDictionary<string, object>();
|
| | |
|
| | | /// <summary>
|
| | |
| | | public Macro(
|
| | | AsyncPackage package,
|
| | | EnvDTE80.DTE2 dte,
|
| | | IntPtr mainWindowHWnd,
|
| | | JoinableTaskFactory joinableTaskFactory,
|
| | | CancellationToken serverLoop)
|
| | | {
|
| | |
| | | JoinableTaskFactory = joinableTaskFactory;
|
| | | ServerLoop = serverLoop;
|
| | | Dte = dte;
|
| | | MainWindowHWnd = mainWindowHWnd;
|
| | | ErrorMsg("Uninitialized");
|
| | | }
|
| | |
|
| | |
| | | return false;
|
| | | break;
|
| | | }
|
| | |
|
| | | csharp.AppendLine();
|
| | | return true;
|
| | | }
|
| | |
|
| | |
| | |
|
| | | csharp.AppendFormat(@"
|
| | | await WaitExpr({0}, () => UiContext = {1});", timeout, context);
|
| | |
|
| | | } else if (s.Args[0].Equals("find", IGNORE_CASE)) {
|
| | | //# ui find [all] [_var_name_] [_timeout_] => <_scope_>, <_condition_>
|
| | |
|
| | | var args = new Queue<string>(s.Args.Skip(1));
|
| | |
|
| | | bool findAll = false;
|
| | | if (args.Any() && args.Peek().Equals("all", IGNORE_CASE)) {
|
| | | findAll = true;
|
| | | args.Dequeue();
|
| | | }
|
| | | string funcName = findAll ? "FindAll" : "FindFirst";
|
| | | string varType = findAll ? "AutomationElementCollection" : "AutomationElement";
|
| | |
|
| | | string varName = null;
|
| | | if (args.Any() && !char.IsDigit(args.Peek()[0]))
|
| | | varName = args.Dequeue();
|
| | | if (findAll && string.IsNullOrEmpty(varName))
|
| | | return ErrorMsg("Invalid #ui statement");
|
| | |
|
| | | int timeout = 3000;
|
| | | if (args.Any() && char.IsDigit(args.Peek()[0]))
|
| | | timeout = int.Parse(args.Dequeue());
|
| | |
|
| | | if (varName == null) {
|
| | | varName = "UiContext";
|
| | | } else {
|
| | | csharp.Append($@"
|
| | | {varType} {varName} = null;");
|
| | | }
|
| | | csharp.Append($@"
|
| | | await WaitExpr({timeout}, () => {varName} = UiContext.{funcName}({s.Code}));");
|
| | |
|
| | | } else if (s.Args[0].Equals("pattern", IGNORE_CASE)) {
|
| | | //# ui pattern <_TypeName_> <_VarName_> [ => _string_ [, _string_, ... ] ]
|
| | |
| | | File.Delete(macroDllPath);
|
| | | return ErrorMsg(string.Join("\r\n",
|
| | | CompilerResults.Errors.Cast<CompilerError>()
|
| | | .Select(x => x.ErrorText)));
|
| | | .Select(x => $"{x.Line}: {x.ErrorText}")
|
| | | .Append(CSharpClassCode)
|
| | | .Union(RefAssemblies)));
|
| | | }
|
| | |
|
| | | MacroAssembly = AppDomain.CurrentDomain.Load(File.ReadAllBytes(macroDllPath));
|
| | |
| | | foreach (var globalVar in GlobalVars.Values) {
|
| | | string varName = globalVar.Name;
|
| | | Type varType = globalVar.FieldInfo.FieldType;
|
| | | object value;
|
| | | if (Globals.TryGetValue(varName, out value)) {
|
| | | if (Globals.TryGetValue(varName, out object value)) {
|
| | | Type valueType = value.GetType();
|
| | | if (!varType.IsAssignableFrom(valueType)) {
|
| | | throw new InvalidCastException(string.Format(
|
| | |
| | |
|
| | | static Macro GetMacro(string name)
|
| | | {
|
| | | Macro macro;
|
| | | if (!Macros.TryGetValue(name, out macro))
|
| | | if (!Macros.TryGetValue(name, out Macro macro))
|
| | | return null;
|
| | | return macro;
|
| | | }
|