Esempio n. 1
0
        private async Task <int> SendFiles(string path)
        {
            List <FileInfo> files  = stLib_CS.File.FileHelper.GetFiles(path);
            int             i      = 0;
            NStream         stream = m_Client.stream;

            if (!CurrentPingStatus())
            {
                m_sleeptime = 0;
            }
            await stream.WriteInt32(files.Count);

            await stream.WriteString(GetCurrentHandIn().Path + path.Substring(path.LastIndexOf('\\')));

            foreach (var file in files)
            {
                if (m_sleeptime == 0)
                {
                    m_sleeptime = file.Length * 1000 / 1024 / 200;
                }
                Sleep();
                FileStream fileStream;
                try {
                    fileStream = file.OpenRead();
                } catch (Exception e) {
                    MessageBox.Show("无法打开指定的文件");
                    return(0);
                }
                await stream.WriteInt64(file.Length);

                await stream.WriteString(file.Name);

                int res = await stream.WriteBigFrom(fileStream);

                i++;
                this.Text = "正在发送第" + i.ToString() + "个文件";
            }
            MessageBox.Show("传输成功");
            RefreshText();
            return(0);
        }
Esempio n. 2
0
        private async Task <int> SendFile(string path)
        {
            NStream  stream = m_Client.stream;
            FileInfo file   = new FileInfo(path);

            if (!CurrentPingStatus())
            {
                m_sleeptime = 0;
            }
            await stream.WriteInt32(1);

            await stream.WriteString(GetCurrentHandIn().Path);

            if (m_sleeptime == 0)
            {
                m_sleeptime = file.Length * 1000 / 1024 / 200;
            }
            Sleep();

            FileStream fileStream;

            try {
                fileStream = file.OpenRead();
            } catch (Exception e) {
                MessageBox.Show("无法打开指定的文件");
                return(0);
            }
            await stream.WriteInt64(file.Length);

            await stream.WriteString(file.Name);

            int res = await stream.WriteBigFrom(fileStream);

            MessageBox.Show("传输成功");
            RefreshText();
            return(0);
        }