예제 #1
0
 private void OnDeviceRemoved(object sender, InkDeviceInfo info)
 {
     var ignore = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         RemoveDevice(info);
     });
 }
 private void OnDeviceRemoved(object sender, InkDeviceInfo info)
 {
     //var ignore = Task.Run( () =>
     //{
     RemoveDevice(info);
     //});
 }
예제 #3
0
 private void OnDeviceAdded(object sender, InkDeviceInfo info)
 {
     var ignore = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         m_deviceInfos.Add(info);
     });
 }
 private void OnDeviceAdded(object sender, InkDeviceInfo info)
 {
     //var ignore = Task.Run( () =>
     //{
     m_deviceInfos.Add(info);
     //});
 }
        private async void OnButtonConnectClick(object sender, RoutedEventArgs e)
        {
            int index = listView.SelectedIndex;

            if ((index < 0) || (index >= m_deviceInfos.Count))
            {
                return;
            }

            IDigitalInkDevice device = null;

            m_connectingDeviceInfo = m_deviceInfos[index];

            btnConnect.IsEnabled = false;

            StopScanning();

            try
            {
                device = await InkDeviceFactory.Instance.CreateDeviceAsync(m_connectingDeviceInfo, AppObjects.Instance.AppId, true, false, OnDeviceStatusChanged);
            }
            catch (Exception ex)
            {
                StringBuilder sb     = new StringBuilder($"Device creation failed:\n{ex.Message}");
                string        indent = "  ";
                for (Exception inner = ex.InnerException; inner != null; inner = inner.InnerException)
                {
                    sb.Append($"\n{indent}{inner.Message}");
                    indent = indent + "  ";
                }

                MessageBox.Show(sb.ToString());
            }

            if (device == null)
            {
                m_connectingDeviceInfo = null;
                btnConnect.IsEnabled   = true;
                StartScanning();
                return;
            }

            AppObjects.Instance.DeviceInfo = m_connectingDeviceInfo;
            AppObjects.Instance.Device     = device;
            m_connectingDeviceInfo         = null;

            await AppObjects.SerializeDeviceInfoAsync(AppObjects.Instance.DeviceInfo);

            if (NavigationService.CanGoBack)
            {
                NavigationService.GoBack();
            }
        }
 public static async Task SerializeDeviceInfoAsync(InkDeviceInfo deviceInfo)
 {
     try
     {
         using (FileStream fs = File.Create(Path.Combine(Application.LocalUserAppDataPath, SaveFileName)))
         {
             await Task.Run(new Action(() => deviceInfo.ToStream(fs)));
         }
     }
     catch (Exception)
     {
     }
 }
        private async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            buttonScan.IsEnabled         = false;
            buttonFileTransfer.IsEnabled = false;
            buttonRealTime.IsEnabled     = false;

            if (AppObjects.Instance.DeviceInfo == null)
            {
                AppObjects.Instance.DeviceInfo = await AppObjects.DeserializeDeviceInfoAsync();
            }

            if (AppObjects.Instance.DeviceInfo == null)
            {
                textBlockDeviceName.Text = "Not connected to a device, click the \"Scan for Devices\" button and follow the instructions.";
                buttonScan.IsEnabled     = true;
                return;
            }

            InkDeviceInfo inkDeviceInfo = AppObjects.Instance.DeviceInfo;

            textBlockDeviceName.Text = $"Reconnecting to device {inkDeviceInfo.DeviceName} ({inkDeviceInfo.TransportProtocol}) ...";

            try
            {
                if (AppObjects.Instance.Device == null)
                {
                    AppObjects.Instance.Device = await InkDeviceFactory.Instance.CreateDeviceAsync(inkDeviceInfo, AppObjects.Instance.AppId, false, false, OnDeviceStatusChanged);
                }

                AppObjects.Instance.Device.Disconnected              += OnDeviceDisconnected;
                AppObjects.Instance.Device.DeviceStatusChanged       += OnDeviceStatusChanged;
                AppObjects.Instance.Device.PairingModeEnabledCallback = OnPairingModeEnabledAsync;
            }
            catch (Exception ex)
            {
                textBlockDeviceName.Text = $"Cannot init device: {inkDeviceInfo.DeviceName} [{ex.Message}]";
                buttonScan.IsEnabled     = true;
                return;
            }

            textBlockDeviceName.Text     = $"Current device: {inkDeviceInfo.DeviceName}";
            buttonFileTransfer.IsEnabled = true;
            buttonRealTime.IsEnabled     = true;
            buttonScan.IsEnabled         = true;

            textBlockStatus.Text = AppObjects.GetStringForDeviceStatus(AppObjects.Instance.Device.DeviceStatus);

            await DisplayDevicePropertiesAsync();
        }
        public static async Task SerializeDeviceInfoAsync(InkDeviceInfo deviceInfo)
        {
            try
            {
                StorageFile storageFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(SaveFileName, CreationCollisionOption.ReplaceExisting);

                using (Stream stream = await storageFile.OpenStreamForWriteAsync())
                {
                    deviceInfo.ToStream(stream);
                }
            }
            catch (Exception)
            {
            }
        }
        public static async Task <InkDeviceInfo> DeserializeDeviceInfoAsync()
        {
            try
            {
                using (FileStream fs = File.OpenRead(Path.Combine(Application.LocalUserAppDataPath, SaveFileName)))
                {
                    return(await InkDeviceInfo.FromStreamAsync(fs));
                }
            }
            catch (Exception)
            {
            }

            return(null);
        }
        public static async Task <InkDeviceInfo> DeserializeDeviceInfoAsync()
        {
            try
            {
                StorageFile storageFile = await ApplicationData.Current.LocalFolder.GetFileAsync(SaveFileName);

                using (Stream stream = await storageFile.OpenStreamForReadAsync())
                {
                    return(await InkDeviceInfo.FromStreamAsync(stream));
                }
            }
            catch (Exception)
            {
            }

            return(null);
        }
예제 #11
0
        private void RemoveDevice(InkDeviceInfo info)
        {
            int index = -1;

            for (int i = 0; i < m_deviceInfos.Count; i++)
            {
                if (ReferenceEquals(m_deviceInfos[i], info))
                {
                    index = i;
                    break;
                }
            }

            if (index != -1)
            {
                m_deviceInfos.RemoveAt(index);
            }
        }
        private void RemoveDevice(InkDeviceInfo info)
        {
            int index = -1;

            for (int i = 0; i < m_deviceInfos.Count; i++)
            {
                if (m_deviceInfos[i].DeviceId == info.DeviceId)
                {
                    index = i;
                    break;
                }
            }

            if (index != -1)
            {
                m_deviceInfos.RemoveAt(index);
            }
        }
예제 #13
0
        private async void OnButtonConnectClick(object sender, RoutedEventArgs e)
        {
            int index = listView.SelectedIndex;

            if ((index < 0) || (index >= m_deviceInfos.Count))
            {
                return;
            }

            IDigitalInkDevice device = null;

            m_connectingDeviceInfo = m_deviceInfos[index];

            btnConnect.IsEnabled = false;

            StopScanning();

            SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;

            if (m_connectingDeviceInfo != null)
            {
                string msg = $"Initializing connection with device: \"{m_connectingDeviceInfo.DeviceName}\"";

                switch (m_connectingDeviceInfo.TransportProtocol)
                {
                case TransportProtocol.BLE:
                    tbBle.Text = msg;
                    break;

                case TransportProtocol.USB:
                    tbUsb.Text = msg;
                    break;

                case TransportProtocol.BTC:
                    tbBtc.Text = msg;
                    break;
                }
            }

            try
            {
                device = await InkDeviceFactory.Instance.CreateDeviceAsync(m_connectingDeviceInfo, AppObjects.Instance.AppId, true, false, OnDeviceStatusChanged);
            }
            catch (Exception ex)
            {
                string message = $"Device creation failed: {ex.Message}";

                await new MessageDialog(message).ShowAsync();
            }

            if (device == null)
            {
                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
                m_connectingDeviceInfo = null;
                btnConnect.IsEnabled   = true;
                StartScanning();
                return;
            }

            AppObjects.Instance.DeviceInfo = m_connectingDeviceInfo;
            AppObjects.Instance.Device     = device;
            m_connectingDeviceInfo         = null;

            await AppObjects.SerializeDeviceInfoAsync(AppObjects.Instance.DeviceInfo);

            if (Frame.CanGoBack)
            {
                Frame.GoBack();
            }
        }