Esempio 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);
        }
 public OneFileTransferViewModel(FileTransfersViewModel fileTransfersViewModel,
     OneFileTransferModel oneFileTransferModel)
 {
     _fileTransfersViewModel = fileTransfersViewModel;
     _oneFileTransferModel = oneFileTransferModel;
     _oneFileTransferModel.PropertyChanged += ModelPropertyChangedHandler;
     _progressUpdater = new ProgressUpdater(this);
 }
Esempio n. 3
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);
        }
Esempio n. 4
0
        private void AddTransfer(OneFileTransferModel fileTransferModel)
        {
            var fileTransferViewModel = new OneFileTransferViewModel(this, fileTransferModel);

            if (Transfers.Contains(fileTransferViewModel))
                return;

            Transfers.Add(fileTransferViewModel);

            if (VisualStates.BlockState == FileTransfersVisualStates.TransfersBlockState.Invisible)
            {
                VisualStates.BlockState = FileTransfersVisualStates.TransfersBlockState.Open;
            }
        }
Esempio n. 5
0
 private async void FileTransferAddedHandler(object sender, OneFileTransferModel e)
 {
     await
         CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
             () => { AddTransfer(e); });
 }