private void SnapProperties(HttpRequest httpRequest) { Assumption.AssertNotNull(httpRequest, nameof(httpRequest)); this.Url = httpRequest.Host.Value + httpRequest.Path; this.QueryString = httpRequest.QueryString.Value; this.Params = null; this.Headers = new Dictionary <string, string>(httpRequest.Headers.Count()); foreach (var header in httpRequest.Headers) { this.Headers.Add(header.Key, StringUtility.Combine(header.Value, ", ")); } this.Method = httpRequest.Method; }
/// <summary> /// Truncates the string values. /// </summary> /// <param name="dictionary">The dictionary.</param> /// <param name="encoding">The encoding.</param> /// <param name="stringBytesLimit">The string bytes limit.</param> protected void TruncateStringValues(IDictionary <string, string> dictionary, Encoding encoding, int stringBytesLimit) { Assumption.AssertNotNull(dictionary, nameof(dictionary)); var keys = Enumerable.ToArray(dictionary.Keys); foreach (var key in keys) { string original = dictionary[key]; if (original != null) { string truncated = StringUtility.Truncate(original, encoding, stringBytesLimit); if (!object.ReferenceEquals(original, truncated)) { dictionary[key] = truncated; } } } }
private void SnapProperties(RollbarHttpAttributes httpContext) { Assumption.AssertNotNull(httpContext, nameof(httpContext)); this.Url = httpContext.Host.Value + httpContext.Path; this.QueryString = httpContext.Query.Value; this.Params = null; this.Headers = new Dictionary <string, string>(httpContext.Headers.Count()); foreach (var header in httpContext.Headers) { if (header.Value.Count() == 0) { continue; } this.Headers.Add(header.Key, StringUtility.Combine(header.Value, ", ")); } this.Method = httpContext.Method; }
/// <summary> /// Truncates the specified input. /// </summary> /// <param name="input">The input.</param> /// <param name="encoding">The encoding.</param> /// <param name="encodedBytesLimit">The encoded bytes limit.</param> /// <returns></returns> public static string Truncate(string input, Encoding encoding, int encodedBytesLimit) { if (input == null) { return(input); //nothing to truncate... } byte[] inputEncodedBytes = encoding.GetBytes(input); Assumption.AssertEqual(inputEncodedBytes.Length, encoding.GetByteCount(input), nameof(inputEncodedBytes.Length)); if (inputEncodedBytes.Length <= encodedBytesLimit) { return(input); //nothing to truncate... } int truncationIndicatorTotalBytes = encoding.GetByteCount(TruncationIndicator); int totalBytes = encodedBytesLimit - truncationIndicatorTotalBytes; if (totalBytes < 0) { totalBytes = 0; } string truncatedInput = encoding.GetString(inputEncodedBytes, 0, totalBytes); if ((totalBytes > 0) && (truncatedInput[truncatedInput.Length - 1] != input[truncatedInput.Length - 1]) ) { truncatedInput = truncatedInput.Substring(0, truncatedInput.Length - 1); } truncatedInput += TruncationIndicator; Assumption.AssertTrue(encoding.GetByteCount( truncatedInput) <= encodedBytesLimit || encodedBytesLimit < truncationIndicatorTotalBytes, nameof(truncatedInput) ); return(truncatedInput); }
private static ExtendableDtoMetadata Build(Type extendableDtoType) { ExtendableDtoMetadata result = new ExtendableDtoMetadata(); result.ExtendableDtoType = extendableDtoType; Type reservedPropertiesNestedType = ReflectionUtil.GetNestedTypeByName( extendableDtoType, ExtendableDtoBase.ReservedPropertiesNestedTypeName, BindingFlags.Public | BindingFlags.Static ); Assumption.AssertNotNull(reservedPropertiesNestedType, nameof(reservedPropertiesNestedType)); var reservedAttributes = ReflectionUtil.GetAllPublicStaticFields(reservedPropertiesNestedType); Dictionary <string, PropertyInfo> reservedPropertyInfoByName = new Dictionary <string, PropertyInfo>(reservedAttributes.Length); result.ReservedPropertyInfoByReservedKey = reservedPropertyInfoByName; foreach (var reservedAttribue in reservedAttributes) { var property = extendableDtoType.GetProperty(reservedAttribue.Name, BindingFlags.Public | BindingFlags.Instance); Assumption.AssertNotNull(property, nameof(property)); string reservedKey = ReflectionUtil.GetStaticFieldValue <string>(reservedAttribue); Assumption.AssertNotNullOrWhiteSpace(reservedKey, nameof(reservedKey)); reservedPropertyInfoByName.Add(reservedKey, property); } return(result); }
/// <summary>Gets the static field value.</summary> /// <typeparam name="TFieldDataType">The type of the field data type.</typeparam> /// <param name="staticField">The static field.</param> /// <returns></returns> public static TFieldDataType GetStaticFieldValue <TFieldDataType>(FieldInfo staticField) { Assumption.AssertTrue(staticField.IsStatic, "IsStatic"); return((TFieldDataType)staticField.GetValue((object)null)); }
/// <summary> /// Validates this instance. /// </summary> public override void Validate() { Assumption.AssertNotNullOrWhiteSpace(this.Body, nameof(this.Body)); }