/// <summary> /// Validates the configuration of this stream. /// </summary> /// <returns>A Maybe monad indicating validation success (bool) or error message (string)</returns> public virtual Maybe <string> Validate() { // We should always have some non-zero number of Devices configured if (Device == null && this.Active) { return(Maybe <string> .No("No device, and/or 'this' not Active")); } if (Name == null) { return(Maybe <string> .No("Name was null")); } // Pull MeasurementConversionTarget out of Configuration, if it's not already provided if (MeasurementConversionTarget == null) { object obj; if (!Configuration.TryGetValue("MeasurementConversionTarget", out obj)) { return(Maybe <string> .No("No MeasurementConversionTarget specified in " + Name + "'s Configuration")); } MeasurementConversionTarget = (string)obj; } // Make sure there is a conversions target in the Controller for the MeasurementConversionTarget // unit type specified here; it's not a 100% guarantee that we're covered, since we don't know // the incoming unit type yet, but at least it's better than nothing to start if (MeasurementConversionTarget != Measurement.UNITLESS && !Converters.TestTo(MeasurementConversionTarget)) { return(Maybe <string> .No("Conversion target not found")); } if (Clock == null) { return(Maybe <string> .No("Clock must not be null.")); } return(Maybe <string> .Yes()); }
/// <summary> /// Verify that everything is hooked up correctly /// </summary> /// <returns></returns> public override Maybe <string> Validate() { // Pull MeasurementConversionTarget out of Configuration, if it's not already provided if (MeasurementConversionTarget == null) { object obj; if (!Configuration.TryGetValue("MeasurementConversionTarget", out obj)) { return(Maybe <string> .No("No MeasurementConversionTarget specified in " + Name + "'s Configuration")); } MeasurementConversionTarget = (string)obj; } // Validate that the conversion targets are in the Controller's // Conversions dictionary if (!(MeasurementConversionTarget.Equals(Measurement.UNITLESS) || Converters.TestTo(MeasurementConversionTarget))) { return(Maybe <string> .No(Name + " failed to find conversion target for " + MeasurementConversionTarget)); } return(base.Validate()); }