/// <summary> /// Method that will be invoked if no implementations of <see cref="IHashCodeSubGenerator" /> generates an hash code. /// </summary> /// <param name="report">received report</param> /// <returns>hash code</returns> /// <exception cref="ArgumentNullException">report</exception> protected virtual string DefaultCreateHashCode(ErrorReportEntity report) { if (report == null) { throw new ArgumentNullException("report"); } //TODO: Ta bort radnummers stripparen var hashSource = report.Exception.FullName + "\r\n"; hashSource += Regex.Replace(report.Exception.StackTrace, RemoveLineNumbersRegEx, "", RegexOptions.Multiline); var hash = 23; foreach (var c in hashSource) { hash = hash * 31 + c; } return(hash.ToString("X")); }
/// <summary> /// Generate a new hash code /// </summary> /// <param name="entity">entity</param> /// <returns>hash code</returns> /// <exception cref="ArgumentNullException">entity</exception> public string GenerateHashCode(ErrorReportEntity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } foreach (var generator in _serviceLocator.ResolveAll <IHashCodeSubGenerator>()) { if (generator.CanGenerateFrom(entity)) { // forgiving ones so that we can get the report and process it with a default hash code instead. var code = generator.GenerateHashCode(entity); if (code != null) { return(code); } } } return(DefaultCreateHashCode(entity)); }