public string ResolveText(string strText, Dictionary <string, string> thisConfig, int depth = 0) { string resolvedText = strText; string name; // @"\{\{(?i:(.*?))\}\}" // @"((?<name>.*?(?=\s*=)))(.*?)(?<value>(?<=\().+(?=\)))" MatchCollection matchSymbol = XTRMUtil.GetRegexMatches(strText, @"\{\{(?<name>(.*?))\}\}"); if (matchSymbol != null) { if (matchSymbol.Count > 0) { // Report on each match. foreach (Match match in matchSymbol) { string test = match.Value; GroupCollection groups = match.Groups; name = groups["name"].Value; // Dictionary Lookup. // Substitute into rawParm. string result = ""; switch (name) { default: //result = thisEvent.config.getDictionaryEntry(name); //result = getConfig(thisEvent.config, name); result = getConfig(XDictionary, name); if (result.Equals("")) { result = getConfig(XDictionary, name.ToUpper()); } // If empty, then use name as the value. break; } resolvedText = resolvedText.Replace(match.Value, result); } } } if (!resolvedText.Equals(strText)) { if (depth < 10) { // THIS IS A RECURSIVE CALL! resolvedText = ResolveText(resolvedText, thisConfig, depth++); } } return(resolvedText); }
public string ResolveParm(string rawParm, XTRMEvent thisEvent, Dictionary <string, string> thisConfig, int taskSerial = 0, int jobSerial = -1, int depth = 0) { string resolvedParm = rawParm; string name; // @"\{\{(?i:(.*?))\}\}" // @"((?<name>.*?(?=\s*=)))(.*?)(?<value>(?<=\().+(?=\)))" MatchCollection matchSymbol = XTRMUtil.GetRegexMatches(rawParm, @"\{\{(?<name>(.*?))\}\}"); if (matchSymbol != null) { if (matchSymbol.Count > 0) { // Report on each match. foreach (Match match in matchSymbol) { string test = match.Value; GroupCollection groups = match.Groups; name = groups["name"].Value; // Dictionary Lookup. // Substitute into rawParm. string result = ""; switch (name) { case "JobSerial": result = jobSerial.ToString(); break; case "TaskSerial": result = taskSerial.ToString(); break; case "EventSerial": result = thisEvent.eventSerial.ToString(); break; case "EventSource": result = thisEvent.eventSource; break; case "EventAction": result = thisEvent.eventAction; break; case "EventDate": result = thisEvent.eventDate.ToString(); break; case "EventState": result = thisEvent.eventState.ToString(); break; case "EventUser": result = thisEvent.eventUser; break; case "EventPIN": result = thisEvent.eventPIN; break; case "EventUUID": result = thisEvent.eventUUID; break; case "EventProcessed": result = thisEvent.eventProcessed.ToString(); break; case "EventParm1": result = thisEvent.eventParm1; break; case "EventParm2": result = thisEvent.eventParm2; break; case "EventParm3": result = thisEvent.eventParm3; break; case "EventParm4": result = thisEvent.eventParm4; break; case "EventParm5": result = thisEvent.eventParm5; break; case "EventParm6": result = thisEvent.eventParm6; break; case "EventParm7": result = thisEvent.eventParm7; break; case "EventParm8": result = thisEvent.eventParm8; break; case "EventParm9": result = thisEvent.eventParm9; break; case "EventParm10": result = thisEvent.eventParm10; break; case "EventTag": result = thisEvent.eventTag; break; default: //result = thisEvent.config.getDictionaryEntry(name); //result = getConfig(thisEvent.config, name); result = getConfig(thisConfig, name); // If empty, then use name as the value. break; } resolvedParm = resolvedParm.Replace(match.Value, result); } } } if (!resolvedParm.Equals(rawParm)) { if (depth < 10) { // THIS IS A RECURSIVE CALL! resolvedParm = ResolveParm(resolvedParm, thisEvent, thisConfig, taskSerial, jobSerial, depth++); } } return(resolvedParm); }