// take conditions and JSON, decode it, execute.. public bool?CheckCondition(List <Condition> fel, Object cls, // object with data in it ConditionVariables othervars, // any other variables to present to the condition, in addition to the JSON variables out string errlist, // null if okay.. List <Condition> passed) // null or conditions passed { errlist = null; ConditionVariables valuesneeded = new ConditionVariables(); foreach (Condition fe in fel) // find all values needed { fe.IndicateValuesNeeded(ref valuesneeded); } try { valuesneeded.GetValuesIndicated(cls); valuesneeded.Add(othervars); return(CheckConditions(fel, valuesneeded, out errlist, passed)); // and check, passing in the values collected against the conditions to test. } catch (Exception) { errlist = "JSON failed to parse!"; return(null); } }
public void Add(ConditionVariables d) { if (d != null) { Add(d.values); } }
public ConditionFunctionHandlers(ConditionFunctions c, ConditionVariables v, ConditionPersistentData h, int recd) { caller = c; vars = v; persistentdata = h; recdepth = recd; paras = new List <Parameter>(); }
public ConditionFunctionHandlers(ConditionFunctions c, ConditionVariables v, ConditionFileHandles h, int recd) { caller = c; vars = v; handles = h; recdepth = recd; paras = new List <Parameter>(); }
public void Add(ConditionVariables d) { if (d != null) { foreach (KeyValuePair <string, string> v in d.values) // plus event vars { values[v.Key] = v.Value; } } }
public static delegateGetCFH GetCFH; // SET this to override and add on more functions public ConditionFunctions(ConditionVariables v, ConditionPersistentData f) { vars = v; persistentdata = f; if (GetCFH == null) // Make sure we at least have some functions.. the base ones { GetCFH = DefaultGetCFH; } }
public static delegateGetCFH GetCFH; // SET this to override and add on more functions public ConditionFunctions(ConditionVariables v, ConditionFileHandles f) { vars = v; handles = f; if (GetCFH == null) // Make sure we at least have some functions.. the base ones { GetCFH = DefaultGetCFH; } }
public void IndicateValuesNeeded(ref ConditionVariables vr) { foreach (ConditionEntry fd in fields) { if (!ConditionEntry.IsNullOperation(fd.matchtype) && !fd.itemname.Contains("%")) // nulls need no data.. nor does anything with expand in { vr[fd.itemname] = null; } } }
// check all conditions against these values. public bool?CheckAll(ConditionVariables values, out string errlist, List <Condition> passed = null, ConditionFunctions cf = null) // Check all conditions.. { if (conditionlist.Count == 0) // no filters match, null { errlist = null; return(null); } return(CheckConditions(conditionlist, values, out errlist, passed, cf)); }
public ConditionVariables(ConditionVariables other, ConditionVariables other2) // other can be null, other2 must not be { if (other == null) { values = new Dictionary <string, string>(other2.values); } else { values = new Dictionary <string, string>(other.values); Add(other2); } }
// Filter OUT if condition matches.. public bool CheckFilterFalse(Object cls, string eventname, ConditionVariables othervars, out string errlist, List <Condition> passed) // if none, true, if false, true.. { List <Condition> fel = GetConditionListByEventName(eventname); if (fel != null) // if we have matching filters.. { bool?v = CheckCondition(fel, cls, othervars, out errlist, passed); // true means filter matched bool res = !v.HasValue || v.Value == false; //System.Diagnostics.Debug.WriteLine("Event " + eventname + " res " + res + " v " + v + " v.hv " + v.HasValue); return(res); // no value, true .. false did not match, thus true } else { errlist = null; return(true); } }
// all variables, expand out thru macro expander. does not alter these ones public ConditionVariables ExpandAll(ConditionFunctions e, ConditionVariables vars, out string errlist) { errlist = null; ConditionVariables exp = new ConditionVariables(); foreach (KeyValuePair <string, string> k in values) { if (e.ExpandString(values[k.Key], out errlist) == ConditionFunctions.ExpandResult.Failed) { return(null); } exp[k.Key] = errlist; } errlist = null; return(exp); }
public ConditionVariables ExpandVars(ConditionVariables vars, out string errlist) // expand all variables to new list { errlist = null; ConditionVariables exp = new ConditionVariables(); foreach (string k in vars.NameEnumuerable) { if (ExpandString(vars[k], out errlist) == ConditionFunctions.ExpandResult.Failed) { return(null); } exp[k] = errlist; } errlist = null; return(exp); }
// return a list just with the names matching filter, or filter* public ConditionVariables FilterVars(string filter) { int wildcard = filter.IndexOf('*'); if (wildcard >= 0) { filter = filter.Substring(0, wildcard); } ConditionVariables ret = new ConditionVariables(); foreach (KeyValuePair <string, string> k in values) { if ((wildcard >= 0 && k.Key.StartsWith(filter)) || k.Key.Equals(filter)) { ret[k.Key] = k.Value; } } return(ret); }
// altops, if given, describes the operator of each variable. public void Init(string t, Icon ic, ConditionVariables vbs, Dictionary <string, string> altops = null, bool showone = false, bool showrefresh = false, bool showrefreshstate = false, bool allowadd = false, bool allownoexpand = false, bool allowmultiple = true) { this.Icon = ic; bool winborder = ExtendedControls.ThemeableFormsInstance.Instance.ApplyToForm(this, SystemFonts.DefaultFont); statusStripCustom.Visible = panelTop.Visible = panelTop.Enabled = !winborder; this.Text = label_index.Text = t; showadd = allowadd; shownoexpand = allownoexpand; this.allowmultiple = allowmultiple; int pos = panelmargin; checkBoxCustomRefresh.Enabled = checkBoxCustomRefresh.Visible = showrefresh; checkBoxCustomRefresh.Checked = showrefreshstate; checkBoxCustomRefresh.Location = new Point(pos, panelmargin); if (vbs != null) { foreach (string key in vbs.NameEnumuerable) { CreateEntry(key, vbs[key], (altops != null) ? altops[key] : "="); } } if (groups.Count == 0 && showone) { CreateEntry("", "", "="); } if (groups.Count >= 1) { groups[0].var.Focus(); } }
private void buttonOK_Click(object sender, EventArgs e) { result = new ConditionVariables(); result_altops = new Dictionary <string, string>(); foreach (Group g in groups) { if (g.var.Text.Length > 0) // only ones with names are considered { result[g.var.Text] = g.value.Text.EscapeControlChars(); if (g.op != null) { result_altops[g.var.Text] = g.op.Text; } } } result_refresh = checkBoxCustomRefresh.Checked; DialogResult = DialogResult.OK; Close(); }
public ConditionVariables(ConditionVariables other, ConditionVariables other2, ConditionVariables other3) { values = new Dictionary <string, string>(other.values); Add(other2); Add(other3); }
public ConditionVariables(ConditionVariables other) { values = new Dictionary <string, string>(other.values); }
public SoundEffectSettings(ConditionVariables v) { values = v; }
public SoundEffectSettings() { values = new ConditionVariables(); }
public ConditionFunctionsBase(ConditionFunctions c, ConditionVariables v, ConditionFileHandles h, int recd) : base(c, v, h, recd) { if (functions == null) // one time init, done like this cause can't do it in {} { functions = new Dictionary <string, FuncEntry>(); functions.Add("abs", new FuncEntry(Abs, 2, 2, 1, 0)); // first is var or literal or string functions.Add("alt", new FuncEntry(Alt, 2, 20, 0xfffffff, 0xfffffff)); // first is var or literal or string, etc. functions.Add("closefile", new FuncEntry(CloseFile, 1, 1, 1, 0)); // first is a var functions.Add("datetimenow", new FuncEntry(DateTimeNow, 1, 1, 0)); // literal type functions.Add("datehour", new FuncEntry(DateHour, 1, 1, 1, 1)); // first is a var or string functions.Add("date", new FuncEntry(Date, 2, 2, 1, 1)); // first is a var or string, second is literal functions.Add("direxists", new FuncEntry(DirExists, 1, 20, 0xfffffff, 0xfffffff)); // check var, can be string functions.Add("escapechar", new FuncEntry(EscapeChar, 1, 1, 1, 1)); // check var, can be string functions.Add("eval", new FuncEntry(Eval, 1, 2, 1, 1)); // can be string, can be variable, p2 is not a variable, and can't be a string functions.Add("exist", new FuncEntry(Exists, 1, 20, 0, 0xfffffff)); functions.Add("existsdefault", new FuncEntry(ExistsDefault, 2, 2, 2, 3)); // first is a macro but can not exist, second is a string or macro which must exist functions.Add("expand", new FuncEntry(Expand, 1, 20, 0xfffffff, 0xfffffff)); // check var, can be string (if so expanded) functions.Add("expandarray", new FuncEntry(ExpandArray, 4, 5, 2, 3 + 16)); // var 1 is text root/string, not var, not string, var 2 can be var or string, var 3/4 is integers or variables, checked in function functions.Add("expandvars", new FuncEntry(ExpandVars, 4, 5, 2, 3 + 16)); // var 1 is text root/string, not var, not string, var 2 can be var or string, var 3/4 is integers or variables, checked in function functions.Add("filelength", new FuncEntry(FileLength, 1, 1, 1, 1)); // check var, can be string functions.Add("fileexists", new FuncEntry(FileExists, 1, 20, 0xfffffff, 0xfffffff)); // check var, can be string functions.Add("findline", new FuncEntry(FindLine, 2, 2, 3, 2)); //check var1 and var2, second can be a string functions.Add("floor", new FuncEntry(Floor, 2, 2, 1)); // check var1, not var 2 no strings functions.Add("ifnotempty", new FuncEntry(Ifnotempty, 2, 3, 7, 7)); // check var1-3, allow strings var1-3 functions.Add("ifempty", new FuncEntry(Ifempty, 2, 3, 7, 7)); functions.Add("iftrue", new FuncEntry(Iftrue, 2, 3, 7, 7)); // check var1-3, allow strings var1-3 functions.Add("iffalse", new FuncEntry(Iffalse, 2, 3, 7, 7)); functions.Add("ifzero", new FuncEntry(Ifzero, 2, 3, 7, 7)); // check var1-3, allow strings var1-3 functions.Add("ifnonzero", new FuncEntry(Ifnonzero, 2, 3, 7, 7)); // check var1-3, allow strings var1-3 functions.Add("ifcontains", new FuncEntry(Ifcontains, 3, 5, 31, 31)); // check var1-5, allow strings var1-5 functions.Add("ifnotcontains", new FuncEntry(Ifnotcontains, 3, 5, 31, 31)); functions.Add("ifequal", new FuncEntry(Ifequal, 3, 5, 31, 31)); functions.Add("ifnotequal", new FuncEntry(Ifnotequal, 3, 5, 31, 31)); functions.Add("ifgt", new FuncEntry(Ifnumgreater, 3, 5, 31, 31)); // check var1-5, allow strings var1-5 functions.Add("iflt", new FuncEntry(Ifnumless, 3, 5, 31, 31)); functions.Add("ifge", new FuncEntry(Ifnumgreaterequal, 3, 5, 31, 31)); functions.Add("ifle", new FuncEntry(Ifnumlessequal, 3, 5, 31, 31)); functions.Add("ifeq", new FuncEntry(Ifnumequal, 3, 5, 31, 31)); functions.Add("ifne", new FuncEntry(Ifnumnotequal, 3, 5, 31, 31)); functions.Add("indexof", new FuncEntry(IndexOf, 2, 2, 3, 3)); // check var1 and 2 if normal, allow string in 1 and 2 functions.Add("indirect", new FuncEntry(Indirect, 1, 20, 0xfffffff, 0xfffffff)); // check var, no strings functions.Add("ispresent", new FuncEntry(Ispresent, 2, 3, 2, 2)); // 1 may not be there, 2 either a macro or can be string. 3 is optional and a var or literal functions.Add("join", new FuncEntry(Join, 3, 20, 0xfffffff, 0xfffffff)); // all can be string, check var functions.Add("length", new FuncEntry(Length, 1, 1, 1, 1)); functions.Add("lower", new FuncEntry(Lower, 1, 20, 0xfffffff, 0xfffffff)); // all can be string, check var functions.Add("mkdir", new FuncEntry(MkDir, 1, 1, 1, 1)); // check var, can be string functions.Add("openfile", new FuncEntry(OpenFile, 3, 3, 2, 2)); functions.Add("phrase", new FuncEntry(Phrase, 1, 1, 1, 1)); functions.Add("random", new FuncEntry(Random, 1, 1, 0, 0)); // no change var, not string functions.Add("readline", new FuncEntry(ReadLineFile, 2, 2, 1, 0)); // first must be a macro, second is a literal varname only functions.Add("replace", new FuncEntry(Replace, 3, 3, 7, 7)); // var/string for all functions.Add("replaceescapechar", new FuncEntry(ReplaceEscapeChar, 1, 1, 1, 1)); // check var, can be string functions.Add("replacevar", new FuncEntry(ReplaceVar, 2, 2, 1, 3)); // var/string, literal/var/string functions.Add("round", new FuncEntry(RoundCommon, 3, 3, 1)); functions.Add("roundnz", new FuncEntry(RoundCommon, 4, 4, 1)); functions.Add("roundscale", new FuncEntry(RoundCommon, 5, 5, 1)); functions.Add("rs", new FuncEntry(ReplaceVarSC, 2, 2, 1, 3)); // var/string, literal/var/string functions.Add("rv", new FuncEntry(ReplaceVar, 2, 2, 1, 3)); // var/string, literal/var/string functions.Add("seek", new FuncEntry(SeekFile, 2, 2, 1, 0)); //first is macro, second is literal or macro functions.Add("safevarname", new FuncEntry(SafeVarName, 1, 1, 1, 1)); //macro/string functions.Add("sc", new FuncEntry(SplitCaps, 1, 1, 1, 1)); //shorter alias functions.Add("ship", new FuncEntry(Ship, 1, 1, 1, 1)); //ship translator functions.Add("splitcaps", new FuncEntry(SplitCaps, 1, 1, 1, 1)); //check var, allow strings functions.Add("substring", new FuncEntry(SubString, 3, 3, 1, 1)); // check var1, var1 can be string, var 2 and 3 can either be macro or ints not strings functions.Add("systempath", new FuncEntry(SystemPath, 1, 1, 0, 0)); // literal functions.Add("tell", new FuncEntry(TellFile, 1, 1, 1, 0)); //first is macro functions.Add("tickcount", new FuncEntry(TickCount, 0, 0, 0, 0)); // no paras functions.Add("trim", new FuncEntry(Trim, 1, 2, 1, 1)); functions.Add("upper", new FuncEntry(Upper, 1, 20, 0xfffffff, 0xfffffff)); // all can be string, check var functions.Add("wordlistcount", new FuncEntry(WordListCount, 1, 1, 1)); // first is a var or string functions.Add("wordlistentry", new FuncEntry(WordListEntry, 2, 2, 1, 1)); // first is a var or string, second is a var or literal functions.Add("wordof", new FuncEntry(WordOf, 2, 3, 1 + 4, 1 + 4)); // first is a var or string, second is a var or literal, third is a macro or string functions.Add("write", new FuncEntry(WriteFile, 2, 2, 3, 2)); // first must be a var, second can be macro or string functions.Add("writeline", new FuncEntry(WriteLineFile, 2, 2, 3, 2)); // first must be a var, second can be macro or string } }
// TRUE if filter is True and has value public bool CheckFilterTrue(Object cls, ConditionVariables othervars, out string errlist, List <Condition> passed) // if none, true, if false, true.. { // only if the filter passes do we get a false.. bool?v = CheckCondition(conditionlist, cls, othervars, out errlist, passed); return(v.HasValue && v.Value); // true IF we have a positive result }
// backstop standard functions static public ConditionFunctionHandlers DefaultGetCFH(ConditionFunctions c, ConditionVariables vars, ConditionPersistentData handles, int recdepth) { return(new ConditionFunctionsBase(c, vars, handles, recdepth)); }
public ConditionVariables(ConditionVariables other, string name, string value) { values = new Dictionary <string, string>(other.values); values[name] = value; }
public override bool ExecuteAction(ActionProgramRun ap) { List <string> ctrl = FromString(UserData); if (ctrl != null) { List <string> exp; if (ap.functions.ExpandStrings(ctrl, out exp) != ConditionFunctions.ExpandResult.Failed) { string cmdname = exp[0].ToLower(); string nextword = exp.Count >= 2 ? exp[1] : null; string thirdword = exp.Count >= 3 ? exp[2] : null; string fourthword = exp.Count >= 4 ? exp[3] : null; string fifthword = exp.Count >= 5 ? exp[4] : null; if (cmdname == null) { ap.ReportError("Missing command in Perform"); } else if (cmdname.Equals("3dmap")) { (ap.actioncontroller as ActionController).DiscoveryForm.Open3DMap(null); } else if (cmdname.Equals("2dmap")) { (ap.actioncontroller as ActionController).DiscoveryForm.Open2DMap(); } else if (cmdname.Equals("edsm")) { ActionController ac = (ap.actioncontroller as ActionController); EliteDangerousCore.EDSM.EDSMClass edsm = new EliteDangerousCore.EDSM.EDSMClass(); if (edsm.ValidCredentials) { EliteDangerousCore.EDSM.EDSMJournalSync.SendEDSMEvents(ap.actioncontroller.LogLine, ac.DiscoveryForm.history); } else { ap.ReportError("No valid EDSM Credentials"); } } else if (cmdname.Equals("refresh")) { (ap.actioncontroller as ActionController).DiscoveryForm.RefreshHistoryAsync(); } else if (cmdname.Equals("url")) { if (nextword != null && nextword.StartsWith("http:", StringComparison.InvariantCultureIgnoreCase) || nextword.StartsWith("https:", StringComparison.InvariantCultureIgnoreCase)) // security.. { System.Diagnostics.Process.Start(nextword); } else { ap.ReportError("Perform url must start with http"); } } else if (cmdname.Equals("configurevoice")) { (ap.actioncontroller as ActionController).ConfigureVoice(nextword ?? "Configure Voice Synthesis"); } else if (cmdname.Equals("manageaddons")) { (ap.actioncontroller as ActionController).ManageAddOns(); } else if (cmdname.Equals("editaddons")) { (ap.actioncontroller as ActionController).EditAddOns(); } else if (cmdname.Equals("editlastpack")) { (ap.actioncontroller as ActionController).EditLastPack(); } else if (cmdname.Equals("editpack")) { if (nextword != null) { if (!(ap.actioncontroller as ActionController).EditPack(nextword)) { ap.ReportError("Pack " + nextword + " not found"); } } else { ap.ReportError("EditPack requires a pack name"); } } else if (cmdname.Equals("editspeechtext")) { (ap.actioncontroller as ActionController).EditSpeechText(); } else if (cmdname.Equals("configurewave")) { (ap.actioncontroller as ActionController).ConfigureWave(nextword ?? "Configure Wave Output"); } else if (cmdname.Equals("enableeliteinput")) { (ap.actioncontroller as ActionController).EliteInput(true, true); } else if (cmdname.Equals("enableeliteinputnoaxis")) { (ap.actioncontroller as ActionController).EliteInput(true, false); } else if (cmdname.Equals("disableeliteinput")) { (ap.actioncontroller as ActionController).EliteInput(false, false); } else if (cmdname.Equals("enablevoicerecognition")) { if (nextword != null) { ap["VoiceRecognitionEnabled"] = ((ap.actioncontroller as ActionController).VoiceReconOn(nextword)).ToStringIntValue(); } else { ap.ReportError("EnableVoiceRecognition requires a culture"); } } else if (cmdname.Equals("disablevoicerecognition")) { (ap.actioncontroller as ActionController).VoiceReconOff(); } else if (cmdname.Equals("beginvoicerecognition")) { (ap.actioncontroller as ActionController).VoiceLoadEvents(); } else if (cmdname.Equals("voicerecognitionconfidencelevel")) { float?conf = nextword.InvariantParseFloatNull(); if (conf != null) { (ap.actioncontroller as ActionController).VoiceReconConfidence(conf.Value); } else { ap.ReportError("VoiceRecognitionConfidencelLevel requires a confidence value"); } } else if (cmdname.Equals("voicerecognitionparameters")) { int?babble = nextword.InvariantParseIntNull(); // babble at end int?initialsilence = thirdword.InvariantParseIntNull(); // silence at end int?endsilence = fourthword.InvariantParseIntNull(); // unambigious timeout int?endsilenceambigious = fifthword.InvariantParseIntNull(); // ambiguous timeout if (babble != null && initialsilence != null && endsilence != null && endsilenceambigious != null) { (ap.actioncontroller as ActionController).VoiceReconParameters(babble.Value, initialsilence.Value, endsilence.Value, endsilenceambigious.Value); } else { ap.ReportError("VoiceRecognitionParameters requires four values"); } } else if (cmdname.Equals("voicerecognitionphrases")) { ap["Phrases"] = (ap.actioncontroller as ActionController).VoicePhrases(Environment.NewLine); } else if (cmdname.Equals("listeliteinput")) { ap["EliteInput"] = (ap.actioncontroller as ActionController).EliteInputList(); ap["EliteInputCheck"] = (ap.actioncontroller as ActionController).EliteInputCheck(); } else if (cmdname.Equals("voicenames")) { ap["VoiceNames"] = (ap.actioncontroller as ActionController).SpeechSynthesizer.GetVoiceNames().QuoteStrings(); } else if (cmdname.Equals("bindings")) { ap["Bindings"] = (ap.actioncontroller as ActionController).FrontierBindings.ListBindings(); } else if (cmdname.Equals("bindingvalues")) { ap["BindingValues"] = (ap.actioncontroller as ActionController).FrontierBindings.ListValues(); } else if (cmdname.Equals("datadownload")) { string gitfolder = nextword; string filewildcard = thirdword; string directory = fourthword; string optclean = fifthword; if (gitfolder != null && filewildcard != null && directory != null) { if (System.IO.Directory.Exists(directory)) { BaseUtils.GitHubClass ghc = new BaseUtils.GitHubClass(EDDiscovery.Properties.Resources.URLGithubDataDownload); bool worked = ghc.Download(directory, gitfolder, filewildcard, optclean != null && optclean == "1"); ap["Downloaded"] = worked.ToStringIntValue(); } else { ap.ReportError("Download folder " + directory + " does not exist"); } } else { ap.ReportError("Missing parameters in Perform Datadownload"); } } else if (cmdname.Equals("generateevent")) { if (nextword != null) { ActionEvent f = ActionEventEDList.EventList(excludejournal: true).Find(x => x.TriggerName.Equals(nextword)); if (f != null) { Conditions.ConditionVariables c = new Conditions.ConditionVariables(); for (int w = 2; w < exp.Count; w++) { string vname = exp[w]; int asterisk = vname.IndexOf('*'); if (asterisk >= 0) // pass in name* no complaining if not there { string prefix = vname.Substring(0, asterisk); foreach (string jkey in ap.variables.NameEnumuerable) { if (jkey.StartsWith(prefix)) { c[jkey] = ap.variables[jkey]; } } } else { if (ap.variables.Exists(vname)) // pass in explicit name { c[vname] = ap.variables[vname]; } else { ap.ReportError("No such variable '" + vname + "'"); return(true); } } } if (f.TriggerName.StartsWith("UI") || f.TriggerName.Equals("onEliteUIEvent")) { c["EventClass_EventTimeUTC"] = DateTime.UtcNow.ToStringUS(); c["EventClass_EventTypeID"] = c["EventClass_EventTypeStr"] = f.TriggerName.Substring(2); c["EventClass_UIDisplayed"] = EDDConfig.Instance.ShowUIEvents ? "1" : "0"; (ap.actioncontroller as ActionController).ActionRun(Actions.ActionEventEDList.onUIEvent, c); } (ap.actioncontroller as ActionController).ActionRun(f, c, now: true); } else { try { EliteDangerousCore.JournalEntry je = EliteDangerousCore.JournalEntry.CreateJournalEntry(nextword); ap["GenerateEventName"] = je.EventTypeStr; if (je is EliteDangerousCore.JournalEvents.JournalUnknown) { ap.ReportError("Unknown journal event"); } else { EliteDangerousCore.HistoryEntry he = EliteDangerousCore.HistoryEntry.FromJournalEntry(je, null, out bool journalupdate); (ap.actioncontroller as ActionController).ActionRunOnEntry(he, Actions.ActionEventEDList.NewEntry(he), now: true); } } catch { ap.ReportError("Journal event not in correct JSON form"); } } } else { ap.ReportError("No journal event or event name after GenerateEvent"); } } else { ap.ReportError("Unknown command " + cmdname + " in Performaction"); } } else { ap.ReportError(exp[0]); } } else { ap.ReportError("Perform command line not in correct format"); } return(true); }
public bool?CheckConditions(List <Condition> fel, ConditionVariables values, out string errlist, List <Condition> passed = null, ConditionFunctions cf = null) { errlist = null; bool?outerres = null; foreach (Condition fe in fel) // find all values needed { bool?innerres = null; foreach (ConditionEntry f in fe.fields) { bool matched = false; if (f.matchtype == ConditionEntry.MatchType.AlwaysTrue || f.matchtype == ConditionEntry.MatchType.AlwaysFalse) { if (f.itemname.Length == 0 || f.itemname.Equals("Condition", StringComparison.InvariantCultureIgnoreCase)) // empty (legacy) or { if (f.matchtype == ConditionEntry.MatchType.AlwaysTrue) { matched = true; // matched, else if false, leave as false. } } else { errlist += "AlwaysFalse/True does not have left side text of Condition"; innerres = false; break; } } else { string leftside = null; ConditionFunctions.ExpandResult er = ConditionFunctions.ExpandResult.NoExpansion; if (cf != null) // if we have a string expander, try the left side { er = cf.ExpandString(f.itemname, out leftside); if (er == ConditionFunctions.ExpandResult.Failed) // stop on error { errlist += leftside; // add on errors.. innerres = false; // stop loop, false break; } } if (f.matchtype == ConditionEntry.MatchType.IsPresent) // these use f.itemname without any expansion { if (leftside == null || er == ConditionFunctions.ExpandResult.NoExpansion) // no expansion, must be a variable name { leftside = f.itemname; } if (values.Exists(leftside) && values[leftside] != null) { matched = true; } } else if (f.matchtype == ConditionEntry.MatchType.IsNotPresent) { if (leftside == null || er == ConditionFunctions.ExpandResult.NoExpansion) // no expansion, must be a variable name { leftside = f.itemname; } if (!values.Exists(leftside) || values[leftside] == null) { matched = true; } } else { if (er == ConditionFunctions.ExpandResult.NoExpansion) // no expansion, must be a variable name { leftside = values.Exists(f.itemname) ? values[f.itemname] : null; if (leftside == null) { errlist += "Item " + f.itemname + " is not available" + Environment.NewLine; innerres = false; break; // stop the loop, its a false } } string rightside; if (cf != null) // if we have a string expander, pass it thru { er = cf.ExpandString(f.matchstring, out rightside); if (er == ConditionFunctions.ExpandResult.Failed) // if error, abort { errlist += rightside; // add on errors.. innerres = false; // stop loop, false break; } } else { rightside = f.matchstring; } if (f.matchtype == ConditionEntry.MatchType.DateBefore || f.matchtype == ConditionEntry.MatchType.DateAfter) { DateTime tmevalue, tmecontent; if (!DateTime.TryParse(leftside, System.Globalization.CultureInfo.CreateSpecificCulture("en-US"), System.Globalization.DateTimeStyles.None, out tmevalue)) { errlist += "Date time not in correct format on left side" + Environment.NewLine; innerres = false; break; } else if (!DateTime.TryParse(rightside, System.Globalization.CultureInfo.CreateSpecificCulture("en-US"), System.Globalization.DateTimeStyles.None, out tmecontent)) { errlist += "Date time not in correct format on right side" + Environment.NewLine; innerres = false; break; } else { if (f.matchtype == ConditionEntry.MatchType.DateBefore) { matched = tmevalue.CompareTo(tmecontent) < 0; } else { matched = tmevalue.CompareTo(tmecontent) >= 0; } } } else if (f.matchtype == ConditionEntry.MatchType.Equals) { matched = leftside.Equals(rightside, StringComparison.InvariantCultureIgnoreCase); } else if (f.matchtype == ConditionEntry.MatchType.EqualsCaseSensitive) { matched = leftside.Equals(rightside); } else if (f.matchtype == ConditionEntry.MatchType.NotEqual) { matched = !leftside.Equals(rightside, StringComparison.InvariantCultureIgnoreCase); } else if (f.matchtype == ConditionEntry.MatchType.NotEqualCaseSensitive) { matched = !leftside.Equals(rightside); } else if (f.matchtype == ConditionEntry.MatchType.Contains) { matched = leftside.IndexOf(rightside, StringComparison.InvariantCultureIgnoreCase) >= 0; } else if (f.matchtype == ConditionEntry.MatchType.ContainsCaseSensitive) { matched = leftside.Contains(rightside); } else if (f.matchtype == ConditionEntry.MatchType.DoesNotContain) { matched = leftside.IndexOf(rightside, StringComparison.InvariantCultureIgnoreCase) < 0; } else if (f.matchtype == ConditionEntry.MatchType.DoesNotContainCaseSensitive) { matched = !leftside.Contains(rightside); } else if (f.matchtype == ConditionEntry.MatchType.IsOneOf) { StringParser p = new StringParser(rightside); List <string> ret = p.NextQuotedWordList(); if (ret == null) { errlist += "IsOneOf value list is not in a optionally quoted comma separated form" + Environment.NewLine; innerres = false; break; // stop the loop, its a false } else { matched = ret.Contains(leftside, StringComparer.InvariantCultureIgnoreCase); } } else if (f.matchtype == ConditionEntry.MatchType.AnyOfAny) { StringParser l = new StringParser(leftside); List <string> ll = l.NextQuotedWordList(); StringParser r = new StringParser(rightside); List <string> rl = r.NextQuotedWordList(); if (ll == null || rl == null) { errlist += "AnyOfAny value list is not in a optionally quoted comma separated form on both sides" + Environment.NewLine; innerres = false; break; // stop the loop, its a false } else { foreach (string s in ll) // for all left strings { if (rl.Contains(s, StringComparer.InvariantCultureIgnoreCase)) // if right has it.. { matched = true; // matched and break break; } } } } else if (f.matchtype == ConditionEntry.MatchType.IsEmpty) { matched = leftside.Length == 0; } else if (f.matchtype == ConditionEntry.MatchType.IsNotEmpty) { matched = leftside.Length > 0; } else if (f.matchtype == ConditionEntry.MatchType.IsTrue || f.matchtype == ConditionEntry.MatchType.IsFalse) { int inum = 0; if (leftside.InvariantParse(out inum)) { matched = (f.matchtype == ConditionEntry.MatchType.IsTrue) ? (inum != 0) : (inum == 0); } else { errlist += "True/False value is not an integer on left side" + Environment.NewLine; innerres = false; break; } } else { double fnum = 0, num = 0; if (!leftside.InvariantParse(out num)) { errlist += "Number not in correct format on left side" + Environment.NewLine; innerres = false; break; } else if (!rightside.InvariantParse(out fnum)) { errlist += "Number not in correct format on right side" + Environment.NewLine; innerres = false; break; } else { if (f.matchtype == ConditionEntry.MatchType.NumericEquals) { matched = Math.Abs(num - fnum) < 0.0000000001; // allow for rounding } else if (f.matchtype == ConditionEntry.MatchType.NumericNotEquals) { matched = Math.Abs(num - fnum) >= 0.0000000001; } else if (f.matchtype == ConditionEntry.MatchType.NumericGreater) { matched = num > fnum; } else if (f.matchtype == ConditionEntry.MatchType.NumericGreaterEqual) { matched = num >= fnum; } else if (f.matchtype == ConditionEntry.MatchType.NumericLessThan) { matched = num < fnum; } else if (f.matchtype == ConditionEntry.MatchType.NumericLessThanEqual) { matched = num <= fnum; } else { System.Diagnostics.Debug.Assert(false); } } } } } // System.Diagnostics.Debug.WriteLine(fe.eventname + ":Compare " + f.matchtype + " '" + f.contentmatch + "' with '" + vr.value + "' res " + matched + " IC " + fe.innercondition); if (fe.innercondition == ConditionEntry.LogicalCondition.And) // Short cut, if AND, all must pass, and it did not { if (!matched) { innerres = false; break; } } else if (fe.innercondition == ConditionEntry.LogicalCondition.Nand) // Short cut, if NAND, and not matched { if (!matched) { innerres = true; // positive non match - NAND produces a true break; } } else if (fe.innercondition == ConditionEntry.LogicalCondition.Or) // Short cut, if OR, and matched { if (matched) { innerres = true; break; } } else { // short cut, if NOR, and matched, its false if (matched) { innerres = false; break; } } } if (!innerres.HasValue) // All tests executed, without a short cut, we set it to a definitive state { if (fe.innercondition == ConditionEntry.LogicalCondition.And) // none did not match, producing a false, so therefore AND is true { innerres = true; } else if (fe.innercondition == ConditionEntry.LogicalCondition.Or) // none did match, producing a true, so therefore OR must be false { innerres = false; } else if (fe.innercondition == ConditionEntry.LogicalCondition.Nor) // none did match, producing a false, so therefore NOR must be true { innerres = true; } else // NAND none did match, producing a true, so therefore NAND must be false { innerres = false; } } if (innerres.Value && passed != null) // if want a list of passes, do it { passed.Add(fe); } if (!outerres.HasValue) // if first time, its just the value { outerres = innerres.Value; } else if (fe.outercondition == ConditionEntry.LogicalCondition.Or) { outerres |= innerres.Value; } else if (fe.outercondition == ConditionEntry.LogicalCondition.And) { outerres &= innerres.Value; } else if (fe.outercondition == ConditionEntry.LogicalCondition.Nor) { outerres = !(outerres | innerres.Value); } else if (fe.outercondition == ConditionEntry.LogicalCondition.Nand) { outerres = !(outerres & innerres.Value); } } return(outerres); }