/// <summary> /// 检查上传的图片是否合法 /// </summary> /// <param name="postedFile"></param> /// <param name="errors"></param> public static void checkUploadPic( HttpFile postedFile, Result errors ) { if (postedFile == null) { errors.Add( lang.get( "exPlsUpload" ) ); return; } // 检查文件大小 if (postedFile.ContentLength <= 1) { errors.Add( lang.get( "exPlsUpload" ) ); return; } int uploadMax = 1024 * 1024 * config.Instance.Site.UploadPicMaxMB; if (postedFile.ContentLength > uploadMax) { errors.Add( lang.get( "exUploadMax" ) + " " + config.Instance.Site.UploadPicMaxMB + " MB" ); return; } // TODO: (flash upload) application/octet-stream //if (postedFile.ContentType.ToLower().IndexOf( "image" ) < 0) { // errors.Add( lang.get( "exPhotoFormatTip" ) ); // return; //} // 检查文件格式 if (Uploader.isAllowedPic( postedFile ) == false) { errors.Add( lang.get( "exUploadType" ) + ":" + postedFile.FileName + "(" + postedFile.ContentType + ")" ); } }
public static Result CheckLogin(String username, String password) { Result result = new Result(); if (string.IsNullOrEmpty(username)) { result.Add("Sorry,管理员账号不能为空"); } else if (string.IsNullOrEmpty(password)) { result.Add("Sorry,管理员密码不能为空"); } else { if (password.Length != 32) { password = Encryptor.Md5Encryptor32(Encryptor.Md5Encryptor32(password)); } System.Xml.XmlNode xn = System.IO.XMLHelper.GetDataOne(PathHelper.Map("~/xcenter/data/wechat/manager.xml"), "Manager", System.IO.XMLHelper.CreateEqualParameter("Username", username)); if (xn == null) { result.Add("Sorry,管理员账号不存在"); } else if (xn.Attributes["Password"].Value != password) { result.Add("Sorry,您输入的密码不正确"); } } return result; }
public Result Delete( int id ) { Result result = new Result(); MessageAttachment attachment = GetById( id ); if (attachment == null) { result.Add( lang.get( "exDataNotFound" ) ); return result; } attachment.delete(); String filePath = strUtil.Join( sys.Path.DiskPhoto, attachment.Url ); String absPath = PathHelper.Map( filePath ); if (file.Exists( absPath )) { try { file.Delete( absPath ); } catch (IOException ex) { logger.Error( ex.ToString() ); result.Add( ex.ToString() ); } } else { result.Add( "文件不存在:" + absPath ); } return result; }
public virtual Result Delete( long id ) { Result result = new Result(); UserFile attachment = GetById( id ); if (attachment == null) { result.Add( lang.get( "exDataNotFound" ) ); return result; } attachment.delete(); countDataCount( attachment ); String filePath = strUtil.Join( sys.Path.DiskPhoto, attachment.PathRelative ); String absPath = PathHelper.Map( filePath ); if (file.Exists( absPath )) { try { file.Delete( absPath ); result.Info = attachment; } catch (IOException ex) { logger.Error( ex.ToString() ); result.Add( ex.ToString() ); } } else { result.Add( "文件不存在:" + absPath ); } return result; }
public virtual Result Buy( int buyerId, int creatorId, ForumTopic topic ) { if (topic == null) throw new ArgumentNullException( "ForumBuyLogService.Buy" ); Result result = new Result(); if (topic.Price <= 0) { result.Add( "topic.price <=0" ); return result; } if (incomeService.HasEnoughKeyIncome( buyerId, topic.Price ) == false) { result.Add( String.Format( alang.get( typeof( ForumApp ), "exIncome" ), KeyCurrency.Instance.Name ) ); return result; } // 购买日志 ForumBuyLog log = new ForumBuyLog(); log.UserId = buyerId; log.TopicId = topic.Id; log.insert(); String msg = string.Format( "访问需要购买的帖子 <a href=\"{0}\">{1}</a>", alink.ToAppData( topic ), topic.Title ); incomeService.AddKeyIncome( buyerId, -topic.Price, msg ); String msg2 = string.Format( "销售帖子 <a href=\"{0}\">{1}</a>", alink.ToAppData( topic ), topic.Title ); incomeService.AddKeyIncome( creatorId, topic.Price, msg2 ); return result; }
public Result Create( int ownerId, string targetUserName ) { Result result = new Result(); if (strUtil.IsNullOrEmpty( targetUserName )) { result.Add( lang.get( "exUserName" ) ); return result; } User target = userService.GetByName( targetUserName ); if (target == null) { result.Add( lang.get( "exUser" ) ); return result; } Blacklist b = new Blacklist(); b.User = new User( ownerId ); b.Target = target; result = b.insert(); if (result.IsValid) { friendService.DeleteFriendByBlacklist( ownerId, target.Id ); followerService.DeleteFollow( target.Id, ownerId ); } return result; }
public override void Validate( String action, IEntity target, EntityPropertyInfo info, Result result ) { Object obj = target.get( info.Name ); Boolean isNull = false; if (info.Type == typeof( String )) { if (obj == null) { isNull = true; } else if (strUtil.IsNullOrEmpty( obj.ToString() )) { isNull = true; } } else if (obj == null) { isNull = true; } if (isNull) { if (strUtil.HasText( this.Message )) { result.Add( this.Message ); } else { EntityInfo ei = Entity.GetInfo( target ); String str = "[" + ei.FullName + "] : property \"" + info.Name + "\" "; result.Add( str + "can not be null" ); } } }
public override void Validate( String action, IEntity target, EntityPropertyInfo info, Result result ) { if (!Regex.IsMatch( cvt.ToNotNull( target.get( info.Name ) ), this.Regexp, RegexOptions.Singleline )) { if (strUtil.HasText( this.Message )) { result.Add( this.Message ); } else { EntityInfo ei = Entity.GetInfo( target ); String str = "[" + ei.FullName + "] : property \"" + info.Name + "\" "; result.Add( str + " is not match the format pattern : " + this.Regexp ); } } }
public void ResultAddGivesException() { ClauseComponent r = new Result(); ClauseComponent r2 = new Result(); r.Add(true, r2); }
public Result mainCalculations() { Result res = new Result(); double resEnergy = energy; Vector3D curPosition = position; ResultPoint r; r.Position = position; r.Energy = energy; res.Add(r); do { double ls = WayLength(); Vector3D omega = Omega(); Vector3D contactPoint = ContactPoint(omega, ls, curPosition); curPosition = contactPoint; int elementNumber; if (data.env.Length == 2) { elementNumber = ChooseElement(); } else { elementNumber = 0; } resEnergy = Final(elementNumber, resEnergy, omega); r.Energy = resEnergy; r.Position = contactPoint; res.Add(r); } while (resEnergy >= Et); return res; }
public virtual Result Buy( int buyerId, int creatorId, ForumTopic topic ) { Result result = new Result(); if (userIncomeService.HasEnoughKeyIncome( buyerId, topic.Price ) == false) { result.Add( String.Format( alang.get( typeof( ForumApp ), "exIncome" ), KeyCurrency.Instance.Name ) ); return result; } // 日志:买方减少收入 UserIncomeLog log = new UserIncomeLog(); log.UserId = buyerId; log.CurrencyId = KeyCurrency.Instance.Id; log.Income = -topic.Price; log.DataId = topic.Id; log.ActionId = actionId; db.insert( log ); // 日志:卖方增加收入 UserIncomeLog log2 = new UserIncomeLog(); log2.UserId = creatorId; log2.CurrencyId = KeyCurrency.Instance.Id; log2.Income = topic.Price; log2.DataId = topic.Id; log2.ActionId = actionId; db.insert( log2 ); userIncomeService.AddKeyIncome( buyerId, -topic.Price ); userIncomeService.AddKeyIncome( creatorId, topic.Price ); return result; }
public override void Validate( String action, IEntity target, EntityPropertyInfo info, Result result ) { Object obj = target.get( info.Name ); EntityInfo ei = Entity.GetInfo( target ); int count = getCount( action, target, ei, info, obj ); if (count > 0) { if (strUtil.HasText( this.Message )) { result.Add( this.Message ); } else { String str = "[" + ei.FullName + "] : property \"" + info.Name + "\" "; result.Add( str + " should be unique, but it has been in database" ); } } }
public static Result SendSms(string smstext, string sendto) { Result result = new Result(); try { string url = string.Format("{0}/api/smsapi.aspx?uid={1}&key={2}&smstext={3}&sendto={4}" , cfgHelper.GetAppSettings("WlnServer"), cfgHelper.GetAppSettings("WlnUid"), cfgHelper.GetAppSettings("WlnKey"), smstext, sendto); string resultStr = System.Text.UTF8Encoding.UTF8.GetString(new System.Net.WebClient().DownloadData(url)); SmsResult al = Json.ToObject<SmsResult>(resultStr); if (al != null && !al.success) { result.Add(al.msg); } } catch(Exception ex) { result.Add(ex.Message); } return result; }
public static Result Register(String username, String password,Boolean supper) { Result result = new Result(); if (string.IsNullOrEmpty(username)) { result.Add("Sorry,管理员账号不能为空"); } else if (string.IsNullOrEmpty(password)) { result.Add("Sorry,管理员密码不能为空"); } else { if (password.Length != 32) { password = Encryptor.Md5Encryptor32(Encryptor.Md5Encryptor32(password)); } result.Join(System.IO.XMLHelper.AddData(PathHelper.Map("~/xcenter/data/wechat/manager.xml"), "Manager", System.IO.XMLHelper.CreateInsertParameter("Username", username), System.IO.XMLHelper.CreateInsertParameter("Password", password), System.IO.XMLHelper.CreateInsertParameter("Supper", supper ? "true" : "false"))); } return result; }
public static bool IsHtmlDirError( String htmlDir, Result errors ) { if (strUtil.HasText( htmlDir )) { if (htmlDir.Length > 50) { errors.Add( "目录名称不能超过50个字符" ); return true; } if (isReservedKeyContains( htmlDir )) { errors.Add( "目录名称是保留词,请换一个" ); return true; } if (isHtmlDirUsed( htmlDir )) { errors.Add( "目录名称已被使用,请换一个" ); return true; } } return false; }
/// <summary> /// 检查上传的图片是否合法 /// </summary> /// <param name="postedFile"></param> /// <param name="errors"></param> public static void CheckUploadPic( HttpFile postedFile, Result errors ) { if (postedFile == null) { errors.Add( lang.get( "exPlsUpload" ) ); return; } // 检查文件大小 if (postedFile.ContentLength <= 1) { errors.Add( lang.get( "exPlsUpload" ) ); return; } int uploadMax = 1024 * 1024 * config.Instance.Site.UploadPicMaxMB; if (postedFile.ContentLength > uploadMax) { errors.Add( lang.get( "exUploadMax" ) + " " + config.Instance.Site.UploadPicMaxMB + " MB" ); return; } // 检查文件格式 if (Uploader.IsAllowedPic( postedFile ) == false) { errors.Add( lang.get( "exUploadType" ) + ":" + postedFile.FileName + "(" + postedFile.ContentType + ")" ); } }
public static Result Save( String oPicAbsPath, int userId ) { Result result = new Result(); if (file.Exists( oPicAbsPath ) == false) { String msg = "图片不存在" + oPicAbsPath; logger.Error( msg ); result.Add( msg ); return result; } AvatarSaver aSaver = AvatarSaver.New( oPicAbsPath ); return savePicCommon( aSaver, userId, result, sys.Path.DiskAvatar ); }
public virtual Result CanSend( User user ) { int maxMinutes = config.Instance.Site.UserSendConfirmEmailInterval; Result result = new Result(); UserConfirm ac = db.find<UserConfirm>( "User.Id=" + user.Id+" order by Id desc" ).first(); if (ac == null) return result; if (DateTime.Now.Subtract( ac.Created ).Minutes < maxMinutes) { result.Add( string.Format( "{0} 分钟之内,最多只能发送一次", maxMinutes ) ); return result; } return result; }
protected override void OnLoad(EventArgs e) { if (Session["Account"] == null || string.IsNullOrEmpty(Session["Account"].ToString())) { if (string.IsNullOrEmpty(helper.GetParam("action"))) { Response.Redirect("~/Login.aspx"); } else { Result result = new Result(); result.Add("Sorry,您尚未登录或登录已经超时!"); helper.Result = result; helper.ResponseResult(); } } else { base.OnLoad(e); } }
public virtual Result Sync(long userId, string connectType, int isSync) { Result result = new Result(); AuthConnect connect = AuthConnectFactory.GetConnect( connectType ); if (connect == null) { result.Add( "此连接类型不存在:" + connectType ); return result; } UserConnect x = GetConnectInfo( userId, connect.GetType().FullName ); if (x == null) { result.Add( "对不起,您没有绑定过" ); return result; } x.NoSync = (isSync == 0 ? 1 : 0); x.update(); return result; }
/// <summary> /// 上传图片(自定义保存路径) /// </summary> /// <param name="uploadPath">保存路径(相对路径)</param> /// <param name="postedFile">HttpFile</param> /// <param name="picName">图片名称</param> /// <param name="width">宽度</param> /// <param name="height">高度</param> /// <returns></returns> public static Result SaveImg( String uploadPath, HttpFile postedFile, String picName, int width, int height ) { logger.Info( "uploadPath : " + uploadPath ); logger.Info( "picName : " + picName ); Result result = new Result(); checkUploadPic( postedFile, result ); if (result.HasErrors) return result; String str = PathHelper.Map( uploadPath ); String str2 = picName + "." + Img.GetImageExt( postedFile.ContentType ); String filename = Path.Combine( str, str2 ); try { postedFile.SaveAs( filename ); Img.SaveThumbnail( filename, Img.GetThumbPath( filename ), width, height, SaveThumbnailMode.Cut ); } catch (Exception exception) { logger.Error( lang.get( "exPhotoUploadError" ) + ":" + exception.Message ); result.Add( lang.get( "exPhotoUploadErrorTip" ) ); return result; } result.Info = Path.GetFileName( Img.GetThumbPath( filename ) ); return result; }
/// <summary> /// 保存上传的图片 /// </summary> /// <param name="postedFile"></param> /// <param name="arrThumbType"></param> /// <returns></returns> public static Result SaveImg( HttpFile postedFile, ThumbnailType[] arrThumbType ) { Result result = new Result(); checkUploadPic( postedFile, result ); if (result.HasErrors) { logger.Info( result.ErrorsText ); return result; } String pathName = PathHelper.Map( sys.Path.DiskPhoto ); String photoName = Img.GetPhotoName( pathName, postedFile.ContentType ); String filename = Path.Combine( pathName, photoName ); try { postedFile.SaveAs( filename ); foreach (ThumbnailType ttype in arrThumbType) { saveThumbSmall( filename, ttype ); } } catch (Exception exception) { logger.Error( lang.get( "exPhotoUploadError" ) + ":" + exception.Message ); result.Add( lang.get( "exPhotoUploadErrorTip" ) ); return result; } result.Info = photoName.Replace( @"\", "/" ); return result; }
/// <summary> /// 保存上传的非图片型文件 /// </summary> /// <param name="postedFile"></param> /// <returns></returns> public static Result SaveFile( HttpFile postedFile ) { Result errors = new Result(); checkUploadFile( postedFile, errors ); if (errors.HasErrors) { logger.Info( errors.ErrorsText ); return errors; } String fileExt = Path.GetExtension( postedFile.FileName ); String pathName = PathHelper.Map( sys.Path.DiskPhoto ); String fileName = Img.GetFileName( pathName, fileExt ); String filenameWithPath = Path.Combine( pathName, fileName ); try { postedFile.SaveAs( filenameWithPath ); } catch (Exception exception) { logger.Error( lang.get( "exPhotoUploadError" ) + ":" + exception.Message ); errors.Add( lang.get( "exPhotoUploadErrorTip" ) ); return errors; } errors.Info = fileName.Replace( @"\", "/" ); return errors; }
//---------------------------------------------------------------------- private Result validateUser( User user ) { Result result = new Result(); if (strUtil.IsNullOrEmpty( user.Name )) { result.Add( lang.get( "exUserName" ) ); return result; } if (strUtil.IsNullOrEmpty( user.Url )) { result.Add( lang.get( "exUrl" ) ); return result; } user.Name = user.Name.Trim().TrimEnd( '/' ); user.Url = user.Url.Trim().TrimEnd( '/' ); if (user.Url.IndexOf( "http:" ) >= 0) { result.Add( lang.get( "exUserUrlHttpError" ) ); } else { user.Url = strUtil.SubString( user.Url, config.Instance.Site.UserNameLengthMax ); user.Url = user.Url.ToLower(); } if (strUtil.IsUrlItem( user.Url ) == false) { result.Add( lang.get( "exUserUrlError" ) ); } if (result.HasErrors) { return result; } if (isNameReserved( user.Name )) { result.Add( lang.get( "exNameFound" ) ); return result; } if (isUrlReserved( user.Url )) { result.Add( lang.get( "exUrlFound" ) ); return result; } if (IsExist( user.Name ) != null) { result.Add( lang.get( "exNameFound" ) ); return result; } if (strUtil.HasText( user.Url ) && IsExistUrl( user.Url ) != null) { result.Add( lang.get( "exUrlFound" ) ); return result; } return result; }
public virtual Result JoinGroup( User user, Group group, String joinReason, String ip ) { GroupUser gu = db.find<GroupUser>( "Member.Id=" + user.Id + " and Group.Id=" + group.Id ).first(); if (gu == null) { gu = new GroupUser(); gu.Member = user; gu.Group = group; gu.Msg = joinReason; gu.Ip = ip; gu.Status = GroupRole.GetInitRoleByGroup( group ); Result addResult = db.insert( gu ); if (group.AccessStatus == GroupAccessStatus.Open) { afterJoinDone( user, group, joinReason, gu ); } else { addApprovingMsg( user, group, joinReason ); // 给管理员发消息 } return addResult; } else { Result result = new Result(); if (gu.Status == GroupRole.Blacklist.Id) { result.Add( lang.get( "exGroupBeBlacklist" ) ); } else if (gu.Status == GroupRole.Approving.Id) { result.Add( lang.get( "exGroupApprovingTip" ) ); } else result.Add( lang.get( "exGroupBeMember" ) ); return result; } }
// 检查非法传入的参数 private Result validateFile( String currentFile ) { Result result = new Result(); if (strUtil.IsNullOrEmpty( currentFile )) { result.Add( lang( "NotFound404" ) ); } if (currentFile.IndexOf( "\\" ) >= 0 || currentFile.IndexOf( ":" ) > 0) { result.Add( lang( "NotFound404" ) ); } return result; }
private Result getReceivers( String rawReceiver, int groupId ) { Result result = new Result(); if (strUtil.IsNullOrEmpty( rawReceiver )) { result.Add( lang.get( "exReceiverNotFound" ) ); return result; } List<User> list = new List<User>(); string[] strArray = rawReceiver.Trim().Split( separator ); for (int i = 0; i < strArray.Length; i++) { User user = userService.IsExist( strArray[i] ); if (user == null) { result.Add( lang.get( "exReceiverNotFound" ) + ": \"" + strArray[i] + "\" " ); return result; } if (mgrService.IsGroupMember( user.Id, groupId )) { result.Add( "用户 " + user.Name + " 已经是群组成员" ); return result; } list.Add( user ); } result.Info = list; return result; }
/// <summary> /// 保存上传的图片 /// </summary> /// <param name="postedFile"></param> /// <param name="arrThumbType"></param> /// <returns></returns> public static Result SaveImg( HttpFile postedFile, Dictionary<String, ThumbInfo> arrThumbType ) { Result result = new Result(); CheckUploadPic( postedFile, result ); if (result.HasErrors) { logger.Info( result.ErrorsText ); return result; } String pathName = PathHelper.Map( sys.Path.DiskPhoto ); String photoName = Img.GetPhotoName( pathName, postedFile.ContentType ); String filename = Path.Combine( pathName, photoName ); try { postedFile.SaveAs( filename ); foreach (KeyValuePair<String, ThumbInfo> kv in arrThumbType) { Boolean isValid = SaveThumbSingle( filename, kv.Key, kv.Value ); if (!isValid) { file.Delete( filename ); result.Add( "format error: " + postedFile.FileName ); return result; } } } catch (Exception exception) { logger.Error( lang.get( "exPhotoUploadError" ) + ":" + exception.Message ); result.Add( lang.get( "exPhotoUploadErrorTip" ) ); return result; } result.Info = photoName.Replace( @"\", "/" ); return result; }
public Result CanAddFriend( int userId, int targetId ) { Result result = new Result(); if (userId <= 0) { result.Add( lang.get( "exPlsLogin" ) ); return result; } if (userId == targetId) { result.Add( lang.get( "exFriendSelf" ) ); return result; } User f = userService.GetById( targetId ); if (f == null) { result.Add( lang.get( "exUser" ) ); return result; } BlacklistService blacklistService = new BlacklistService(); if (blacklistService.IsBlack( targetId, userId )) { result.Add( lang.get( "blackFriend" ) ); } else if (IsFriend( userId, targetId )) { result.Add( lang.get( "exFriendBeen" ) ); } else if (IsWaitingFriendApproving( userId, targetId )) { result.Add( lang.get( "inApproveFriend" ) ); } return result; }
/// <summary> /// 上传图片(自定义保存路径),同时生成最小的缩略图 /// </summary> /// <param name="uploadPath">保存路径(相对路径)</param> /// <param name="postedFile">HttpFile</param> /// <param name="picName">图片名称</param> /// <param name="width">宽度</param> /// <param name="height">高度</param> /// <returns></returns> public static Result SaveImg( String uploadPath, HttpFile postedFile, String picName, int width, int height, SaveThumbnailMode mode ) { logger.Info( "uploadPath : " + uploadPath ); logger.Info( "picName : " + picName ); Result result = new Result(); CheckUploadPic( postedFile, result ); if (result.HasErrors) return result; String str = PathHelper.Map( uploadPath ); String str2 = picName + "." + Img.GetImageExt( postedFile.ContentType ); String filename = Path.Combine( str, str2 ); try { String oldFile = null; if (file.Exists( filename )) { oldFile = filename + "." + Guid.NewGuid() + Path.GetExtension( filename ); file.Move( filename, oldFile ); } postedFile.SaveAs( filename ); try { saveThumbImagePrivate( filename, ThumbnailType.Small, width, height, mode ); if (strUtil.HasText( oldFile )) { file.Delete( oldFile ); } } catch (OutOfMemoryException ex) { file.Delete( filename ); if (strUtil.HasText( oldFile )) { file.Move( oldFile, filename ); } String msg = "file format error: " + picName; logger.Error( msg ); result.Add( msg ); return result; } } catch (Exception exception) { logger.Error( lang.get( "exPhotoUploadError" ) + ":" + exception.Message ); result.Add( lang.get( "exPhotoUploadErrorTip" ) ); return result; } result.Info = Path.GetFileName( Img.GetThumbPath( filename ) ); return result; }