/// <summary> /// Generate a new hash code /// </summary> /// <param name="entity">entity</param> /// <returns>hashcode</returns> /// <exception cref="ArgumentNullException">entity</exception> public string GenerateHashCode(ErrorReportEntity entity) { string requestUrl = null; var httpCode = 0; foreach (var collection in entity.ContextCollections) { if (collection.Properties.TryGetValue("HttpCode", out var value)) { int.TryParse(value, out httpCode); } if (!collection.Properties.TryGetValue("RequestUrl", out requestUrl)) { collection.Properties.TryGetValue("Url", out requestUrl); } } if (httpCode == 0 || string.IsNullOrWhiteSpace(requestUrl)) { return(null); } var pos = requestUrl.IndexOf("?"); if (pos != -1) { requestUrl = requestUrl.Remove(pos); } return(HashCodeUtility.GetPersistentHashCode(httpCode + "-" + requestUrl).ToString("X")); }
/// <summary> /// Generate a new hash code /// </summary> /// <param name="entity">entity</param> /// <returns>hashcode</returns> /// <exception cref="ArgumentNullException">entity</exception> public ErrorHashCode GenerateHashCode(ErrorReportEntity entity) { string requestUrl = null; var httpCode = 0; foreach (var collection in entity.ContextCollections) { if (collection.Properties.TryGetValue("HttpCode", out var value)) { int.TryParse(value, out httpCode); // Server side errors are typically handled by other handlers. if (httpCode == 500) { return(null); } } if (!collection.Properties.TryGetValue("RequestUrl", out requestUrl)) { collection.Properties.TryGetValue("Url", out requestUrl); } } if (httpCode == 0 || string.IsNullOrWhiteSpace(requestUrl)) { return(null); } // Since this is for a specific application, remove host to make sure that errors // for different environments/servers are treated as the same error. // Remove host or correct uris if (requestUrl.Contains("://")) { var pos2 = requestUrl.IndexOf("//"); pos2 = requestUrl.IndexOf("/", pos2 + 2); requestUrl = requestUrl.Remove(0, pos2); } // and query string var pos = requestUrl.IndexOf("?"); if (pos != -1) { requestUrl = requestUrl.Remove(pos); } return(new ErrorHashCode { HashCode = HashCodeUtility.GetPersistentHashCode($"{httpCode};{requestUrl}").ToString("X"), CollisionIdentifier = $"{httpCode};{requestUrl}" }); }
/// <summary> /// Generate a new hash code /// </summary> /// <param name="entity">entity</param> /// <returns>hashcode</returns> /// <exception cref="ArgumentNullException">entity</exception> public ErrorHashCode GenerateHashCode(ErrorReportEntity entity) { string requestUrl = null; var httpCode = 0; foreach (var collection in entity.ContextCollections) { if (collection.Properties.TryGetValue("HttpCode", out var value)) { int.TryParse(value, out httpCode); // Server side errors are typically handled by other handlers. if (httpCode == 500) { return(null); } } if (!collection.Properties.TryGetValue("RequestUrl", out requestUrl)) { collection.Properties.TryGetValue("Url", out requestUrl); } } if (httpCode == 0 || string.IsNullOrWhiteSpace(requestUrl)) { return(null); } var pos = requestUrl.IndexOf("?"); if (pos != -1) { requestUrl = requestUrl.Remove(pos); } return(new ErrorHashCode { HashCode = HashCodeUtility.GetPersistentHashCode($"{httpCode}-{requestUrl}").ToString("X"), CollisionIdentifier = $"{httpCode}-{requestUrl}" }); }