Пример #1
0
        /// <summary>
        /// 获取商品相册图片的储存文件
        /// </summary>
        /// <param name="id">商品Id</param>
        /// <param name="index">图片序号,null时返回主图的路径</param>
        /// <param name="type">商品相册的图片类型,原图或缩略图等</param>
        /// <returns></returns>
        public virtual IFileEntry GetAlbumImageStorageFile(
            Guid id, long?index, ProductAlbumImageType type)
        {
            var fileStorage = Application.Ioc.Resolve <IFileStorage>();
            var indexString = index.HasValue ? index.Value.ToString() : "main";
            var suffix      = type.GetAttribute <ProductAlbumImageSuffixAttribute>().Suffix;
            var path        = string.Format(AlbumImagePathFormat, id, indexString, suffix);

            return(fileStorage.GetStorageFile(path.Split('/').Skip(1).ToArray()));
        }
        /// <summary>
        /// 获取商品相册图片的储存路径,路径不一定存在
        /// </summary>
        /// <param name="id">商品Id</param>
        /// <param name="index">图片序号,null时返回主图的路径</param>
        /// <param name="type">商品相册的图片类型,原图或缩略图等</param>
        /// <returns></returns>
        public virtual string GetAlbumImageStoragePath(
            long id, long?index, ProductAlbumImageType type)
        {
            var pathManager = Application.Ioc.Resolve <PathManager>();
            var indexString = index.HasValue ? index.Value.ToString() : "main";
            var suffix      = type.GetAttribute <ProductAlbumImageSuffixAttribute>().Suffix;
            var path        = string.Format(AlbumImagePathFormat, id, indexString, suffix);

            return(pathManager.GetStorageFullPath(path.Split('/').Skip(1).ToArray()));
        }
Пример #3
0
        /// <summary>
        /// 获取商品相册图片的网页路径,不存在时返回默认路径
        /// </summary>
        /// <param name="id">商品Id</param>
        /// <param name="index">图片序号,null时返回主图的路径</param>
        /// <param name="type">商品相册的图片类型,原图或缩略图等</param>
        /// <param name="defaultPath">不存在时返回的默认路径</param>
        /// <returns></returns>
        public virtual string GetAlbumImageWebPath(
            Guid id, long?index, ProductAlbumImageType type, string defaultPath = DefaultAlbumImagePath)
        {
            var storageFile = GetAlbumImageStorageFile(id, index, type);

            if (!storageFile.Exists)
            {
                return(defaultPath);
            }
            var indexString = index.HasValue ? index.Value.ToString() : "main";
            var suffix      = type.GetAttribute <ProductAlbumImageSuffixAttribute>().Suffix;
            var webPath     = string.Format(AlbumImagePathFormat, id, indexString, suffix);

            webPath += "?mtime=" + storageFile.LastWriteTimeUtc.Ticks;
            return(webPath);
        }
        /// <summary>
        /// 获取商品相册图片的网页路径,不存在时返回默认路径
        /// </summary>
        /// <param name="id">商品Id</param>
        /// <param name="index">图片序号,null时返回主图的路径</param>
        /// <param name="type">商品相册的图片类型,原图或缩略图等</param>
        /// <param name="defaultPath">不存在时返回的默认路径</param>
        /// <returns></returns>
        public virtual string GetAlbumImageWebPath(
            long id, long?index, ProductAlbumImageType type, string defaultPath = DefaultAlbumImagePath)
        {
            var storagePath     = GetAlbumImageStoragePath(id, index, type);
            var storagePathInfo = new FileInfo(storagePath);

            if (!storagePathInfo.Exists)
            {
                return(defaultPath);
            }
            var pathManager = Application.Ioc.Resolve <PathManager>();
            var indexString = index.HasValue ? index.Value.ToString() : "main";
            var suffix      = type.GetAttribute <ProductAlbumImageSuffixAttribute>().Suffix;
            var webPath     = string.Format(AlbumImagePathFormat, id, indexString, suffix);

            webPath += "?mtime=" + storagePathInfo.LastWriteTimeUtc.Ticks;
            return(webPath);
        }