Esempio n. 1
0
        public override async Task <bool> RecieveOfFileTransferRequest(FileRecieveRequest request, IPEndPoint endPoint, ContactForm contact,
                                                                       ResultOfOperation result)
        {
            var args = new RecieveOfFileTransferRequestEventArgs()
            {
                FileName = request.Name,
                Login    = contact.Login,
                Ip       = endPoint.Address,
                Length   = request.Length
            };

            await OnFileReciveBegining(args).ConfigureAwait(false);

            var remoteFile = args.RemoteFileStream;

            if (args.IsAllow)
            {
                if (remoteFile == null)
                {
                    var dirFull = DirForFileSaving + @"\" + request.Name;
                    var stream  = new FileStream(dirFull, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
                    await Task.Run(() => stream.SetLength(request.Length)).ConfigureAwait(false);

                    MoleClientSender sender;
                    if (!Senders.TryGetValue(contact.Login, out sender))
                    {
                        sender = new MoleClientSender(contact, PossibleAlgs, this, true);
                        Senders.TryAdd(contact.Login, sender);
                    }
                    await sender.Inicialize(endPoint).ConfigureAwait(false);

                    await sender.GetSessionKey().ConfigureAwait(false);

                    await sender.AuthenticateAsync().ConfigureAwait(false);

                    remoteFile = new RemoteFileStreamMole(sender, stream, request.Name);
                    await remoteFile.InitializeAsync().ConfigureAwait(false);
                }

                await
                OnFileRecievingPrepared(new FileRecievingPreparedEventArgs(request.Name, request.Length, remoteFile))
                .ConfigureAwait(false);

                result.OperationWasFinishedSuccessful = true;
                return(true);
            }
            result.ErrorMessage = "Пользователь отказался принять файл.";
            result.OperationWasFinishedSuccessful = false;
            return(false);
        }
Esempio n. 2
0
 public abstract Task <bool> RecieveOfFileTransferRequest(FileRecieveRequest request, IPEndPoint endPoint, ContactForm contact,
                                                          ResultOfOperation result);