/// <summary> /// 事件过滤器,如果为true,则发送事件,否则不发送 /// </summary> /// <param name="e">The e.</param> /// <param name="eventBehaviorStorager">The event behavior storage.</param> /// <returns></returns> protected virtual bool EventFilter(IOperateEvent e, EventBehaviorStorager eventBehaviorStorager) { if (this.eventFilter != null) { return(this.eventFilter.Invoke(e, eventBehaviorStorager)); } return(true); }
/// <summary> /// /// </summary> /// <param name="operaEvent"></param> /// <param name="jsonSerializer"></param> /// <returns></returns> public static EventStreamMessage ConvertTo(IOperateEvent operaEvent, Serialization.IJsonSerializer jsonSerializer) { var type = operaEvent.Event.GetType(); var message = new EventStreamMessage() { AggregateType = operaEvent.AggregateType.FullName, AppDomain = operaEvent.AppDomain, CreateDate = operaEvent.CreateDate, Creator = operaEvent.Creator, EventContent = jsonSerializer.SerializeObject(operaEvent.Event), EventName = type.Name, EventType = Regex.Replace(type.AssemblyQualifiedName, "version=(.*?),", "", RegexOptions.IgnoreCase), HashCode = operaEvent.HashCode, Increment = operaEvent.Increment, AggregateId = operaEvent.AggregateId, AggregateIdType = Regex.Replace(operaEvent.AggregateIdType.AssemblyQualifiedName, "version=(.*?),", "", RegexOptions.IgnoreCase), Version = operaEvent.Version, }; return(message); }
/// <summary> /// 发送一个事件,该事件会被包装为<see cref="EventStreamMessage"/> 并发送到指定队列中 /// </summary> /// <param name="e">The e.</param> protected virtual void Send(IOperateEvent e) { if (this.messageProducer == null) { return; } this.Startup(); var message = e.ConvertTo(this.jsonSerializer); try { this.messageProducer.Send(new MessagePacket() { ContentType = MessagePacket.GetContentType(message), Body = this.jsonSerializer.Serialize(message), }, null); } catch (Exception ex) { this.HandlerException(ex); } }
/// <summary> /// /// </summary> /// <param name="operaEvent"></param> /// <param name="jsonSerializer"></param> /// <returns></returns> public static EventStreamMessage ConvertTo(this IOperateEvent operaEvent, Serialization.IJsonSerializer jsonSerializer) { return(EventStreamHelper.ConvertTo(operaEvent, jsonSerializer)); }
/// <summary> /// /// </summary> /// <param name="operaEvent"></param> /// <returns></returns> public static EventStreamMessage ConvertTo(this IOperateEvent operaEvent) { return(EventStreamHelper.ConvertTo(operaEvent)); }
/// <summary> /// /// </summary> /// <param name="operaEvent"></param> /// <returns></returns> public static EventStreamMessage ConvertTo(IOperateEvent operaEvent) { return(ConvertTo(operaEvent, Never.Serialization.SerializeEnvironment.JsonSerializer)); }