Esempio n. 1
0
 /// <summary>
 /// 对方拒绝续传;文件又处于暂停状态;
 /// </summary>
 /// <param name="FileLabel">文件标签</param>
 public void FileNoContinue(int FileLabel)
 {
     EngineTool.EventInvoket(() => { this.fileMustBase.FileNoContinue(FileLabel); });
 }
Esempio n. 2
0
 /// <summary>
 /// 文件已中断;状态已自动改为暂停状态;等待对方上线的时候;进行续传;
 /// </summary>
 /// <param name="FileLabel">文件标签</param>
 /// <param name="Reason">中断原因</param>
 public void FileBreak(int FileLabel, string Reason)
 {
     EngineTool.EventInvoket(() => { this.fileMustBase.FileBreak(FileLabel, Reason); });
 }
Esempio n. 3
0
 /// <summary>
 /// 文件接收完成
 /// </summary>
 /// <param name="FileLabel">文件标签</param>
 public void ReceiveSuccess(int FileLabel)
 {
     EngineTool.EventInvoket(() => { this.fileReceiveMust.ReceiveSuccess(FileLabel); });
 }
Esempio n. 4
0
 /// <summary>
 /// 对方暂停;我方也已经暂停;等待着对方的再一次请求传输;会在FileOrNotContingue这里触发
 /// </summary>
 /// <param name="FileLabel">文件标签</param>
 public void FileStop(int FileLabel)
 {
     EngineTool.EventInvoket(() => { this.fileMustBase.FileStop(FileLabel); });
 }
Esempio n. 5
0
        /// <summary>
        /// 发送方发过来的数据;
        /// </summary>
        /// <param name="receiveToDate">收到的数据</param>
        /// <param name="stateOne">StateBase</param>
        /// <returns>需要回复的数据</returns>
        internal byte[] ReceiveDateTO(byte[] receiveToDate, StateBase stateOne)
        {
            byte[] haveDate  = null;
            int    fileLabel = ByteToDate.ByteToInt(3, receiveToDate);
            byte   code      = receiveToDate[2];

            if (code == PasswordCode._fileHeadCode)//说明发送过来的是文件是否传输的包头信息
            {
                FileStream fs        = null;
                FileState  stateHead = EncryptionDecryptFile.FileHeadDecrypt(receiveToDate, fs);
                string     fileName  = ReceiveMust.ReceiveOrNo(stateHead.FileLabel, stateHead.FileName, stateHead.FileLenth);
                if (fileName == "")
                {
                    haveDate = EncryptionDecryptFile.FileSevenEncryption(PasswordCode._receiveUser, PasswordCode._fileRefuse, fileLabel);
                }
                else
                {
                    fs = EngineTool.FileStreamWrite(fileName);
                    if (fs == null)
                    {
                        haveDate = EncryptionDecryptFile.FileSevenEncryption(PasswordCode._receiveUser, PasswordCode._fileRefuse, fileLabel);
                    }
                    else
                    {
                        ExpandBuffer(stateHead, stateOne);
                        stateHead.FileName = fileName; stateHead.Filestream = fs; stateHead.StateFile = 1;

                        FS.Add(stateHead);
                        haveDate = EncryptionDecryptFile.FileSevenEncryption(PasswordCode._receiveUser, PasswordCode._fileOk, fileLabel);
                    }
                }
                return(haveDate);
            }
            FileState state = FileLabelToState(fileLabel);

            if (state == null)
            {
                if (code == PasswordCode._fileCancel)
                {
                    return(null);
                }
                else
                {
                    return(EncryptionDecryptFile.FileSevenEncryption(PasswordCode._receiveUser, PasswordCode._fileCancel, fileLabel));
                }
            }
            else
            {
                switch (code)
                {
                case PasswordCode._fileSubjectCode:           //收到的是文件主体代码
                    haveDate = EncryptionDecryptFile.FileSubjectDecrypt(state, receiveToDate);
                    ReceiveMust.FileProgress(state);          //输出文件进度
                    if (state.FileOkLenth >= state.FileLenth) //说明文件接收完成了
                    {
                        FileRemove(fileLabel); ReceiveMust.ReceiveSuccess(fileLabel);
                    }
                    break;

                case PasswordCode._fileCancel:    //对方已经取消了这个文件;
                    FileRemove(fileLabel);
                    ReceiveMust.FileCancel(fileLabel);
                    break;

                case PasswordCode._sendStop:    //对方暂停发送
                    FileStopIn(state, ReceiveMust);
                    break;

                case PasswordCode._fileContinue:                             //对方发过来一个续传的确认信息;你是否同意;
                    ExpandBuffer(state, stateOne);                           //有可能是stateOne换过了;
                    FileStopIn(state, ReceiveMust);                          //对方已经暂停了这个文件;我这边肯定也要先暂停掉
                    bool orStop = ReceiveMust.FileOrNotContingue(fileLabel); //让客户确认;是否续传
                    if (orStop)
                    {
                        haveDate        = EncryptionDecryptFile.ReceiveContingueEncryption(PasswordCode._fileContinueOk, state);
                        state.StateFile = 1;
                        ReceiveMust.FileContinue(fileLabel);
                    }
                    else
                    {
                        haveDate = EncryptionDecryptFile.FileSevenEncryption(PasswordCode._receiveUser, PasswordCode._fileContinueNo, fileLabel);
                    }
                    break;

                case PasswordCode._fileContinueOk:    //对方同意续传
                    state.StateFile = 1;
                    ReceiveMust.FileContinue(fileLabel);
                    haveDate = EncryptionDecryptFile.FileSubjectDecrypt(state, receiveToDate);
                    if (state.FileOkLenth >= state.FileLenth)    //说明文件接收完成了
                    {
                        FileRemove(fileLabel); ReceiveMust.ReceiveSuccess(fileLabel);
                    }
                    break;

                case PasswordCode._fileContinueNo:    //对方拒绝续传
                    ReceiveMust.FileNoContinue(fileLabel);
                    FileStopIn(state, ReceiveMust);
                    break;
                }
            }
            return(haveDate);
        }