public void SavePost(int sectionId) { if (shouldApprove(ctx.viewer.obj)) { saveTempPost(sectionId, null); if (ctx.HasErrors) { echoError(); } return; } ContentPost post = ContentValidator.Validate(sectionService.GetById(sectionId, ctx.app.Id), ctx); ContentValidator.ValidateArticle(post, ctx); if (strUtil.HasText(post.ImgLink)) { post.CategoryId = PostCategory.Img; post.Width = 100; post.Height = 85; } if (ctx.HasErrors) { run(SubmitPost, sectionId); } else { postService.Insert(post, ctx.Post("TagList")); echoRedirect("发布成功,谢谢", to(new ContentController().Index)); } }
public async Task Should_add_error_if_field_object_is_defined() { var schema = new Schema("my-schema") .AddUI(1, "my-ui1", Partitioning.Invariant) .AddUI(2, "my-ui2", Partitioning.Invariant); var data = new NamedContentData() .AddField("my-ui1", new ContentFieldData()) .AddField("my-ui2", new ContentFieldData() .AddValue("iv", null)); var validationContext = ValidationTestExtensions.ValidContext; var validator = new ContentValidator(schema, x => InvariantPartitioning.Instance, validationContext); await validator.ValidateAsync(data); validator.Errors.Should().BeEquivalentTo( new[] { new ValidationError("Value must not be defined.", "my-ui1"), new ValidationError("Value must not be defined.", "my-ui2") }); }
public virtual void Update(long postId) { ContentPost post = postService.GetById(postId, ctx.owner.Id); if (post == null) { echo(lang("exDataNotFound")); return; } ContentValidator.SetPostValue(post, ctx); ContentValidator.ValidateTalk(post, ctx); if (errors.HasErrors) { Edit(postId); } else { post.Title = strUtil.SubString(post.Content, 20); postService.Update(post, ctx.Post("TagList")); echoToParentPart(lang("opok")); HtmlHelper.SetPostToContext(ctx, post); } }
public virtual void Update(long postId) { ContentPost post = topicService.GetById(postId, ctx.owner.Id); if (post == null) { echo(lang("exDataNotFound")); return; } post = ContentValidator.SetPostValue(post, ctx); String sectionIds = sectionService.GetSectionIdsByPost(post.Id); topicService.Update(post, sectionIds, ctx.Post("TagList")); // update Poll ContentPoll poll = pollService.GetByTopicId(postId); poll.Title = post.Title; poll.Created = post.Created; poll.Hits = post.Hits; pollService.Update(poll); echoToParentPart(lang("opok")); HtmlHelper.SetPostToContext(ctx, post); }
private static void CheckErrors(ContentValidator validator) { if (validator.Errors.Count > 0) { throw new ValidationException(validator.Errors.ToList()); } }
public void Create(int sectionId) { ContentSection section = sectionService.GetById(sectionId, ctx.app.Id); ContentPost post = ContentValidator.SetValueBySection(sectionService.GetById(sectionId, ctx.app.Id), ctx); if (strUtil.IsNullOrEmpty(post.Title)) { post.Title = section.Title + " " + DateTime.Now.ToShortDateString(); } if (strUtil.IsNullOrEmpty(post.Content)) { errors.Add(lang("exContent")); run(Add, sectionId); } else { post.CategoryId = PostCategory.Notice; postService.Insert(post, null); echoToParentPart(lang("opok")); HtmlHelper.SetPostToContext(ctx, post); } }
public void SaveVideo(int sectionId) { if (shouldApprove(ctx.viewer.obj)) { saveTempPost(sectionId, typeof(ContentVideo)); if (ctx.HasErrors) { echoError(); } return; } ContentPost post = ContentValidator.Validate(sectionService.GetById(sectionId, ctx.app.Id), ctx); ContentValidator.ValidateVideo(post, ctx); if (ctx.HasErrors) { run(SubmitVideo, sectionId); } else { postService.Insert(post, ctx.Post("TagList")); echoRedirect("发布成功,谢谢", to(new ContentController().Index)); } }
public WriteFromFile(ContentValidator validator, ContentInsertDbCommand insertDbCommand, IUtcDateTimeProvider dateTimeProvider, ContentDbContext contentDbContext) { _Validator = validator ?? throw new ArgumentNullException(nameof(validator)); _InsertDbCommand = insertDbCommand ?? throw new ArgumentNullException(nameof(insertDbCommand)); _DateTimeProvider = dateTimeProvider ?? throw new ArgumentNullException(nameof(dateTimeProvider)); _ContentDbContext = contentDbContext ?? throw new ArgumentNullException(nameof(contentDbContext)); }
public PublishContentCommand(ContentValidator validator, ContentInsertDbCommand insertDbCommand, IUtcDateTimeProvider dateTimeProvider, ContentDbContext contentDbContext, ILogger <PublishContentCommand> logger) { _Validator = validator ?? throw new ArgumentNullException(nameof(validator)); _InsertDbCommand = insertDbCommand ?? throw new ArgumentNullException(nameof(insertDbCommand)); _DateTimeProvider = dateTimeProvider ?? throw new ArgumentNullException(nameof(dateTimeProvider)); _ContentDbContext = contentDbContext ?? throw new ArgumentNullException(nameof(contentDbContext)); _Logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
public ContentPublisher(PublishContentLoggingExtensions logger, IUtcDateTimeProvider dateTimeProvider, ContentValidator validator, ContentDbContext contentDbContext, ContentInsertDbCommand insertDbCommand) { _Logger = logger ?? throw new ArgumentNullException(nameof(logger)); _DateTimeProvider = dateTimeProvider ?? throw new ArgumentNullException(nameof(dateTimeProvider)); _Validator = validator ?? throw new ArgumentNullException(nameof(validator)); _ContentDbContext = contentDbContext ?? throw new ArgumentNullException(nameof(contentDbContext)); _InsertDbCommand = insertDbCommand ?? throw new ArgumentNullException(nameof(insertDbCommand)); }
public ContentDatabaseCreateCommand(ContentDbContext dbContextProvider, IUtcDateTimeProvider dateTimeProvider, ContentValidator validator, ContentInsertDbCommand insertDbCommand) { _DbContextProvider = dbContextProvider ?? throw new ArgumentNullException(nameof(dbContextProvider)); _DateTimeProvider = dateTimeProvider ?? throw new ArgumentNullException(nameof(dateTimeProvider)); _Validator = validator ?? throw new ArgumentNullException(nameof(validator)); _InsertDbCommand = insertDbCommand ?? throw new ArgumentNullException(nameof(insertDbCommand)); _Snapshot = _DateTimeProvider.Now(); }
public async Task ValidateInputPartialAsync(NamedContentData data) { var validator = new ContentValidator(app.PartitionResolver(), validationContext, factories); await validator.ValidateInputPartialAsync(data); CheckErrors(validator); }
public async Task ValidateContentAsync(NamedContentData data) { var validator = new ContentValidator(Partition(), validationContext, validators, log); await validator.ValidateContentAsync(data); CheckErrors(validator); }
public async Task ValidateInputAsync(NamedContentData data, bool publish) { var validator = new ContentValidator(Partition(), validationContext.AsPublishing(publish), validators, log); await validator.ValidateInputAsync(data); CheckErrors(validator); }
public OperationResult SetContent(string content) { var operationResult = new ContentValidator().Validate(content); if (operationResult.Success) { Content = content; } return(operationResult); }
public async Task <IEnumerable <ValidationError> > GetErrorsAsync(NamedContentData data) { var validator = new ContentValidator(Partition(), validationContext, validators, log); await validator.ValidateInputAsync(data); await validator.ValidateContentAsync(data); return(validator.Errors); }
//-------------------------------------------------------------------------------------------------------- public void Create() { ContentPost post = ContentValidator.SetValue(ctx); ContentValidator.ValidateTitleBody(post, ctx); String sectionIds = ctx.PostIdList("postSection"); if (strUtil.IsNullOrEmpty(sectionIds)) { errors.Add("请选择区块"); } int[] arrAttachmentIds = cvt.ToIntArray(ctx.PostIdList("attachmentIds")); // 图片默认值处理 if (strUtil.HasText(post.ImgLink)) { if (post.Width <= 0) { post.Width = 100; post.Height = 85; } } if (ctx.HasErrors) { echoError(); return; } // 处理远程图片 if (ctx.PostIsCheck("isDowloadPic") == 1) { post.Content = wojilu.Net.PageLoader.ProcessPic(post.Content, ""); } postService.Insert(post, sectionIds, ctx.Post("TagList")); attachService.UpdateAtachments(arrAttachmentIds, post); if (ctx.GetInt("fromList") > 0) { echoRedirectPart(lang("opok"), to(List, 0), 1); } else { echoToParentPart(lang("opok")); } HtmlHelper.SetPostToContext(ctx, post); }
public VideoService( AudioService audioService, VideoUtil videoUtil, ContentValidator content, SubtitleValidator subtitle, BackgroundValidator background) { _audioService = audioService; _videoUtil = videoUtil; _content = content; _subtitle = subtitle; _background = background; }
public virtual void Create(long columnId) { ContentSection section = ContentValidator.SetSectionValueAndValidate(columnId, ctx); if (errors.HasErrors) { run(Add, columnId); } else { sectionService.Insert(section); echoToParentPart(lang("opok")); } }
public static async Task ValidateAsync(this NamedContentData data, PartitionResolver partitionResolver, IList <ValidationError> errors, Schema?schema = null, ValidationMode mode = ValidationMode.Default, Func <ValidationContext, ValidationContext>?updater = null) { var context = CreateContext(schema, mode, updater); var validator = new ContentValidator(partitionResolver, context, Enumerable.Repeat(Factory, 1)); await validator.ValidateInputAsync(data); foreach (var error in validator.Errors) { errors.Add(error); } }
public void Create(int columnId) { ContentSection section = ContentValidator.ValidateSection(columnId, ctx); if (errors.HasErrors) { run(Add, columnId); } else { sectionService.Insert(section); echoToParentPart(lang("opok")); } }
public void Create(int sectionId) { ContentPost post = ContentValidator.Validate(sectionService.GetById(sectionId, ctx.app.Id), ctx); ContentValidator.ValidateVideo(post, ctx); if (ctx.HasErrors) { run(Add, sectionId); } else { postService.Insert(post, null); echoToParentPart(lang("opok")); } }
public void CreateFeed(int layoutId) { String rssUrl = ctx.Post("Url"); if (strUtil.IsNullOrEmpty(rssUrl)) { errors.Add("rss url can not be empty"); run(AddFeed, layoutId); return; } // 获取feed源 FeedSource s = feedService.CreateRss(rssUrl); if (s == null) { errors.Add("create rss error"); run(AddFeed, layoutId); return; } // 创建区块 ContentSection section = ContentValidator.PopulateFeed(layoutId, ctx); String title = ctx.Post("Title"); section.Title = strUtil.HasText(title) ? title : s.Title; section.MoreLink = s.Link; // rss数据源的ID section.ServiceId = 18; // 仅使用单列列表模板 section.TemplateId = 2; sectionService.Insert(section); // 设置参数 int count = ctx.PostInt("Count"); if (count <= 0 || count > 30) { count = 5; } updateFeedParamValues(section, rssUrl, count); echoToParentPart(lang("opok")); }
public static async Task ValidateAsync(this NamedContentData data, PartitionResolver partitionResolver, IList <ValidationError> errors, Schema?schema = null, ValidationMode mode = ValidationMode.Default, ValidationUpdater?updater = null, IValidatorsFactory?factory = null) { var context = CreateContext(schema, mode, updater); var validator = new ContentValidator(partitionResolver, context, Factories(factory), Log); await validator.ValidateInputAsync(data); foreach (var error in validator.Errors) { errors.Add(error); } }
public void CreateAuto(int columnId) { ContentSection section = ContentValidator.ValidateSection(columnId, ctx); if (errors.HasErrors) { run(AddAutoThree, columnId); } else { sectionService.Insert(section); // 给参数赋值 SectionSettingController.updateParamValues(section, sectionService, ctx); echoToParentPart(lang("opok")); } }
public virtual void Create(long sectionId) { ContentPost post = ContentValidator.SetValueBySection(sectionService.GetById(sectionId, ctx.app.Id), ctx); ContentValidator.ValidateVideo(post, ctx); if (ctx.HasErrors) { run(Add, sectionId); } else { postService.Insert(post, ctx.Post("TagList")); echoToParentPart(lang("opok")); HtmlHelper.SetPostToContext(ctx, post); } }
public async Task ValidateOnPublishAsync(NamedContentData data) { if (!schema.SchemaDef.Properties.ValidateOnPublish) { return; } var validator = new ContentValidator(Partition(), validationContext.AsPublishing(), validators, log); await validator.ValidateInputAsync(data); await validator.ValidateContentAsync(data); CheckErrors(validator); }
public void Create(int sectionId) { ContentPost post = ContentValidator.SetValue(ctx); ContentPoll poll = new PollValidator <ContentPoll>().Validate(ctx); if (errors.HasErrors) { echoError(); return; } pollService.CreatePoll(sectionId, poll, post, ctx.Post("TagList")); echoToParentPart(lang("opok")); HtmlHelper.SetPostToContext(ctx, post); }
public ContentIterator(XPathNode nd, Shape shape) { this.node = nd; XmlSchemaElement xse = shape.XmlSchemaElement; Debug.Assert(null != xse); SchemaElementDecl decl = xse.ElementDecl; Debug.Assert(null != decl); this.contentValidator = decl.ContentValidator; this.currentState = new ValidationState(); this.contentValidator.InitValidation(this.currentState); this.currentState.ProcessContents = XmlSchemaContentProcessing.Strict; if (nd != null) { Advance(); } }
private static ContentValidator GetValidator(this OperationContext context, bool optimize, bool published) { var validationContext = new ValidationContext(context.Resolve <IJsonSerializer>(), context.App.NamedId(), context.Schema.NamedId(), context.SchemaDef, context.ContentId) .Optimized(optimize).AsPublishing(published); var validator = new ContentValidator(context.Partition(), validationContext, context.Resolve <IEnumerable <IValidatorsFactory> >(), context.Resolve <ISemanticLog>()); return(validator); }