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
 async void obexService_DeviceConnected(object sender, EventArgs e)
 {
     if (this.filesToShare.Count > 0)
     {
         //filesToShare[0].ShareStatus = FileShareStatus.Connecting;
         OnChangeStatus(FileShareStatus.Connecting);
         await obexService.SendFileAsync(filesToShare[0].FileToShare);
     }
     else
     {
         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;
     }
 }
Exemple #5
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();
            }
        }