Esempio n. 1
0
        /// <summary>
        /// 从本地获取预览文件
        /// </summary>
        /// <param name="softData"></param>
        /// <param name="previewDataResult"></param>
        /// <returns></returns>
        private bool GetPreViewDataFromLocal(SoftData softData, out PreViewResult previewDataResult)
        {
            previewDataResult = new PreViewResult {
                PreViewAddresses = new List <string>()
            };
            var localDir = ConvertToLocalDir(softData);

            if (Directory.Exists(localDir))
            {
                var files = Directory.GetFiles(localDir);
                previewDataResult.PreViewAddresses = files;                 // TODO 将物理路径转换为虚拟路径
            }
            return(previewDataResult.PreViewAddresses.Count > 0);
        }
Esempio n. 2
0
        /// <summary>
        /// 预览处理
        /// </summary>
        /// <param name="softData"></param>
        /// <returns></returns>
        public IHttpActionResult Get(SoftData softData)
        {
            PreViewResult preViewResult;

            // 从本地缓存获取
            if (!GetPreViewDataFromLocal(softData, out preViewResult))
            {
                // 从OSS上获取文件放到本地缓存
                if (GetPreViewDataFromOss(softData.SoftAddress))
                {
                    // 从本地缓存获取
                    if (!GetPreViewDataFromLocal(softData, out preViewResult))
                    {
                        // TODO 打日志 - 从oss获取文件成功, 但是本地找不到
                    }
                }
                else
                {
                    // todo 打日志 - 从oss获取文件失败
                }
            }
            return(Json(preViewResult));
        }
Esempio n. 3
0
        /// <summary>
        /// 将数据库地址转换为本地地址
        /// </summary>
        /// <param name="softAddress">数据库地址</param>
        /// <remarks>何士雄 2016-06-15</remarks>
        /// <returns></returns>
        private string ConvertToLocalDir(SoftData softData)
        {
            var match = Regex.Match(softData.SoftAddress, "{%.+?%}(?<address>.+?)\\..+?$");

            return(match.Success ? HttpContext.Current.Server.MapPath(match.Result("${address}") + "/") : "");
        }