static internal string EvaluateCondition(string sValue)
        {
            sValue = sValue.Replace("\r", " ").Replace("\n", " ");

            MatchCollection mItems = Regex.Matches(sValue, @"\{(.*?)\}");

            foreach (Match matchString in mItems)
            {
                if (matchString.Success)
                {
                    string[] args = matchString.ToString().Split(';');
                    if (args[0].Contains("*"))
                    {
                        args[0] = ParsingTools.ParseTokens(args[0]);
                    }
                    if (args[0].Contains("evalBool"))
                    {
                        string condition = args[0].Replace("{", string.Empty)
                                           .Replace("evalBool", string.Empty)
                                           .Replace("(", string.Empty)
                                           .Replace(")", string.Empty).ToValues();

                        bool e;

                        if (condition.Contains("~>"))
                        {
                            string[] vals = Regex.Split(condition, "~>");
                            e = vals[0].Replace("\"", string.Empty).Contains(vals[1].Replace("\"", string.Empty));
                        }
                        else
                        {
                            e = Evaluator.EvaluateToBool(condition);
                        }

                        sValue = e ? sValue.Replace(matchString.ToString(), Parser.Instance.Parse(args[1].Replace(" ", ";"), false, true)) :
                                 sValue.Replace(matchString.ToString(), Parser.Instance.Parse(args[2].Replace(" ", ";"), false, true));
                    }
                }
            }
            return(sValue);
        }
Beispiel #2
0
        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);
            }
        }