private void CommandTestInit() { ICommand command = m_Device.CreateCommand("CommandTest", "Test command description"); command.AddParameter(m_CommandTest_Param_1_Int, "Integer > 0", m_DDK.CreateInt(0, 1000)); command.AddParameter(m_CommandTest_Param_2_Double, "Double Percent [0, 100]", Property.CreatePercentType(m_DDK, 0, 100, 2)); command.AddParameter(m_CommandTest_Param_3_Bool, "Bool", Property.CreateBoolType(m_DDK)); command.AddParameter(m_CommandTest_Param_4_String, "String 1 to 20 characters", m_DDK.CreateString(20)); command.OnPreflightCommand += OnCommandTestPreflight; command.OnCommand += OnCommandTest; }
public static void AddParametersToCommand(ICommand command, Uri uri) { try { NameValueCollection nameValueCollection = HttpUtility.ParseQueryString(uri.Query); foreach (string key in nameValueCollection.Keys) { if (key == null || string.IsNullOrWhiteSpace(key)) { object[] str = new object[1]; str[0] = uri.ToString(); throw new DataServiceException(0x190, ExceptionHelpers.GetDataServiceExceptionMessage(HttpStatusCode.BadRequest, Resources.InvalidQueryParameterMessage, str)); } else { string[] values = nameValueCollection.GetValues(key); if ((int)values.Length == 1) { string str1 = values[0]; if (!string.IsNullOrWhiteSpace(str1)) { string str2 = key.Trim(); if (str2.StartsWith("$", StringComparison.OrdinalIgnoreCase)) { continue; } try { command.AddParameter(str2, str1.Trim(), true); } catch (ArgumentException argumentException1) { ArgumentException argumentException = argumentException1; object[] objArray = new object[1]; objArray[0] = uri.ToString(); throw new DataServiceException(0x190, string.Empty, ExceptionHelpers.GetDataServiceExceptionMessage(HttpStatusCode.BadRequest, Resources.InvalidQueryParameterMessage, objArray), string.Empty, argumentException); } } else { object[] objArray1 = new object[1]; objArray1[0] = uri.ToString(); throw new DataServiceException(0x190, ExceptionHelpers.GetExceptionMessage(Resources.InvalidQueryParameterMessage, objArray1)); } } else { object[] objArray2 = new object[1]; objArray2[0] = uri.ToString(); throw new DataServiceException(0x190, ExceptionHelpers.GetDataServiceExceptionMessage(HttpStatusCode.BadRequest, Resources.InvalidQueryParameterMessage, objArray2)); } } } } catch (Exception exception) { TraceHelper.Current.UriParsingFailed(uri.ToString()); throw; } }
// private const string m_CommandTest_Param_1_Int = "Param_1_Int"; private void CommandTransferData() { ICommand command = m_Device.CreateCommand("CommandTest1", "Test command description"); command.AddParameter("CommandTest1", "Test command description nice", m_DDK.CreateDouble(0, 1000, 3)); command.OnPreflightCommand += OnCommandTestPreflight; //command.OnCommand += O }
public MyPage(IContextFactory sqlContextFactory, ICommandFactory sqlCommandFactory, IMapper sqlMapper) { _sqlContextFactory = sqlContextFactory; _sqlCommandFactory = sqlCommandFactory; _sqlMapper = sqlMapper; if (_command == null) { _command = _sqlCommandFactory.CreateStoredProcedure("getProfileById"); _profileIdParameter = _command.AddParameter("id", System.Data.SqlDbType.BigInt); } }
static void AddParameter(this ICommand command, object parameters, PropertyInfo property) { var dbType = DbTypeResolvers.Instance.TryResolve(property.PropertyType); if (!dbType.HasValue) { // this will ignore all types we do not know :( // maybe it's better to let package user to define will it be ignored or not // TODO if configured to allow unknown types and treat them as Object return; } command.AddParameter(parameters, property, dbType); }
public static void AddParameters(this ICommand command, object parameters) { if (command == null) { throw new ArgumentNullException(nameof(command)); } if (parameters != null) { var properties = parameters.GetType().GetProperties(); foreach (var property in properties) { command.AddParameter(parameters, property); } } }
/// <summary> /// Create our Dionex.Chromeleon.Symbols.IDevice and our Properties and Commands /// </summary> /// <param name="cmDDK">The DDK instance</param> /// <param name="name">The name for our device</param> /// <returns>our IDevice object</returns> internal IDevice Create(IDDK cmDDK, string name) { m_MyCmDDK = cmDDK; // Create the Dionex.Chromeleon.Symbols.IDevice m_MyCmDevice = cmDDK.CreateDevice(name, "This is an example device."); // create a few example properties // A Data type for a flow ranging from 0.000 - 10.000 ITypeDouble tFlow = cmDDK.CreateDouble(0, 10, 3); tFlow.Unit = "ml/min"; // Create our flow handler. The flow handler creates a Flow.Nominal, // a Flow.Value and 2 eluent component properties for us. m_FlowHandler = m_MyCmDevice.CreateFlowHandler(tFlow, 2, 2); // initialize the flow m_FlowHandler.FlowNominalProperty.Update(0); // initialize the components m_FlowHandler.ComponentProperties[0].Update(100.0); m_FlowHandler.ComponentProperties[1].Update(0); // All properties support ramps m_FlowHandler.FlowNominalProperty.RampSyntax = true; m_FlowHandler.ComponentProperties[0].RampSyntax = true; m_FlowHandler.ComponentProperties[1].RampSyntax = true; // Attach various handlers m_FlowHandler.FlowNominalProperty.OnSetProperty += new SetPropertyEventHandler(m_RampedFlowProperty_OnSetProperty); m_FlowHandler.ComponentProperties[1].OnSetProperty += new SetPropertyEventHandler(m_RampedPercentageProperty_OnSetProperty); m_FlowHandler.FlowNominalProperty.OnSetRamp += new SetRampEventHandler(m_RampedFlowProperty_OnSetRamp); m_FlowHandler.ComponentProperties[1].OnSetRamp += new SetRampEventHandler(m_RampedPercentageProperty_OnSetRamp); m_FlowHandler.FlowNominalProperty.OnPreflightSetProperty += new SetPropertyEventHandler(m_RampedFlowProperty_OnPreflightSetProperty); m_FlowHandler.ComponentProperties[1].OnPreflightSetProperty += new SetPropertyEventHandler(m_RampedPercentageProperty_OnPreflightSetProperty); m_FlowHandler.FlowNominalProperty.OnPreflightSetRamp += new SetRampEventHandler(m_RampedFlowProperty_OnPreflightSetRamp); m_FlowHandler.ComponentProperties[1].OnPreflightSetRamp += new SetRampEventHandler(m_RampedPercentageProperty_OnPreflightSetRamp); m_MyCmDevice.OnSetTimeTable += new SetTimeTableEventHandler(m_MyCmDevice_OnSetTimeTable); m_MyCmDevice.OnPreflightSetTimeTable += new SetTimeTableEventHandler(m_MyCmDevice_OnPreflightSetTimeTable); // now create the properties and command for valve simulation ITypeInt valvePropType = cmDDK.CreateInt(1, 2); valvePropType.LegalValues = new[] { 1, 2 }; m_ValveState = m_MyCmDevice.CreateProperty("ValveState", "The state of the simulated valve, can be '1' or '2'.", valvePropType); m_ValveState.OnSetProperty += new SetPropertyEventHandler(m_ValveState_OnSetProperty); m_ValveState.OnPreflightSetProperty += new SetPropertyEventHandler(m_ValveState_OnPreflightSetProperty); m_ValveCommandTo1 = m_MyCmDevice.CreateCommand("SwitchValveTo1", "Switch the simulated valve to '1' state."); m_ValveCommandTo1.OnCommand += new CommandEventHandler(m_ValveCommandTo1_OnCommand); m_ValveCommandTo1.OnPreflightCommand += new CommandEventHandler(m_ValveCommandTo1_OnPreflightCommand); m_ValveCommandTo2 = m_MyCmDevice.CreateCommand("SwitchValveTo2", "Switch the simulated valve to '2' state."); m_ValveCommandTo2.OnCommand += new CommandEventHandler(m_ValveCommandTo2_OnCommand); m_ValveCommandTo2.OnPreflightCommand += new CommandEventHandler(m_ValveCommandTo2_OnPreflightCommand); m_ValveCommandWithPar = m_MyCmDevice.CreateCommand("SwitchValve", "Switch the simulated valve according to parameters."); m_ValveStateParameter = m_ValveCommandWithPar.AddParameter("NewState", "The new state of the simulated valve, can be '1' or '2'.", valvePropType); m_ValveStateParameter.Required = true; m_ValveLogParameter = m_ValveCommandWithPar.AddParameter("Message", "A message to be written when executing the command.", m_MyCmDDK.CreateString(64)); m_ValveLogParameter.Required = false; m_ValveCommandWithPar.OnCommand += new CommandEventHandler(m_ValveCommandWithPar_OnCommand); m_ValveCommandWithPar.OnPreflightCommand += new CommandEventHandler(m_ValveCommandWithPar_OnPreflightCommand); return(m_MyCmDevice); }
/// Create our Dionex.Chromeleon.Symbols.IDevice and our Properties internal IDevice Create(IDDK cmDDK, string name) { // Create a device for temperature control m_Device = cmDDK.CreateDevice(name, "Example for a temperature control device"); // Create a type for a temperature logging command ITypeInt tyTempLogParam = cmDDK.CreateInt(0, 2); tyTempLogParam.AddNamedValue("Start", 0); tyTempLogParam.AddNamedValue("Stop", 1); tyTempLogParam.AddNamedValue("Pause", 2); // Create a temperature logging command ICommand logTemperature = m_Device.CreateCommand("LogTemperature", "Switches temperature logging on / off"); // Add a parameter for the tewmperature logging command logTemperature.AddParameter("LogParameter", "Starts, stops or pauses temperature logging", tyTempLogParam); // Create a boolean property to signal if the device is ready for an inject operation. ITypeInt tyReady = cmDDK.CreateInt(0, 1); tyReady.AddNamedValue("False", 0); tyReady.AddNamedValue("True", 1); IProperty readyProp = m_Device.CreateStandardProperty(StandardPropertyID.Ready, tyReady); // Create a data type that represent the activation state of the temperature control. ITypeInt tOnOff = cmDDK.CreateInt((int)TempCtrlState.Off, (int)TempCtrlState.On); tOnOff.AddNamedValue("Off", (int)TempCtrlState.Off); tOnOff.AddNamedValue("On", (int)TempCtrlState.On); // Create a property to activate / deactivate temperature control // This property must be writable m_TempCtrlProperty = m_Device.CreateProperty("TemperatureControl", "Activates /deactivates temperature control", tOnOff); m_TempCtrlProperty.Writeable = true; // Create a struct that holds standard properties for temperature and temperature limits m_TempCtrlStruct = m_Device.CreateStruct("Temperature", "Temperature of Column Oven."); // Create a data type that applies to all temperature properties ITypeDouble tTemperature = cmDDK.CreateDouble(0, 100, 1); tTemperature.Unit = "°C"; // Create a property that holds the current temperature // This property is read-only m_CurrentTempProperty = m_TempCtrlStruct.CreateStandardProperty(StandardPropertyID.Value, tTemperature); // Create a property that holds the nominal temperature // This property must be writeable m_NominalTempProperty = m_TempCtrlStruct.CreateStandardProperty(StandardPropertyID.Nominal, tTemperature); m_NominalTempProperty.Update(30.0); //set default value m_NominalTempProperty.OnSetProperty += new SetPropertyEventHandler(OnSetTemperature); // Create a property that holds the minimal temperature // This property must be writeable m_MinTempProperty = m_TempCtrlStruct.CreateStandardProperty(StandardPropertyID.LowerLimit, tTemperature); m_MinTempProperty.Update(15.0); //set default value m_MinTempProperty.Writeable = true; // Create a property that holds the maximal temperature // This property must be writeable m_MaxTempProperty = m_TempCtrlStruct.CreateStandardProperty(StandardPropertyID.UpperLimit, tTemperature); m_MaxTempProperty.Update(110.0);//set default value m_MaxTempProperty.Writeable = true; // Set the default read and write properties for the struct m_TempCtrlStruct.DefaultSetProperty = m_NominalTempProperty; m_TempCtrlStruct.DefaultGetProperty = m_CurrentTempProperty; // Update property values. They must be readable before the device has been connected. // The device may not be connected when UI-Modules read the default values. m_TempCtrlProperty.Update((int)m_TempCtrl); m_NominalTempProperty.Update(m_NominalTemp); m_MinTempProperty.Update(m_MinTemp); m_MaxTempProperty.Update(m_MaxTemp); m_CurrentTempProperty.Update(m_CurrentTemp); return(m_Device); }
/// <summary> /// Create our Dionex.Chromeleon.Symbols.IDevice and our Properties and Commands /// </summary> /// <param name="cmDDK">The DDK instance</param> /// <param name="name">The name for our device</param> /// <returns>our IDevice object</returns> internal IDevice Create(IDDK cmDDK, string name) { // Create the Dionex.Chromeleon.Symbols.IDevice m_MyCmDevice = cmDDK.CreateDevice(name, "This is an example device."); // create a few example properties // A Data type for seconds ranging from 0 - 59 ITypeInt tSeconds = cmDDK.CreateInt(0, 59); tSeconds.Unit = "s"; // Create the "Clock" property m_ClockProperty = m_MyCmDevice.CreateProperty("Clock", "This is a second counter", tSeconds); // Attach the OnSetClockProperty handler to the "Clock" property m_ClockProperty.OnSetProperty += new SetPropertyEventHandler(OnSetClockProperty); // we will use a timer to update the clock property each second // Attach the OnTimedEvent handler to the timer. m_clockTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); // A Data type with two values 0 and 1 ITypeInt tEnable = cmDDK.CreateInt(0, 1); tEnable.AddNamedValue("false", 0); tEnable.AddNamedValue("true", 1); // Create the "EnableClock" property m_EnableClockProperty = m_MyCmDevice.CreateProperty("EnableClock", "Enable / disable the clock", tEnable); // Attach the OnEnableClock handler to the "EnableClock" property m_EnableClockProperty.OnSetProperty += new SetPropertyEventHandler(OnEnableClock); // A Data type for a percentage ranging from 0.0 - 100.0 ITypeDouble tPercent = cmDDK.CreateDouble(0, 100, 2); tPercent.Unit = "%"; // Create the "Percentage" property m_PercentageProperty = m_MyCmDevice.CreateProperty("Percentage", "This is a percentage property", tPercent); // Attach the OnSetProperty handler to the "Percentage" property m_PercentageProperty.OnSetProperty += new SetPropertyEventHandler(OnSetProperty); // A Data type for a time constant ranging from 1.0 - 10.0 ITypeDouble tTimeConstant = cmDDK.CreateDouble(1.0, 10.0, 1); tTimeConstant.AddNamedValue("Off", 0.0); tTimeConstant.Unit = "s"; // Create the "Percentage" property m_FilterTimeConstantProperty = m_MyCmDevice.CreateProperty("FilterTimeConstant", "This is a numeric property with one special named value.", tTimeConstant); // Attach the OnSetProperty handler to the "FilterTimeConstant" property m_FilterTimeConstantProperty.OnSetProperty += new SetPropertyEventHandler(OnSetProperty); // A Data type for the measurement range property ITypeDouble tMeasurementRange = cmDDK.CreateDouble(0.01, 100.0, 2); tMeasurementRange.LegalValues = new double[] { 0.01, 0.1, 1.0, 10.0, 100.0 }; tMeasurementRange.EnforceLegalValues = true; tMeasurementRange.Unit = "V"; // Create the "Percentage" property m_MeasurementRangeProperty = m_MyCmDevice.CreateProperty("MeasurementRange", "This is a numeric property with 5 legal (valid) values.", tMeasurementRange); // Attach the OnSetProperty handler to the "FilterTimeConstant" property m_MeasurementRangeProperty.OnSetProperty += new SetPropertyEventHandler(OnSetProperty); // A Data type for a string with 20 characters at most ITypeString tString = cmDDK.CreateString(20); // Create the "AnyText" property m_AnyTextProperty = m_MyCmDevice.CreateProperty("AnyText", "This is a string property", tString); // Attach the OnSetProperty handler to the "AnyText" property m_AnyTextProperty.OnSetProperty += new SetPropertyEventHandler(OnSetProperty); // Create the "ToggleEnableClock" example command m_Command = m_MyCmDevice.CreateCommand("ToggleEnableClock", "This is a simple command that toggles the EnableClock property."); // Attach the OnToggleEnableClock handler to the "ToggleEnableClock" command m_Command.OnCommand += new CommandEventHandler(OnToggleEnableClock); // Create the "SetEnableClock" command which uses a parameter. m_SetEnableClockCommand = m_MyCmDevice.CreateCommand("SetEnableClock", "This is a command with one required parameter. Set true or false to enable/disable the clock."); // Add the "Enable" parameter to the "SetEnableClock" command IParameter parameter = m_SetEnableClockCommand.AddParameter("Enable", "Set true or false to enable/disable the clock", tEnable); // This is a required parameter. parameter.Required = true; // Attach the OnSetEnableClock handler to the "SetEnableClock" command m_SetEnableClockCommand.OnCommand += new CommandEventHandler(OnSetEnableClock); // Create the "SetPercentage" command which uses a parameter. m_SetPercentageCommand = m_MyCmDevice.CreateCommand("SetPercentage", "This is a command with one required parameter to set the \"Percentage\" property."); // Add the "Value" parameter to the "SetPercentage" command parameter = m_SetPercentageCommand.AddParameter("Value", "Set to 0.00 - 100.00", tPercent); // This is a required parameter. parameter.Required = true; // Attach the OnSetPercentage handler to the "SetPercentage" command m_SetPercentageCommand.OnCommand += new CommandEventHandler(OnSetPercentage); // Create the "CommandWith4Parameters" command which uses 4 optional parameters. m_CommandWith4Parameters = m_MyCmDevice.CreateCommand("CommandWith4Parameters", "This is a command with four optional parameters."); // Add the parameters to the "CommandWith4Parameters" command m_CommandWith4Parameters.AddParameter("Param1", "Set true or false", tEnable); m_CommandWith4Parameters.AddParameter("Param2", "Set to 0.00 - 100.00", tPercent); m_CommandWith4Parameters.AddParameter("Param3", "Set true or false", tEnable); m_CommandWith4Parameters.AddParameter("Param4", "A string with 20 characters", tString); // Attach the OnCommandWith4Parameters handler to the "CommandWith4Parameters" command m_CommandWith4Parameters.OnCommand += new CommandEventHandler(OnCommandWith4Parameters); return(m_MyCmDevice); }