Episerver语言 - 如何在事件期间发送通知消息已发布内容事件



我已经看到了几个如何在编辑内容时将验证消息发送回UI的示例,如下所示。

public class StandardPageValidator : IValidate<standardpage>
{
    IEnumerable<validationerror> IValidate<standardpage>.Validate(StandardPage instance)
    {
        // Silly example to validate if the PageName and MainBody properties start with the same letter
        if (instance.PageName.StartsWith(EPiServer.Core.Html.TextIndexer.StripHtml(instance.MainBody.ToHtmlString().Substring(0, 1), int.MaxValue)))
        {
            return new[] { new ValidationError() { 
                ErrorMessage = "Main body and PageName cannot start with the same letter", 
                PropertyName = "PageName", RelatedProperties = new string[] { "MainBody" }, 
                Severity = ValidationErrorSeverity.Error, 
                ValidationType = ValidationErrorType.AttributeMatched
            } };
        }
        return new ValidationError[0];
    }
}

但是,我想在拦截已发布内容事件后将消息发送回 UI,但此方法返回 void,那么我该怎么做呢?

    public void Initialize(InitializationEngine context)
    {
        var events = ServiceLocator.Current.GetInstance<IContentEvents>();
        events.PublishedContent += EventsPublishedContent;
    }
    private void EventsPublishedContent(object sender, ContentEventArgs e)
    {
    if (e.Content is myType)
    {
        //do some business logic work....

       //How can I send a Info Message back to the UI here?
    }
}
您可以在

代码示例中EventsPublishedContent执行此操作:

e.CancelAction = true;
e.CancelReason = "This message will be displayed in the UI.";

相关内容

  • 没有找到相关文章

最新更新