Пример #1
0
        private static async Task LogExample()
        {
            // Set up our log handler to print logs to stdout
            ButtplugFFILog.LogMessage += (obj, msg) =>
            {
                Console.WriteLine(msg);
            };
            // Report everything at level Debug and higher, and since we're reporting to the
            // console, don't use JSON output. (JSON output is handy for log parsing later if
            // you need it.)
            ButtplugFFILog.StartLogHandler(ButtplugLogLevel.Debug, false);

            // If you want to change log levels without recompiling, you can use the Env Logger.
            // Just make sure you don't try to use StartLogHandler and ActivateEnvLogger in the
            // same session, they will conflict with each other and throw errors.
            //
            // To set the env logger filter level, you'll need to set the RUST_LOG environment
            // variable. i.e. in powershell: $env:RUST_LOG="debug"
            //
            // Comment the code above this and uncomment this if you want to try the env logger.
            //
            // ButtplugFFILog.ActivateEnvLogger();

            // Completing our embedded connection should cause log messages to print.
            var connector = new ButtplugEmbeddedConnectorOptions();
            var client    = new ButtplugClient("Example Client");
            await client.ConnectAsync(connector);
        }
Пример #2
0
        public LogControl()
        {
            var c = LogManager.Configuration ?? new LoggingConfiguration();

            _logs = new LogList();

            InitializeComponent();

            // Null check Dispatcher, otherwise test bringup for GUI tests will fail.
            if (Dispatcher != null)
            {
                _logTarget = new IntifaceNLogTarget(_logs);
                c.AddTarget("IntifaceLogger", _logTarget);
                _outgoingLoggingRule = new LoggingRule("*", LogLevel.Debug, _logTarget);
                c.LoggingRules.Add(_outgoingLoggingRule);
                LogManager.Configuration = c;
            }

            //LogLevelComboBox.SelectionChanged += LogLevelSelectionChangedHandler;
            LogListBox.ItemsSource = _logs;
            ButtplugFFILog.StartLogHandler(ButtplugLogLevel.Info, false);
            B******g.ButtplugFFILog.LogMessage += (obj, msg) => _logs.Add(msg.Trim());
        }
Пример #3
0
        private static async Task RunExample()
        {
            ButtplugFFILog.LogMessage += (aObj, aMsg) => { Console.WriteLine($"LOG: {aMsg}"); };
            ButtplugFFILog.SetLogOptions(ButtplugLogLevel.Info, true);
            var client = new ButtplugClient("Test Client");

            client.DeviceAdded += (obj, args) =>
            {
                var device = args.Device;
                Console.WriteLine($"Device Added: {device.Name}");
                foreach (var msg in args.Device.AllowedMessages)
                {
                    Console.WriteLine($"{msg.Key} {msg.Value}");
                    foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(msg.Value))
                    {
                        string name  = descriptor.Name;
                        object value = descriptor.GetValue(obj);
                        Console.WriteLine("{0}={1}", name, value);
                    }
                }
                //await device.SendVibrateCmd(1.0);
            };
            client.DeviceRemoved += (obj, args) =>
            {
                Console.WriteLine($"Device removed: {args.Device.Name}");
            };
            client.ScanningFinished += (obj, args) =>
            {
                Console.WriteLine("Scanning finished.");
            };
            client.ServerDisconnect += (obj, args) =>
            {
                Console.WriteLine("Server disconnected.");
            };
            var options = new B******g.ButtplugEmbeddedConnectorOptions();
            //options.AllowRawMessages = true;
            await client.ConnectAsync(options).ConfigureAwait(false);

            /*
             * await client.ConnectAsync(new B******g.ButtplugWebsocketConnectorOptions(new Uri("ws://localhost:12345")));
             * await client.StartScanningAsync();
             * await WaitForKey();
             * Console.WriteLine("Disconnecting");
             * await client.DisconnectAsync();
             * await WaitForKey();
             * await client.ConnectAsync(new B******g.ButtplugWebsocketConnectorOptions(new Uri("ws://localhost:12345")));
             * await client.StartScanningAsync();
             * await WaitForKey();
             * Console.WriteLine("Disconnecting");
             * await client.DisconnectAsync();
             * await WaitForKey();
             * await client.ConnectAsync(new B******g.ButtplugWebsocketConnectorOptions(new Uri("ws://localhost:12345")));
             */
            await client.StartScanningAsync().ConfigureAwait(false);

            Console.WriteLine($"Is Scanning: {client.IsScanning}");
            await WaitForKey().ConfigureAwait(false);

//            ButtplugFFILog.SetLogOptions(ButtplugLogLevel.Debug, true);
            await client.StopScanningAsync().ConfigureAwait(false);

            /*
             * while (true) {
             *  foreach (var device in client.Devices) {
             *      if (device.AllowedMessages.ContainsKey(ServerMessage.Types.MessageAttributeType.BatteryLevelCmd))
             *      {
             *          Console.WriteLine("Fetching Battery");
             *          Console.WriteLine($"Battery: {await device.SendBatteryLevelCmd()}");
             *          //await device.SendRawWriteCmd(Endpoint.Tx, Encoding.ASCII.GetBytes("Vibrate:10;"), false);
             *          //await device.SendVibrateCmd(0.5);
             *          await Task.Delay(500);
             *          //await device.SendStopDeviceCmd();
             *          //await device.SendRawWriteCmd(Endpoint.Tx, System.Text.Encoding.ASCII.GetBytes("Air:Level:3;"), false);
             *      }
             *  }
             * }
             */
            await WaitForKey().ConfigureAwait(false);

            Console.WriteLine("killing log?");
            ButtplugFFILog.SetLogOptions(ButtplugLogLevel.Off, true);
            await WaitForKey().ConfigureAwait(false);

            client.Dispose();
            client = null;
            await WaitForKey().ConfigureAwait(false);
        }
Пример #4
0
        private static async Task RunExample()
        {
            //ButtplugFFILog.SetLogCallback(LogCallback, ButtplugLogLevel.Info);
            //ButtplugFFILog.SetLogLevel(ButtplugLogLevel.Error);
            ButtplugFFILog.StartLogHandler(ButtplugLogLevel.Info, true);
            ButtplugFFILog.LogMessage += (aObj, aMsg) => { Console.WriteLine($"LOG: {aMsg}"); };
            var client = new ButtplugClient("Test Client");

            client.DeviceAdded += async(obj, args) =>
            {
                var device = args.Device;
                foreach (var msg in args.Device.AllowedMessages)
                {
                    Console.WriteLine($"{msg.Key} {msg.Value}");
                    foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(msg.Value))
                    {
                        string name  = descriptor.Name;
                        object value = descriptor.GetValue(obj);
                        Console.WriteLine("{0}={1}", name, value);
                    }
                }
                if (device.AllowedMessages.ContainsKey(ServerMessage.Types.MessageAttributeType.BatteryLevelCmd))
                {
                    Console.WriteLine("Fetching Battery");
                    Console.WriteLine($"Battery: {await device.SendBatteryLevelCmd()}");
                    //await device.SendRawWriteCmd(Endpoint.Tx, Encoding.ASCII.GetBytes("Vibrate:10;"), false);
                    await device.SendVibrateCmd(0.5);

                    await Task.Delay(500);

                    await device.SendStopDeviceCmd();
                }
            };
            client.DeviceRemoved += (obj, args) =>
            {
                Console.WriteLine($"Device removed: {args.Device.Name}");
            };
            client.ScanningFinished += (obj, args) =>
            {
                Console.WriteLine("Scanning finished.");
            };
            client.ServerDisconnect += (obj, args) =>
            {
                Console.WriteLine("Server disconnected.");
            };
            await client.ConnectAsync(new B******g.ButtplugEmbeddedConnectorOptions());

            //await client.ConnectAsync(new B******g.ButtplugWebsocketConnectorOptions(new Uri("ws://localhost:12345")));
            await client.StartScanningAsync();

            await WaitForKey();

            Console.WriteLine("Disconnecting");
            await client.DisconnectAsync();

            await WaitForKey();

            client.Dispose();
            client = null;
            await WaitForKey();
        }