예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RequestLog"/> class.
        /// </summary>
        /// <param name="aLogLevel">Log level the server should sent</param>
        /// <param name="aId">Message ID</param>
        public RequestLog(string aLogLevel, uint aId = ButtplugConsts.DefaultMsgId)
            : base(aId)
        {
            if (!Enum.TryParse(aLogLevel, out ButtplugLogLevel level))
            {
                throw new ArgumentException("Invalid log level");
            }

            LogLevel = level;
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RequestLog"/> class.
        /// </summary>
        /// <param name="aLogLevel">Log level the server should sent</param>
        /// <param name="aId">Message ID</param>
        public RequestLog(string aLogLevel, uint aId = ButtplugConsts.DefaultMsgId)
            : base(aId)
        {
            try
            {
                var level = (ButtplugLogLevel)Enum.Parse(typeof(ButtplugLogLevel), aLogLevel, true);
                if (!Enum.IsDefined(typeof(ButtplugLogLevel), level))
                {
                    throw new ArgumentException("Invalid log level");
                }

                LogLevel = level;
            }
            catch (Exception)
            {
                throw new ArgumentException("Invalid log level");
            }
        }
        public static void SetLogOptions(ButtplugLogLevel aMaxLevel, bool aUseJSON)
        {
            if (aMaxLevel != ButtplugLogLevel.Off)
            {
                if (_logHandleSet)
                {
                    throw new InvalidOperationException("Cannot set logging options twice (this is a bug, will be fixed at some point, see https://github.com/buttplugio/b******g-rs-ffi/issues/23).");
                }

                _logHandle    = ButtplugFFILogCalls.ButtplugCreateLogHandle(_logCallback, IntPtr.Zero, aMaxLevel.ToString(), aUseJSON);
                _logHandleSet = true;
            }
            else
            {
                if (_logHandle != null)
                {
                    _logHandle.Dispose();
                    _logHandle = null;
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ButtplugLogMessageEventArgs"/> class.
 /// </summary>
 /// <param name="aLogLevel">Log level</param>
 /// <param name="aMessage">Log message</param>
 public ButtplugLogMessageEventArgs(ButtplugLogLevel aLogLevel, string aMessage)
 {
     LogMessage = new Log(aLogLevel, aMessage);
 }
예제 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Log"/> class.
 /// </summary>
 /// <param name="aLogLevel">Log level</param>
 /// <param name="aLogMessage">Log message</param>
 public Log(ButtplugLogLevel aLogLevel, string aLogMessage)
     : base(ButtplugConsts.SystemMsgId)
 {
     LogLevel   = aLogLevel;
     LogMessage = aLogMessage;
 }
예제 #6
0
 /// <summary>
 /// Instructs the server to either forward or stop log entries to the client. Log entries
 /// will be raised as <see cref="Log"/> events.
 /// </summary>
 /// <param name="aLogLevel">The maximum log level to send.</param>
 /// <param name="aToken">Cancellation token, for cancelling action externally if it is not yet finished.</param>
 /// <returns>
 /// Void on success, throws <see cref="ButtplugClientException" /> otherwise.
 /// </returns>
 // ReSharper disable once UnusedMember.Global
 public async Task RequestLogAsync(ButtplugLogLevel aLogLevel, CancellationToken aToken = default(CancellationToken))
 {
     await SendMessageExpectOk(new RequestLog(aLogLevel), aToken).ConfigureAwait(false);
 }
예제 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Log"/> class.
 /// </summary>
 /// <param name="aLogLevel">Log level.</param>
 /// <param name="aLogMessage">Log message.</param>
 public Log(ButtplugLogLevel aLogLevel, string aLogMessage)
     : base(ButtplugConsts.SystemMsgId) => (LogLevel, LogMessage) = (aLogLevel, aLogMessage);
예제 #8
0
 /// <inheritdoc />
 public RequestLog(ButtplugLogLevel aLogLevel = ButtplugLogLevel.Off, uint aId = ButtplugConsts.DefaultMsgId)
     : base(aId) => LogLevel = aLogLevel;
예제 #9
0
 public static void StartLogHandler(ButtplugLogLevel aMaxLevel, bool aUseJSON)
 {
     Console.WriteLine(aMaxLevel.ToString());
     ButtplugFFILogCalls.buttplug_add_log_handler(LogCallback, aMaxLevel.ToString(), aUseJSON);
 }