/// <summary> /// Called when the SwitchValve command is triggered by Chromeleon. /// </summary> /// <param name="args">The CommandEventArgs contain the parameter values.</param> private void m_ValveCommandWithPar_OnCommand(CommandEventArgs args) { IIntParameterValue stateValue = args.ParameterValue(m_ValveStateParameter) as IIntParameterValue; if ((stateValue == null) || !stateValue.Value.HasValue) { m_MyCmDevice.AuditMessage(AuditLevel.Error, "ValveState is a required parameter, should have a value!"); return; } IStringParameterValue logValue = args.ParameterValue(m_ValveLogParameter) as IStringParameterValue; if ((logValue != null) && !String.IsNullOrEmpty(logValue.Value)) { // Write a the message from command parameter to the audit trail m_MyCmDevice.AuditMessage(AuditLevel.Message, logValue.Value); } else { // Write a default message to the audit trail String message = String.Format(CultureInfo.InvariantCulture, "m_ValveCommandWithPar_OnCommand(time: {1}, state {0})", stateValue.Value.Value, RetentionToString(args.RetentionTime)); m_MyCmDevice.AuditMessage(AuditLevel.Message, message); } // As we simulate the valve only, we update the property direcly. m_ValveState.Update(stateValue.Value.Value); }
private static bool GetParameterString(CommandEventArgs args, string paramName, bool throwException, bool allowNull, out string value) { value = null; IParameterValue parameterValue = GetParameterValue(args, paramName, throwException); if (parameterValue == null) { return(false); } IStringParameterValue param = parameterValue as IStringParameterValue; if (param == null) { if (throwException) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CommandParameterIncorrectType, args.Command.Name, paramName, parameterValue.GetType().FullName, typeof(IStringParameterValue).FullName)); } return(false); } value = param.Value; if (string.IsNullOrEmpty(value) && !allowNull) { if (throwException) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CommandParameterValueIsEmpty, args.Command.Name, paramName)); } } return(true); }
private void m_ValveCommandWithPar_OnPreflightCommand(CommandEventArgs args) { string stateValueFormatted = "<noValue>"; string logValueFormatted = "<noValue>"; IIntParameterValue stateValue = args.ParameterValue(m_ValveStateParameter) as IIntParameterValue; if ((stateValue != null) && stateValue.Value.HasValue) { stateValueFormatted = stateValue.Value.Value.ToString(CultureInfo.InvariantCulture); } IStringParameterValue logValue = args.ParameterValue(m_ValveLogParameter) as IStringParameterValue; if ((logValue != null) && !String.IsNullOrEmpty(logValue.Value)) { logValueFormatted = logValue.Value; } // Write a message to the preflight results String message = String.Format(CultureInfo.InvariantCulture, "m_ValveCommandWithPar_OnPreflightCommand(time: {0}, state {1}, log {2})", RetentionToString(args.RetentionTime), stateValueFormatted, logValueFormatted); #if (PreflightMessagesToCM) m_MyCmDevice.AuditMessage(AuditLevel.Warning, message); #else Debug.WriteLine("PreflightMessage: " + message); #endif }
/// <summary> /// Called when the "CommandWith4Parameters" command is sent by Chromeleon. /// </summary> /// <param name="args">The CommandEventArgs contain a reference to /// the command being called and the argument list.</param> private void OnCommandWith4Parameters(CommandEventArgs args) { Debug.Assert(args.Command == m_CommandWith4Parameters); // This command does not really do anything but retrieving the different parameters // and showing them in the audit trail. StringBuilder sb = new StringBuilder("CommandWith4Parameters was called with the following parameters:"); // check for Param1 IIntParameterValue param1Value = args.ParameterValue(m_CommandWith4Parameters.FindParameter("Param1")) as IIntParameterValue; sb.Append("\nParam1="); if (param1Value != null) { sb.Append(param1Value.Value); } else { sb.Append("<not set>"); } // check for Param2 IDoubleParameterValue param2Value = args.ParameterValue(m_CommandWith4Parameters.FindParameter("Param2")) as IDoubleParameterValue; sb.Append("\nParam2="); if (param2Value != null) { sb.Append(param2Value.Value); } else { sb.Append("<not set>"); } // check for Param3 IIntParameterValue param3Value = args.ParameterValue(m_CommandWith4Parameters.FindParameter("Param3")) as IIntParameterValue; sb.Append("\nParam3="); if (param3Value != null) { sb.Append(param3Value.Value); } else { sb.Append("<not set>"); } // check for Param4 IStringParameterValue param4Value = args.ParameterValue(m_CommandWith4Parameters.FindParameter("Param4")) as IStringParameterValue; sb.Append("\nParam4="); if (param4Value != null) { sb.Append(param4Value.Value); } else { sb.Append("<not set>"); } m_MyCmDevice.AuditMessage(AuditLevel.Message, sb.ToString()); }