/// <summary> /// Constructs the <see cref="ElementMatch"/> with the given name and /// and no prefix. /// </summary> public ElementMatch(string name, MatchMode mode) : base(name) { if (!Enum.IsDefined(typeof(MatchMode), mode)) throw new ArgumentException(Properties.Resources.InvalidMode, "mode"); this.mode = mode; }
public static int Convert(MatchMode matchMode, IEnumerable<string> list) { string search = matchMode == MatchMode.Exact ? "exact" : matchMode == MatchMode.RegularExpression ? "regularexpression" : "substring"; return Math.Max(0, list.IndexOf(search, new CaseInsensitiveComparer<string>())); }
/// <summary> /// 采用指定匹配模式添加Conditions项。 /// </summary> /// <param name="matchMode">Conditions匹配方式。</param> /// <param name="name">Condition名称。</param> /// <param name="value">Condition数值。</param> public void AddConditionItem(MatchMode matchMode, string name, string value) { MatchRuleChecker.Check(matchMode, name); switch (matchMode) { case MatchMode.Exact: _conds.Add(new EqualConditionItem(name, value, TupleType.Three)); break; case MatchMode.StartWith: _conds.Add(new StartWithConditionItem(name, value)); break; default: throw new InvalidEnumArgumentException("Unsupported match mode " + matchMode); } }
public Highlighter(string name, bool enabled, LogEntryField field, MatchMode mode, string pattern, HighlighterStyle style) { Name = name; Enabled = enabled; Field = field; Mode = mode; Pattern = pattern; Style = style; regex = new Regex(pattern); PropertyChanged += (sender, e) => { if (e.PropertyName == "Field" || e.PropertyName == "Mode" || e.PropertyName == "Pattern") { if (Mode == MatchMode.RegularExpression && Pattern != null) regex = new Regex(Pattern); OnPropertyChanged("Description"); } }; }
public void SetNext(HtmlElementSelector selector, MatchMode matchModel = MatchMode.AnyChildLevel) { if (this.Next != null) { this.Next.SetNext(selector, matchModel); } else { this.Next = selector; this.Next.MatchMode = matchModel; } }
public XmlPathProcessor(string pathExpression, MatchMode matchMode, Action<XmlReader> action, XmlNamespaceManager nsManager) : this(PathExpressionParser.Parse(pathExpression, matchMode), action, nsManager) { }
public static string GetModeString(MatchMode mode) { return(Loc.LS(ExtMatchMode.ToString(mode))); }
protected AbstractConditionItem(string name, MatchMode matchMode, TupleType tupleType) { Name = name; MatchMode = matchMode; TupleType = tupleType; }
/// <summary> /// Constructs the <see cref="ElementMatch"/> with the given name and prefix. /// </summary> public ElementMatch(string prefix, string name, MatchMode mode) : base(prefix, name) { this.mode = mode; }
public void Initialize (MatchLane other) { for (int n=0; n<=other.Index; n++) { Positions [n] = other.Positions [n]; Lengths [n] = other.Lengths [n]; } MatchMode = other.MatchMode; MatchIndex = other.MatchIndex; Index = other.Index; ExactCaseMatches = other.ExactCaseMatches; WordStartsMatched = other.WordStartsMatched; }
MatchLane CreateLane (MatchMode mode, int pos) { MatchLane lane = GetPoolLane (); lane.Initialize (mode, pos); if (mode == MatchMode.Acronym) lane.WordStartsMatched = 1; return lane; }
/// <summary> /// Initializes a new instance of the <see cref="InsensitiveLikeExpression"/> class. /// </summary> /// <param name="projection">The projection.</param> /// <param name="value">The value.</param> /// <param name="matchMode">The match mode.</param> public InsensitiveLikeExpression(IProjection projection, string value, MatchMode matchMode) { this.projection = projection; this.value = matchMode.ToMatchString(value); }
public HtmlElementSelector(MatchMode matchModel = MatchMode.AnyChildLevel) { MatchMode = matchModel; }
/// <summary> /// Apply a "like" restriction in a QueryOver expression /// Note: throws an exception outside of a QueryOver expression /// </summary> public static bool IsLike(this string projection, string comparison, MatchMode matchMode, char? escapeChar) { throw new Exception("Not to be used directly - use inside QueryOver expression"); }
public Resource(string path, MatchMode matchMode) : this(path, new ResourcePathProvider(), matchMode) { }
/// <summary> /// Constructor /// </summary> /// <param name="match">Match string</param> /// <param name="mode">Match mode</param> public HttpMatchEntry(string match, MatchMode mode) { _match = match; Mode = mode; }
public override ReturnCode Execute( Interpreter interpreter, IClientData clientData, ArgumentList arguments, ref Result result ) { ReturnCode code = ReturnCode.Ok; if (interpreter != null) { if (arguments != null) { if ((arguments.Count == 5) || (arguments.Count == 6)) { /////////////////////////////////////////////////////////////////////////////////////////////// // // test name description ?constraints? body result // /////////////////////////////////////////////////////////////////////////////////////////////// string name = arguments[1]; #if DEBUGGER if (DebuggerOps.CanHitBreakpoints(interpreter, EngineFlags.None, BreakpointType.Test)) { code = interpreter.CheckBreakpoints( code, BreakpointType.Test, name, null, null, this, null, clientData, arguments, ref result); } if (code == ReturnCode.Ok) #endif { string description = arguments[2]; string constraints; string body; IScriptLocation bodyLocation; string expectedResult; if (arguments.Count == 6) { constraints = arguments[3]; body = arguments[4]; bodyLocation = arguments[4]; expectedResult = arguments[5]; } else { constraints = null; body = arguments[3]; bodyLocation = arguments[3]; expectedResult = arguments[4]; } ReturnCodeList returnCodes = new ReturnCodeList(new ReturnCode[] { ReturnCode.Ok, ReturnCode.Return }); MatchMode mode = StringOps.DefaultResultMatchMode; bool noCase = false; /////////////////////////////////////////////////////////////////////////////////////////////// int testLevels = interpreter.EnterTestLevel(); try { // // NOTE: Create a place to put all the output of the this command. // StringBuilder testData = StringOps.NewStringBuilder(); // // NOTE: Are we going to skip this test? // bool skip = false; bool fail = true; code = TestOps.CheckConstraints( interpreter, testLevels, name, constraints, false, false, testData, ref skip, ref fail, ref result); // // NOTE: Track the fact that we handled this test. // int[] testStatistics = null; if (code == ReturnCode.Ok) { testStatistics = interpreter.TestStatistics; if ((testStatistics != null) && (testLevels == 1) && skip) { Interlocked.Increment(ref testStatistics[ (int)TestInformationType.Total]); } } if ((code == ReturnCode.Ok) && !skip) { code = TestOps.RecordInformation( interpreter, TestInformationType.Counts, name, null, true, ref result); } // // NOTE: Check test constraints to see if we should run the test. // if ((code == ReturnCode.Ok) && !skip) { ReturnCode bodyCode = ReturnCode.Ok; Result bodyResult = null; // // NOTE: Only run the test body if the setup is successful. // if (body != null) { TestOps.AppendFormat( interpreter, testData, TestOutputType.Start, "---- {0} start", name); TestOps.AppendLine( interpreter, testData, TestOutputType.Start); int savedPreviousLevels = interpreter.BeginNestedExecution(); try { ICallFrame frame = interpreter.NewTrackingCallFrame( StringList.MakeList(this.Name, "body", name), CallFrameFlags.Test); interpreter.PushAutomaticCallFrame(frame); try { bodyCode = interpreter.EvaluateScript( body, bodyLocation, ref bodyResult); if ((bodyResult == null) && ScriptOps.HasFlags( interpreter, InterpreterFlags.TestNullIsEmpty, true)) { bodyResult = String.Empty; } if (bodyCode == ReturnCode.Error) { /* IGNORED */ interpreter.CopyErrorInformation( VariableFlags.None, ref bodyResult); } } finally { // // NOTE: Pop the original call frame that we pushed above // and any intervening scope call frames that may be // leftover (i.e. they were not explicitly closed). // /* IGNORED */ interpreter.PopScopeCallFramesAndOneMore(); } } catch (Exception e) { bodyResult = e; bodyCode = ReturnCode.Error; } finally { interpreter.EndNestedExecution(savedPreviousLevels); } } // // NOTE: Did we fail to match the return code? // bool codeFailure = !returnCodes.Contains(bodyCode); // // NOTE: Does the actual result match the expected result? // bool scriptFailure = false; ReturnCode scriptCode = ReturnCode.Ok; Result scriptResult = null; if (!codeFailure) { if (expectedResult != null) { scriptCode = TestOps.Match( interpreter, mode, bodyResult, expectedResult, noCase, null, TestOps.RegExOptions, false, ref scriptFailure, ref scriptResult); if (scriptCode == ReturnCode.Ok) { scriptFailure = !scriptFailure; } else { scriptFailure = true; } } } // // NOTE: If any of the important things failed, the test fails. // if (!(codeFailure || scriptFailure)) { // // PASS: Test ran with no errors and the results match // what we expected. // if ((testStatistics != null) && (testLevels == 1)) { Interlocked.Increment(ref testStatistics[ (int)TestInformationType.Passed]); Interlocked.Increment(ref testStatistics[ (int)TestInformationType.Total]); } TestOps.AppendFormat( interpreter, testData, TestOutputType.Pass, "++++ {0} PASSED", name); TestOps.AppendLine( interpreter, testData, TestOutputType.Pass); } else { // // FAIL: Test ran with errors or the result does not match // what we expected. // if ((testStatistics != null) && (testLevels == 1)) { if (fail) { Interlocked.Increment(ref testStatistics[ (int)TestInformationType.Failed]); Interlocked.Increment(ref testStatistics[ (int)TestInformationType.Total]); } } // // NOTE: Keep track of each test that fails. // if (testLevels == 1) { TestOps.RecordInformation( interpreter, TestInformationType.FailedNames, name, null, true); } TestOps.AppendLine( interpreter, testData, TestOutputType.Fail); TestOps.AppendFormat( interpreter, testData, TestOutputType.Fail, "==== {0} {1} {2}", name, description.Trim(), fail ? "FAILED" : "IGNORED"); TestOps.AppendLine( interpreter, testData, TestOutputType.Fail); if (body != null) { TestOps.AppendLine( interpreter, testData, TestOutputType.Body, "==== Contents of test case:"); TestOps.AppendLine( interpreter, testData, TestOutputType.Body, body); } if (scriptFailure) { if (scriptCode == ReturnCode.Ok) { TestOps.AppendLine( interpreter, testData, TestOutputType.Reason, "---- Result was:"); TestOps.AppendLine( interpreter, testData, TestOutputType.Reason, bodyResult); TestOps.AppendFormat( interpreter, testData, TestOutputType.Reason, "---- Result should have been ({0} matching):", mode); TestOps.AppendLine( interpreter, testData, TestOutputType.Reason); TestOps.AppendLine( interpreter, testData, TestOutputType.Reason, expectedResult); } else { TestOps.Append( interpreter, testData, TestOutputType.Reason, "---- Error testing result: "); TestOps.AppendLine( interpreter, testData, TestOutputType.Reason, scriptResult); if ((scriptResult != null) && (scriptResult.ErrorInfo != null)) { TestOps.Append( interpreter, testData, TestOutputType.Error, "---- errorInfo(matchResult): "); TestOps.AppendLine( interpreter, testData, TestOutputType.Error, scriptResult.ErrorInfo); TestOps.Append( interpreter, testData, TestOutputType.Error, "---- errorCode(matchResult): "); TestOps.AppendLine( interpreter, testData, TestOutputType.Error, scriptResult.ErrorCode); } } } if (codeFailure) { ReturnCodeDictionary returnCodeMessages = interpreter.TestReturnCodeMessages; string codeMessage; if ((returnCodeMessages == null) || (!returnCodeMessages.TryGetValue( bodyCode, out codeMessage) && !returnCodeMessages.TryGetValue( ReturnCode.Invalid, out codeMessage))) { codeMessage = "Unknown"; } TestOps.AppendFormat( interpreter, testData, TestOutputType.Reason, "---- {0}; Return code was: {1}", codeMessage, bodyCode); TestOps.AppendLine( interpreter, testData, TestOutputType.Reason); TestOps.Append( interpreter, testData, TestOutputType.Reason, "---- Return code should have been one of: "); TestOps.AppendLine( interpreter, testData, TestOutputType.Reason, returnCodes.ToString()); if ((bodyResult != null) && (bodyResult.ErrorInfo != null) && !returnCodes.Contains(ReturnCode.Error)) { TestOps.Append( interpreter, testData, TestOutputType.Error, "---- errorInfo(body): "); TestOps.AppendLine( interpreter, testData, TestOutputType.Error, bodyResult.ErrorInfo); TestOps.Append( interpreter, testData, TestOutputType.Error, "---- errorCode(body): "); TestOps.AppendLine( interpreter, testData, TestOutputType.Error, bodyResult.ErrorCode); } } TestOps.AppendFormat( interpreter, testData, TestOutputType.Fail, "==== {0} {1}", name, fail ? "FAILED" : "IGNORED"); TestOps.AppendLine( interpreter, testData, TestOutputType.Fail); } } // // NOTE: Did the above code succeed? // if (code == ReturnCode.Ok) { // // NOTE: The result is the complete output produced by the // entire test. // if (testData != null) { result = testData; } else { result = String.Empty; } } } catch (Exception e) { Engine.SetExceptionErrorCode(interpreter, e); result = e; code = ReturnCode.Error; } finally { interpreter.ExitTestLevel(); } } } else { result = String.Format( "wrong # args: should be \"{0} name description constraints body result\"", this.Name); code = ReturnCode.Error; } } else { result = "invalid argument list"; code = ReturnCode.Error; } } else { result = "invalid interpreter"; code = ReturnCode.Error; } return(code); }
// there's a mode argument but in actual usage this is always NetworkMatch.GetMode() // so ignore it here, since the default value MatchMode.NUM means CTF now :( static bool Prefix(MatchMode mode, ref string __result) { __result = MPModPrivateData.GetModeString(NetworkMatch.GetMode()); return(false); }
/// <summary> /// Apply a "like" restriction in a QueryOver expression /// Note: throws an exception outside of a QueryOver expression /// </summary> public static bool IsInsensitiveLike(this string projection, string comparison, MatchMode matchMode) { throw new Exception("Not to be used directly - use inside QueryOver expression"); }
/// <summary> /// Adds a action that will be executed with the given /// <see cref="pathExpression"/> is matched by the reader, specifying /// whether the expression should match an end element and the /// namespace manager to resolve prefixes in the expression. /// </summary> /// <param name="pathExpression">The path of the item to match, /// with the format specified by <see cref="PathExpressionParser"/>. /// </param> /// <param name="matchMode">Kind of matching to perform against elements. /// </param> /// <param name="action">The action to invoke when the current /// node matches the expression.</param> /// <param name="nsManager">The <see cref="XmlNamespaceManager"/> to /// use to resolve prefixes in the <paramref name="pathExpression"/>.</param> public void AddPathAction(string pathExpression, MatchMode matchMode, Action<XmlReader> action, XmlNamespaceManager nsManager) { base.Processors.Add(new XmlPathProcessor( pathExpression, matchMode, action, nsManager)); }
/// <summary> /// Adds a action that will be executed with the given /// <see cref="pathExpression"/> is matched by the reader, specifying /// whether the expression should match an end element. /// </summary> /// <param name="pathExpression">The path of the item to match, /// with the format specified by <see cref="PathExpressionParser"/>. /// </param> /// <param name="matchMode">Kind of matching to perform against elements. /// </param> /// <param name="action">The action to invoke when the current /// node matches the expression.</param> public void AddPathAction(string pathExpression, MatchMode matchMode, Action<XmlReader> action) { AddPathAction(pathExpression, matchMode, action, new XmlNamespaceManager(this.NameTable)); }
bool LaneExists (MatchMode mode, int matchIndex) { if (matchLanes == null) return false; for (int n=0; n<matchLanes.Count; n++) { MatchLane lane = matchLanes [n]; if (lane != null && lane.MatchMode == mode && lane.MatchIndex == matchIndex) return true; } return false; }
private static XmlMatch CreateMatch(bool isRootMatch, MatchMode mode, string prefix, string name) { if (name.StartsWith("@", StringComparison.Ordinal)) { return new AttributeMatch(prefix, name.Substring(1)); } else if (prefix.StartsWith("@", StringComparison.Ordinal)) { return new AttributeMatch(prefix.Substring(1), name); } else { if (isRootMatch) { return new RootElementMatch(prefix, name, mode); } else { return new ElementMatch(prefix, name, mode); } } }
public void Initialize (MatchMode mode, int pos) { MatchMode = mode; Positions [0] = pos; Lengths [0] = 1; Index = 0; MatchIndex = 1; ExactCaseMatches = 0; WordStartsMatched = 0; }
public static List<XmlMatch> Parse(string expression, MatchMode mode) { Guard.ArgumentNotNullOrEmptyString(expression, "expression"); bool isRoot = false; List<XmlMatch> names = new List<XmlMatch>(); string normalized = expression; if (normalized.StartsWith("//", StringComparison.Ordinal)) { normalized = normalized.Substring(2); } else if (normalized.StartsWith("/", StringComparison.Ordinal)) { isRoot = true; normalized = normalized.Substring(1); } string[] paths = normalized.Split('/'); try { for (int i = 0; i < paths.Length; i++) { string path = paths[i]; if (path.Length == 0) ThrowInvalidPath(expression); // Attribute match can only be the last in the expression. if (path.StartsWith("@", StringComparison.Ordinal) && i != paths.Length - 1) { throw new ArgumentException(String.Format( CultureInfo.CurrentCulture, Properties.Resources.AttributeAxisInvalid, expression)); } XmlMatch match; string[] xmlName = path.Split(':'); string prefix, name; if (xmlName.Length == 2) { prefix = xmlName[0]; name = xmlName[1]; if (prefix.Length == 0) ThrowInvalidPath(expression); else if (name.Length == 0) ThrowInvalidPath(expression); } else { name = xmlName[0]; prefix = String.Empty; } match = CreateMatch( isRoot && i == 0, /* Only pass the actual match mode when we're at the last segment */ (i == paths.Length - 1) ? mode : MatchMode.StartElement, prefix, name); if (match is AttributeMatch && names.Count > 0) { // Build a composite that matches element with the given attribute. ElementMatch parent = names[names.Count - 1] as ElementMatch; if (mode == MatchMode.EndElement) throw new ArgumentException(Properties.Resources.AttributeMatchCannotBeEndElement); names.RemoveAt(names.Count - 1); names.Add(new ElementAttributeMatch(parent, (AttributeMatch)match)); } else { names.Add(match); } } } catch (ArgumentException aex) { throw new ArgumentException(String.Format( CultureInfo.CurrentCulture, Properties.Resources.InvalidPath, expression), aex); } return names; }
public Set() : base("Set") { Mode = MatchMode.ALL; }
/// <summary> /// Constructs the <see cref="RootElementMatch"/> with the given name and /// and no prefix. /// </summary> public RootElementMatch(string name, MatchMode mode) : base(name, mode) { }
public LikeBuilder(MatchMode mode) { Mode = mode; }
/// <summary> /// Constructs the <see cref="RootElementMatch"/> with the given name and prefix. /// </summary> public RootElementMatch(string prefix, string name, MatchMode mode) : base(prefix, name, mode) { }
public static void Check(MatchMode matchMode, string condName) { if (_supportedMatchRules.ContainsKey(condName)) { var mms = _supportedMatchRules[condName]; if (!mms.Contains(matchMode)) { throw new ArgumentException( String.Format("Unsupported match mode for condition item {0}", condName)); } } }
public LikeExpression(string propertyName, string value, MatchMode matchMode, char? escapeChar, bool ignoreCase) : this(propertyName, matchMode.ToMatchString(value), escapeChar, ignoreCase) { }
public XmlPathProcessor(string pathExpression, MatchMode matchMode, Action<XmlReader> action, XmlNameTable readerNameTable) : this(PathExpressionParser.Parse(pathExpression, matchMode), action, readerNameTable) { }
public StandardHighlighter(string name, bool enabled, LogEntryField field, MatchMode mode, string pattern, HighlighterStyle style) : base(name, enabled, field, mode, pattern, style) { }
public LikeExpression( string propertyName, string value, MatchMode matchMode ) : this( propertyName, matchMode.ToMatchString( value ) ) { }