public void GetMacroElementsFromNccTest() { var macroElements = MacroEntry.GetMacroElementsFromNcc(dtb1NccUri); var ncc = Utils.LoadXDocument(dtb1NccUri); Assert.AreEqual(ncc.Descendants(Utils.XhtmlNs + "h1").Count(), macroElements.Count(), "Number of macro elements must match number of h1 elements"); }
public void WillExceptionEvent() { MacroEntry me = new MacroEntry { Macro = "kjdkdsdksdfsdk" }; MacroInvoker mi = MacroInvoker.GetInstance(); AutoResetEvent are = new AutoResetEvent(false); void OnExceptionEvent(Exception e) { Assert.IsTrue(mi.IsFaulted); Assert.IsNotNull(mi.Exception); are.Set(); } mi.ExceptionEvent += OnExceptionEvent; mi.Execute(me); bool result = are.WaitOne(5000); Assert.IsTrue(result); }
public static void CreateMacroButton(MacroEntry macroEntry) { try { GameScene gameScene = new GameScene(); IEnumerable <Macro> allMacros = gameScene.Macros.GetAllMacros(); Macro macroObj = allMacros.FirstOrDefault(e => e.Name == macroEntry.Name); if (macroObj == null) { macroObj = new Macro(macroEntry.Name); gameScene.Macros.PushToBack(macroObj); } macroObj.Items = new MacroObjectString(macroEntry.Name); MacroButtonGump macroButton = new MacroButtonGump(macroObj, 200, 200); UIManager.Add(macroButton); } catch (Exception e) { SentrySdk.CaptureException(e); UO.Commands.SystemMessage(string.Format(Strings.Reflection_Error___0_, e.Message)); } }
public string ReplaceParms(MacroEntry me, string[] actual_parms) { Match m; int istart = 0; string subst = me.Subst; while ((m = iden.Match(subst, istart)) != Match.Empty) { int idx = Array.IndexOf(me.Parms, m.Value); int len = m.Length; if (idx != -1) { string actual = actual_parms[idx]; // A _single_ # before a token means the 'stringizing' operator if (m.Index > 0 && subst[m.Index - 1] == '#') { // whereas ## means 'token-pasting'! #s will be removed later! if (!(m.Index > 1 && subst[m.Index - 2] == '#')) { actual = '\"' + actual + '\"'; } } subst = iden.Replace(subst, actual, 1, istart); len = actual.Length; } istart = m.Index + len; } subst = subst.Replace("#", ""); return(subst); }
static MacroManager() { Macros = new Dictionary <uint, MacroEntry>(); LLKH = new LowLevelKeyboardHook(); CurrentMacro = new List <uint>(); MacroLock = new object(); try { string path = $@"{AppData}\{Path}"; if (File.Exists(path)) { using (BinaryReader data = new BinaryReader(new MemoryStream(File.ReadAllBytes(path)))) { MacroEntry entry; int count = data.ReadInt32(); for (int i = 0; i < count; i++) { entry = new MacroEntry(); entry.Deserialize(data); Macros.Add(entry.Id, entry); NextFreeId = Math.Max(NextFreeId, entry.Id + 1); } } } } catch (Exception e) { Program.MainForm.Notify(e.ToString(), "Loading Error", ToolTipIcon.Error); } LLKH.KeyboardAction += OnKeyboardAction; LLKH.Start(); }
private void EditMacro(MacroEntry macro) { MacroSaveForm form = new MacroSaveForm(NextFreeId, macro); form.ShowDialog(); ReloadMacros(); }
public static bool Playing(string macroName) { MacroManager manager = MacroManager.GetInstance(); MacroEntry macro = manager.Items.FirstOrDefault(m => m.Name.Equals(macroName)); return(macro != null && macro.IsRunning); }
public void WillExecute() { MacroEntry me = new MacroEntry(); MacroManager mi = MacroManager.GetInstance(); mi.Execute(me); }
public static void Replay() { MacroManager manager = MacroManager.GetInstance(); MacroEntry current = manager.GetCurrentMacro(); Task.Run(() => current.Action(current)); }
public MacroEntry(MacroEntry other) { Id = other.Id; Enabled = other.Enabled; Type = other.Type; Binding = new MacroBinding(other.Binding); Function = other.Function.Clone() as MacroFunction; Description = other.Description; }
public void AddMacro(string name, string subst, string[] parms) { MacroEntry me = new MacroEntry(); string pstr = ""; if (parms != null) pstr = string.Join(",",parms); me.Subst = subst; me.Parms = parms; macroTable[name] = me; }
void ProcessCommand(string line) { Match m = cmdSplit.Match(line); string cmd = m.Groups[1].ToString(); string arg = m.Groups[2].ToString().TrimStart(null); switch (cmd) { case "n": AddNamespace(arg); break; case "r": AddReference(arg); break; case "v": foreach (string v in varTable.Keys) { Utils.Print(v + " = " + varTable[v]); } break; case "dcl": MustDeclare = !MustDeclare; break; case "code": // show code sent to compiler! showCode = !showCode; break; default: // a macro may be used as a command; the line is split up and // and supplied as arguments. // For macros taking one argument, the whole line is supplied. MacroEntry me = macro.Lookup(cmd); if (me != null && me.Parms != null) { string[] parms; if (me.Parms.Length > 1) { parms = spaces.Split(arg); } else { parms = new string[] { arg } }; string s = macro.ReplaceParms(me, parms); ExecuteLine(s); } else { Utils.Print("unrecognized command, or bad macro"); } break; } }
public void RemoveCommandWillRemoveItem() { _model.NewMacroCommand.Execute(null); MacroEntry item = _model.Items.FirstOrDefault(); _model.RemoveMacroCommand.Execute(item); Assert.AreEqual(0, _model.Items.Count); }
/// <summary> Gets a VelocimacroProxy object by the name / source template duple. /// /// </summary> /// <param name="vmName">Name of the VelocityMacro to look up. /// </param> /// <param name="namespace">Namespace in which to look up the macro. /// </param> /// <param name="renderingTemplate">Name of the template we are currently rendering. /// </param> /// <returns> A proxy representing the Macro. /// </returns> /// <since> 1.6 /// </since> public virtual VelocimacroProxy Get(string vmName, string namespace_Renamed, string renderingTemplate) { if (inlineReplacesGlobal && renderingTemplate != null) { /* * if VM_PERM_ALLOW_INLINE_REPLACE_GLOBAL is true (local macros can * override global macros) and we know which template we are rendering at the * moment, check if local namespace contains a macro we are looking for * if so, return it instead of the global one */ IDictionary local = GetNamespace(renderingTemplate, false); if (local != null) { MacroEntry me = (MacroEntry)local[vmName]; if (me != null) { return(me.GetProxy(namespace_Renamed)); } } } if (UsingNamespaces(namespace_Renamed)) { IDictionary local = GetNamespace(namespace_Renamed, false); /* * if we have macros defined for this template */ if (local != null) { MacroEntry me = (MacroEntry)local[vmName]; if (me != null) { return(me.GetProxy(namespace_Renamed)); } } } /* * if we didn't return from there, we need to simply see * if it's in the global namespace */ MacroEntry me2 = (MacroEntry)globalNamespace[vmName]; if (me2 != null) { return(me2.GetProxy(namespace_Renamed)); } return(null); }
/// <summary> /// 매크로 엔트리를 리턴. 없을 경우엔 생성한다. /// </summary> /// <param name="name"></param> /// <returns></returns> MacroEntry GetMacroEntry(string name) { MacroEntry entry = null; if (!m_macroDict.TryGetValue(name, out entry)) // 항목이 기존에 없었을 시에는 생성 { entry = new MacroEntry(); m_macroDict[name] = entry; } return(entry); }
public MacroSaveForm(uint id, MacroEntry entry = null) { InitializeComponent(); m_entry = new MacroEntry { Id = id }; if (entry != null) { m_edit = true; m_entry = new MacroEntry(entry); } }
public void AddMacro(string name, string subst, string[] parms) { MacroEntry me = new MacroEntry(); string pstr = ""; if (parms != null) { pstr = string.Join(",", parms); } me.Subst = subst; me.Parms = parms; macroTable[name] = me; }
public void WillExecuteRunDummy() { MacroEntry me = new MacroEntry { Macro = "Dummy(5,7)" }; MacroInvoker mi = MacroInvoker.GetInstance(); mi.Execute(me); mi.Thread.Join(); Assert.IsFalse(mi.IsFaulted); }
internal CompiledMacroBank(Dictionary <int, Macro> inMap, string[] inStrings) { m_MacroMap = new Dictionary <int, Macro>(inMap); m_StringEntries = (string[])inStrings.Clone(); m_MacroEntries = new MacroEntry[m_MacroMap.Count]; int idx = 0; foreach (var kv in m_MacroMap) { m_MacroEntries[idx++] = new MacroEntry(kv.Key, kv.Value); } }
public static bool IsRunning(string name) { MacroManager manager = MacroManager.GetInstance(); MacroEntry macro = manager.Items.FirstOrDefault(m => m.Name == name); if (macro != null) { return(macro.IsRunning); } UOC.SystemMessage(Strings.Unknown_macro___, (int)UOC.SystemMessageHues.Normal, true); return(false); }
public static void PlayMacro(string name) { MacroManager manager = MacroManager.GetInstance(); MacroEntry macro = manager.Items.FirstOrDefault(m => m.Name == name); if (macro == null) { UOC.SystemMessage(Strings.Unknown_macro___); return; } Task.Run(() => macro.Action(macro)); }
public static void Replay() { MacroManager manager = MacroManager.GetInstance(); MacroEntry current = manager?.GetCurrentMacro(); if (current?.Action == null) { return; } manager.Replay = true; Task.Run(() => current.Action(current)); }
private void button6_Click(object sender, EventArgs e) { if (curclient != null) { //Macro'ing might seem more slightly more complicated then it was //but this is a direct forward to the client's implementation... //build macroentry (Say macro = macro #1) MacroEntry me = new MacroEntry(1, 0, textBox1.Text); //build macrotable (max 10 macroentries... maybe i'll change this to more entries (or non-fixed size) later on, not sure if the client sets a limit... but i need a fixed size to get evertyhing marshalled automatically, so i just always copy 10 entries, 0-entries are added to get to 10 if needed) MacroTable mt = new MacroTable(new MacroEntry[] { me }); //execute first entry in the table curclient.Macro(mt, 0); } }
public void WillAbortRunning() { MacroEntry me = new MacroEntry { Macro = "while true:\r\n\t" }; MacroInvoker mi = MacroInvoker.GetInstance(); mi.Execute(me); mi.Stop(); bool result = mi.Thread.Join(5000); Assert.IsTrue(result); }
public static void UnsetAlias(string aliasName) { MacroEntry macro = MacroManager.GetInstance().GetCurrentMacro(); if (macro != null) { if (macro.Aliases.ContainsKey(aliasName)) { macro.Aliases.Remove(aliasName); } } if (_aliases.ContainsKey(aliasName)) { _aliases.Remove(aliasName); } }
/// <summary> /// 치환하기 /// </summary> public string Replace(string original) { if (original.IndexOf(c_replaceTokenPair[0]) < 0) // Quick estimation : 매크로가 없는 문자열인 경우 그대로 리턴 { return(original); } var output = new System.Text.StringBuilder(); int starti = 0; int mstarti = -1; while ((mstarti = original.IndexOf(c_replaceTokenPair[0], starti)) >= 0) // 매크로가 계속 존재하면 반복 { int mendi = original.IndexOf(c_replaceTokenPair[1], mstarti); if (mendi < 0) { throw new System.InvalidOperationException("여는 기호만 존재하고 닫는 기호가 존재하지 않아 매크로를 치환할 수 없습니다."); } else { output.Append(original.Substring(starti, mstarti - starti)); // 매크로 치환 이전까지의 텍스트 출력 var macroname = original.Substring(mstarti + 1, mendi - mstarti - 1); MacroEntry entry = null; string replaced = null; if (m_macroDict.TryGetValue(macroname, out entry)) // 매크로가 존재할 경우에만 치환할 텍스트를 얻어온다 { replaced = entry.Text; } if (replaced == null) // 치환할 텍스트가 없다면 경고 메세지 후 매크로 이름을 대신 출력한다. { Debug.LogWarningFormat("해당 매크로가 존재하지 않거나, 현재 조건으로는 매크로를 치환할 수가 없습니다. - {0}", macroname); replaced = string.Format("({0})", macroname); } output.Append(replaced); // 치환한 텍스트 출력하기 starti = mendi + 1; // 매크로 치환 기호 바로 뒤부터 다시 처리 시작 } } output.Append(original.Substring(starti)); // 남은 문자열 모두 출력하기 return(output.ToString()); }
public static int GetAlias(string aliasName) { MacroEntry macro = MacroManager.GetInstance().GetCurrentMacro(); if (macro != null) { if (macro.Aliases.ContainsKey(aliasName.ToLower())) { return(macro.Aliases[aliasName.ToLower()]); } } if (_aliases.ContainsKey(aliasName.ToLower())) { return(_aliases[aliasName.ToLower()]); } return(-1); }
public void WillRaiseStoppedEvent() { MacroEntry me = new MacroEntry(); MacroInvoker mi = MacroInvoker.GetInstance(); AutoResetEvent are = new AutoResetEvent(false); void OnStoppedEvent() { are.Set(); } mi.StoppedEvent += OnStoppedEvent; mi.Execute(me); bool result = are.WaitOne(5000); Assert.IsTrue(result); }
public static void SetMacroAlias(string aliasName, object obj) { int value = ResolveSerial(obj); MacroEntry macro = MacroManager.GetInstance().GetCurrentMacro(); if (macro == null) { SetAlias(aliasName, obj); return; } if (macro.Aliases.ContainsKey(aliasName.ToLower())) { macro.Aliases[aliasName.ToLower()] = value; } else { macro.Aliases.Add(aliasName.ToLower(), value); } }
public static bool CheckCommand(byte[] data, int length) { string text = null; if (data[0] == 0xAD) { text = ParseUnicodeSpeech(data, data.Length); } else if (data[0] == 0x03) { text = ParseAsciiSpeech(data, data.Length); } if (text != null && text.Length >= 7 && text.Substring(0, 7).Equals(">macro ")) { string macroName = text.Substring(7, text.Length - 7); MacroEntry macro = MacroManager.GetInstance().Items.FirstOrDefault(m => m.Name == macroName); if (macro == null) { UOC.SystemMessage(Strings.Macro_not_found___, 35); } else { macro.Execute(); } return(true); } if (string.IsNullOrEmpty(text) || text[0] != Options.CurrentOptions.CommandPrefix) { return(false); } string[] args = text.Remove(0, 1).Split(' '); return(_commands.ContainsKey(args[0]) && _commands[args[0]].Invoke(args.Skip(1).ToArray())); }
public static void PlayMacro(string name) { MacroManager manager = MacroManager.GetInstance(); MacroEntry current = manager.GetCurrentMacro(); if (current != null && current.IsBackground) { UOC.SystemMessage(Strings.Cannot_PlayMacro_from_background_macro___); return; } MacroEntry macro = manager.Items.FirstOrDefault(m => m.Name == name); if (macro == null) { UOC.SystemMessage(Strings.Unknown_macro___); return; } Task.Run(() => macro.Action(macro)); }
public string ReplaceParms(MacroEntry me, string[] actual_parms) { Match m; int istart = 0; string subst = me.Subst; while ((m = iden.Match(subst,istart)) != Match.Empty) { int idx = Array.IndexOf(me.Parms,m.Value); int len = m.Length; if (idx != -1) { string actual = actual_parms[idx]; // A _single_ # before a token means the 'stringizing' operator if (m.Index > 0 && subst[m.Index-1] == '#') { // whereas ## means 'token-pasting'! #s will be removed later! if (! (m.Index > 1 && subst[m.Index-2] == '#')) actual = '\"' + actual + '\"'; } subst = iden.Replace(subst,actual,1,istart); len = actual.Length; } istart = m.Index + len; } subst = subst.Replace("#",""); return subst; }
/// <summary> Adds a VM definition to the cache. /// </summary> /// <returns>Whether everything went okay. /// /// </returns> public bool AddVM(String vmName, String macroBody, String[] argArray, String ns) { MacroEntry me = new MacroEntry(this, this, vmName, macroBody, argArray, ns); me.FromLibrary = registerFromLib; /* * the client (VMFactory) will signal to us via * registerFromLib that we are in startup mode registering * new VMs from libraries. Therefore, we want to * addto the library map for subsequent auto reloads */ bool isLib = true; if (registerFromLib) { SupportClass.PutElement(libraryMap, ns, ns); } else { /* * now, we first want to check to see if this namespace (template) * is actually a library - if so, we need to use the global namespace * we don't have to do this when registering, as namespaces should * be shut off. If not, the default value is true, so we still go * global */ isLib = libraryMap.ContainsKey(ns); } if (!isLib && UsingNamespaces(ns)) { /* * first, do we have a namespace hash already for this namespace? * if not, add it to the namespaces, and add the VM */ Hashtable local = GetNamespace(ns, true); SupportClass.PutElement(local, vmName, me); return true; } else { /* * otherwise, add to global template. First, check if we * already have it to preserve some of the autoload information */ MacroEntry exist = (MacroEntry) GetNamespace(GLOBAL_NAMESPACE)[vmName]; if (exist != null) { me.FromLibrary = exist.FromLibrary; } /* * now add it */ SupportClass.PutElement(GetNamespace(GLOBAL_NAMESPACE), vmName, me); return true; } }
/// <summary> /// 매크로 엔트리를 리턴. 없을 경우엔 생성한다. /// </summary> /// <param name="name"></param> /// <returns></returns> MacroEntry GetMacroEntry(string name) { MacroEntry entry = null; if (!m_macroDict.TryGetValue(name, out entry)) // 항목이 기존에 없었을 시에는 생성 { entry = new MacroEntry(); m_macroDict[name] = entry; } return entry; }