/// <summary> /// Use the pipeline to process this FlowData instance and /// populate the aspect data values. /// </summary> /// <exception cref="PipelineException"> /// Thrown if this flow data object has already been processed. /// </exception> /// <exception cref="ObjectDisposedException"> /// Thrown if the Pipeline has already been disposed. /// </exception> public void Process() { if (_processed) { throw new PipelineException(Messages.ExceptionFlowDataAlreadyProcessed); } _processed = true; PipelineInternal.Process(this); }
/// <summary> /// Get the specified property as the specified type. /// </summary> /// <typeparam name="T"> /// The type to return the property value as /// </typeparam> /// <param name="propertyName"> /// The name of the property to get /// </param> /// <returns> /// The property value /// </returns> /// <exception cref="PipelineException"> /// Thrown if this FlowData instance has not been processed yet. /// </exception> /// <exception cref="PipelineDataException"> /// Thrown if the requested property cannot be found or if multiple /// flow elements use the same property name. /// </exception> /// <exception cref="InvalidCastException"> /// Thrown if property value cannot be cast to the requested type. /// </exception> /// <exception cref="KeyNotFoundException"> /// Thrown if property value is expected to be present but was not /// found. /// </exception> public T GetAs <T>(string propertyName) { T result; // Throw an error if the instance has not yet been processed. if (_processed == false) { _logger.LogError(Messages.ExceptionFlowDataNotYetProcessed); throw new PipelineException(Messages.ExceptionFlowDataNotYetProcessed); } var property = PipelineInternal.GetMetaDataForProperty(propertyName); // Attempt to cast the property value object to the desired type. // If this fails then log an error message and throw an exception. try { result = (T)Get(property.Element.ElementDataKey)[property.Name]; } catch (InvalidCastException) { string message = $"Failed to cast property '{propertyName}'" + $" to '{typeof(T).Name}'. " + $"Expected property type is '{property.Type.Name}'"; _logger.LogError(message); throw; } catch (KeyNotFoundException) { string message = $"Property '{propertyName}' was not in " + $"the data from '{property.Element.GetType().Name}' " + $"as expected."; _logger.LogError(message); throw; } return(result); }