Esempio n. 1
0
        /// <summary>
        /// 构造(下载文件)
        /// </summary>
        /// <param name="serverEP">服务器主机信息</param>
        /// <param name="tFileInfo">下载文件信息</param>
        public FileTransmitBase(IPEndPoint serverEP, TFileInfo tFileInfo)
        {
            TFileInfo = tFileInfo;
            TFileInfo.LengthStr = Operation.Calculate.GetSizeStr(TFileInfo.Length);//计算文件长度
            ServerEP = serverEP;
            _IsSend = false;

            ///创建接收文件夹
            System.IO.DirectoryInfo dInfo = new System.IO.DirectoryInfo(System.Windows.Forms.Application.StartupPath + "\\ReceivedFile");
            if (!dInfo.Exists)
                dInfo.Create();
            dInfo = null;

            ///创建接收缓存文件夹
            dInfo = new System.IO.DirectoryInfo(System.Windows.Forms.Application.StartupPath + "\\FileCache");
            if (!dInfo.Exists)
                dInfo.Create();
            dInfo = null;
        }
Esempio n. 2
0
        /// <summary>
        /// 构造(下载文件)
        /// </summary>
        /// <param name="serverEP">服务器主机信息</param>
        /// <param name="tFileInfo">下载文件信息</param>
        public FileTransmitBase(IPEndPoint serverEP, TFileInfo tFileInfo)
        {
            TFileInfo           = tFileInfo;
            TFileInfo.LengthStr = Operation.Calculate.GetSizeStr(TFileInfo.Length);//计算文件长度
            ServerEP            = serverEP;
            _IsSend             = false;

            ///创建接收文件夹
            System.IO.DirectoryInfo dInfo = new System.IO.DirectoryInfo(System.Windows.Forms.Application.StartupPath + "\\ReceivedFile");
            if (!dInfo.Exists)
            {
                dInfo.Create();
            }
            dInfo = null;

            ///创建接收缓存文件夹
            dInfo = new System.IO.DirectoryInfo(System.Windows.Forms.Application.StartupPath + "\\FileCache");
            if (!dInfo.Exists)
            {
                dInfo.Create();
            }
            dInfo = null;
        }
Esempio n. 3
0
 /// <summary>
 /// 接收文件方使用此构造函数
 /// </summary>
 /// <param name="serverEP">代理服务器主机信息</param>
 /// <param name="tFileInfo">接收文件的信息</param>
 public p2pFileClient(IPEndPoint serverEP, TFileInfo tFileInfo)
     : base(serverEP, tFileInfo)
 {
     CacheFile = System.Windows.Forms.Application.StartupPath + "\\FileCache\\" + TFileInfo.MD5;
 }
Esempio n. 4
0
 /// <summary>
 /// 构造(下载文件)
 /// </summary>
 /// <param name="serverEP">服务器主机信息</param>
 /// <param name="tFileInfo">下载文件信息</param>
 public ImageFileClient(IPEndPoint serverEP, TFileInfo tFileInfo)
     : base(serverEP, tFileInfo)
 {
     mtu = 10240;//1次下载10K
     Start();
 }
Esempio n. 5
0
        /// <summary>
        /// 处理接收图片文件 
        /// </summary>
        /// <param name="msg"></param>
        private void onTCPImageFile(ImageFileMsg msg)
        {
            exUser user = findUser(msg.from);
            if (user == null) return;
            if (user.UserID == MyAuth.UserID) return;//如果是自己发送给自己的消息,则不处理

            System.IO.DirectoryInfo dInfo = new System.IO.DirectoryInfo(MyAuth.UserID + "\\ArrivalImage");
            if (!dInfo.Exists)
                dInfo.Create();

            string fileName = MyAuth.UserID + "\\ArrivalImage\\" + msg.MD5 + msg.Extension;

            if (System.IO.File.Exists(fileName)) return;//如果本地已经有此文件已经存在,则退出(不接收文件)

            TFileInfo fileinfo = new TFileInfo();
            fileinfo.MD5 = msg.MD5;
            fileinfo.Length = msg.Length;
            fileinfo.Extension = msg.Extension;
            fileinfo.fullName = fileName;

            if (msg.MessageType == IMLibrary3.Enmu.MessageType.User)//如果图片发送给用户
            {
                ImageFileClient tcpfile = new ImageFileClient(Global.ImageServerEP, fileinfo);
                tcpfile.fileTransmitted += delegate(object sender, fileTransmitEvnetArgs e)
                {
                    FormTalkUser fs = user.Tag as FormTalkUser;
                    if (fs != null)
                    {
                        List<MyPicture> needRecPics = fs.GetNeedRecPicture();
                        foreach (MyPicture pic in needRecPics)
                            if (pic.MD5 == e.fileInfo.MD5)
                            {
                                needRecPics.Remove(pic);
                                pic.Image = System.Drawing.Image.FromFile(e.fileInfo.fullName);
                                fs.Invalidate();
                            }
                    }
                    (sender as ImageFileClient).Dispose();
                    sender = null;
                };
            }
            else if (msg.MessageType == IMLibrary3.Enmu.MessageType.Group)//如果图片发送给群
            {

                exRoom room = findRoom(msg.to);//获得消息接收群
                if (room == null) return;
                FormTalkRoom fs = room.Tag as FormTalkRoom;

                ImageFileClient tcpfile = new ImageFileClient(Global.ImageServerEP, fileinfo);
                tcpfile.fileTransmitted += delegate(object sender, fileTransmitEvnetArgs e)
                {
                    if (fs != null)
                    {
                        List<MyPicture> needRecPics = fs.GetNeedRecPicture();
                        foreach (MyPicture pic in needRecPics)
                            if (pic.MD5 == e.fileInfo.MD5)
                            {
                                needRecPics.Remove(pic);
                                pic.Image = System.Drawing.Image.FromFile(e.fileInfo.fullName);
                                fs.Invalidate();
                            }
                    }
                    (sender as ImageFileClient).Dispose();
                    sender = null;
                };
            } 
        }
Esempio n. 6
0
 /// <summary>
 /// 构造(下载文件)
 /// </summary>
 /// <param name="serverEP">服务器主机信息</param>
 /// <param name="tFileInfo">下载文件信息</param>
 public ImageFileClient(IPEndPoint serverEP, TFileInfo tFileInfo)
     : base(serverEP, tFileInfo)
 {
     mtu = 10240;//1次下载10K
     Start();
 }
Esempio n. 7
0
 /// <summary>
 /// 构造
 /// </summary>
 /// <param name="FileInfo">文件信息</param>
 public fileTransmitEvnetArgs(TFileInfo FileInfo)
 {
     fileInfo = FileInfo;
 }
Esempio n. 8
0
 /// <summary>
 /// 构造
 /// </summary>
 /// <param name="FileInfo">文件信息</param>
 public fileTransmitEvnetArgs(TFileInfo FileInfo)
 {
     fileInfo = FileInfo;
 }
Esempio n. 9
0
        private void SetRecControl(TransmitState State, TFileInfo fileinfo)
        {
            if (State == TransmitState.Transmitting)
            {
                this.progressBar1.Value = Convert.ToInt32(((decimal)fileinfo.CurrLength / fileinfo.Length) * 100);
                this.labelFileLengthString.Text = IMLibrary3.Operation.Calculate.GetSizeStr(fileinfo.CurrLength) + "/" + fileinfo.LengthStr;
            }
            else if (State == TransmitState.Connected)
            {
                linkLabelOffline.Visible = false;

                if (isSend)
                    this.labelRequest.Text = "正在发送文件...";
                else
                    this.labelRequest.Text = "正在接收文件...";

                if (fileinfo.connectedType == ConnectedType.UDPLocal)
                    labelConType.Text = "[UDP直连]";
                else if (fileinfo.connectedType == ConnectedType.UDPRemote)
                    labelConType.Text = "[UDP直连]";
                else
                    labelConType.Text = "[服务器中转连接]";
            }
            else if (State == TransmitState.Over)
            {
                if (fileTransmitted != null) fileTransmitted(this);//触发文件
            }
        }
Esempio n. 10
0
        /// <summary>
        /// 准备接收文件传输
        /// </summary>
        /// <param name="pfile"></param>
        public void ReceiveFile(IMLibrary3.Protocol.P2PFileMsg  pfile)
        {
            TFileInfo tFileInfo = new TFileInfo();
            tFileInfo.Name = pfile.Name;
            tFileInfo.Length = pfile.Length;
            tFileInfo.Extension = pfile.Extension;
            tFileInfo.MD5 = pfile.MD5;

            OurMsg.Controls.FileTransmit ft = new Controls.FileTransmit();
            ft.P2PFileTransmit = new p2pFileClient(Global.FileTransmitServerEP, tFileInfo);
            ft.fileTransmitCancel += new OurMsg.Controls.FileTransmit.fileTransmitEventHandler(ft_fileTransmitCancel);
            ft.P2PFileTransmit.GetIPEndPoint += new FileTransmitBase.GetIPEndPointEventHandler(P2PFileTransmit_GetIPEndPoint);
            ft.fileTransmitted += new OurMsg.Controls.FileTransmit.fileTransmitEventHandler(ft_fileTransmitted);
            flowLayoutPanel1.Controls.Add(ft);
        }
Esempio n. 11
0
 /// <summary>
 /// 接收文件方使用此构造函数
 /// </summary>
 /// <param name="serverEP">代理服务器主机信息</param>
 /// <param name="tFileInfo">接收文件的信息</param>
 public p2pFileClient(IPEndPoint serverEP, TFileInfo tFileInfo)
     : base(serverEP, tFileInfo)
 {
     CacheFile = System.Windows.Forms.Application.StartupPath + "\\FileCache\\" + TFileInfo.MD5;
 }