Example #1
0
        private async void ConfirmCopy_Click(object sender, RoutedEventArgs e)
        {
            // todo: quality: transfer file in chunks with progress bar & cancel option
            ClientFileTextBox.IsEnabled    = false;
            ServerFileTextBox.IsEnabled    = false;
            SendClientFileButton.IsEnabled = false;
            GetServerFileButton.IsEnabled  = false;
            ConfirmTransferFlyout.Hide();
            TranferRing.IsActive = true;
            Stopwatch s = new Stopwatch();

            try
            {
                s.Start();

                if (sending)
                {
                    bool isFile = true;
                    try
                    {
                        await StorageFile.GetFileFromPathAsync(Environment.ExpandEnvironmentVariables(ClientFileTextBox.Text));
                    }
                    catch (Exception)
                    {
                        isFile = false;
                    }

                    if (isFile)
                    {
                        await Client.SendFileToDevice(ClientFileTextBox.Text, ServerFileTextBox.Text, (bool)ContainerCheckBox.IsChecked);
                    }
                    else
                    {
                        await Client.SendDirectoryToDevice(ClientFileTextBox.Text, ServerFileTextBox.Text, (bool)ContainerCheckBox.IsChecked);
                    }
                }
                else
                {
                    try
                    {
                        await Client.GetFileFromDevice(ServerFileTextBox.Text, ClientFileTextBox.Text, (bool)ContainerCheckBox.IsChecked);
                    }
                    catch (FileNotFoundException)
                    {
                        await Client.GetDirectoryFromDevice(ServerFileTextBox.Text, ClientFileTextBox.Text, (bool)ContainerCheckBox.IsChecked);
                    }
                }

                s.Stop();

                ContentDialog errorDialog = new ContentDialog
                {
                    Title           = "Transfer Succeeded!",
                    Content         = $"Transfer completed in {s.Elapsed}",
                    CloseButtonText = "Ok"
                };

                _ = await errorDialog.ShowAsync();
            }
            catch (Exception ex)
            {
                ContentDialog errorDialog = new ContentDialog
                {
                    Title           = "Transfer Error!",
                    Content         = $"{ex.Message}",
                    CloseButtonText = "Ok"
                };

                _ = await errorDialog.ShowAsync();
            }

            ClientFileTextBox.IsEnabled    = true;
            ServerFileTextBox.IsEnabled    = true;
            SendClientFileButton.IsEnabled = true;
            GetServerFileButton.IsEnabled  = true;
            TranferRing.IsActive           = false;
            _ = sending ? SendClientFileButton.Focus(FocusState.Programmatic) : GetServerFileButton.Focus(FocusState.Programmatic);
        }
Example #2
0
 private void CancelCopy_Click(object sender, RoutedEventArgs e)
 {
     ConfirmTransferFlyout.Hide();
 }