示例#1
0
        public byte[] Get_local_File_info(string PATH)
        {
            DirectoryInfo dir = new DirectoryInfo(PATH);

            FileSystemInfo[] fsinfos = dir.GetFileSystemInfos();
            SocketTCPClient  t1      = new SocketTCPClient();

            List <file_info_json_pull> file_json = new List <file_info_json_pull>();

            //  traverse files and dirs
            int level = 0;

            listDirectory(PATH, PATH, level, file_json);

            /**
             * json file_info demo
             *
             *  [
             *      {
             *          "Name":"1.txt",
             *          "Typ":1,
             *          "Digest":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
             *      },
             *      {
             *          "Name":"2.txt",
             *          "Typ":1,
             *          "Digest":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
             *      }
             *  ]
             *
             **/

            // Json serialize
            string MsgBody_str = JsonConvert.SerializeObject(file_json);

            byte[] MsgBody = System.Text.Encoding.Default.GetBytes(MsgBody_str);
            // encapsulate packets
            byte[] MessageBodyByte = new byte[MsgBody.Length + 30];
            MessageBodyByte = t1.BuildDataPackage_For_Pull(MsgBody, 0x2, Device_id);

            return(MessageBodyByte);
        }
示例#2
0
        private string send_data_rev_data()
        {
            SocketTCPClient t1 = new SocketTCPClient();

            string testdata = null;

            /**
             * json file_info demo
             *
             *  [
             *      {
             *          "Name":"1.txt",
             *          "Typ":1,
             *          "Digest":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
             *      },
             *      {
             *          "Name":"2.txt",
             *          "Typ":1,
             *          "Digest":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
             *      }
             *  ]
             *
             **/
            // for text md5 = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]


            // convert to json list
            // Typ = 0x1 => file
            // Typ = 0x2 => Directory

            byte[] md11 = t1.HexStrTobyte(t1.GetMD5HashFromFile("F:\\fortest\\1.txt"));
            byte[] md22 = t1.HexStrTobyte(t1.GetMD5HashFromFile("F:\\fortest\\2.txt"));

            List <byte> file_1_md5 = new List <byte>();

            for (int i = 0; i < 16; i++)
            {
                file_1_md5.Add(md11[i]);
            }

            List <byte> file_2_md5 = new List <byte>();

            for (int i = 0; i < 16; i++)
            {
                file_1_md5.Add(md22[i]);
            }


            List <file_info_json> testdemo = new List <file_info_json>()
            {
                new file_info_json()
                {
                    Name   = "1.txt",
                    Typ    = 0x1,
                    Digest = file_1_md5
                },

                new file_info_json()
                {
                    Name   = "2.txt",
                    Typ    = 0x1,
                    Digest = file_2_md5
                }
            };

            // Json serialize
            testdata = JsonConvert.SerializeObject(testdemo);

            t1.CreateInstance();

            //byte[] test = t1.HexStrTobyte(testdata);

            byte[] test            = System.Text.Encoding.Default.GetBytes(testdata);
            byte[] MessageBodyByte = new byte[test.Length + 30];

            MessageBodyByte = t1.BuildDataPackage_For_Pull(test, 0x2, Device_id);


            t1.SendMessage(MessageBodyByte);
            byte[] result = t1.ReceiveMessage();

            List <string> file_name = t1.Check_If_Upload(result);

            string status_file = null;

            if (file_name.Count != 0)
            {
                status_file = t1.Upload_File(file_name);
            }

            // string result_str = System.Text.Encoding.Default.GetString(result);
            // fortest.Text = result_str;


            // test for download
            byte[] test_for_download            = null;
            byte[] MessageBodyByte_for_download = new byte[30];
            MessageBodyByte_for_download = t1.BuildDataPackage_For_Pull(test_for_download, 0x21, Device_id);
            t1.SendMessage(MessageBodyByte_for_download);

            string str_status_1 = t1.ReceiveMessage_For_download();
            string str_status_2 = t1.ReceiveMessage_For_download();

            return(status_file + " + " + str_status_1 + " + " + str_status_2);
        }