Ejemplo n.º 1
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.Info, _logTarget);
                c.LoggingRules.Add(_outgoingLoggingRule);
                LogManager.Configuration = c;
            }

            //LogLevelComboBox.SelectionChanged += LogLevelSelectionChangedHandler;
            LogListBox.ItemsSource = _logs;

            ButtplugFFILog.SetLogOptions(ButtplugLogLevel.Info, false);
            B******g.ButtplugFFILog.LogMessage += (obj, msg) => _logs.Add(msg.Trim());
        }
Ejemplo n.º 2
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);
        }