private static void Validate(NameValueCollection httpHeaders, IMatchResult matchResult, Validation validation) { foreach (var test in validation) { var value = matchResult[test.Key]; if (test.Value.IsMatch(value) == false) { var message = new StringBuilder(); message.AppendFormat( "HttpHeader test failed for Property '{0}' and test '{1}' with result '{2}'.\r\n", test.Key, test.Value, value); for (int i = 0; i < httpHeaders.Count; i++) { message.AppendFormat( "{0}-{1} {2}\r\n", i, httpHeaders.GetKey(i), httpHeaders.GetValues(i).FirstOrDefault()); } Assert.Fail(message.ToString()); } } }
public async Task Process(Match match, IMatchResult result) { if (ProcessScores) { await scoreProcessor.Process(match, result.Scores); } if (ProcessRewardTracks) { await rewardTrackProcessor.Process(result.Contributions); } if (ProcessFighterExperience) { await fighterExperienceProcessor.Process(match, result.Contributions); } if (ProcessFighterElo) { await fighterEloProcessor.Process(match, result.Contributions); } if (ProcessFighterContribution) { await contributionProcessor.Process(match, result.Contributions); } if (ProcessLog) { await logProcessor.Process(match, result); } }
public void Append(IMatchResult matchResult) { if (stack.Count == 0) { if (matchResult is Match match) { SetNewCurrentAndAddTag(match, false); } else { current.AddContent(matchResult.Content); } } else { if (matchResult is Match match) { if (stack.Peek().MdTag == matchResult.Content) { CloseCurrentTag(match); } else { SetNewCurrentAndAddTag(match, true); } } else { current.AddContent(matchResult.Content); } } }
private static void Output(PatternWrapper wrapper, IMatchResult results) { Output((IWrapper)wrapper, (IMatchResult)results); Console.WriteLine("User-Agent -> {0}", results.UserAgent); Console.WriteLine("Rank -> {0}", results.Rank); Console.WriteLine("Difference -> {0}", results.Difference); Console.WriteLine("Method -> {0}", results.Method); }
/// <summary> /// Returns gets all the property values and updates the check sum for /// the values. /// </summary> /// <param name="results"></param> /// <param name="match"></param> /// <param name="state"></param> public static void GetAllProperties(Results results, IMatchResult match, object state) { int checkSum = 0; foreach (var propertyName in (IEnumerable <string>)state) { checkSum += match[propertyName].GetHashCode(); } Interlocked.Add(ref results.CheckSum, checkSum); }
private static void Output(IWrapper wrapper, IMatchResult results) { Console.WriteLine(wrapper.GetType().Name); foreach (var item in wrapper.AvailableProperties) { Console.WriteLine("{0} -> {1}", item, results.getValue(item)); } }
/// <summary> /// Computes a hash based on values of the 51Degrees properties that /// were passed as part of the Match object. Only property values are /// used to compute hash. /// </summary> /// <param name="match"> /// Object containing 51Degrees device detection results. /// </param> /// <returns> /// Hash value of the provided Match object. /// </returns> public static long getHash(IMatchResult match) { long hash = 0L; foreach (var property in provider.AvailableProperties) { hash += match.getValue(property).GetHashCode(); } return(hash); }
public void Remove(IMatchResult matchResult) { if (!matchResult.IsMatch) { return; } Actions.RemoveAll(a => a.ScreenId == matchResult.ItemFather.Screen.Id.ToString()); Actions.RemoveAll(a => a.ScreenId == matchResult.ItemSon.Screen.Id.ToString()); }
public IMatchResult Match(SwipeActionToScreen swipeActionToScreen) { IMatchResult matchResult = null; matchResult = _mosaicStore.Match(swipeActionToScreen); if (matchResult.IsMatch) { _mosaicStore.ClearAppsEmpty(); } return(matchResult); }
public async Task Process(Match match, IMatchResult result) { databaseContext.MatchResults.Add(new Models.Matches.MatchResult() { MatchId = match.Id, RoundTicks = JsonConvert.SerializeObject(result.Ticks.AsDto(), new JsonSerializerSettings() { ContractResolver = new CamelCasePropertyNamesContractResolver(), }).Compress(), }); await databaseContext.SaveChangesAsync(); }
private static double GetFitness(IFighterStats geneticFighter, IMatchResult result) { var contribution = result.Contributions.First(o => o.FighterId == geneticFighter.Id); var fitness = 0D; if (contribution.HasWon) { fitness += 200; } fitness += contribution.Kills.Count() * 50; fitness += 25 * contribution.PercentageOfRoundsAlive; fitness += 15 * contribution.MatchParticipation; return(fitness); }
public IMatchResult Match(SwipeAction action, int milliseconds) { IMatchResult matchResult = null; var actionOpposite = GetOppositeAction(action); if (actionOpposite != null) { SwipeAction actionAux; //TODO: Thinking order if (actionOpposite.Timestamp.Subtract(action.Timestamp).TotalMilliseconds < 0) { actionAux = actionOpposite; actionOpposite = action; action = actionAux; } var mosaic = _mosaicStore.GetByScreenId(action.ScreenId); if (mosaic.Items.Count == 1) { matchResult = _mosaicStore.Match(action.ScreenId, actionOpposite.ScreenId, action.Direction); } else { matchResult = _mosaicStore.Match(action.ScreenId, actionOpposite.ScreenId, action.Direction); } if (matchResult.IsMatch) { Remove(matchResult); } Remove(milliseconds); } return(matchResult); }
internal GroupCollection(string text, IMatchResult matcher, Match regexMatch) { this.regexMatch = regexMatch; groups.Add(regexMatch); regexMatch.Regex.PatternConverter.PatternMap.ValidateTargetGroupCount(matcher.GroupCount()); for (var i = 1; i <= regexMatch.Regex.PatternConverter.PatternMap.GetSourceGroupCount(); i++) { var groupIndexes = regexMatch.Regex.PatternConverter.PatternMap.GetSourceToTargetsIndex(i); Group group = null; foreach (var groupIndex in groupIndexes) { var start = matcher.Start(groupIndex); if (start != -1) { var end = matcher.End(groupIndex); if (group == null) { group = new Group(text, start, end); } else { group.Captures.Add(new Capture(text, start, end)); } } } //no successfull match found if (group == null) { group = new Group(text, -1, -1); } groups.Add(group); } }
private void VerifyMatchResult(IMatchResult result) { var allFighterTicks = result.Ticks .SelectMany(o => o.Ticks); Assert.NotEmpty(allFighterTicks); var killed = result.Scores.SelectMany(o => o.Kills).ToList(); var deaths = result.Scores.Where(o => o.TotalDeaths > 0).Select(o => o.Id).ToList(); var differences = deaths.Except(killed).ToList(); Assert.Empty(differences); foreach (var score in result.Scores) { VerifyMatchScore(allFighterTicks, score, o => o.Fighter.Id == score.Id, o => o.Target.Id == score.Id, o => o.Source.Id == score.Id); } foreach (var teamScore in result.TeamScores) { VerifyMatchScore(allFighterTicks, teamScore, o => o.Fighter.Team == teamScore.Id, o => o.Target.Team == teamScore.Id, o => o.Source.Team == teamScore.Id); } foreach (var contribution in result.Contributions) { var score = result.Scores.First(o => o.Id == contribution.FighterId); Assert.Equal(score.TotalKills, contribution.Kills.Count()); Assert.Equal(result.Scores.First().Id == contribution.FighterId, contribution.HasWon); } var contributedKills = result.Contributions.Sum(o => o.Kills.Count()); Assert.True(contributedKills >= result.Scores.Sum(o => o.TotalDeaths)); Assert.NotEqual(0, result.Contributions.Sum(o => o.MatchParticipation)); Assert.NotEqual(0, result.Contributions.Sum(o => o.PercentageOfRoundsAlive)); }
internal GroupCollection(string text, IMatchResult matcher, Match regexMatch) { this.regexMatch = regexMatch; groups.Add(regexMatch); regexMatch.Regex.PatternConverter.PatternMap.ValidateTargetGroupCount(matcher.GroupCount()); for (var i = 1; i <= regexMatch.Regex.PatternConverter.PatternMap.GetSourceGroupCount(); i++) { var groupIndexes = regexMatch.Regex.PatternConverter.PatternMap.GetSourceToTargetsIndex(i); Group group = null; foreach (var groupIndex in groupIndexes) { var start = matcher.Start(groupIndex); if (start != -1) { var end = matcher.End(groupIndex); if (group == null) { group = new Group(text, start, end); } else { group.Captures.Add(new Capture(text, start, end)); } } } //no successfull match found if(group == null) group = new Group(text, -1, -1); groups.Add(group); } }
public BaseConstraintResult(IConstraint constraint, object actualValue, IMatchResult result) : base(constraint, actualValue, result.Matches ? ConstraintStatus.Success : ConstraintStatus.Failure) { this.result = result; }
/// <summary> /// Checks if this <see cref="CommandRoute" /> matches the /// provided <paramref name="command" />. /// </summary> /// <param name="command"></param> /// <returns> /// <see cref="CommandResult" /> if it matches otherwise it returns null. /// </returns> public CommandResult Match(IEnumerable <string> command) { var results = new List <IMatchResult>(); var optionalResults = new List <IMatchResult>(); var commandEnumerator = ListToPairList(command).GetEnumerator(); var segmentEnumerator = Segments.GetEnumerator(); using (commandEnumerator) { using (segmentEnumerator) { while (segmentEnumerator.MoveNext()) { if (!commandEnumerator.MoveNext()) { //not match, the number of commands is less than the number of segments return(null); } var match = segmentEnumerator.Current?.Match(commandEnumerator.Current.Item1); if (match == null) { return(null); } results.Add(match); } } while (commandEnumerator.MoveNext()) { var current = commandEnumerator.Current; IMatchResult result = null; foreach (var optionalSegment in OptionalSegments) { //verify this isn't the last piece if (current.Item2 != null) { result = optionalSegment.Match($"{current.Item1} {current.Item2}"); if (result != null) { //skip ahead by one because we matched both the current and next command piece commandEnumerator.MoveNext(); break; } } result = optionalSegment.Match(current.Item1); if (result != null) { break; } } if (result == null) { return(null); } optionalResults.Add(result); } } return(new CommandResult { MatchResults = results, OptionalMatchResults = optionalResults }); }
/// <summary> /// Returns gets all the property values and updates the check sum for /// the values. /// </summary> /// <param name="results"></param> /// <param name="match"></param> /// <param name="state"></param> public static void GetAllProperties(Results results, IMatchResult match, object state) { int checkSum = 0; foreach (var propertyName in (IEnumerable<string>)state) { checkSum += match[propertyName].GetHashCode(); } Interlocked.Add(ref results.CheckSum, checkSum); }
public override ConstraintResult ApplyTo <TActual>(TActual actual) { IMatchResult result = Matches(actual); return(new BaseConstraintResult(this, actual, result)); }