using System; using System.Collections.Generic; using System.Text; using Zhaizj.Framework.Web; using Zhaizj.Framework.Drawing; using Zhaizj.Framework.Web.Utils; using Zhaizj.Framework.DI; using Zhaizj.Framework.Members.Interface; namespace Zhaizj.Framework.Members { /// /// 继承自IMember对象的帮助方法,用于logo的保存,缩略图路径、皮肤路径等的获取 /// public class MemberHelper { private static Dictionary Types = getMemberTypes(); private static Dictionary getMemberTypes() { Dictionary map = new Dictionary(); foreach (KeyValuePair kv in ObjectContext.Instance.TypeList) { if (rft.IsInterface( kv.Value, typeof( IMember ) ) == false) continue; IMember obj = rft.GetInstance( kv.Value ) as IMember; map.Add( kv.Value, obj.GetUrl() ); } return map; } public static Dictionary GetMemberTypes() { return MemberHelper.Types; } private int _logoWidth = 120; private int _logoHeight = 120; private String _picExt = ".jpg"; /// /// logo的宽度,默认是120px /// public int LogoWidth { get { return _logoWidth; } set { _logoWidth = value; } } /// /// logo的高度,默认是120px /// public int LogoHeight { get { return _logoHeight; } set { _logoHeight = value; } } /// /// logo图片的后缀名,包括点号,默认是.jpg /// public String PicExt { get { return _picExt; } set { _picExt = value; } } protected String memberPath { get; set; } public String GetLogoOriginal( String relativeUrl ) { relativeUrl = processEmptyLogo( relativeUrl ); return Zhaizj.Framework.Drawing.Img.GetOriginalPath( LogoPath + relativeUrl ); } public String GetLogoThumb( String relativeUrl ) { return GetLogoThumb( relativeUrl, ThumbnailType.Small ); } public String GetLogoThumb( String relativeUrl, ThumbnailType ttype ) { String original = GetLogoOriginal( relativeUrl ); return Zhaizj.Framework.Drawing.Img.GetThumbPath( original, ttype ); } private String LogoPath { get { return strUtil.Join( sys.Path.Upload, memberPath + "/" ); } } private String LogoDiskPath { get { return strUtil.Join( sys.Path.DiskUpload, memberPath + "/" ); } } public String SkinDiskPath { get { return strUtil.Join( sys.Path.DiskStatic, "skin/" + memberPath + "/" ); } } public Result SaveLogo( HttpFile afile, String url ) { return Uploader.SaveImg( this.LogoDiskPath, afile, url, this.LogoWidth, this.LogoHeight ); } //------------------------------------------------------ private String processEmptyLogo( String relativeUrl ) { if (strUtil.IsNullOrEmpty( relativeUrl )) return logoPicName; return relativeUrl; } private String logoPicName { get { return memberPath + this.PicExt; } } public String SkinPath { get { return strUtil.Join( sys.Path.Skin, memberPath + "/" ); } } } }