Esempio n. 1
0
        //public string GetAvatarUrl(UserAvatarType type, int userID, string fileProfix, bool isChcech)
        //{
        //    if (StringUtil.StartsWith(fileProfix, '~'))
        //    {
        //        //int index = fileProfix.LastIndexOf("/");

        //        return fileProfix.Replace("{size}", type.ToString());
        //    }

        //    string url;

        //    GetAvatarPathAndUrl(type, userID, fileProfix, isChcech, false, false, out url);
        //    return url;
        //}

        //public string GetAvatarPhysicalPath(UserAvatarType type, int userID, string fileProfix, bool isChcech)
        //{
        //    string url;
        //    return GetAvatarPathAndUrl(type, userID, fileProfix, isChcech, true, true, out url);
        //}

        //public string GetAvatarPath(UserAvatarType type, int userID, string fileProfix, bool isCheched, out string virtualPath)
        //{
        //    return GetAvatarPathAndUrl(type, userID, fileProfix, isCheched, false, true, out virtualPath);
        //}

        //private string GetAvatarPathAndUrl(UserAvatarType type, int userID, string fileProfix, bool isCheched, bool createDirectory, bool getPhysicsPath, out string virtualPath)
        //{
        //    if (fileProfix.Length > 4)
        //    {
        //        virtualPath = string.Empty;
        //        return string.Empty;
        //    }

        //    if (string.IsNullOrEmpty(fileProfix))
        //    {
        //        fileProfix = ".jpg";
        //    }
        //    else
        //    {
        //        if (!StringUtil.StartsWith(fileProfix, '.'))
        //        {
        //            fileProfix = "." + fileProfix;
        //        }
        //    }

        //    string fileName = userID + fileProfix;
        //    string pathLevel = GetUserAvatarPathLevel(userID);

        //    string temp1 = IOUtil.JoinPath(isCheched ? string.Empty : Consts.User_UncheckAvatarSuffix, type.ToString(), pathLevel);

        //    virtualPath = UrlUtil.JoinUrl(Globals.GetRelativeUrl(SystemDirecotry.Upload_Avatar), temp1, fileName);

        //    if (getPhysicsPath || createDirectory)
        //    {
        //        string dir = IOUtil.JoinPath(Globals.GetPath(SystemDirecotry.Upload_Avatar), temp1);
        //        if (createDirectory) IOUtil.CreateDirectory(dir);

        //        if (getPhysicsPath) return IOUtil.JoinPath(dir, fileName);
        //    }

        //    return string.Empty;
        //}

        /// <summary>
        /// 验证用户临时头像
        /// </summary>
        /// <param name="operatorUserID"></param>
        /// <param name="targetUserIds"></param>
        /// <param name="isChecked"></param>
        public void CheckUserAvatar(AuthUser operatorUser, IEnumerable <int> targetUserIds, bool isChecked)
        {
            if (!CanAvatarCheck(operatorUser))
            {
                ThrowError(new NoPermissionEditUserProfileError());
                return;
            }

            UserTempAvatarCollection tempAvatarDatas = UserTempAvatarDao.Instance.GetUserTempAvatars(targetUserIds);
            string defaultDir = GetAvatarSizeDirectoryName(UserAvatarSize.Default);
            string bigDir     = GetAvatarSizeDirectoryName(UserAvatarSize.Big);
            string smallDir   = GetAvatarSizeDirectoryName(UserAvatarSize.Small);

            foreach (UserTempAvatar ta in tempAvatarDatas)
            {
#if !DEBUG
                try
                {
#endif
                if (isChecked)//审核通过
                {
                    if (!string.IsNullOrEmpty(ta.CurrentAvatar))
                    {
                        IOUtil.DeleteFile(GetAvatarPhysicalPath(ta.UserID, UserAvatarSize.Small, ta.CurrentAvatar));
                        IOUtil.DeleteFile(GetAvatarPhysicalPath(ta.UserID, UserAvatarSize.Default, ta.CurrentAvatar));
                        IOUtil.DeleteFile(GetAvatarPhysicalPath(ta.UserID, UserAvatarSize.Big, ta.CurrentAvatar));
                    }

                    string newFileType  = Path.GetExtension(ta.TempAvatar);
                    string newAvatarSrc = GetAvatarLevel(ta.UserID, "/", newFileType);
                    string newFilePath  = Globals.GetPath(SystemDirecotry.Upload_Avatar, "{0}", newAvatarSrc);


                    IOUtil.MoveFile(IOUtil.MapPath(string.Format(ta.TempAvatar, smallDir))
                                    , string.Format(newFilePath, smallDir));

                    IOUtil.MoveFile(IOUtil.MapPath(string.Format(ta.TempAvatar, defaultDir))
                                    , string.Format(newFilePath, defaultDir));

                    IOUtil.MoveFile(IOUtil.MapPath(string.Format(ta.TempAvatar, bigDir))
                                    , string.Format(newFilePath, bigDir));

                    User u = UserBO.Instance.GetUser(ta.UserID);
                    u.AvatarSrc = newAvatarSrc;
                    if (OnUserAvatarChanged != null)
                    {
                        OnUserAvatarChanged(u.UserID, u.AvatarSrc, u.SmallAvatarPath, u.AvatarPath, u.BigAvatarPath);
                    }
                    UserDao.Instance.UpdateAvatar(u.UserID, u.AvatarPropFlag.GetStringForSave(), true);
                }
                else //未审核通过
                {
                    IOUtil.DeleteFile(IOUtil.MapPath(string.Format(ta.TempAvatar, defaultDir)));
                    IOUtil.DeleteFile(IOUtil.MapPath(string.Format(ta.TempAvatar, bigDir)));
                    IOUtil.DeleteFile(IOUtil.MapPath(string.Format(ta.TempAvatar, smallDir)));
                }
#if !DEBUG
            }
            catch
            {
            }
#endif
            }
            UserTempDataBO.Instance.Delete(targetUserIds, UserTempDataType.Avatar);
        }