Example #1
0
 /// <summary>
 /// Execute the command on the device.
 /// </summary>
 /// <exception cref="ArgumentNullException">Config is null. -or- ParameterSet is null.</exception>
 /// <exception cref="ArgumentException">Config is invalid. -or- ParameterSet is invalid.</exception>
 /// <exception cref="NetOpnApiHttpException">An HTTP error is raised or an invalid HTTP status code is returned.</exception>
 /// <exception cref="NetOpnApiNotAuthorizedException">The configured API key does not have sufficient access.</exception>
 /// <exception cref="NetOpnApiNotImplementedException">The command is not implemented on the device.</exception>
 /// <exception cref="NetOpnApiInvalidResponseException">The command returns an invalid response.</exception>
 public static void Execute <TResponse, TParameterSet>(this ICommandWithResponseAndParameterSet <TResponse, TParameterSet> self)
     where TParameterSet : IParameterSet
 => ExecuteCommand(
     self,
     self.CreateRequest,
     self.SetEmptyResponse,
     self.SetResponse
     );
Example #2
0
        /// <summary>
        /// Try to executed the command.
        /// </summary>
        /// <param name="self"></param>
        /// <param name="errorCode">Returns the error code if command execution fails.</param>
        /// <returns></returns>
        public static bool TryExecute <TResponse, TParameterSet>(this ICommandWithResponseAndParameterSet <TResponse, TParameterSet> self, out ErrorCode errorCode)
            where TParameterSet : IParameterSet
        {
            errorCode = ErrorCode.NoError;

            try
            {
                self.Execute();
                return(true);
            }
            catch (NetOpnApiException e)
            {
                errorCode = e.Code;
                return(false);
            }
        }