コード例 #1
0
        public static void DownloadFile(Packet packet)
        {
            Packet sendPacket;

            try
            {
                string[] splited = packet.Argument.Split(char.Parse("|"));
                Project  project = new Project(splited[0]);
                string   path    = splited[1];
                ConsoleUtils.Print(string.Format("[{0}]'s Request: Download file from project {1} [{2}]", packet.ClientIP, project.ProjectName, packet.Username));

                FileStoreHelper.DownloadFile(project.FullPath + path, packet.Stream);

                sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Success, packet.Token);
                packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length);
                ConsoleUtils.Print(string.Format("[{0}]'s Request: Download file success: {1} [{2}]", packet.ClientIP, path.Substring(path.LastIndexOf(char.Parse("/"))), packet.Username));
            }
            catch (Exception e)
            {
                ConsoleUtils.Print(string.Format("Download File Error: [{0}] {1}", e.GetType().ToString(), e.Message));
                sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Failure, packet.Token);
                packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length);
                return;
            }
        }