internal static string IntelParser(string arg) { string output = string.Empty; var method = Methods.Instance; string tmpSchedule = "schedule-" + method.GetDay() + method.GetCalendarYear() + "_" + method.GetHour() + method.GetMinute() + DateTime.Now.Second; arg = arg.ToLower(); if (arg.Contains("set alarm at") || arg.Contains("set an alarm for") || arg.Contains("set alarm for")) { string t = arg.Replace("set alarm at", string.Empty).Replace(".", string.Empty) .Replace("set an alarm for", string.Empty).Replace(".", string.Empty) .Replace("set alarm for", string.Empty).Replace(".", string.Empty) .Trim(); string when = "%calendardate%"; if (Convert.ToInt32(t.ToHour24().Substring(0, t.ToHour24().IndexOf(':'))) < DateTime.Now.Hour || Convert.ToInt32(t.ToHour24().Substring(0, t.ToHour24().IndexOf(':'))) >= DateTime.Now.Hour && Convert.ToInt32(t.ToHour24().Substring(t.ToHour24().IndexOf(':') + 1)) < DateTime.Now.Minute) { when = String.Format("{0:d/M/yyyy}", DateTime.Now.AddDays(1).Date); } Judoers.JudoParser("judo schedule add " + tmpSchedule + " " + when + " " + t.ToHour24() + " __SYS_ALARM"); output = "Setting alarm for " + t; } if (arg.Contains("repeat after me")) { Parser.SayText(arg.Replace("repeat after me", string.Empty).Trim()); } return(output); }
/// <summary> /// args - more than one in-line argument separated by semicolon. /// Example: Parse ("judo serial open; judo server start; %checkin%); /// ReturnAsHTML - In web request it formats the \r\n to html break <br />. /// </summary> /// <param name="args"> /// A <see cref="System.String"/> /// </param> /// <param name = "returnAsHTML"></param> /// <param name="ReturnAsHTML"> /// A <see cref="System.Boolean"/> /// </param> /// <returns> /// A <see cref="System.String"/> /// </returns> /// <param name="disableSpeech"></param> internal string Parse(string args, bool returnAsHTML, bool disableSpeech) { if (args.Contains("{mute}") || args.Contains("{widget}")) { args = args.Replace("{mute}", string.Empty).Replace("{widget}", string.Empty); disableSpeech = true; } if (args.Contains("</lock>")) { if (returnAsHTML) { return(Judoers.JudoParser(args).Replace("\r", string.Empty).Replace("\n", "<br />")); } else { return(Judoers.JudoParser(args)); } } string[] InstructionSet = args.Split(';'); string results = string.Empty; foreach (string Instruction in InstructionSet) { if (Instruction.Trim() != string.Empty) { results += Execute(Instruction.Trim(), disableSpeech); } } return(returnAsHTML ? results.Replace("<", "<").Replace(">", ">").Replace("\r", string.Empty).Replace("\n", "<br />") : results); }
internal string Parse(string args, DataType dataType, bool disableSpeech) { if (args.Contains("{mute}") || args.Contains("{widget}")) { args = args.Replace("{mute}", string.Empty).Replace("{widget}", string.Empty); disableSpeech = true; } if (args.Contains("</lock>")) // lock is extension of judo parser. No need for extra parsing { if (dataType.Equals(DataType.html)) { return(Judoers.JudoParser(args).Replace("\r", string.Empty).Replace("\n", "<br />")); } else { return(Judoers.JudoParser(args)); } } string[] InstructionSets = args.Replace('&', ';').Split(';'); var results = new Dictionary <string, KeyValuePair <string, string> >(); foreach (string Instruction in InstructionSets) { if (Instruction.Trim() != string.Empty) { var exe = Execute(Instruction.Trim(), disableSpeech).Replace("\r", string.Empty); if (exe.EndsWith("\n")) { exe = exe.Substring(0, exe.LastIndexOf("\n")); } var key = Instruction.Trim().Replace(" ", "_").Replace("%", string.Empty); try { results.Add(key, new KeyValuePair <string, string>(Instruction.Trim(), exe)); } catch { // Duplicate keys are not allowed. } } } switch (dataType) { case DataType.html: return(results.ToDebugString().Replace("<", "<").Replace(">", ">").Replace("\n", "<br />")); case DataType.json: return(results.ToJson()); } return(results.ToDebugString()); }
internal static string ParseTokens(string sValue) { if (sValue.Contains("%")) { if (sValue.Substring(0, 1) == "%") { return(string.Format("{0}\r\n", sValue.ToLower().ToValues())); } else { sValue = sValue.ToValues(); } } while (sValue.Contains("*")) { MatchCollection mItems = Regex.Matches(sValue, @"[*][a-zA-Z0-9_-]+"); if (mItems.Count > 0) { foreach (Match matchString in mItems) { if (matchString.Success) { string retval = ParseTokens(Methods.Instance.GetInstructionSet(matchString.ToString().Trim()).Item(0).InnerText); sValue = sValue.Replace(matchString.ToString().Trim(), retval); } } } else { break; } } if (sValue.Contains("evalBool")) { sValue = Evaluator.EvaluateCondition(sValue); } if (sValue.Contains("./") || sValue.Contains("judo")) { if (sValue.Substring(0, 2).Contains("./")) { MatchCollection mItems = Regex.Matches(sValue, @"('[^']+')|(`[^`]+`)"); String fileName = string.Empty; String arguments = string.Empty; if (mItems.Count == 0) { fileName = sValue.Replace("./", string.Empty); } else if (mItems.Count == 1) { fileName = mItems[0].Value.Replace("`", string.Empty).Replace("'", string.Empty); } if (mItems.Count == 2) { fileName = mItems[0].Value.Replace("`", string.Empty).Replace("'", string.Empty); arguments = mItems[1].Value.Replace("`", string.Empty).Replace("'", string.Empty); } return(Process.Instance.Start(fileName, arguments)); } switch (sValue.Substring(0, 4)) { case "judo": return(sValue.Replace(sValue, Judoers.JudoParser(sValue))); } // + "\r\n"; Causing problem to evaluation - need solution } return(sValue); }
string Execute(string arg, bool disableSpeech) { string output = string.Empty; var method = Methods.Instance; try { if (arg.StartsWith("%") || arg.StartsWith("./") || arg.StartsWith("judo")) { return(ParsingTools.ParseTokens(arg)); } else { XmlNodeList xList = method.GetInstructionSet(arg.Replace("*", string.Empty)); if (xList.Count <= 0 && !arg.Contains("*")) { output = Judoers.IntelParser(arg); if (output == string.Empty) { Logger.Instance.Append("obj [ Parser.Execute ]: arg [ " + arg + ", not found. ]"); output = arg + ", not found."; } } else { foreach (XmlNode nodeItem in xList) { output += string.Format("{0}\r\n", ParsingTools.ParseTokens(nodeItem.InnerText)); } } } if (method.HasInternetConnection() && !disableSpeech) { if (!User.Status && output.Trim() != string.Empty && File.Exists(method.GetApplicationPath() + ".smtpsettings")) { XmlNodeList xList = method.GetMailHeaders(); foreach (XmlNode nodeItem in xList) { Action SendNotification = () => new Net.Mail().Send(nodeItem.SelectSingleNode("MailFrom").InnerText, nodeItem.SelectSingleNode("MailTo").InnerText, nodeItem.SelectSingleNode("MailSubject").InnerText, output); Process.CallWithTimeout(SendNotification, 10000); } } } if (output.Trim() != string.Empty && !Mute && !disableSpeech) { var t = new Thread(() => SayText(output.Replace("Parser: ", string.Empty))); t.IsBackground = true; t.Start(); } if (!ParserState) { Thread.Sleep(1000); Environment.Exit(0); } return(string.Format("{0}\r\n", output.Trim())); } catch (Exception e) { if (!e.Message.Contains("Parameter name: length")) { Logger.Instance.Append("obj [ Parser.Execute <Exception> ]: Argument: [ " + arg + " ] Exception: [ " + e.Message + " ]"); return(e.Message); } return(string.Empty); } }