in Source/Rules/SmallBatchDetectionRule.cs [56:121]
public override RuleResult Run(IEnumerable<ServiceCallItem> items, ServiceCallStats stats)
{
RuleResult result = InitializeResult(DisplayName, Description);
//check invalid log versions
if (items.Count(item => item.m_logVersion == Constants.Version1509) > 0)
{
result.AddViolation(ViolationLevel.Warning, "Data version does not support this rule. You need an updated Xbox Live SDK to support this rule");
return result;
}
StringBuilder description = new StringBuilder();
// Traverse through each pattern set found in rule parameter
foreach (var pattern in m_MatchPatterns)
{
Dictionary<ServiceCallItem, int> matchesFoundDict = new Dictionary<ServiceCallItem, int>();
int patternInstancesFound = 0;
int lowXUIDInstancesFound = 0;
// This first section reports on violations which are from batch calls made with not enough XUIDs in the request body
foreach (ServiceCallItem thisItem in items)
{
Match match = Regex.Match(thisItem.m_uri, pattern.Key);
if (match.Success)
{
if (!thisItem.m_reqHeader.Contains("SocialManager"))
{
patternInstancesFound++;
try
{
JObject requestBodyJSON = JObject.Parse(thisItem.m_reqBody);
var values = requestBodyJSON.SelectToken(pattern.Value) as JArray;
if (values != null)
{
matchesFoundDict.Add(thisItem, values.Count);
if (values.Count < m_minBatchXUIDsPerBatchCall)
{
lowXUIDInstancesFound++;
description.Clear();
description.AppendFormat("Batch call detected for endpoint for a small sized set of {0} XUIDs.", values.Count);
result.AddViolation(ViolationLevel.Warning, description.ToString(), thisItem);
}
}
}
catch (Exception)
{
// ignored
}
}
}
} // finished traversing calls made to endpoint
m_patternInstancesFound.Add(new Tuple<int, int>(patternInstancesFound, lowXUIDInstancesFound));
} // end of foreach pattern in patterns
var finalStats = PatternsFoundSumAsTuple();
result.Results.Add("Total Batch Calls", finalStats.Item1);
result.Results.Add("Min. Users Allowed", m_minBatchXUIDsPerBatchCall);
result.Results.Add("Calls Below Count", finalStats.Item2);
result.Results.Add("% Below Count",(double)(finalStats.Item2) / finalStats.Item1);
return result;
}