// Retrieves an event value from a property that is named in the metadata. For example, if the metadataPropertyName parameter is // "ResponseCodeProperty", we read the "ResponseCodeProperty" from the metadata. Suppose its value is "returnCode". // Then we look into the event and try to find "returnCode" property in the payload. If successful, we return its value to the caller // (e.g. it could be "200 OK", indicating successful HTTP call). public DataRetrievalResult GetEventPropertyValue <T>( EventData eventData, string metadataPropertyName, out T eventPropertyValue) { Requires.NotNull(eventData, nameof(eventData)); Requires.NotNullOrEmpty(metadataPropertyName, nameof(metadataPropertyName)); eventPropertyValue = default(T); string eventPropertyName = this[metadataPropertyName]; if (string.IsNullOrWhiteSpace(eventPropertyName)) { return(DataRetrievalResult.MissingMetadataProperty(metadataPropertyName)); } T value = default(T); if (!eventData.GetValueFromPayload <T>(eventPropertyName, (v) => value = v)) { return(DataRetrievalResult.DataMissingOrInvalid(eventPropertyName)); } else { eventPropertyValue = value; } return(DataRetrievalResult.Success); }
public override bool Equals(object obj) { DataRetrievalResult other = obj as DataRetrievalResult; if (other == null) { return(false); } return(this.Status == other.Status && string.Equals(this.Message, other.Message, StringComparison.Ordinal)); }
public static DataRetrievalResult TryGetData( EventData eventData, EventMetadata dependencyMetadata, out DependencyData dependency) { Requires.NotNull(eventData, nameof(eventData)); Requires.NotNull(dependencyMetadata, nameof(dependencyMetadata)); dependency = null; if (!DependencyMetadataKind.Equals(dependencyMetadata.MetadataType, System.StringComparison.OrdinalIgnoreCase)) { return(DataRetrievalResult.InvalidMetadataType(dependencyMetadata.MetadataType, DependencyMetadataKind)); } DataRetrievalResult result = GetSuccessValue(eventData, dependencyMetadata, out bool?success); if (result.Status != DataRetrievalStatus.Success) { return(result); } result = GetDurationValue(eventData, dependencyMetadata, out TimeSpan? duration); if (result.Status != DataRetrievalStatus.Success) { return(result); } result = GetResponseCodeValue(eventData, dependencyMetadata, out string responseCode); if (result.Status != DataRetrievalStatus.Success) { return(result); } result = dependencyMetadata.GetEventPropertyValue(eventData, TargetPropertyMoniker, out string target); if (result.Status != DataRetrievalStatus.Success) { return(result); } string dependencyType = dependencyMetadata[DependecyTypeMoniker]; dependency = new DependencyData(); dependency.IsSuccess = success; dependency.Duration = duration; dependency.ResponseCode = responseCode; dependency.Target = target; dependency.DependencyType = dependencyType; return(DataRetrievalResult.Success); }
public static DataRetrievalResult TryGetData(EventData eventData, EventMetadata metricMetadata, out MetricData metric) { Requires.NotNull(eventData, nameof(eventData)); Requires.NotNull(metricMetadata, nameof(metricMetadata)); metric = null; if (!MetricMetadataKind.Equals(metricMetadata.MetadataType, System.StringComparison.OrdinalIgnoreCase)) { return(DataRetrievalResult.InvalidMetadataType(metricMetadata.MetadataType, MetricMetadataKind)); } string metricName = metricMetadata[MetricNameMoniker]; if (string.IsNullOrEmpty(metricName)) { return(DataRetrievalResult.MissingMetadataProperty(MetricNameMoniker)); } double value = 0.0; string metricValueProperty = metricMetadata[MetricValuePropertyMoniker]; if (string.IsNullOrEmpty(metricValueProperty)) { string rawValue = metricMetadata[MetricValueMoniker]; if (string.IsNullOrEmpty(rawValue)) { return(DataRetrievalResult.MissingMetadataProperty(MetricValueMoniker)); } if (!double.TryParse(rawValue, out value)) { return(DataRetrievalResult.InvalidMetadataPropertyValue(MetricValueMoniker, rawValue)); } } else { if (!eventData.GetValueFromPayload <double>(metricValueProperty, (v) => value = v)) { return(DataRetrievalResult.DataMissingOrInvalid(metricValueProperty)); } } metric = new MetricData(); metric.MetricName = metricName; metric.Value = value; return(DataRetrievalResult.Success); }
public static DataRetrievalResult TryGetData( EventData eventData, EventMetadata requestMetadata, out RequestData request) { Requires.NotNull(eventData, nameof(eventData)); Requires.NotNull(requestMetadata, nameof(requestMetadata)); request = null; if (!RequestMetadataKind.Equals(requestMetadata.MetadataType, System.StringComparison.OrdinalIgnoreCase)) { return(DataRetrievalResult.InvalidMetadataType(requestMetadata.MetadataType, RequestMetadataKind)); } // Inability to retrieve request name is not a terminating error--ignore the return value from GetEventPropertyValue here. requestMetadata.GetEventPropertyValue(eventData, RequestNamePropertyMoniker, out string requestName); DataRetrievalResult result = GetSuccessValue(eventData, requestMetadata, out bool?success); if (result.Status != DataRetrievalStatus.Success) { return(result); } result = GetDurationValue(eventData, requestMetadata, out TimeSpan? duration); if (result.Status != DataRetrievalStatus.Success) { return(result); } result = GetResponseCodeValue(eventData, requestMetadata, out string responseCode); if (result.Status != DataRetrievalStatus.Success) { return(result); } request = new RequestData(); request.RequestName = requestName; request.IsSuccess = success; request.Duration = duration; request.ResponseCode = responseCode; return(DataRetrievalResult.Success); }
protected static DataRetrievalResult GetResponseCodeValue(EventData eventData, EventMetadata networkCallMetadata, out string responseCode) { responseCode = null; string responseCodeProperty = networkCallMetadata[ResponseCodePropertyMoniker]; if (!string.IsNullOrWhiteSpace(responseCodeProperty)) { string localResponseCodeVal = null; if (!eventData.GetValueFromPayload <string>(responseCodeProperty, (v) => localResponseCodeVal = v)) { return(DataRetrievalResult.DataMissingOrInvalid(responseCodeProperty)); } else { responseCode = localResponseCodeVal; } } return(DataRetrievalResult.Success); }
protected static DataRetrievalResult GetSuccessValue(EventData eventData, EventMetadata networkCallMetadata, out bool?success) { success = null; string isSuccessProperty = networkCallMetadata[IsSuccessPropertyMoniker]; if (!string.IsNullOrWhiteSpace(isSuccessProperty)) { bool?localSuccessVal = null; if (!eventData.GetValueFromPayload <bool>(isSuccessProperty, (v) => localSuccessVal = v)) { return(DataRetrievalResult.DataMissingOrInvalid(isSuccessProperty)); } else { success = localSuccessVal; } } return(DataRetrievalResult.Success); }
protected static DataRetrievalResult GetDurationValue(EventData eventData, EventMetadata networkCallMetadata, out TimeSpan?duration) { duration = null; string durationProperty = networkCallMetadata[DurationPropertyMoniker]; if (!string.IsNullOrWhiteSpace(durationProperty)) { DurationUnit durationUnit; string durationUnitOverride = networkCallMetadata[DurationUnitMoniker]; if (string.IsNullOrEmpty(durationUnitOverride) || !Enum.TryParse <DurationUnit>(durationUnitOverride, ignoreCase: true, result: out durationUnit)) { // By default we assume duration is stored as a double value representing milliseconds durationUnit = DurationUnit.Milliseconds; } if (durationUnit != DurationUnit.TimeSpan) { double tempDuration = 0.0; if (!eventData.GetValueFromPayload <double>(durationProperty, (v) => tempDuration = v)) { return(DataRetrievalResult.DataMissingOrInvalid(durationProperty)); } duration = ToTimeSpan(tempDuration, durationUnit); } else { TimeSpan?localDurationVal = null; if (!eventData.GetValueFromPayload <TimeSpan>(durationProperty, (v) => localDurationVal = v)) { return(DataRetrievalResult.DataMissingOrInvalid(durationProperty)); } else { duration = localDurationVal; } } } return(DataRetrievalResult.Success); }
public static DataRetrievalResult TryGetData( EventData eventData, EventMetadata exceptionMetadata, out ExceptionData exceptionData) { Requires.NotNull(eventData, nameof(eventData)); Requires.NotNull(exceptionMetadata, nameof(exceptionMetadata)); exceptionData = null; if (!ExceptionMetadataKind.Equals(exceptionMetadata.MetadataType, System.StringComparison.OrdinalIgnoreCase)) { return(DataRetrievalResult.InvalidMetadataType(exceptionMetadata.MetadataType, ExceptionMetadataKind)); } DataRetrievalResult result = exceptionMetadata.GetEventPropertyValue(eventData, ExceptionPropertyMoniker, out Exception e); if (result.Status == DataRetrievalStatus.Success) { exceptionData = new ExceptionData(e); } return(result); }
public static DataRetrievalResult TryGetData( EventData eventData, EventMetadata requestMetadata, out RequestData request) { Requires.NotNull(eventData, nameof(eventData)); Requires.NotNull(requestMetadata, nameof(requestMetadata)); request = null; string requestNameProperty = requestMetadata[RequestNamePropertyMoniker]; if (string.IsNullOrWhiteSpace(requestNameProperty)) { return(DataRetrievalResult.MissingMetadataProperty(RequestNamePropertyMoniker)); } string requestName = null; if (!eventData.GetValueFromPayload <string>(requestNameProperty, (v) => requestName = v)) { return(DataRetrievalResult.DataMissingOrInvalid(requestNameProperty)); } bool? success = null; string isSuccessProperty = requestMetadata[IsSuccessPropertyMoniker]; if (!string.IsNullOrWhiteSpace(isSuccessProperty)) { if (!eventData.GetValueFromPayload <bool>(isSuccessProperty, (v) => success = v)) { return(DataRetrievalResult.DataMissingOrInvalid(isSuccessProperty)); } } TimeSpan?duration = null; string durationProperty = requestMetadata[DurationPropertyMoniker]; if (!string.IsNullOrWhiteSpace(durationProperty)) { DurationUnit durationUnit; string durationUnitOverride = requestMetadata[DurationUnitMoniker]; if (string.IsNullOrEmpty(durationUnitOverride) || !Enum.TryParse <DurationUnit>(durationUnitOverride, ignoreCase: true, result: out durationUnit)) { // By default we assume duration is stored as a double value representing milliseconds durationUnit = DurationUnit.Milliseconds; } if (durationUnit != DurationUnit.TimeSpan) { double tempDuration = 0.0; if (!eventData.GetValueFromPayload <double>(durationProperty, (v) => tempDuration = v)) { return(DataRetrievalResult.DataMissingOrInvalid(durationProperty)); } duration = ToTimeSpan(tempDuration, durationUnit); } else { if (!eventData.GetValueFromPayload <TimeSpan>(durationProperty, (v) => duration = v)) { return(DataRetrievalResult.DataMissingOrInvalid(durationProperty)); } } } string responseCode = null; string responseCodeProperty = requestMetadata[ResponseCodePropertyMoniker]; if (!string.IsNullOrWhiteSpace(responseCodeProperty)) { if (!eventData.GetValueFromPayload <string>(responseCodeProperty, (v) => responseCode = v)) { return(DataRetrievalResult.DataMissingOrInvalid(responseCodeProperty)); } } request = new RequestData(); request.RequestName = requestName; request.IsSuccess = success; request.Duration = duration; request.ResponseCode = responseCode; return(DataRetrievalResult.Success()); }