private async void BluetoothFileTransfer_Loaded(object sender, RoutedEventArgs e)
        {
            ObexClient.DataTransferFailed     += ObexClient_DataTransferFailed;
            ObexClient.DataTransferProgressed += ObexClient_DataTransferProgressed;
            ObexClient.DataTransferSucceeded  += ObexClient_DataTransferSucceeded;
            ObexClient.ConnectionFailed       += ObexClient_ConnectionFailed;
            ObexClient.Aborted         += ObexClient_Aborted;
            ObexClient.Disconnected    += ObexClient_Disconnected;
            ObexClient.DeviceConnected += ObexClient_DeviceConnected;

            await ObexClient.ConnectAsync();

            if (UseStorageFileRatherThanStream)
            {
                await ObexClient.SendFileAsync(FileToSend);
            }
            else
            {
                StorageFile file = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(FileName, CreationCollisionOption.ReplaceExisting);

                using (Stream stream = await file.OpenStreamForWriteAsync())
                {
                    using (StreamToSend)
                    {
                        await StreamToSend.CopyToAsync(stream);
                    }
                }
                ToDeleteFile = file;

                await ObexClient.SendFileAsync(file);
            }
        }
        private async void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            var Deferral = args.GetDeferral();

            if (SecondaryButtonText == "中止")
            {
                args.Cancel   = true;
                AbortFromHere = true;

                try
                {
                    await ObexClient.AbortAsync();
                }
                catch (Exception) { }
            }
            else if (SecondaryButtonText == "重试")
            {
                args.Cancel       = true;
                ProgressText.Text = "0%";

                ObexClient.DataTransferFailed     -= ObexClient_DataTransferFailed;
                ObexClient.DataTransferProgressed -= ObexClient_DataTransferProgressed;
                ObexClient.DataTransferSucceeded  -= ObexClient_DataTransferSucceeded;
                ObexClient.ConnectionFailed       -= ObexClient_ConnectionFailed;
                ObexClient.Aborted         -= ObexClient_Aborted;
                ObexClient.Disconnected    -= ObexClient_Disconnected;
                ObexClient.DeviceConnected -= ObexClient_DeviceConnected;

                ObexClient = ObexServiceProvider.GetObexNewInstance();

                ObexClient.DataTransferFailed     += ObexClient_DataTransferFailed;
                ObexClient.DataTransferProgressed += ObexClient_DataTransferProgressed;
                ObexClient.DataTransferSucceeded  += ObexClient_DataTransferSucceeded;
                ObexClient.ConnectionFailed       += ObexClient_ConnectionFailed;
                ObexClient.Aborted         += ObexClient_Aborted;
                ObexClient.Disconnected    += ObexClient_Disconnected;
                ObexClient.DeviceConnected += ObexClient_DeviceConnected;

                try
                {
                    ProgressControl.Value = 0;
                    CloseButtonText       = "";
                    SecondaryButtonText   = "中止";
                    await ObexClient.ConnectAsync();

                    await ObexClient.SendFileAsync(ToDeleteFile);
                }
                catch (Exception)
                {
                    ProgressText.Text = "尝试重新连接失败";
                }
            }

            Deferral.Complete();
        }
Exemple #3
0
        private async void BluetoothFileTransfer_Loaded(object sender, RoutedEventArgs e)
        {
            ObexClient.DataTransferFailed     += ObexClient_DataTransferFailed;
            ObexClient.DataTransferProgressed += ObexClient_DataTransferProgressed;
            ObexClient.DataTransferSucceeded  += ObexClient_DataTransferSucceeded;
            ObexClient.ConnectionFailed       += ObexClient_ConnectionFailed;
            ObexClient.Aborted         += ObexClient_Aborted;
            ObexClient.Disconnected    += ObexClient_Disconnected;
            ObexClient.DeviceConnected += ObexClient_DeviceConnected;

            await ObexClient.ConnectAsync().ConfigureAwait(false);

            await ObexClient.SendFileAsync(FileToSend).ConfigureAwait(false);
        }
Exemple #4
0
 public async void StartService(BluetoothDevice BTDevice)
 {
     BtDevice                            = BTDevice;
     obexService                         = ObexService.GetDefaultForBluetoothDevice(BtDevice);
     obexService.Aborted                += obexService_Aborted;
     obexService.ConnectionFailed       += obexService_ConnectionFailed;
     obexService.DataTransferFailed     += obexService_DataTransferFailed;
     obexService.DataTransferProgressed += obexService_DataTransferProgressed;
     obexService.DataTransferSucceeded  += obexService_DataTransferSucceeded;
     obexService.DeviceConnected        += obexService_DeviceConnected;
     obexService.Disconnected           += obexService_Disconnected;
     obexService.Disconnecting          += obexService_Disconnecting;
     obexService.ServiceConnected       += obexService_ServiceConnected;
     await obexService.ConnectAsync();
 }
Exemple #5
0
        async void obexService_Disconnected(object sender, EventArgs e)
        {
            obexService.Aborted                -= obexService_Aborted;
            obexService.ConnectionFailed       -= obexService_ConnectionFailed;
            obexService.DataTransferFailed     -= obexService_DataTransferFailed;
            obexService.DataTransferProgressed -= obexService_DataTransferProgressed;
            obexService.DataTransferSucceeded  -= obexService_DataTransferSucceeded;
            obexService.DeviceConnected        -= obexService_DeviceConnected;
            obexService.Disconnected           -= obexService_Disconnected;
            obexService.Disconnecting          -= obexService_Disconnecting;
            obexService.ServiceConnected       -= obexService_ServiceConnected;
            obexService = null;

            if (filesToShare.Count.Equals(0))
            {
                OnTransferCompleted(AppConstants.FilesSharedOK);
            }
            else if (this.filesToShare[0].ShareStatus.Equals(FileShareStatus.Error) || this.filesToShare[0].ShareStatus.Equals(FileShareStatus.Cancelled))
            {
                OnTransferCompleted(AppConstants.FilesSharedError);
            }
            else
            {
                obexService = ObexService.GetDefaultForBluetoothDevice(BtDevice);
                obexService.DeviceConnected        += obexService_DeviceConnected;
                obexService.ServiceConnected       += obexService_ServiceConnected;
                obexService.ConnectionFailed       += obexService_ConnectionFailed;
                obexService.DataTransferProgressed += obexService_DataTransferProgressed;
                obexService.DataTransferSucceeded  += obexService_DataTransferSucceeded;
                obexService.DataTransferFailed     += obexService_DataTransferFailed;
                obexService.Disconnecting          += obexService_Disconnecting;
                obexService.Disconnected           += obexService_Disconnected;
                obexService.Aborted += obexService_Aborted;
                await obexService.ConnectAsync();
            }
        }
Exemple #6
0
        private async void QueueContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            var Deferral = args.GetDeferral();

            try
            {
                if (SecondaryButtonText == Globalization.GetString("Bluetooth_Transfer_RetryButton"))
                {
                    args.Cancel = true;
                    ProgressControl.IsIndeterminate = true;
                    ProgressText.Text = "0%";

                    ObexClient.DataTransferFailed     -= ObexClient_DataTransferFailed;
                    ObexClient.DataTransferProgressed -= ObexClient_DataTransferProgressed;
                    ObexClient.DataTransferSucceeded  -= ObexClient_DataTransferSucceeded;
                    ObexClient.ConnectionFailed       -= ObexClient_ConnectionFailed;
                    ObexClient.Aborted         -= ObexClient_Aborted;
                    ObexClient.Disconnected    -= ObexClient_Disconnected;
                    ObexClient.DeviceConnected -= ObexClient_DeviceConnected;

                    ObexClient = ObexServiceProvider.GetObexInstance();

                    ObexClient.DataTransferFailed     += ObexClient_DataTransferFailed;
                    ObexClient.DataTransferProgressed += ObexClient_DataTransferProgressed;
                    ObexClient.DataTransferSucceeded  += ObexClient_DataTransferSucceeded;
                    ObexClient.ConnectionFailed       += ObexClient_ConnectionFailed;
                    ObexClient.Aborted         += ObexClient_Aborted;
                    ObexClient.Disconnected    += ObexClient_Disconnected;
                    ObexClient.DeviceConnected += ObexClient_DeviceConnected;

                    try
                    {
                        ProgressControl.Value = 0;
                        CloseButtonText       = string.Empty;
                        SecondaryButtonText   = Globalization.GetString("BluetoothTranfer.SecondaryButtonText");
                        await ObexClient.ConnectAsync().ConfigureAwait(true);

                        await ObexClient.SendFileAsync(FileToSend).ConfigureAwait(true);
                    }
                    catch (Exception)
                    {
                        ProgressText.Text = Globalization.GetString("Bluetooth_Transfer_Description_6");
                    }
                }
                else
                {
                    args.Cancel   = true;
                    AbortFromHere = true;

                    try
                    {
                        await ObexClient.AbortAsync().ConfigureAwait(true);
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            finally
            {
                Deferral.Complete();
            }
        }