Example #1
0
        public async Task StartUpload()
        {
            try
            {
                NotifyUploadStatus(FileUploadCommand, FileTransferCompletionStatus.Started);
                DateTime startTime         = DateTime.Now;
                int      numberOfFileParts = FileTransferHelper.GetNumberOfFileParts(FilePath, Program.FilePartSize);
                progress.Maximum = numberOfFileParts;

                int partIndex = 0;
                while (partIndex < numberOfFileParts)
                {
                    var data = FileTransferHelper.GetFilePartData(FilePath, partIndex, Program.FilePartSize);
                    await _communications.UploadFilePart(FileUploadCommand, data, partIndex);

                    partIndex++;
                    progress.Value++;
                }

                _logger.LogInformation(string.Format("File '{0}' uploaded successfully. Duration : {1}", FilePath, DateTime.Now.Subtract(startTime)));
                ShowFinishedStatus("Upload Completed", true);
                NotifyUploadStatus(FileUploadCommand, FileTransferCompletionStatus.Successful);
                return;
            }
            catch (Exception ex)
            {
                _logger.LogInformation(string.Format("An error occurred uploading file '{0}' (Id : {1}). Error : {2}", FilePath, FileUploadCommand.FileId, ex.Message));
                ShowFinishedStatus("Upload failed. " + ex.Message, false);
            }
            NotifyUploadStatus(FileUploadCommand, FileTransferCompletionStatus.Error);
        }
Example #2
0
        private async void cmdSendFile_Click(object sender, EventArgs e)
        {
            try
            {
                if (comboUser.SelectedItem == null)
                {
                    MessageBox.Show("A User must be selected", "Information Required", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (txtSendFilePath.Text == "")
                {
                    MessageBox.Show("A file must be specified", "Information Required", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (!File.Exists(txtSendFilePath.Text))
                {
                    MessageBox.Show("The specified File is invalid", "Information Required", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                FileInfo fileInfo = new FileInfo(txtSendFilePath.Text);

                FileOfferModel fileOffer = new FileOfferModel()
                {
                    OfferedToUserName = comboUser.SelectedItem.ToString(),
                    Description       = txtSendFileDescription.Text,
                    FileName          = Path.GetFileName(txtSendFilePath.Text),
                    Size = fileInfo.Length,
                    NumberOfFileParts = FileTransferHelper.GetNumberOfFileParts(txtSendFilePath.Text, Program.FilePartSize),
                    Hash = FileTransferHelper.GetSHA1Hash(txtSendFilePath.Text)
                };
                Guid fileId = await _communications.SendFileTransferOffer(fileOffer);

                _filePaths.Add(fileId, txtSendFilePath.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occurred sending file. " + ex.Message);
            }
        }