예제 #1
0
파일: Avatar.cs 프로젝트: xiongeee/BBX
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            AvatarSize avatarSize;

            switch (DNTRequest.GetString("size").ToLower())
            {
            case "large":
                avatarSize = AvatarSize.Large;
                break;

            case "medium":
                avatarSize = AvatarSize.Medium;
                break;

            case "small":
                avatarSize = AvatarSize.Small;
                break;

            default:
                avatarSize = AvatarSize.Medium;
                break;
            }

            var uid = DNTRequest.GetInt("uid");

            // 如果物理文件存在,直接返回
            var fi = Avatars.GetPhysicsAvatarPath(uid + "", avatarSize);

            // 如果没有缓存,文件也不在,那么直接返回默认
            if (!File.Exists(fi))
            {
                fi = Utils.GetMapPath(BaseConfigs.GetForumPath.CombinePath("avatars/avatar_" + avatarSize.ToString().ToLower() + ".jpg"));
            }
            if (File.Exists(fi))
            {
                var ci = GetData(fi);

                // 检查缓存是否有效
                var wd = new WebDownload();
                wd.BrowserCache = true;
                wd.ModifyTime   = ci.ModifyTime;
                if (wd.CheckCache())
                {
                    return;
                }

                wd.Stream = new MemoryStream(ci.Data);
                //wd.Mode = WebDownload.DispositionMode.Inline;
                wd.ContentType = "image/" + Path.GetExtension(fi).TrimStart('.');

                // 启用浏览器缓存
                wd.BrowserCache = true;

                wd.Speed = 0;
                wd.Render();

                return;
            }

            //var avatarUrl = Avatars.GetAvatarUrl(uid + "", avatarSize);
            //XTrace.WriteLine("头像{0}未取到,跳转地址 {1}", fi, avatarUrl);
            //HttpContext.Current.Response.Redirect(avatarUrl);
        }