Exemplo n.º 1
0
        private FileDownloadResponse InitResponse(int code, string fileName, byte[] buffer)
        {
            FileDownloadResponse response = new FileDownloadResponse();
            response.ret = code;
            response.message = ErrorCodeDic.GetInstance().CodeMessage(code);
            response.File_name = fileName;
            response.File_buffer = buffer;

            return response;
        }
Exemplo n.º 2
0
        /// <summary>
        /// 文件二进制流下载
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public object Post(FileDownloadRequest request)
        {
            int code = (int)FS_ErrorCode.Request_Success;

            if (string.IsNullOrEmpty(request.file_guid))
            {
                code = (int)FS_ErrorCode.RequestParam_Err;
                return new FileDownloadResponse { ret = code, message = ErrorCodeDic.GetInstance().CodeMessage(code), File_name = string.Empty, File_buffer = null };
            }

            FileDownloadResponse response = new FileDownloadResponse();
            try
            {
                ICommonFilesService fileSvr = new CommonFilesService();
                response = fileSvr.FileDownload(request.file_guid);
            }
            catch (Exception e)
            {
                string err = string.Format("CommonFileServiceHost.FileDownloadRequest error = {0}, request = {1}", e.ToString(), JsonUtil<FileDownloadRequest>.ToJson(request));
                LogUtil.Error(err);
            }

            return response;
        }
Exemplo n.º 3
0
        public FileDownloadResponse FileDownload(string file_guid)
        {
            FileDownloadResponse response = new FileDownloadResponse();
            try
            {
                // 根据FileGuid 查询FilePath
                FileEntity entity = fileDA_R.GetFileEntityByGuid(file_guid);
                if (entity == null)
                {
                    return InitResponse((int)FS_ErrorCode.DB_FilePath_Null, string.Empty, null);
                }

                string filePath = entity.file_path;
                Stopwatch watch = new Stopwatch();
                watch.Start();
                FSManager.DownloadFile(filePath, (ex, fileBufferOnFDFS) =>
                {
                    if (null != ex)
                    {
                        LogUtil.Error(string.Format("Error in FSManager.DownloadFile callback: {0}", ex.ToString()));
                        response = InitResponse(errorCode,entity.file_full_name, null);
                        errorCode = (int)FS_ErrorCode.Download_err;
                        response.File_buffer = null;
                        response.ret = errorCode;
                        response.message = ErrorCodeDic.GetInstance().CodeMessage(errorCode);
                        return;
                    }

                    response = InitResponse(errorCode, entity.file_full_name, fileBufferOnFDFS);

                    watch.Stop();
                    string info = string.Format("sync download at server(ProcessId = {0}, ThreadId = {1}, CurrTheadsNum = {2}): file_guid = {3}, file_full_name = {4}, file_path = {5},"
                                + " file_md5 = {6}, file_size = {7}, invoking time = {8}ms", Process.GetCurrentProcess().Id, Thread.CurrentThread.ManagedThreadId, Process.GetCurrentProcess().Threads.Count, file_guid, entity.file_full_name, entity.file_path, entity.file_md5, entity.file_size, watch.ElapsedMilliseconds);
                    LogUtil.Info(info);
                });
            }
            catch (Exception ex)
            {
                LogUtil.Error(string.Format("Exception FSService.Post(FileDownloadRequest): {0}", ex.ToString()));
                errorCode = (int)FS_ErrorCode.Download_err;

                response = InitResponse(errorCode, string.Empty, null);
            }

            return response;
        }