Ejemplo n.º 1
0
        private void OnResponeSendFile(ResponeTraFransfersFile data)
        {
            SendFileManager sendFileManager;

            if (!SendFileManagerList.TryGetValue(
                    data.MD5,
                    out sendFileManager))
            {
                return;
            }
            if (data.Size > 0)
            {
                OnFileSendBuffer(new FileSendBufferEventArgs(
                                     sendFileManager,
                                     data.Size));
            }
            if (data.Index == 0)
            {
                if (sendFileManager != null)
                {
                    OnFileSendAccept(new FileSendEventArgs(sendFileManager));
                    sendFileManager.Read(data.Index);
                }
            }
            else
            {
                if (data.Index == -1)
                {
                    OnFileSendRefuse(new FileSendEventArgs(sendFileManager));
                }
                SendFileManagerList.Remove(data.MD5);
                sendFileManager.Dispose();
            }
        }
Ejemplo n.º 2
0
        private void ReceiveFileManagerReceiveFileTimeout(
            object sender, EventArgs e)
        {
            ReceiveFileManager receiveFileManager =
                sender as ReceiveFileManager;
            ResponeTraFransfersFile responeTraFransfersFile =
                new ResponeTraFransfersFile(
                    receiveFileManager.MD5,
                    0,
                    receiveFileManager.GetNextReceiveIndex());

            Send(
                (int)Command.ResponeSendFilePack,
                responeTraFransfersFile,
                receiveFileManager.RemoteIP);
        }
Ejemplo n.º 3
0
        private void OnRecieveBuffer(
            TraFransfersFile traFransfersFile,
            IPEndPoint remoteEP)
        {
            ReceiveFileManager receiveFileManager;

            if (!ReceiveFileManagerList.TryGetValue(
                    traFransfersFile.MD5,
                    out receiveFileManager))
            {
                return;
            }
            if (receiveFileManager != null)
            {
                ResponeTraFransfersFile responeTraFransfersFile;
                int size = receiveFileManager.ReceiveBuffer(
                    traFransfersFile.Index,
                    traFransfersFile.Buffer);

                if (receiveFileManager.Completed)
                {
                    responeTraFransfersFile = new ResponeTraFransfersFile(
                        traFransfersFile.MD5,
                        size,
                        -2);
                    Send(
                        (int)Command.ResponeSendFilePack,
                        responeTraFransfersFile,
                        remoteEP);
                }
                else
                {
                    responeTraFransfersFile = new ResponeTraFransfersFile(
                        traFransfersFile.MD5,
                        size,
                        receiveFileManager.GetNextReceiveIndex());
                    Send(
                        (int)Command.ResponeSendFilePack,
                        responeTraFransfersFile,
                        remoteEP);
                }
                OnFileReceiveBuffer(
                    new FileReceiveBufferEventArgs(
                        receiveFileManager, traFransfersFile.Buffer.Length));
            }
        }
Ejemplo n.º 4
0
        public void AcceptReceive(RequestSendFileEventArgs e)
        {
            TraFransfersFileStart   traFransfersFileStart = e.TraFransfersFileStart;
            IPEndPoint              remoteIP = e.RemoteIP;
            ResponeTraFransfersFile responeTraFransfersFile;

            if (e.Cancel)
            {
                responeTraFransfersFile = new ResponeTraFransfersFile(
                    traFransfersFileStart.MD5, 0, -1);
                Send((int)Command.ResponeSendFile, responeTraFransfersFile, remoteIP);
            }
            else
            {
                ReceiveFileManager receiveFileManager;
                if (!ReceiveFileManagerList.TryGetValue(
                        traFransfersFileStart.MD5,
                        out receiveFileManager))
                {
                    receiveFileManager = new ReceiveFileManager(
                        traFransfersFileStart.MD5,
                        e.Path,
                        traFransfersFileStart.FileName,
                        traFransfersFileStart.PartCount,
                        traFransfersFileStart.PartSize,
                        traFransfersFileStart.Length,
                        remoteIP);
                    receiveFileManager.ReceiveFileComplete +=
                        new FileReceiveCompleteEventHandler(
                            ReceiveFileManagerReceiveFileComplete);
                    receiveFileManager.ReceiveFileTimeout +=
                        new EventHandler(ReceiveFileManagerReceiveFileTimeout);
                    ReceiveFileManagerList.Add(
                        traFransfersFileStart.MD5,
                        receiveFileManager);
                    receiveFileManager.Start();
                }
                responeTraFransfersFile = new ResponeTraFransfersFile(
                    traFransfersFileStart.MD5, 0, 0);
                Send((int)Command.ResponeSendFile, responeTraFransfersFile, remoteIP);
            }
        }