public FormsApp(IBluetoothLowEnergyAdapter adapter, IUserDialogs dialogs)
        {
            InitializeComponent();

            m_dialogs = dialogs;
            var logsVm = new LogsViewModel();

            SystemLog.Instance.AddSink(logsVm);

            var bleAssembly = adapter.GetType().GetTypeInfo().Assembly.GetName();

            Log.Info(bleAssembly.Name + "@" + bleAssembly.Version);


            var bleScanViewModel = new BleDeviceScannerViewModel(
                bleAdapter: adapter,
                dialogs: dialogs);

            m_rootPage = new NavigationPage(
                new TabbedPage
            {
                Title    = "BLE.net Sample App",
                Children = { new BleDeviceScannerPage(bleScanViewModel), new LogsPage(logsVm) }
            });

            MainPage = m_rootPage;
        }
Beispiel #2
0
        public FormsApp(IBluetoothLowEnergyAdapter adapter, IUserDialogs dialogs)
        {
            InitializeComponent();

            m_dialogs = dialogs;
            var logsVm = new LogsViewModel();

            SystemLog.Instance.AddSink(logsVm);

            var bleAssembly = adapter.GetType().GetTypeInfo().Assembly.GetName();

            Log.Info(bleAssembly.Name + "@" + bleAssembly.Version);

            var bleGattServerViewModel = new BleGattServerViewModel(dialogs, adapter);
            var bleScanViewModel       = new BleDeviceScannerViewModel(
                bleAdapter: adapter,
                dialogs: dialogs,
                onSelectDevice: async p =>
            {
                //更新 Server 中的设备信息
                await bleGattServerViewModel.Update(p);
                // 点击了 连接 后,跳转到 设备的 Server 的页面.
                await m_rootPage.PushAsync(
                    new BleGattServerPage(
                        model: bleGattServerViewModel,
                        //点击了 ListView 中的 Service 后,跳转到 Service 页.
                        bleServiceSelected: async s => { await m_rootPage.PushAsync(new BleGattServicePage(s)); }));

                //连接设备
                await bleGattServerViewModel.OpenConnection();
            });

            m_rootPage = new NavigationPage(
                new TabbedPage
            {
                Title = "BLE.net Sample App",
                // Tab 中的 Scan View 和 Log View.
                Children = { new BleDeviceScannerPage(bleScanViewModel), new LogsPage(logsVm) }
            });

            MainPage = m_rootPage;
        }