public XplMsg() { mStrictInterpretation = DefaultStrictInterpretation; mXplMsgType = xPLMsgType.cmnd; mTargetIsAll = true; mKeysValues = new List <KeyValuePair>(); mValidRawXPL = false; mExtractedOldWay = false; //to be removed in future versions //to be removed in future versions //XPL_Raw = ""; }
public XplMsg() { mStrictInterpretation = DefaultStrictInterpretation; mXplMsgType = xPLMsgType.cmnd; mTargetIsAll = true; mKeysValues = new List<KeyValuePair>(); mValidRawXPL = false; mExtractedOldWay = false; //to be removed in future versions //to be removed in future versions //XPL_Raw = ""; }
private bool ExtractContents(string themsg) { Regex r = default(Regex); bool ok = false; if (mStrictInterpretation) { //no uppercase allowed r = new Regex("^xpl-(?<msgtype>trig|stat|cmnd)\\n" + "\\{\\n" + "(?:hop=\\d\\n" + "|source=(?<sv>[0-9a-z]{1,8})-(?<sd>[0-9a-z]{1,8})\\.(?<si>[0-9a-z/-]{1,16})\\n" + "|target=(?<target>(?<tv>[0-9a-z]{1,8})-(?<td>[0-9a-z]{1,8})\\.(?<ti>[0-9a-z/-]{1,16})|\\*)\\n){3}" + "\\}\\n" + "(?<class>[0-9a-z/-]{1,8})\\.(?<type>[0-9a-z/-]{1,8})\\n" + "\\{\\n" + "(?:(?<key>[0-9a-z/-]{1,16})=(?<val>[\\x20-\\x7E]{0,128})\\n)*" + "\\}\\n$", RegexOptions.Compiled | RegexOptions.Singleline); } else { //mixed case allowed r = new Regex("^xpl-(?<msgtype>trig|stat|cmnd)\\n" + "\\{\\n" + "(?:hop=\\d\\n" + "|source=(?<sv>[0-9a-z]{1,8})-(?<sd>[0-9a-z]{1,8})\\.(?<si>[0-9a-z/-]{1,16})\\n" + "|target=(?<target>(?<tv>[0-9a-z]{1,8})-(?<td>[0-9a-z]{1,8})\\.(?<ti>[0-9a-z/-]{1,16})|\\*)\\n){3}" + "\\}\\n" + "(?<class>[0-9a-z/-]{1,8})\\.(?<type>[0-9a-z/-]{1,8})\\n" + "\\{\\n" + "(?:(?<key>[0-9a-z/-]{1,16})=(?<val>[\\x20-\\x7E]{0,128})\\n)*" + "\\}\\n$", RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.IgnoreCase); } Match m = r.Match(themsg); if (m.Success) { switch (m.Groups["msgtype"].Captures[0].Value.ToLower()) { case "trig": mXplMsgType = xPLMsgType.trig; break; case "cmnd": mXplMsgType = xPLMsgType.cmnd; break; case "stat": mXplMsgType = xPLMsgType.stat; break; } mSourceVendor = m.Groups["sv"].Captures[0].Value; mSourceDevice = m.Groups["sd"].Captures[0].Value; mSourceInstance = m.Groups["si"].Captures[0].Value; if (m.Groups["target"].Captures[0].Value == "*") { mTargetIsAll = true; mTargetVendor = "*"; mTargetDevice = "*"; mTargetInstance = "*"; } else { mTargetIsAll = false; mTargetVendor = m.Groups["tv"].Captures[0].Value; mTargetDevice = m.Groups["td"].Captures[0].Value; mTargetInstance = m.Groups["ti"].Captures[0].Value; } mClass = m.Groups["class"].Captures[0].Value; mType = m.Groups["type"].Captures[0].Value; int ival = 0; mKeysValues = new List<KeyValuePair>(); foreach (Capture c in m.Groups["key"].Captures) { mKeysValues.Add(new KeyValuePair(c.Value, m.Groups["val"].Captures[ival].Value)); ival += 1; } mRawXPL = themsg; mValidRawXPL = true; ok = true; } return ok; }
private bool ExtractContents(string themsg) { Regex r = default(Regex); bool ok = false; if (mStrictInterpretation) { //no uppercase allowed r = new Regex("^xpl-(?<msgtype>trig|stat|cmnd)\\n" + "\\{\\n" + "(?:hop=\\d\\n" + "|source=(?<sv>[0-9a-z]{1,8})-(?<sd>[0-9a-z]{1,8})\\.(?<si>[0-9a-z/-]{1,16})\\n" + "|target=(?<target>(?<tv>[0-9a-z]{1,8})-(?<td>[0-9a-z]{1,8})\\.(?<ti>[0-9a-z/-]{1,16})|\\*)\\n){3}" + "\\}\\n" + "(?<class>[0-9a-z/-]{1,8})\\.(?<type>[0-9a-z/-]{1,8})\\n" + "\\{\\n" + "(?:(?<key>[0-9a-z/-]{1,16})=(?<val>[\\x20-\\x7E]{0,128})\\n)*" + "\\}\\n$", RegexOptions.Compiled | RegexOptions.Singleline); } else { //mixed case allowed r = new Regex("^xpl-(?<msgtype>trig|stat|cmnd)\\n" + "\\{\\n" + "(?:hop=\\d\\n" + "|source=(?<sv>[0-9a-z]{1,8})-(?<sd>[0-9a-z]{1,8})\\.(?<si>[0-9a-z/-]{1,16})\\n" + "|target=(?<target>(?<tv>[0-9a-z]{1,8})-(?<td>[0-9a-z]{1,8})\\.(?<ti>[0-9a-z/-]{1,16})|\\*)\\n){3}" + "\\}\\n" + "(?<class>[0-9a-z/-]{1,8})\\.(?<type>[0-9a-z/-]{1,8})\\n" + "\\{\\n" + "(?:(?<key>[0-9a-z/-]{1,16})=(?<val>[\\x20-\\x7E]{0,128})\\n)*" + "\\}\\n$", RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.IgnoreCase); } Match m = r.Match(themsg); if (m.Success) { switch (m.Groups["msgtype"].Captures[0].Value.ToLower()) { case "trig": mXplMsgType = xPLMsgType.trig; break; case "cmnd": mXplMsgType = xPLMsgType.cmnd; break; case "stat": mXplMsgType = xPLMsgType.stat; break; } mSourceVendor = m.Groups["sv"].Captures[0].Value; mSourceDevice = m.Groups["sd"].Captures[0].Value; mSourceInstance = m.Groups["si"].Captures[0].Value; if (m.Groups["target"].Captures[0].Value == "*") { mTargetIsAll = true; mTargetVendor = "*"; mTargetDevice = "*"; mTargetInstance = "*"; } else { mTargetIsAll = false; mTargetVendor = m.Groups["tv"].Captures[0].Value; mTargetDevice = m.Groups["td"].Captures[0].Value; mTargetInstance = m.Groups["ti"].Captures[0].Value; } mClass = m.Groups["class"].Captures[0].Value; mType = m.Groups["type"].Captures[0].Value; int ival = 0; mKeysValues = new List <KeyValuePair>(); foreach (Capture c in m.Groups["key"].Captures) { mKeysValues.Add(new KeyValuePair(c.Value, m.Groups["val"].Captures[ival].Value)); ival += 1; } mRawXPL = themsg; mValidRawXPL = true; ok = true; } return(ok); }