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();
        }
Beispiel #2
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();
            }
        }