private void lvwFiles_DoubleClick(object sender, EventArgs e)
        {
            string path;

            try
            {
                //path = e.Node.FullPath;
                //ee = e;
                //ListViewItem items = lvwFiles.SelectedItems.ToString();

                Details_toServer details = new Details_toServer();
                details.Type = (int)PacketType.상세정보서버;
                details.name = lvwFiles.SelectedItems.ToString();
                //details.tag =
                //Packet.Serialize(details).CopyTo(this.sendBuffer, 0);
                //this.Send();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            //OpenFiles();
        }
Esempio n. 2
0
        public void RUN()
        {
            if (txt_path.Text == "" || txt_ip.Text == "" || txt_port.Text == "")
            {
                if (txt_path.Text == "")
                {
                    MessageBox.Show("경로가 설정되어있지 않습니다.");
                    return;
                }
                if (txt_ip.Text == "" || txt_port.Text == "")
                {
                    MessageBox.Show("IP와 PORT를 정확히 입력하십시오.");
                    return;
                }
            }
            else
            {
                CSafeSetText(btn_server, "서버끊기");


                this.ipaddress = IPAddress.Parse(txt_ip.Text);
                this.PORT      = int.Parse(txt_port.Text);
                this.server    = new TcpListener(ipaddress, PORT);
                this.server.Start();

                //btn_server.Text = "서버끊기";
                //btn_server.ForeColor = Color.Red;

                if (!this.m_bClientOn)
                {
                    this.Invoke(new MethodInvoker(delegate()
                    {
                        this.txt_server_state.AppendText("클라이언트 접속 대기중..." + "\r\n");
                    }));
                }

                TcpClient client = this.server.AcceptTcpClient();


                if (client.Connected)
                {
                    this.m_bClientOn = true;
                    this.Invoke(new MethodInvoker(delegate()
                    {
                        this.txt_server_state.AppendText("클라이언트 접속..." + "\r\n");
                    }));
                    networkstream = client.GetStream();
                }



                int nRead = 0;


                while (this.m_bClientOn)
                {
                    try
                    {
                        nRead = 0;
                        init();
                        nRead = this.networkstream.Read(readBuffer, 0, 1024 * 4);
                    }
                    catch
                    {
                        this.m_bClientOn   = false;
                        this.networkstream = null;
                    }


                    Packet packet = (Packet)Packet.Desserialize(this.readBuffer);

                    switch ((int)packet.Type)
                    {
                    case (int)PacketType.택서버:
                    {
                        this.m_selectClass = (Select_toServer)Packet.Desserialize(this.readBuffer);

                        this.Invoke(new MethodInvoker(delegate()
                            {
                                this.txt_server_state.AppendText("beforeSelect 데이터 요청.." + "\r\n");
                                Select_toClient select = new Select_toClient();

                                select.Type = (int)PacketType.택손님;

                                select.path = this.m_selectClass.path;

                                DirectoryInfo[] di = new DirectoryInfo(select.path).GetDirectories();
                                //list_dir
                                List <string> list = new List <string>();
                                //select.dir = new DirectoryInfo(select.path).GetDirectories();
                                for (int i = 0; i < di.Length; i++)
                                {
                                    list.Add(di[i].ToString());
                                }
                                select.dir = list;

                                List <string> dir_date = new List <string>();
                                for (int i = 0; i < di.Length; i++)
                                {
                                    dir_date.Add(di[i].LastWriteTime.ToString());
                                }
                                select.dir_date = dir_date;

                                FileInfo[] fi = new DirectoryInfo(select.path).GetFiles();
                                //list_file
                                List <string> list_f = new List <string>();
                                //select.fil = new DirectoryInfo(select.path).GetFiles();
                                for (int i = 0; i < fi.Length; i++)
                                {
                                    list_f.Add(fi[i].ToString());
                                }
                                select.fil = list_f;

                                //dir_num
                                List <int> list_num = new List <int>();

                                for (int i = 0; i < list.Count; i++)
                                {
                                    DirectoryInfo[] di_num = new DirectoryInfo(select.path + "\\" + di[i]).GetDirectories();
                                    list_num.Add(di_num.Length);
                                }
                                select.dir_num = list_num;

                                //file_info
                                Dictionary <string, string> file_Info = new Dictionary <string, string>();
                                for (int i = 0; i < fi.Length; i++)
                                {
                                    file_Info.Add(fi[i].Length.ToString(), fi[i].LastWriteTime.ToString());
                                }
                                select.file_info = file_Info;


                                Packet.Serialize(select).CopyTo(this.sendBuffer, 0);
                                this.Send();
                            }));
                    }
                    break;

                    case (int)PacketType.확장서버:
                    {
                        this.m_expandclientClass = (Expand_toServer)Packet.Desserialize(this.readBuffer);

                        this.Invoke(new MethodInvoker(delegate()
                            {
                                this.txt_server_state.AppendText("beforeExpand 데이터 요청.." + "\r\n");
                                Expand_toClient expand = new Expand_toClient();
                                expand.Type            = (int)PacketType.확장손님;
                                expand.path            = this.m_expandclientClass.path;
                                DirectoryInfo[] di     = new DirectoryInfo(expand.path).GetDirectories();
                                List <string> list     = new List <string>();

                                for (int i = 0; i < di.Length; i++)
                                {
                                    list.Add(di[i].ToString());
                                }
                                // string[] a = list.
                                expand.dir = list;

                                List <int> list_num = new List <int>();

                                for (int i = 0; i < list.Count; i++)
                                {
                                    DirectoryInfo[] di_num = new DirectoryInfo(expand.path + "\\" + di[i]).GetDirectories();
                                    list_num.Add(di_num.Length);
                                }
                                expand.dir_num = list_num;

                                List <string> dir_date = new List <string>();
                                for (int i = 0; i < di.Length; i++)
                                {
                                    dir_date.Add(di[i].LastWriteTime.ToString());
                                }
                                expand.dir_date = dir_date;

                                Packet.Serialize(expand).CopyTo(this.sendBuffer, 0);
                                this.Send();
                            }));
                    }
                    break;

                    case (int)PacketType.상세정보서버:
                    {
                        this.m_detailsClass = (Details_toServer)Packet.Desserialize(this.readBuffer);
                        this.Invoke(new MethodInvoker(delegate()
                            {
                                if (this.m_detailsClass.tag != "D")
                                {
                                    Details_toClient details = new Details_toClient();
                                    details.Type             = (int)PacketType.상세정보손님;
                                    details.path             = m_detailsClass.name;
                                    //public FileInformation(string fileInfo, string structure, string path, int size, string date, string modify_date, string access_date)
                                    string[] name     = details.path.Split('\\');       //이름
                                    details.fileInfo  = name[name.Length - 1];          //이름
                                    details.structure = details.fileInfo.Split('.')[1]; //형식
                                    FileInfo di       = new FileInfo(details.fileInfo); //파일의 정보가져오기
                                    details.size      = di.Length;                      //파일의 크기

                                    details.date        = di.CreationTime.ToString();   //만든 날짜
                                    details.modify_date = di.LastWriteTime.ToString();  //마지막으로 수정한 날짜
                                    details.access_date = di.LastAccessTime.ToString(); //마지막으로 접근한 날짜

                                    Packet.Serialize(details).CopyTo(this.sendBuffer, 0);
                                    this.Send();

                                    this.txt_server_state.AppendText("상세정보 데이터 요청.." + "\r\n");
                                }
                            }));
                    }
                    break;
                    }
                }
            }
        }