public MainPage() { this.InitializeComponent(); if (account == null) { account = MessageAccount.Get(Guid.Parse("0CCC09A6-BB68-4155-9844-B690222E3E79")); // テスト用アカウント } list.ItemsSource = account.Threads; if (transfer is null) { transfer = new MessageTransfer(account); } var toastContent = new ToastContent() { Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = "スレッド名" }, new AdaptiveText() { Text = "メッセージの本文" } } } } }; }
private async void Init(MessageAccount account) { foreach (var msg in account.GetMessages()) { queue.Add(msg.Binary); } var result = await GattServiceProvider.CreateAsync(ServiceId); if (result.Error == BluetoothError.Success) { var serviceProvider = result.ServiceProvider; var prm = new GattLocalCharacteristicParameters() { CharacteristicProperties = GattCharacteristicProperties.WriteWithoutResponse, UserDescription = "DMsg" }; var characteristicResult = await serviceProvider.Service.CreateCharacteristicAsync(cServiceId, prm); if (characteristicResult.Error != BluetoothError.Success) { // An error occurred. return; } var _readCharacteristic = characteristicResult.Characteristic; _readCharacteristic.WriteRequested += OnWriteMessage; var advParameters = new GattServiceProviderAdvertisingParameters { IsDiscoverable = true, //IsConnectable = true }; serviceProvider.StartAdvertising(advParameters); } string[] requestedProperties = { "System.Devices.Aep.DeviceAddress", "System.Devices.Aep.IsConnected" }; var deviceWatcher = DeviceInformation.CreateWatcher(BluetoothLEDevice.GetDeviceSelectorFromPairingState(false), requestedProperties, DeviceInformationKind.AssociationEndpoint); deviceWatcher.Added += OnAddDevice; deviceWatcher.Start(); var udp = new UdpClient(AddressFamily.InterNetworkV6); udp.EnableBroadcast = true; udp.Client.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, 0); udp.Client.Bind(new IPEndPoint(IPAddress.IPv6Any, 24680)); MessageBroadcast(udp); while (true) { var ures = await udp.ReceiveAsync(); try { account.AddMessage(ures.Buffer); } catch (Exception) { } } }
public MessageTransfer(MessageAccount account) { Init(account); Instance = this; }