예제 #1
0
파일: PhotoManager.cs 프로젝트: dkme/moooyo
        /// <summary>
        /// 审核图片不可访问
        /// </summary>
        /// <param name="photoID"></param>
        /// <returns></returns>
        public static CBB.ExceptionHelper.OperationResult BindedPhoto(String photoID)
        {
            try
            {
                MongoDatabase md = MongoDBHelper.MongoDB;
                MongoCollection<Photo> mc = md.GetCollection<Photo>("Photos");
                IMongoQuery qc = Query.And(Query.EQ("_id", ObjectId.Parse(photoID)));

                Photo photo = PhotoManager.GetPhoto(photoID);

                String ReplacePic = "";
                if (photo.PhotoType == PhotoType.MemberAvatar)
                {
                    ReplacePic = CBB.ConfigurationHelper.AppSettingHelper.GetConfig("MemberAvatarIsNotPassAuditReplacePic");
                    //更改用户头像
                    BiZ.Member.ModifyPicturePath.ModifyPicturePathHandler modiPicPathHand =
                        new BiZ.Member.ModifyPicturePath.ModifyPicturePathHandler();
                    modiPicPathHand.MemberId = photo.MemberID;
                    modiPicPathHand.PictureId = "";
                    modiPicPathHand.PicturePath = ReplacePic;
                    //替换审核不通过的图片
                    modiPicPathHand.OldPicturePath = photo.FileName;
                    modiPicPathHand.ModifyPicPathEvent +=
                        new BiZ.Member.ModifyPicturePath.ModifyPicturePathHandler.ModifyPicPathEventHandler(
                            new BiZ.Member.ModifyPicturePath.ModifyPicturePathProvider().ModifyMemberAvatarPicPath
                            ); //注册方法
                    modiPicPathHand.ModifyPicPath(); //自动调用注册过对象的方法
                    BiZ.MemberManager.MemberManager.RemoveMemberToNew(photo.MemberID);//从新用户列表中删除
                }
                else  if (photo.PhotoType== PhotoType.ImageContentPhoto || photo.PhotoType== PhotoType.SuoSuoContentPhoto || photo.PhotoType== PhotoType.CallForContentPhoto)
                {
                    ReplacePic = CBB.ConfigurationHelper.AppSettingHelper.GetConfig("PhotoIsNotPassAuditReplacePic");
                    //删除内容
                    BiZ.Content.ContentProvider.RemoveContentWhereHasImage(photo.MemberID, photo.FileName);
                }

                DeletePhoto(photo.ID);
                return new CBB.ExceptionHelper.OperationResult(true);
            }
            catch (CBB.ExceptionHelper.OperationException err)
            {
                throw new CBB.ExceptionHelper.OperationException(
                    CBB.ExceptionHelper.ErrType.SystemErr,
                    CBB.ExceptionHelper.ErrNo.DBOperationError,
                    err);
            }
        }
예제 #2
0
        /// <summary>
        /// 剪裁图片
        /// </summary>
        /// <param name="memberID">用户编号</param>
        /// <param name="x">剪裁区域X坐标</param>
        /// <param name="y">剪裁区域Y坐标</param>
        /// <param name="w">剪裁区域宽</param>
        /// <param name="h">剪裁区域高</param>
        /// <param name="uploadPhoto">图片名称</param>
        /// <param name="phototype">图片类型</param>
        /// <param name="skintype">用户皮肤类型</param>
        /// <param name="photoRelativePath">图片虚拟路径</param>
        /// <returns>操作状态</returns>
        private String CustomPicture(
            String memberID, String x, String y, String w, String h, String uploadPhoto,
            String phototype, String skintype, String photoRelativePath
            //, String contentId
            )
        {
            CBB.ExceptionHelper.OperationResult result = null;
            Moooyo.BiZ.Photo.Photo myp = new BiZ.Photo.Photo();
            ViewData["photoRelativePath"] = photoRelativePath != null ? photoRelativePath : "";
            ViewData["phototype"] = phototype;
            ViewData["skinType"] = skintype;

            if (x != null && y != null && w != null && h != null && uploadPhoto != null && phototype != null)
            {
                int photType = Convert.ToInt32(phototype);

                int xCoord = int.Parse(x);
                int yCoord = int.Parse(y);
                int width = int.Parse(w);
                int height = int.Parse(h);
                //裁图并保存图片
                String photoPath = CropImage(uploadPhoto, width, height, xCoord, yCoord, memberID);
                if (photoPath == "error")
                {
                    //return new CBB.ExceptionHelper.OperationResult(false, "图片有误");
                    return "";
                }

                //uploadPhoto = uploadPhoto.Replace("original", "modifiedsize");
                String strPhotoPath = System.Web.Hosting.HostingEnvironment.MapPath(photoPath);
                //用文件流的方式打开该张图片
                System.IO.FileStream tfs = System.IO.File.Open(strPhotoPath, System.IO.FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

                String strRelativePath = "/temp_up_file/";
                int strRelativePathLength = strRelativePath.Length;
                UpController upControl = new UpController();

                //保存图片数据到数据库
                myp = upControl.SavePhoto(memberID, Convert.ToInt32(phototype), tfs, photoPath.Substring(strRelativePathLength, photoPath.Length - strRelativePathLength));
                //图片类型是用户头像类型
                if (photType == 1)
                {
                    BiZ.Member.ModifyPicturePath.ModifyPicturePathHandler modiPicPathHand =
                        new BiZ.Member.ModifyPicturePath.ModifyPicturePathHandler();
                    modiPicPathHand.MemberId = memberID;
                    modiPicPathHand.PictureId = myp.ID;
                    modiPicPathHand.PicturePath = myp.FileName;
                    modiPicPathHand.ModifyPicPathEvent +=
                        new BiZ.Member.ModifyPicturePath.ModifyPicturePathHandler.ModifyPicPathEventHandler(
                            new BiZ.Member.ModifyPicturePath.ModifyPicturePathProvider().ModifyMemberAvatarPicPath
                            ); //注册方法
                    modiPicPathHand.ModifyPicPath(); //自动调用注册过对象的方法

                    //同步发布说说
                    IList<BiZ.InterestCenter.Interest> interestList = BiZ.InterestCenter.InterestFactory.GetMemberInterest(memberID, 0, 0);
                    String interestIds = "";
                    if (interestList != null)
                    {
                        foreach (BiZ.InterestCenter.Interest interest in interestList)
                        {
                            interestIds += interest.ID + ",";
                        }
                    }
                    String userID = memberID, permissions = "0", interestids = interestIds, lat = "0", lng = "0", type = "修改个人头像";
                    BiZ.Content.MemberContent imageContent = null;
                    if (userID != "" && permissions != "" && interestids != "" && lat != "" && lng != "" && type != "")
                    {
                        //创建兴趣操作内容对象
                        imageContent = new BiZ.Content.MemberContent(userID, ContentController.getContentPerMissions(permissions), interestids.Split(',').ToList(), Double.Parse(lat), Double.Parse(lng), type);
                        //保存兴趣操作内容对象
                        imageContent = imageContent.Save(imageContent);
                        //判断是否是新用户
                        Boolean ifnewmember = BiZ.MemberManager.MemberManager.getMemberToNew(userID) != null ? false : true;
                        if (ifnewmember)
                        {
                            BiZ.Member.MemberToNew newmember = new BiZ.Member.MemberToNew(userID, imageContent.ID, BiZ.Member.MemberToNewType.ImageContent);
                            newmember.Save(newmember);
                        }
                    }

                    BiZ.Member.Member member = BiZ.MemberManager.MemberManager.GetMember(memberID);

                    //增加动态
                    BiZ.Member.Activity.ActivityController.AddActivity(
                        memberID,
                        BiZ.Member.Activity.ActivityType.SetICON,
                        BiZ.Member.Activity.ActivityController.GetActivityContent_SetICON_Title(),
                        BiZ.Member.Activity.ActivityController.GetActivityContent_SetICON(member),
                        true);

                    //增加用户动态到后台
                    string operateUrl = "";
                    if (member.UniqueNumber != null)
                        operateUrl = "/u/" + member.UniqueNumber.ConvertedID;
                    else
                        operateUrl = "/Content/TaContent/" + member.ID;
                    BiZ.Sys.MemberActivity.MemberActivityProvider.CreateMemberActivity(
                        member.ID,
                        "",
                        BiZ.Sys.MemberActivity.MemberActivityType.UploadAvatar,
                        operateUrl);

                    string filename = UploadPictureToTemporary(memberID, member.MemberInfomation.IconPath);
                    Session["shareWeiBoImage"] = filename;

                    ////上传头像分享到外部平台
                    //string bindedPlatforms = Models.DisplayObjProvider.MemberBindingPlatform(member.ID);
                    //MicroConnController mcc = new MicroConnController();
                    //mcc.PlatformShareInfo(
                    //    member.ID,
                    //    bindedPlatforms,
                    //    member.MemberInfomation.NickName,
                    //    Server.MapPath(strPhotoPath.Replace("modifiedsize", "original")),
                    //    "/Content/ContentDetail/" + imageContent.ID
                    //    );

                }
                ////图片类型内容图片
                //if (photType >= 201 && photType <= 203 && contentId != null)
                //{
                //    List<BiZ.Content.Image> listImage = new List<BiZ.Content.Image>();
                //    BiZ.Content.Image image = new BiZ.Content.Image(myp.FileName);
                //    listImage.Add(image);
                //    BiZ.TopImagePush.ImagePush imagePush = new BiZ.TopImagePush.ImagePush(contentId, memberID, listImage,
                //}

                //构造源图片成FileInfo对象
                System.IO.FileInfo fileOriginalPhoto = new System.IO.FileInfo(strPhotoPath.Replace("modifiedsize", "original"));
                tfs.Dispose();
                tfs.Close();
                System.GC.Collect(); //强制对所有代码进行即时垃圾回收*(不回收就会被iis进程占用文件)
                //如果文件已存在,则删除
                if (fileOriginalPhoto.Exists) fileOriginalPhoto.Delete(); //删除单个文件(original)

                //{
                //    System.IO.File.Delete(strPhotoPath.Replace("modifiedsize", "original"));
                //}
                System.IO.File.Delete(strPhotoPath); //删除临时文件夹的剪裁后的图片(modifiedsize)

                //设置个性图片
                if (photType == 11 || photType == 12)
                {
                    if (skintype != null && skintype != "")
                    {
                        //设置个性图片
                        AddMemberSkinPicture(memberID, skintype, myp);
                    }
                }
            }

            return myp.ID + "|" + myp.FileName;
        }