Beispiel #1
0
        public override void ProcessCmd(string[] args)
        {
            if (args.Length != 3)
            {
                UnknowCommand();
                return;
            }
            //3.1 创建子文件存放的文件夹
            string fileName       = args[2];
            string remoteFilePath = args[1];

            if (remoteFilePath.EndsWith(".part"))
            {
                string partFileFolder = fileName + ".part";
                if (Directory.Exists(partFileFolder))
                {
                    Directory.Delete(partFileFolder, true);
                }
                Directory.CreateDirectory(partFileFolder);

                List <string> workers = new List <string>(StateHelper.GetChildren("ISE://system/state/worker"));
                for (int i = 0; i < workers.Count; i++)
                {
                    //3.2 通知下载文件
                    string[] ip =
                        workers[i].Substring(workers[i].LastIndexOf('/') + 1,
                                             workers[i].Length - workers[i].LastIndexOf('/') - 1)
                        .Split(',');
                    Framework.Network.Synchronous.Client transfer = new Framework.Network.Synchronous.Client(ip[0],
                                                                                                             int.Parse(ip[1]));
                    ExcutePacket codePacket = new ExcutePacket(Encoding.UTF8.GetBytes(remoteFilePath), string.Empty,
                                                               string.Empty, string.Empty,
                                                               ExcutePacket.Type.Download);
                    codePacket.SetReturnAddress(Dns.GetHostName(), 8800);
                    //1207
                    codePacket.WaiteCallBack = false;
                    transfer.Send <bool>(codePacket);
                    Logger.Info(ip[0] + "," + ip[1] + " has been noticed to send file " + fileName);

                    //3.3 准备接收文件块
                    FileTransfer fileTransfer = new FileTransfer();
                    fileTransfer.Receive(7002, partFileFolder + "/" + i);
                }

                //3.4 合并文件
                FileBlock.Merge(partFileFolder, fileName);
                Directory.Delete(partFileFolder, true);
            }
            else
            {
                List <string> workers = new List <string>(StateHelper.GetChildren("ISE://system/state/worker"));
                string[]      ip      =
                    workers[0].Substring(workers[0].LastIndexOf('/') + 1,
                                         workers[0].Length - workers[0].LastIndexOf('/') - 1)
                    .Split(',');
                Framework.Network.Synchronous.Client transfer = new Framework.Network.Synchronous.Client(ip[0],
                                                                                                         int.Parse(ip[1]));
                ExcutePacket codePacket = new ExcutePacket(Encoding.UTF8.GetBytes(remoteFilePath), string.Empty,
                                                           string.Empty, string.Empty,
                                                           ExcutePacket.Type.Download);
                codePacket.SetReturnAddress(Dns.GetHostName(), 8800);
                //1207
                codePacket.WaiteCallBack = false;
                transfer.Send <bool>(codePacket);
                Logger.Info(ip[0] + "," + ip[1] + " has been noticed to send file " + fileName);
                FileTransfer fileTransfer = new FileTransfer();
                fileTransfer.Receive(7002, fileName);
            }
        }