protected bool TryMakeProxyFromAndToAddresses(TryMakeDelegate <string> @delegate, out IPAddress fromIp, out IPAddress toIp) { fromIp = null; toIp = null; if (TryMake(@delegate, out var fromAddress) == false) { return(false); } if (!IPAddress.TryParse(fromAddress, out fromIp)) { return(false); } Enumerator.Skip(TokenKind.Space); if (TryMake(@delegate, out var toAddress) == false) { return(false); } if (!IPAddress.TryParse(toAddress, out toIp)) { return(false); } return(true); }
private static bool TryMake <T>(TokenEnumerator enumerator, TryMakeDelegate <T> make, out T found) { int index = enumerator.Index; if (make(enumerator, out found)) { return(true); } enumerator.Index = index; return(false); }
/// <summary> /// Try to make a callback in a transactional way. /// </summary> /// <param name="delegate">The callback to perform the match.</param> /// <returns>true if the match could be made, false if not.</returns> protected bool TryMake(TryMakeDelegate @delegate) { var checkpoint = Enumerator.Checkpoint(); if (@delegate() == false) { checkpoint.Rollback(); return(false); } checkpoint.Dispose(); return(true); }
/// <summary> /// Try to make a callback in a transactional way. /// </summary> /// <param name="delegate">The callback to perform the match.</param> /// <param name="found">The parameter that was returned from the matching function.</param> /// <returns>true if the match could be made, false if not.</returns> protected bool TryMake <TOut>(TryMakeDelegate <TOut> @delegate, out TOut found) { var checkpoint = Enumerator.Checkpoint(); if (@delegate(out found) == false) { checkpoint.Rollback(); return(false); } checkpoint.Dispose(); return(true); }
/// <summary> /// Try to match a function on the enumerator ensuring that the enumerator is restored on failure. /// </summary> /// <param name="enumerator">The enumerator to attempt to match on.</param> /// <param name="make">The callback function to match on the enumerator.</param> /// <param name="found">The out value that was found.</param> /// <returns>true if the matching function successfully made a match, false if not.</returns> static bool TryMake <T>(TokenEnumerator enumerator, TryMakeDelegate <T> make, out T found) { using (var checkpoint = enumerator.Checkpoint()) { if (make(enumerator, out found)) { return(true); } checkpoint.Rollback(); } return(false); }
/// <summary> /// Try to make a callback in a transactional way. /// </summary> /// <param name="delegate">The callback to perform the match.</param> /// <returns>true if the match could be made, false if not.</returns> public bool TryMake(TryMakeDelegate @delegate) { var span = _span; var spanIndex = _spanIndex; var spanPosition = _spanPosition; if (@delegate(ref this) == false) { _span = span; _spanIndex = spanIndex; _spanPosition = spanPosition; _hasPeeked = false; return(false); } return(true); }
/// <summary> /// Try to make a callback in a transactional way. /// </summary> /// <param name="delegate">The callback to perform the match.</param> /// <param name="value1">The first out parameter that was found during the make operation.</param> /// <param name="value2">The second out parameter that was found during the make operation.</param> /// <returns>true if the match could be made, false if not.</returns> public bool TryMake <TOut1, TOut2>(TryMakeDelegate <TOut1, TOut2> @delegate, out TOut1 value1, out TOut2 value2) { if (_buffer.IsSingleSegment) { var index = _spanIndex; if (@delegate(ref this, out value1, out value2) == false) { _spanIndex = index; _hasPeeked = false; return(false); } return(true); } throw new NotImplementedException(); }
/// <summary> /// Try to make a callback in a transactional way. /// </summary> /// <param name="delegate">The callback to perform the match.</param> /// <param name="found">The parameter that was returned from the matching function.</param> /// <returns>true if the match could be made, false if not.</returns> public bool TryMake <TOut>(TryMakeDelegate <TOut> @delegate, out TOut found) { var span = _span; var spanIndex = _spanIndex; var spanPosition = _spanPosition; if (@delegate(ref this, out found) == false) { _span = span; _spanIndex = spanIndex; _spanPosition = spanPosition; _hasPeeked = false; return(false); } return(true); }
/// <summary> /// Try to make a callback in a transactional way. /// </summary> /// <param name="delegate">The callback to perform the match.</param> /// <param name="buffer">The buffer that was made.</param> /// <returns>true if the match could be made, false if not.</returns> public bool TryMake(TryMakeDelegate @delegate, out ReadOnlySequence <byte> buffer) { buffer = default; var span = _span; var spanIndex = _spanIndex; var spanPosition = _spanPosition; if (@delegate(ref this) == false) { _span = span; _spanIndex = spanIndex; _spanPosition = spanPosition; _hasPeeked = false; return(false); } buffer = _buffer.Slice(spanIndex, _spanIndex - spanIndex); return(true); }
/// <summary> /// Constructor. /// </summary> /// <param name="delegate">The delegate to match the input.</param> /// <param name="transition">The transition function to move from the previous state to the new state.</param> public StateTransition(TryMakeDelegate @delegate, Func <SmtpSessionContext, SmtpState> transition) { Delegate = @delegate; Transition = transition; }
/// <summary> /// Add a state action. /// </summary> /// <param name="command">The name of the SMTP command.</param> /// <param name="tryMake">The function callback to create the command.</param> /// <param name="transitionTo">The state to transition to.</param> public void Replace(string command, TryMakeDelegate tryMake, SmtpState?transitionTo = null) { Remove(command); Add(command, tryMake, transitionTo ?? StateId); }
/// <summary> /// Add a state action. /// </summary> /// <param name="command">The name of the SMTP command.</param> /// <param name="tryMake">The function callback to create the command.</param> /// <param name="transition">The function to determine the new state.</param> public void Add(string command, TryMakeDelegate tryMake, Func <SmtpSessionContext, SmtpState> transition) { Transitions.Add(command, new StateTransition(tryMake, transition)); }
/// <summary> /// Add a state action. /// </summary> /// <param name="command">The name of the SMTP command.</param> /// <param name="tryMake">The function callback to create the command.</param> /// <param name="transition">The state to transition to.</param> public void Add(string command, TryMakeDelegate tryMake, SmtpState transition) { Add(command, tryMake, context => transition); }
/// <summary> /// Add a state action. /// </summary> /// <param name="command">The name of the SMTP command.</param> /// <param name="tryMake">The function callback to create the command.</param> public void Add(string command, TryMakeDelegate tryMake) { Add(command, tryMake, context => StateId); }
/// <summary> /// Add a state action. /// </summary> /// <param name="command">The name of the SMTP command.</param> /// <param name="tryMake">The function callback to create the command.</param> /// <param name="transitionTo">The state to transition to.</param> public void Add(string command, TryMakeDelegate tryMake, SmtpState?transitionTo = null) { Actions.Add(command, Tuple.Create(tryMake, transitionTo ?? StateId)); }
/// <summary> /// Add a state action. /// </summary> /// <param name="command">The name of the SMTP command.</param> /// <param name="tryMake">The function callback to create the command.</param> /// <param name="transitionTo">The state to transition to.</param> public void Add(string command, TryMakeDelegate tryMake, SmtpState? transitionTo = null) { Actions.Add(command, Tuple.Create(tryMake, transitionTo ?? StateId)); }