private static void QueryMemoryUsage(String postfix, IEnsoService service) { List <Process> processes = new List <Process>(GetProcesses(postfix)); int processCount = processes.Count(); if (processCount > 0) { String message = ""; if (processCount == 1) { message = "<p>" + GetProcessMemoryUsage(processes[0], true) + "</p>"; } else if (processCount <= 5) { processes.Sort((Process l, Process r) => - l.WorkingSet64.CompareTo(r.WorkingSet64)); foreach (Process process in processes) { message += "<p>" + GetProcessMemoryUsage(process, true) + "</p>"; } } else { processes.Sort((Process l, Process r) => - l.WorkingSet64.CompareTo(r.WorkingSet64)); foreach (Process process in processes) { message += "<caption>" + GetProcessMemoryUsage(process, true) + "</caption>"; } } service.DisplayMessage(new FreeFormatMessage(message)); } else { service.DisplayMessage(new EnsoMessage("Process " + postfix + " not found")); } }
private static void ListProcesses(String postfix, IEnsoService service) { Process[] processes = Process.GetProcesses(); SortedSet <String> uniqueNames = new SortedSet <String>(); foreach (Process p in processes) { uniqueNames.Add(p.ProcessName); } char initial = '\0'; String message = ""; foreach (String s in uniqueNames) { String name = s.ToLower(); if (name.Length > 0 && !name[0].Equals(initial)) { initial = name[0]; name = char.ToUpper(name[0]) + name.Substring(1); } message += name + " "; } message = "<p>" + message.Trim() + "</p>"; service.DisplayMessage(new FreeFormatMessage(message)); }
private static void QuitLingvo(String postfix, IEnsoService service) { try { ILingvoApplication lingvo = new CLingvoApplication(); lingvo.Quit(); } catch (Exception) { service.DisplayMessage(new EnsoMessage(ERROR_MESSAGE)); } }
public void OnCommand(EnsoCommand command, String postfix) { Match m = boundsParser.Match(postfix); int from = 0; String s_from = m.Groups[1].Value; try { if (!"".Equals(s_from.Trim())) { from = Convert.ToInt32(s_from); } } catch (Exception) { service.DisplayMessage(new EnsoMessage(INVALID_BOUNDS_ERROR)); } int to = int.MaxValue; String s_to = m.Groups[2].Value; try { if (!"".Equals(s_to.Trim())) { to = Convert.ToInt32(s_to); } } catch (Exception) { service.DisplayMessage(new EnsoMessage(INVALID_BOUNDS_ERROR)); } int result = random.Next(from, to); service.InsertUnicodeAtCursor(result.ToString(), command); }
private static void DialInternet(String postfix, IEnsoService service) { try { if (!"".Equals(postfix)) { RAS.Dial(postfix); } } catch (Exception) { service.DisplayMessage(new EnsoMessage(CONNECT_ERROR)); } }
private static void HangupInternet(String postfix, IEnsoService service) { try { if (!"".Equals(postfix)) { IntPtr hConn = RAS.GetConnection(postfix); if (hConn != IntPtr.Zero) { RAS.HangUp(hConn); } } } catch (Exception) { service.DisplayMessage(new EnsoMessage(HANGUP_ERROR)); } }
private static void KillProcess(String postfix, IEnsoService service) { Process [] processes = GetProcesses(postfix); if (processes.Count() > 0) { foreach (Process process in processes) { try { process.Kill(); } catch (Exception) { } } } else { service.DisplayMessage(new EnsoMessage("Process " + postfix + " not found")); } }
private static void TranslateWord(String postfix, IEnsoService service) { Match m = wordParser.Match(postfix); String word = m.Groups[1].Value; if ("".Equals(word.Trim())) { word = service.GetUnicodeSelection(); } bool isLatin = latinMatcher.IsMatch(word); m = directionParser.Match(postfix); String from = m.Groups[1].Value; if (!lang2code.Keys.Contains(from)) { from = isLatin ? LINGVO_SECONDARY_LANG : LINGVO_CORE_LANG; } String to = m.Groups[2].Value; if (!lang2code.Keys.Contains(to)) { to = isLatin ? LINGVO_CORE_LANG : LINGVO_SECONDARY_LANG; } try { ILingvoApplication lingvo = new CLingvoApplication(); lingvo.TranslateTextInDirection(word, lang2code[from], lang2code[to]); } catch (Exception) { service.DisplayMessage(new EnsoMessage(ERROR_MESSAGE)); } }
private static void DialInternet(String postfix, IEnsoService service) { try { if (!"".Equals(postfix)) RAS.Dial(postfix); } catch (Exception) { service.DisplayMessage(new EnsoMessage(CONNECT_ERROR)); } }
private static void HangupInternet(String postfix, IEnsoService service) { try { if (!"".Equals(postfix)) { IntPtr hConn = RAS.GetConnection(postfix); if (hConn != IntPtr.Zero) RAS.HangUp(hConn); } } catch (Exception) { service.DisplayMessage(new EnsoMessage(HANGUP_ERROR)); } }
private static void TranslateWord(String postfix, IEnsoService service) { Match m = wordParser.Match(postfix); String word = m.Groups[1].Value; if ("".Equals(word.Trim())) word = service.GetUnicodeSelection(); bool isLatin = latinMatcher.IsMatch(word); m = directionParser.Match(postfix); String from = m.Groups[1].Value; if (!lang2code.Keys.Contains(from)) from = isLatin ? LINGVO_SECONDARY_LANG : LINGVO_CORE_LANG; String to = m.Groups[2].Value; if (!lang2code.Keys.Contains(to)) to = isLatin ? LINGVO_CORE_LANG : LINGVO_SECONDARY_LANG; try { ILingvoApplication lingvo = new CLingvoApplication(); lingvo.TranslateTextInDirection(word, lang2code[from], lang2code[to]); } catch (Exception) { service.DisplayMessage(new EnsoMessage(ERROR_MESSAGE)); } }
private static void QuitLingvo(String postfix, IEnsoService service) { try { ILingvoApplication lingvo = new CLingvoApplication(); lingvo.Quit(); } catch (Exception) { service.DisplayMessage(new EnsoMessage(ERROR_MESSAGE)); } }