/// <summary> /// Gets the value of the property if it exists /// if the property does not exist and throwIfNotExist = true => throw an exception /// if the property does not exist and throwIfNotExist = false => return null /// </summary> /// <exception > /// if the key not found and throwIfNotExist = true, throws an exception with event dump /// </exception> /// <param name="property">The property value to get</param> /// <param name="throwIfNotExist">if true throw an exception if the property does not exist</param> /// <returns>The value, or null if it does not exist and throwIfNotExist = false</returns> public string GetPropertyValue(AuditMessageProperty property, bool throwIfNotExist = true) { bool propertyExist = MessageData.TryGetValue(property, out string prop); if (!propertyExist && throwIfNotExist) { throw new AuditEventPropertyNotFoundException(Type, Id, MessageData, property, EventText); } return(prop); }
/// <summary> /// Tries to get a value of a specific property from a ausearch output line /// </summary> /// <param name="eventText">The ausearch line</param> /// <param name="property">The property to get</param> /// <param name="value">The value of the property, null if not found</param> /// <returns>True if property found, false if not</returns> private static bool TryGetPropertyValue(string eventText, AuditMessageProperty property, out string value) { DisplayAttribute displayNameAttribute = property.GetAttribute <DisplayAttribute>(); if (displayNameAttribute == null) { value = null; return(false); } foreach (var regexTemplate in propertyRegexTemplates) { var regexMatch = Regex.Match(eventText, string.Format(regexTemplate, displayNameAttribute.Name)); if (regexMatch.Success) { value = regexMatch.Value; return(regexMatch.Success); } } value = null; return(false); }