Пример #1
0
        private void _CreateDir_Click(object sender, EventArgs e)
        {
            NewDir tmp = new NewDir();

            tmp.ShowDialog();

            if (!string.IsNullOrEmpty(tmp.DirName))
            {
                string fullname = CurrentDir + tmp.DirName;
                if (CurrentDir[CurrentDir.Length - 1] != '\\')
                {
                    fullname = CurrentDir + "\\" + tmp.DirName;
                }



                PackHandler.NewDir ndir = new PackHandler.NewDir()
                {
                    DirName = fullname
                };



                SocketManager.Send(BufferFormatV2.FormatFCA(ndir, Deflate.Compress));
            }
        }
Пример #2
0
        private void CheckDown()
        {
            CheckB p = IsCheckTable.Find(x => x.Checkd == false);

            if (p == null)
            {
                BufferFormatV2 buff = new BufferFormatV2((int)PackType.DownClose);
                buff.AddItem(down.DownKey);
                SocketManager.Send(buff.Finish());

                FStream.Close();



                this.BeginInvoke(new EventHandler((a, b) =>
                {
                    this.Text         = DownDir + "--下载完毕";
                    this.button1.Text = "完成";
                    MessageBox.Show(Text);
                }));
            }
            else
            {
                BufferFormatV2 buff = new BufferFormatV2((int)PackType.ReBytes);
                buff.AddItem(down.DownKey);
                buff.AddItem(p.StartPostion);
                buff.AddItem(p.Size);
                SocketManager.Send(buff.Finish());
            }
        }
Пример #3
0
        private void _Del_Click(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count > 0)
            {
                if (MessageBox.Show("你确定要删除吗?删除后将不可恢复", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    DelFile Dfile = new DelFile();
                    Dfile.DelFileList = new List <DelFileName>();


                    foreach (ListViewItem p in this.listView1.SelectedItems)
                    {
                        FileSystem fs = p.Tag as FileSystem;

                        Dfile.DelFileList.Add(new DelFileName()
                        {
                            FullName = fs.FullName,
                            FType    = fs.FileType
                        });
                    }


                    SocketManager.Send(BufferFormatV2.FormatFCA(Dfile, Deflate.Compress));
                }
            }
        }
Пример #4
0
        private void LogOnX(string username, string password)
        {
            string ip   = System.Configuration.ConfigurationManager.AppSettings["Host"];
            int    port = int.Parse(System.Configuration.ConfigurationManager.AppSettings["Port"]);

            if (!SocketManager.IsConnent)
            {
                if (!SocketManager.Connent(ip, port))
                {
                    MessageBox.Show("无法连接服务器");
                    //Close();
                }
                else
                {
                    SocketManager.StartRead();
                }
            }

            PackHandler.LogOn logon = new PackHandler.LogOn()
            {
                UserName = username,
                PassWord = password
            };

            SocketManager.Send(BufferFormatV2.FormatFCA(logon, Deflate.Compress));
        }
Пример #5
0
        private void button2_Click(object sender, EventArgs e)
        {
            BufferFormatV2 buffcheck = new BufferFormatV2((int)PackType.UpCheck);

            buffcheck.AddItem(Key);
            SocketManager.Send(buffcheck.Finish());
        }
Пример #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(CurrentDir))
            {
                LoadingDiskInfo();
                return;
            }

            DirectoryInfo dir = new DirectoryInfo(CurrentDir);

            if (dir.Parent != null)
            {
                string newdir = dir.Parent.FullName;


                Dir tmp = new Dir()
                {
                    DirName        = newdir,
                    FileSystemList = new List <FileSystem>(),
                    IsSuccess      = false,
                    Msg            = ""
                };

                SocketManager.Send(BufferFormatV2.FormatFCA(tmp, Deflate.Compress));
            }
            else
            {
                LoadingDiskInfo();
            }
        }
Пример #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            string ip   = System.Configuration.ConfigurationManager.AppSettings["Host"];
            int    port = int.Parse(System.Configuration.ConfigurationManager.AppSettings["Port"]);

            if (!SocketManager.IsConnent)
            {
                if (!SocketManager.Connent(ip, port))
                {
                    MessageBox.Show("无法连接服务器");
                    //Close();
                }
                else
                {
                    SocketManager.StartRead();
                }
            }

            PackHandler.LogOn logon = new PackHandler.LogOn()
            {
                UserName = this.textBox1.Text,
                PassWord = this.textBox2.Text
            };

            SocketManager.Send(BufferFormatV2.FormatFCA(logon, Deflate.Compress));
        }
Пример #8
0
        void main_UpFileClose(long key)
        {
            if (key == Key)
            {
                if (RConfig.ReadInt("IsCloseUP") != 1)
                {
                    IsClose           = true;
                    this.Text         = "上传完毕";
                    this.button1.Text = "完成";
                    this.Text        += "----完成";

                    BufferFormatV2 buffcheck = new BufferFormatV2((int)PackType.UpCheck);
                    buffcheck.AddItem(Key);
                    SocketManager.Send(buffcheck.Finish());
                }
                else
                {
                    IsClose           = true;
                    this.Text         = "上传完毕";
                    this.button1.Text = "完成";
                    this.Text        += "----完成";
                    BufferFormatV2 buffcheck = new BufferFormatV2((int)PackType.UpCheck);
                    buffcheck.AddItem(Key);
                    SocketManager.Send(buffcheck.Finish());
                    main.GotoDir();
                    this.Close();
                }
            }
        }
Пример #9
0
        private void listView1_DoubleClick(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count > 0)
            {
                ListViewItem item = listView1.SelectedItems[listView1.SelectedItems.Count - 1];


                string DirName = "";

                FileSystem dirinfo = item.Tag as FileSystem;

                if (dirinfo != null)
                {
                    if (dirinfo.FileType == FileType.Dir)
                    {
                        DirName = dirinfo.FullName;
                    }
                    else
                    {
                        if (MessageBox.Show("是否下载文件:" + dirinfo.Name + "?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            FileSystem downFile = (this.listView1.SelectedItems[this.listView1.SelectedItems.Count - 1].Tag as FileSystem);

                            if (downFile != null)
                            {
                                Down down = new Down()
                                {
                                    FullName = downFile.FullName
                                };

                                SocketManager.Send(BufferFormatV2.FormatFCA(down, Deflate.Compress));
                            }
                        }

                        return;
                    }
                }
                else
                {
                    DiskInfo info = item.Tag as DiskInfo;

                    if (info != null)
                    {
                        DirName = info.Name;
                    }
                }


                Dir tmp = new Dir()
                {
                    DirName        = DirName,
                    FileSystemList = new List <FileSystem>(),
                    IsSuccess      = false,
                    Msg            = ""
                };

                SocketManager.Send(BufferFormatV2.FormatFCA(tmp, Deflate.Compress));
            }
        }
Пример #10
0
        private void MoveFileSystem(string oldName, string newName, FileType filetype)
        {
            PackHandler.MoveFileSystem mfs = new MoveFileSystem();
            mfs.OldName  = oldName;
            mfs.NewName  = newName;
            mfs.FileType = filetype;

            SocketManager.Send(BufferFormatV2.FormatFCA(mfs, Deflate.Compress));
        }
Пример #11
0
        void UpFiles_FormClosed(object sender, FormClosedEventArgs e)
        {
            BufferFormatV2 buff = new BufferFormatV2((int)PackType.UpClose);

            buff.AddItem(Key);
            SocketManager.Send(buff.Finish());

            main.UpFileClose -= new UpFileCloseHandler(main_UpFileClose);
        }
Пример #12
0
        private void UpFileEx(string cudir, string name)
        {
            FileInfo file = new FileInfo(name);

            if (file.Exists)
            {
                FileStream stream = new FileStream(name, FileMode.Open, FileAccess.Read);

Re:
                long key = DateTime.Now.Ticks;

                if (UpFileList.ContainsKey(key))
                {
                    System.Threading.Thread.Sleep(1);
                    goto Re;
                }
                UpFileList.Add(key, stream);

                string upfilename = System.IO.Path.Combine(cudir, file.Name);

                UpFile upfile = new UpFile()
                {
                    FullName = upfilename,
                    Size     = stream.Length,
                    UpKey    = key,
                };


                SocketManager.Send(BufferFormatV2.FormatFCA(upfile, Deflate.Compress));
            }
            else
            {
                DirectoryInfo dir = new DirectoryInfo(name);

                if (dir.Exists)
                {
                    string fullname = System.IO.Path.Combine(cudir, dir.Name);


                    PackHandler.NewDir ndir = new PackHandler.NewDir()
                    {
                        DirName = fullname
                    };

                    SocketManager.Send(BufferFormatV2.FormatFCA(ndir, Deflate.Compress));


                    foreach (var item in dir.GetFileSystemInfos())
                    {
                        UpFileEx(fullname, item.FullName);
                    }
                }
            }
        }
Пример #13
0
        private void GotoDir()
        {
            Dir tmp = new Dir()
            {
                DirName        = this.textBox1.Text,
                FileSystemList = new List <FileSystem>(),
                IsSuccess      = false,
                Msg            = ""
            };

            SocketManager.Send(BufferFormatV2.FormatFCA(tmp, Deflate.Compress));
        }
Пример #14
0
        private void listView1_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string str = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();


                FileInfo file = new FileInfo(str);

                if (file.Exists)
                {
                    FileStream stream = new FileStream(str, FileMode.Open, FileAccess.Read);

Re:
                    long key = DateTime.Now.Ticks;

                    if (UpFileList.ContainsKey(key))
                    {
                        System.Threading.Thread.Sleep(1);
                        goto Re;
                    }
                    UpFileList.Add(key, stream);



                    string upfilename = CurrentDir + file.Name;

                    if (CurrentDir[CurrentDir.Length - 1] != '\\')
                    {
                        upfilename = CurrentDir + "\\" + file.Name;
                    }

                    UpFile upfile = new UpFile()
                    {
                        FullName = upfilename,
                        Size     = stream.Length,
                        UpKey    = key,
                    };


                    SocketManager.Send(BufferFormatV2.FormatFCA(upfile, Deflate.Compress));
                }
            }

            else if (e.Data.GetDataPresent(DataFormats.Text))
            {
                MessageBox.Show((e.Data.GetData(DataFormats.Text)).ToString(), "提示信息", MessageBoxButtons.OK);
            }
        }
Пример #15
0
        void DownFile_FormClosed(object sender, FormClosedEventArgs e)
        {
            BufferFormatV2 buff = new BufferFormatV2((int)PackType.DownClose);

            buff.AddItem(down.DownKey);
            SocketManager.Send(buff.Finish());


            if (FStream != null)
            {
                FStream.Close();
            }

            SocketManager.BinaryInput -= new ZYSocket.ClientB.ClientBinaryInputHandler(SocketManager_BinaryInput);
        }
Пример #16
0
        private void _Run_Click(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count > 0)
            {
                FileSystem fs = (this.listView1.SelectedItems[this.listView1.SelectedItems.Count - 1].Tag as FileSystem);

                if (fs != null)
                {
                    Run run = new Run()
                    {
                        File = fs.FullName
                    };
                    SocketManager.Send(BufferFormatV2.FormatFCA(run, Deflate.Compress));
                }
            }
        }
Пример #17
0
        private void _Down_Click(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count > 0)
            {
                FileSystem downFile = (this.listView1.SelectedItems[this.listView1.SelectedItems.Count - 1].Tag as FileSystem);

                if (downFile != null)
                {
                    Down down = new Down()
                    {
                        FullName = downFile.FullName
                    };

                    SocketManager.Send(BufferFormatV2.FormatFCA(down, Deflate.Compress));
                }
            }
        }
Пример #18
0
        private void _Up_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string filename = openFileDialog1.FileName;



                FileInfo file = new FileInfo(filename);

                if (file.Exists)
                {
                    FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read);

Re:
                    long key = DateTime.Now.Ticks;

                    if (UpFileList.ContainsKey(key))
                    {
                        System.Threading.Thread.Sleep(1);
                        goto Re;
                    }
                    UpFileList.Add(key, stream);



                    string upfilename = CurrentDir + file.Name;

                    if (CurrentDir[CurrentDir.Length - 1] != '\\')
                    {
                        upfilename = CurrentDir + "\\" + file.Name;
                    }

                    UpFile upfile = new UpFile()
                    {
                        FullName = upfilename,
                        Size     = stream.Length,
                        UpKey    = key,
                    };


                    SocketManager.Send(BufferFormatV2.FormatFCA(upfile, Deflate.Compress));
                }
            }
        }
Пример #19
0
        public void GotoDir()
        {
            try
            {
                DirectoryInfo np  = new DirectoryInfo(Path + this.textBox1.Text);
                Dir           tmp = new Dir()
                {
                    DirName        = np.FullName,
                    FileSystemList = new List <FileSystem>(),
                    IsSuccess      = false,
                    Msg            = ""
                };

                SocketManager.Send(BufferFormatV2.FormatFCA(tmp, Deflate.Compress));
            }
            catch (Exception er)
            {
                MessageBox.Show(er.Message);
            }
        }
Пример #20
0
        private void _CreateDir_Click(object sender, EventArgs e)
        {
            NewDir tmp = new NewDir();

            tmp.ShowDialog();

            if (!string.IsNullOrEmpty(tmp.DirName))
            {
                string fullname = System.IO.Path.Combine(CurrentDir, tmp.DirName);


                PackHandler.NewDir ndir = new PackHandler.NewDir()
                {
                    DirName = fullname
                };



                SocketManager.Send(BufferFormatV2.FormatFCA(ndir, Deflate.Compress));
            }
        }
Пример #21
0
        private void DownFile_Load(object sender, EventArgs e)
        {
            SocketManager.BinaryInput += new ZYSocket.ClientB.ClientBinaryInputHandler(SocketManager_BinaryInput);

            LoadingCheckTable();

            ProcessMax = IsCheckTable.Count;

            this.progressBar1.Maximum = ProcessMax;
            this.progressBar1.Value   = ProcessValue;

            FileInfo test = new FileInfo(down.FullName);

            saveFileDialog1.FileName = test.Name;
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                FStream = new FileStream(saveFileDialog1.FileName, FileMode.Create, FileAccess.ReadWrite);

                // FStream.SetLength(down.Size);

                DownDir = saveFileDialog1.FileName;
                if (down.Size == 0)
                {
                    this.Text         = DownDir + "--下载完毕";
                    this.button1.Text = "完成";
                    MessageBox.Show(Text);

                    Close();
                    return;
                }

                BufferFormatV2 buff = new BufferFormatV2((int)PackType.DownNow);
                buff.AddItem(down.DownKey);
                SocketManager.Send(buff.Finish());
            }
            else
            {
                this.Close();
            }
        }
Пример #22
0
        private void UpFileThread(object o)
        {
            try
            {
                byte[] data = new byte[bytelengt];

                int  r = 0;
                long p = 0;
                do
                {
                    if (IsClose)
                    {
                        break;
                    }

                    r = Stream.Read(data, 0, data.Length);

                    if (r < data.Length && r > 0)
                    {
                        byte[] buffb = new byte[r];

                        Buffer.BlockCopy(data, 0, buffb, 0, buffb.Length);
                        BufferFormatV2 buff = new BufferFormatV2((int)PackType.DateUp);
                        buff.AddItem(Key);
                        buff.AddItem(p);
                        buff.AddItem(p + r - 1);
                        buff.AddItem(buffb);

                        SocketManager.Send(buff.Finish());

                        sendlength += r;

                        this.BeginInvoke(new EventHandler((a, b) =>
                        {
                            //if( this.progressBar1.Value< this.progressBar1.Maximum)
                            //    this.progressBar1.Value++;
                            this.label1.Text = Math.Round(((double)sendlength / 1024 / 1024), 4) + "MB/" + Math.Round(((double)fileLength / 1024 / 1024), 4) + "MB";

                            double x = ((double)sendlength / fileLength * 1000);

                            this.progressBar1.Value = (int)x;
                        }));

                        break;
                    }
                    else if (r > 0)
                    {
                        BufferFormatV2 buff = new BufferFormatV2((int)PackType.DateUp);
                        buff.AddItem(Key);
                        buff.AddItem(p);
                        buff.AddItem(p + r - 1);
                        buff.AddItem(data);
                        SocketManager.Send(buff.Finish());

                        p += r;
                    }

                    sendlength += r;

                    this.BeginInvoke(new EventHandler((a, b) =>
                    {
                        this.label1.Text = Math.Round(((double)sendlength / 1024 / 1024), 4) + "MB/" + Math.Round(((double)fileLength / 1024 / 1024), 4) + "MB";

                        double x = ((double)sendlength / fileLength * 1000);

                        this.progressBar1.Value = (int)x;
                    }));
                } while (r > 0);



                BufferFormatV2 buffcheck = new BufferFormatV2((int)PackType.UpCheck);
                buffcheck.AddItem(Key);
                SocketManager.Send(buffcheck.Finish());

                this.BeginInvoke(new EventHandler((a, b) =>
                {
                    button2.Enabled = true;
                }));
            }
            catch (System.Net.Sockets.SocketException e)
            {
                MessageBox.Show("上传文件发生错误:" + e.Message);
                IsClose = true;
            }
            catch (Exception er)
            {
                BufferFormatV2 buff = new BufferFormatV2((int)PackType.UpClose, Deflate.Compress);
                buff.AddItem(Key);
                SocketManager.Send(buff.Finish());
                IsClose = true;
                MessageBox.Show("上传文件发生错误:" + er.Message);
            }
        }
Пример #23
0
        private void LoadingDiskInfo()
        {
            Dir disk = new Dir();

            SocketManager.Send(BufferFormatV2.FormatFCA(disk, Deflate.Compress));
        }
Пример #24
0
        void SocketManager_BinaryInput(byte[] data)
        {
            ReadBytesV2 read = new ReadBytesV2(data, Deflate.Decompress);
            int         lengt;
            int         cmd;

            if (read.ReadInt32(out lengt) && lengt == read.Length && read.ReadInt32(out cmd))
            {
                PackType cmdtype = (PackType)cmd;

                switch (cmdtype)
                {
                case PackType.GetDisk:
                case PackType.Dir:
                {
                    Dir dir;
                    if (read.ReadObject <Dir>(out dir))
                    {
                        this.BeginInvoke(new EventHandler((a, b) =>
                            {
                                if (dir.IsSuccess)
                                {
                                    this.button1.Enabled = true;
                                    this.button1.Text    = "上层目录";

                                    this.listView1.Clear();

                                    dir.FileSystemList.Sort(new Comparison <FileSystem>((a1, a2) =>
                                    {
                                        if (a1.FileType == FileType.Dir && a2.FileType == FileType.Dir)
                                        {
                                            return(a1.Name.CompareTo(a2.Name));
                                        }
                                        else if (a1.FileType != FileType.Dir && a2.FileType != FileType.Dir)
                                        {
                                            return(a1.Name.CompareTo(a2.Name));
                                        }
                                        else if (a1.FileType == FileType.Dir && a2.FileType == FileType.File)
                                        {
                                            return(-1);
                                        }
                                        else if (a2.FileType == FileType.Dir && a1.FileType == FileType.File)
                                        {
                                            return(1);
                                        }
                                        else
                                        {
                                            return(0);
                                        }
                                    }));


                                    SystemICO.ListViewSysImages(this.listView1);
                                    int x1 = 0, x2 = 0;
                                    foreach (FileSystem p in dir.FileSystemList)
                                    {
                                        if (p.FileType == FileType.File)
                                        {
                                            this.listView1.Items.Add(new ListViewItem()
                                            {
                                                Text       = p.Name,
                                                ImageIndex = GetImageIndex(p.Name),
                                                Tag        = p
                                            });
                                            x1++;
                                        }
                                        else
                                        {
                                            this.listView1.Items.Add(new ListViewItem()
                                            {
                                                Text       = p.Name,
                                                ImageIndex = 1,
                                                Tag        = p
                                            });

                                            x2++;
                                        }
                                    }

                                    if (!string.IsNullOrEmpty(Path))
                                    {
                                        string apath = dir.DirName;

                                        apath = apath.Remove(0, Path.Length);

                                        if (string.IsNullOrEmpty(apath))
                                        {
                                            apath = "\\";
                                        }

                                        this.textBox1.Text = apath;
                                    }
                                    else
                                    {
                                        this.textBox1.Text = dir.DirName;
                                    }

                                    CurrentDir = dir.DirName;

                                    this.label2.Text = "共找到目录:" + x2 + "个,文件:" + x1 + "个";
                                }
                                else
                                {
                                    MessageBox.Show(dir.Msg);
                                }
                            }));
                    }
                }
                break;

                case PackType.DelFile:
                {
                    DelFile dfile;
                    if (read.ReadObject <DelFile>(out dfile))
                    {
                        this.BeginInvoke(new EventHandler((a, b) =>
                            {
                                string isErr = "";
                                foreach (DelFileName p in dfile.DelFileList)
                                {
                                    if (!p.IsSuccess)
                                    {
                                        isErr += p.Msg + "\r\n";
                                    }
                                }

                                if (isErr == "")
                                {
                                    MessageBox.Show("删除成功");
                                }
                                else
                                {
                                    MessageBox.Show(isErr);
                                }

                                GotoDir();
                            }));
                    }
                }
                break;

                case PackType.NewDir:
                {
                    PackHandler.NewDir ndir;
                    if (read.ReadObject <PackHandler.NewDir>(out ndir))
                    {
                        this.BeginInvoke(new EventHandler((a, b) =>
                            {
                                if (ndir.IsSuccess)
                                {
                                    GotoDir();
                                }
                                else
                                {
                                    MessageBox.Show(ndir.Msg);
                                    GotoDir();
                                }
                            }));
                    }
                }
                break;

                case PackType.MoveFileSystem:
                {
                    PackHandler.MoveFileSystem mfs;

                    if (read.ReadObject <PackHandler.MoveFileSystem>(out mfs))
                    {
                        this.BeginInvoke(new EventHandler((a, b) =>
                            {
                                if (!mfs.IsSuccess)
                                {
                                    MessageBox.Show(mfs.Msg);
                                    GotoDir();
                                }

                                if (this.MoveFile != null)
                                {
                                    if (mfs.OldName == MoveFile.FullName)
                                    {
                                        GotoDir();

                                        this.MoveFile = null;
                                    }
                                }
                            }));
                    }
                }
                break;

                case PackType.Run:
                {
                    Run run;
                    if (read.ReadObject <Run>(out run))
                    {
                        this.BeginInvoke(new EventHandler((a, b) =>
                            {
                                if (run.IsSuccess)
                                {
                                    MessageBox.Show("运行成功");
                                }
                                else
                                {
                                    MessageBox.Show(run.Msg);
                                }
                            }));
                    }
                }
                break;

                case PackType.Down:
                {
                    Down down;
                    if (read.ReadObject <Down>(out down))
                    {
                        this.BeginInvoke(new EventHandler((a, b) =>
                            {
                                if (down.IsSuccess)
                                {
                                    DownFile downwin = new DownFile(down);
                                    downwin.Show();
                                }
                                else
                                {
                                    MessageBox.Show(down.Msg);
                                }
                            }));
                    }
                }
                break;

                case PackType.UpFile:
                {
                    UpFile upFile;
                    if (read.ReadObject <UpFile>(out upFile))
                    {
                        if (!upFile.IsSuccess)
                        {
                            this.BeginInvoke(new EventHandler((a, b) =>
                                {
                                    MessageBox.Show("上传文件发生错误:" + upFile.Msg);
                                }));
                        }
                        else
                        {
                            if (UpFileList.ContainsKey(upFile.UpKey))
                            {
                                this.BeginInvoke(new EventHandler((a, b) =>
                                    {
                                        FileStream stream = UpFileList[upFile.UpKey];

                                        UpFiles win = new UpFiles(this, upFile.FullName, upFile.UpKey, stream);
                                        win.Show();
                                    }));
                            }
                            else
                            {
                                this.BeginInvoke(new EventHandler((a, b) =>
                                    {
                                        MessageBox.Show("上传文件发生错误:无法找到KEY所指定的文件");
                                    }));
                            }
                        }
                    }
                }
                break;

                case PackType.UpClose:
                {
                    long key;
                    if (read.ReadInt64(out key))
                    {
                        if (UpFileList.ContainsKey(key))
                        {
                            this.UpFileList[key].Close();
                            this.UpFileList.Remove(key);
                            this.BeginInvoke(new EventHandler((a, b) =>
                                {
                                    if (UpFileClose != null)
                                    {
                                        UpFileClose(key);
                                    }
                                }));
                        }
                    }
                }
                break;

                case PackType.ReBytes:
                {
                    long downkey;

                    if (read.ReadInt64(out downkey))
                    {
                        long startpostion;
                        int  size;

                        if (read.ReadInt64(out startpostion) && read.ReadInt32(out size))
                        {
                            if (this.UpFileList.ContainsKey(downkey))
                            {
                                FileStream strem = UpFileList[downkey];

                                strem.Position = startpostion;

                                byte[] xdata = new byte[size];

                                strem.Read(xdata, 0, xdata.Length);


                                BufferFormatV2 buff = new BufferFormatV2((int)PackType.DataSet);
                                buff.AddItem(downkey);
                                buff.AddItem(startpostion);
                                buff.AddItem(xdata);
                                SocketManager.Send(buff.Finish());
                            }
                            else
                            {
                                BufferFormatV2 buff = new BufferFormatV2((int)PackType.UpClose);
                                buff.AddItem(downkey);
                                SocketManager.Send(buff.Finish());
                            }
                        }
                    }
                }
                break;
                }
            }
        }
Пример #25
0
        void SocketManager_BinaryInput(byte[] data)
        {
            ReadBytesV2 read = new ReadBytesV2(data);

            int lengt;
            int cmd;

            if (read.ReadInt32(out lengt) && lengt == read.Length && read.ReadInt32(out cmd))
            {
                switch (cmd)
                {
                case 2001:
                {
                    long Key;
                    if (read.ReadInt64(out Key))
                    {
                        if (Key == down.DownKey)
                        {
                            string msg;
                            if (read.ReadString(out msg))
                            {
                                this.BeginInvoke(new EventHandler((a, b) =>
                                    {
                                        MessageBox.Show(msg);
                                        this.Close();
                                    }));
                            }
                        }
                    }
                }
                break;

                case 2002:
                {
                    long Key;
                    if (read.ReadInt64(out Key))
                    {
                        if (Key == down.DownKey)
                        {
                            long   startp;
                            long   endp;
                            byte[] buff;

                            if (read.ReadInt64(out startp) && read.ReadInt64(out endp) && read.ReadByteArray(out buff))
                            {
                                System.Threading.ThreadPool.QueueUserWorkItem((a) =>
                                    {
                                        CheckB cb = IsCheckTable.Find(p => p.StartPostion == startp);

                                        if (cb != null)
                                        {
                                            if (cb.EndPostion == endp && buff.Length >= cb.Size)
                                            {
                                                cb.Checkd = true;

                                                FStream.Position = cb.StartPostion;
                                                FStream.Write(buff, 0, cb.Size);
                                                SizeR += cb.Size;


                                                this.BeginInvoke(new EventHandler((a1, b1) =>
                                                {
                                                    ProcessValue++;
                                                    if (ProcessValue <= this.progressBar1.Maximum)
                                                    {
                                                        this.progressBar1.Value = ProcessValue;
                                                    }
                                                    else
                                                    {
                                                        this.progressBar1.Value = this.progressBar1.Maximum;
                                                    }

                                                    this.label1.Text = Math.Round(((double)SizeR / 1024 / 1024), 2) + "MB /" + Math.Round((double)down.Size / 1024 / 1024, 2) + "MB";
                                                }));
                                            }
                                        }
                                        else
                                        {
                                            this.BeginInvoke(new EventHandler((a1, b1) =>
                                            {
                                                BufferFormatV2 bufff = new BufferFormatV2((int)PackType.DownClose);
                                                bufff.AddItem(down.DownKey);
                                                SocketManager.Send(bufff.Finish());
                                                MessageBox.Show("数据验证出错??");
                                                Close();
                                            }));
                                        }
                                    });
                            }
                        }
                    }
                }
                break;

                case 2003:
                {
                    long Key;
                    if (read.ReadInt64(out Key))
                    {
                        if (Key == down.DownKey)
                        {
                            this.BeginInvoke(new EventHandler((a, b) =>
                                {
                                    CheckDown();
                                }));
                        }
                    }
                }
                break;

                case 2004:
                {
                    long Key;
                    if (read.ReadInt64(out Key))
                    {
                        if (Key == down.DownKey)
                        {
                            long   startP;
                            byte[] xdata;

                            if (read.ReadInt64(out startP) && read.ReadByteArray(out xdata))
                            {
                                this.BeginInvoke(new EventHandler((a, b) =>
                                    {
                                        CheckB cb = IsCheckTable.Find(p => p.StartPostion == startP);

                                        if (xdata.Length >= cb.Size)
                                        {
                                            cb.Checkd = true;

                                            FStream.Position = cb.StartPostion;
                                            FStream.Write(xdata, 0, cb.Size);
                                            SizeR += cb.Size;


                                            this.BeginInvoke(new EventHandler((a1, b1) =>
                                            {
                                                ProcessValue++;
                                                this.progressBar1.Value = ProcessValue;

                                                this.label1.Text = Math.Round(((double)SizeR / 1024 / 1024), 2) + "MB /" + Math.Round((double)down.Size / 1024 / 1024, 2) + "MB";
                                            }));
                                        }


                                        CheckDown();
                                    }));
                            }
                        }
                    }
                }
                break;
                }
            }
        }
Пример #26
0
        static void AddProducts(SocketManager socketManager)
        {
            List <Task> t  = new List <Task>();
            int         aa = 5000;

            while (true)
            {//若有键按下,且是 ESC 键,则度退出循环
                ConsoleKey InputKey = Console.ReadKey(true).Key;
                if (InputKey == ConsoleKey.Escape)
                {
                    break;
                }

                if (InputKey == ConsoleKey.Spacebar)
                {
                    Random ran = new Random();
                    for (int i = 0; i < aa; i++)
                    {
                        #region 创建消息
                        Person person = new Person()
                        {
                            Aliases    = string.Empty,
                            BodyLength = 10,
                        };
                        int RandKey = ran.Next(300, 800);
                        for (int j = 0; j < RandKey; j++)
                        {
                            person.Aliases += "1";
                        }
                        person.BodyLength = RandKey;

                        byte[] send = System.Text.Encoding.UTF8.GetBytes(message);
                        person.Body = ByteString.CopyFrom(send);
                        #endregion
                        t.Add(Task.Run(() =>
                        {
                            socketManager.Send(person);
                        }));
                    }
                    //t.Add(Task.Run(() =>
                    //{
                    //    ruoxiao();
                    //}));
                }
                while (true)
                {
                    if (socketManager.m_numConnectedSockets == aa)
                    {
                        try
                        {
                            Task.WaitAll(t.ToArray());
                            Console.WriteLine("所有结束");
                            t.Clear();
                        }
                        catch (AggregateException e)
                        {
                            Console.WriteLine("\nThe following exceptions have been thrown by WaitAll(): (THIS WAS EXPECTED)");
                            for (int j = 0; j < e.InnerExceptions.Count; j++)
                            {
                                Console.WriteLine("\n-------------------------------------------------\n{0}", e.InnerExceptions[j].ToString());
                            }
                        }
                        socketManager.m_numConnectedSockets = 0;
                        break;
                    }
                }
            }
        }