/// <summary>
        /// 下载文件
        /// </summary>
        /// <param name="dlfile"></param>
        /// <returns></returns>
        public DlFileResult DownLoadFile(DlFile dlfile)
        {
            string path = FileProcessingHelper.GetUpLoadFilePath() + dlfile.ProjectName + "\\" + dlfile.FileName;

            if (!File.Exists(path))
            {
                var result = new DlFileResult();
                result.Size       = 0;
                result.IsSuccess  = false;
                result.Message    = "";
                result.FileStream = new MemoryStream();
                return(result);
            }
            DlFileResult file = new DlFileResult();

            file.FileStream = new MemoryStream();
            Stream     ms = new MemoryStream();
            FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);

            fs.CopyTo(ms);
            ms.Position     = 0;
            file.Size       = ms.Length;
            file.FileStream = ms;
            file.IsSuccess  = true;
            fs.Flush();
            fs.Close();
            return(file);
        }
Beispiel #2
0
        //public bool SetApplicationInfo(ApplicationInfo appInfo)
        //{
        //    var currentAppEntity = FileProcessingHelper.GetFiles(appInfo.AppPath);
        //    writeTxt("apppath:"+appInfo.AppPath+"1111");
        //    if (currentAppEntity != null && currentAppEntity.MDir != null)
        //    {
        //        currentAppEntity.AppName = appInfo.AppName;
        //        currentAppEntity.AppVersion = appInfo.AppVersion;
        //        if (AppList == null)
        //            AppList = new List<ApplicationEntity>();
        //        AppList.Add(currentAppEntity);
        //        return true;
        //    }
        //    return false;
        //}

        /// <summary>
        /// 下载文件
        /// </summary>
        /// <param name="dlfile"></param>
        /// <returns></returns>
        public DlFileResult DownLoadFile(DlFile dlfile)
        {
            string       path = FileProcessingHelper.GetUpLoadFilePath() + dlfile.ProjectName + "\\" + dlfile.FileName;
            DlFileResult file = new DlFileResult();

            try
            {
                if (!File.Exists(path))
                {
                    var result = new DlFileResult();
                    result.Size       = 0;
                    result.IsSuccess  = false;
                    result.Message    = "";
                    result.FileStream = new MemoryStream();
                    return(result);
                }
                file.FileStream = new MemoryStream();
                Stream     ms = new MemoryStream();
                FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
                fs.CopyTo(ms);
                ms.Position     = 0;
                file.Size       = ms.Length;
                file.FileStream = ms;
                file.IsSuccess  = true;
                fs.Flush();
                fs.Close();
            }
            catch (Exception ex)
            {
                MyLog4NetInfo.ErrorInfo(string.Format("下载文件报错,文件名称:{0},错误消息:{1},错误堆栈{2},错误实例{3}", dlfile.FileName, ex.Message, ex.StackTrace, ex.InnerException));
                throw;
            }
            return(file);
        }