public UpdateComponentDataOutput UpdateComponentData(UpdateComponentDataInput input) { List <ContentComponentData> contentComponentDatas = new List <ContentComponentData>(); foreach (var item in input.ComponentDatas) { var componentData = new ContentComponentData() { Sign = item.Sign, }; componentData.SingleDatas = new List <SingleComponentData>(); foreach (var singleData in item.SingleDatas) { componentData.SingleDatas.Add(new SingleComponentData() { Name = singleData.Name, SortIndex = singleData.SortIndex, Field1 = singleData.Field1, Field2 = singleData.Field2, Field3 = singleData.Field3, Field4 = singleData.Field4, Field5 = singleData.Field5, }); } contentComponentDatas.Add(componentData); } _pageDataManager.SetContentComponentDatas(input.PageName, input.PageDataName, contentComponentDatas); return(new UpdateComponentDataOutput()); }
public void Exec( Logic logic, string pageName, string pageDataName, string contentComponentDataSign, int userId, string request) { var pages = _pageManager.GetPagesForCache(); var page = _pageManager.GetPagesForCache().FirstOrDefault(e => e.Name == pageName); if (page == null) { throw new UserFriendlyException($"指定的页面{pageName}不存在"); } var post = _pageDataManager.PostRepository.GetAllIncluding(e => e.Tags).FirstOrDefault(e => e.Name == pageDataName); ContentComponentData componentData = null; if (post != null) { componentData = _componentDataManager.ComponentDataRepository.GetAllIncluding(e => e.SingleDatas).OfType <ContentComponentData>().FirstOrDefault(e => e.PageDataId == post.Id && e.Sign == contentComponentDataSign); } var actuator = _actuatorFactory.GetActuator(logic.Name); if (actuator == null) { try { _actuatorFactory.Register(logic.Name, logic.Code); } catch (Exception e) { throw new UserFriendlyException(e.Message); } actuator = _actuatorFactory.GetActuator(logic.Name); } User user = null; if (userId > 0) { _userManager.UserRepository.NoTracking(); user = _userManager.UserRepository.FirstOrDefault(userId); _userManager.UserRepository.Tracking(); } try { actuator.Exec(componentData, post, page, user, request); } catch (Exception ex) { throw ex.InnerException; } }
protected ContentComponentData CreateContentComponentData(string sign, PageData pageData) { var componentDataRepository = IocManager.Instance.Resolve <IRepository <ContentComponentData> >(); ContentComponentData contentComponentData = new ContentComponentData() { Sign = sign, PageData = pageData, SingleDatas = new List <ComponentSingleData>() }; componentDataRepository.Insert(contentComponentData); return(contentComponentData); }
public void Register_ManyRegisterTest() { var actuatorFactory = LocalIocManager.Resolve <IActuatorFactory>(); actuatorFactory.Register("Test1", @" public override void Exec(ContentComponentData componentData, PageData pageData, Page page, User user, string request) { componentData.Id = 1; } "); var actuator = actuatorFactory.GetActuator("Test1"); ContentComponentData componentData = new ContentComponentData(); actuator.Exec(componentData, null, null, null, null); Assert.True(componentData.Id == 1); actuatorFactory.Register("Test2", @" public override void Exec(ContentComponentData componentData, PageData pageData, Page page, User user, string request) { componentData.Id = 2; } "); actuatorFactory.Register("Test3", @" public override void Exec(ContentComponentData componentData, PageData pageData, Page page, User user, string request) { componentData.Id = 3; } "); actuator = actuatorFactory.GetActuator("Test1"); componentData = new ContentComponentData(); actuator.Exec(componentData, null, null, null, null); Assert.True(componentData.Id == 1); actuator = actuatorFactory.GetActuator("Test2"); componentData = new ContentComponentData(); actuator.Exec(componentData, null, null, null, null); Assert.True(componentData.Id == 2); actuator = actuatorFactory.GetActuator("Test3"); componentData = new ContentComponentData(); actuator.Exec(componentData, null, null, null, null); Assert.True(componentData.Id == 3); }
public override void Exec(ContentComponentData componentData, PageComponentBase pageComponent, PageData pageData, PageBase page, User user, string request) { if (user == null) { throw new AbpAuthorizationException("未登录,请先登录"); } if (pageData == null) { throw new UserFriendlyException("组件只能在文章页面被调用"); } var curComponentData = componentData; if (curComponentData == null) { curComponentData = CreateContentComponentData(pageComponent.Sign, pageData); } if (curComponentData.GetSingleDatas(_commentName).Count() > 1000) { throw new UserFriendlyException("评论已达到上限,无法再评论"); } if (request.Length > 1000) { throw new UserFriendlyException("评论过长"); } if (request.Length < 10) { throw new UserFriendlyException("评论过短"); } var commentData = curComponentData.CreateSingleData(_commentName); commentData.Field1 = user.Id.ToString(); commentData.Field2 = user.Name; commentData.Field3 = user.HeadSculpture; commentData.Field4 = request; DateTime now = DateTime.Now; commentData.Field5 = $"{now.Year}-{now.Month}-{now.Day} {now.Hour}:{now.Minute}"; }
public void Register_BaseTest() { string code = @" public override void Exec(ContentComponentData componentData, PageData pageData, Page page, User user, string request) { componentData.Id = 1; } "; var actuatorFactory = LocalIocManager.Resolve <IActuatorFactory>(); actuatorFactory.Register("Test", code); var actuator = actuatorFactory.GetActuator("Test"); ContentComponentData componentData = new ContentComponentData(); actuator.Exec(componentData, null, null, null, null); Assert.True(componentData.Id == 1); }
/// <summary> /// 创造者更新文章数据 /// </summary> /// <param name="input"></param> /// <returns></returns> public UpdateComponentDataOutput UpdateComponentDataOfCreator(UpdateComponentDataInput input) { List <ContentComponentData> contentComponentDatas = new List <ContentComponentData>(); foreach (var item in input.ComponentDatas) { var componentData = new ContentComponentData() { Sign = item.Sign, }; componentData.SingleDatas = new List <ComponentSingleData>(); foreach (var singleData in item.SingleDatas) { componentData.SingleDatas.Add(new ComponentSingleData() { Name = singleData.Name, SortIndex = singleData.SortIndex, Field1 = singleData.Field1, Field2 = singleData.Field2, Field3 = singleData.Field3, Field4 = singleData.Field4, Field5 = singleData.Field5, }); } contentComponentDatas.Add(componentData); } var pageData = _pageDataManager.PostRepository.FirstOrDefault(e => e.Name == input.PageDataName && e.PageName == input.PageName); var editor = _userManager.GetUser((int)_abpSession.UserId.Value); _updateContentComponentDataService.UpdateContentComponentDataOfCreator(pageData, contentComponentDatas, editor); return(new UpdateComponentDataOutput()); }
public abstract void Exec(ContentComponentData componentData, PageData pageData, Page page, User user, string request);
public override void Exec(ContentComponentData componentData, PageData pageData, Page page, User user, string request) { }