| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- using System;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.Text;
- using System.ConsoleApp;
- using System.ConsoleApp.Commands;
- namespace Speech.Commands {
- [ConsoleCommand("cache")]
- public class cache_command : BaseCommand {
- public static bool execute(string line, string command, NameValueCollection arg) {
- switch(arg["general"].ToLower()) {
- case "count":
- count(line, arg);
- break;
- case "clear":
- clear(line, arg);
- break;
- case "list":
- list(line, arg);
- break;
- default:
- return true;
- }
- return false;
- }
- public static string LineStartText() {
- return "Cache";
- }
- [ConsoleCommand("qqq")]
- [ConsoleCommand("exit")]
- [ConsoleCommand("quit")]
- public static bool exit() {
- return false;
- }
- [ConsoleCommand("count")]
- public static bool count(string line, NameValueCollection arg) {
- WriteLine("Items in cache: " + SpeechExecute.Cache.Count);
- return true;
- }
- [ConsoleCommand("clear")]
- public static bool clear(string line, NameValueCollection arg) {
- bool bRes = false;
- Input("Do you realy want to clear all cached items?", ref bRes);
- if (bRes) {
- SpeechExecute.Cache.Clear();
- }
- return true;
- }
- [ConsoleCommand("list")]
- public static bool list(string line, NameValueCollection arg) {
- BeginWrite();
- ConsoleColor cc = Console.ForegroundColor;
- int i = 0;
- Console.WriteLine("ID".PadRight(7) + " " + "Text".PadRight(60) + " " + "File".PadRight(40));
- Console.WriteLine(new string('=',113));
- foreach(SpeechCacheEntry e in SpeechExecute.Cache.Entry) {
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.Write(i.ToString().PadLeft(7));
- Console.ForegroundColor = cc;
- if(e.Text.Length>60)
- Console.Write(" | " + e.Text.Substring(0, 57) + "...");
- else
- Console.Write(" | " + e.Text.PadRight(60));
- if (e.File.Length > 30)
- Console.Write(" | " + e.File.Substring(0, 40));
- else
- Console.Write(" | " + e.File.PadRight(40));
- Console.Write("\n");
- i++;
- }
- Console.ForegroundColor = cc;
- EndWrite();
- return true;
- }
- [ConsoleCommand("find")]
- public static bool find(string line, NameValueCollection arg) {
- BeginWrite();
- ConsoleColor cc = Console.ForegroundColor;
- int i = 0;
- Console.WriteLine("ID".PadRight(7) + " " + "Text".PadRight(60) + " " + "File".PadRight(40));
- Console.WriteLine(new string('=', 113));
- System.Text.RegularExpressions.Regex r;
- if(!String.IsNullOrEmpty(arg["regex"])) {
- r = new System.Text.RegularExpressions.Regex(arg["regex"]);
- } else if (!String.IsNullOrEmpty(arg["r"])) {
- r = new System.Text.RegularExpressions.Regex(arg["r"]);
- }
- foreach (SpeechCacheEntry e in SpeechExecute.Cache.Entry) {
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.Write(i.ToString().PadLeft(7));
- Console.ForegroundColor = cc;
- if (e.Text.Length > 60)
- Console.Write(" | " + e.Text.Substring(0, 57) + "...");
- else
- Console.Write(" | " + e.Text.PadRight(60));
- if (e.File.Length > 30)
- Console.Write(" | " + e.File.Substring(0, 40));
- else
- Console.Write(" | " + e.File.PadRight(40));
- Console.Write("\n");
- i++;
- }
- Console.ForegroundColor = cc;
- EndWrite();
- return true;
- }
- }
- }
|