Ejemplo n.º 1
0
        private async void FileSendRequestReceivedHandler(object sender,
                                                          ToxEventArgs.FileSendRequestEventArgs e)
        {
            if (e.FileKind != ToxFileKind.Data || e.FriendNumber != _friendNumber)
            {
                return;
            }

            var fileId     = _toxModel.FileGetId(e.FriendNumber, e.FileNumber);
            var resumeData = await _fileTransferResumer.GetDownloadData(fileId);

            OneFileTransferModel oneFileTransferModel;

            // If we could find the resume data for this download, we resume it instead of handling it as a new transfer.
            if (resumeData != null)
            {
                oneFileTransferModel =
                    await
                    OneBrokenFileTransferModel.CreateInstance(_dataService, e.FriendNumber, e.FileNumber,
                                                              resumeData.File.Name,
                                                              e.FileSize, TransferDirection.Down, resumeData.File, resumeData.TransferredBytes);
            }
            else
            {
                // We add a transfer with a null value instead of an actual stream here. We will replace it with an actual file stream
                // in OneFileTransferModel.AcceptTransfer() when the user accepts the request and chooses a location to save the file to.
                oneFileTransferModel =
                    await
                    OneFileTransferModel.CreateInstance(_dataService, e.FriendNumber, e.FileNumber, e.FileName,
                                                        e.FileSize,
                                                        TransferDirection.Down, null);
            }

            FileTransferAdded?.Invoke(this, oneFileTransferModel);
        }
Ejemplo n.º 2
0
        public async Task <OneFileTransferModel> SendFile(StorageFile file)
        {
            var fileSizeInBytes = await GetFileSizeInBytes(file);

            bool successfulFileSend;
            var  fileInfo = _toxModel.FileSend(_friendNumber, ToxFileKind.Data, fileSizeInBytes, file.Name,
                                               out successfulFileSend);

            if (successfulFileSend)
            {
                var transferModel =
                    await OneFileTransferModel.CreateInstance(_dataService, _friendNumber, fileInfo.Number, file.Name,
                                                              fileSizeInBytes, TransferDirection.Up, file);

                return(transferModel);
            }

            return(null);
        }