protected async Task <bool> RaiseEvent(IEventBase <K> @event, string uniqueId = null, string mqHashKey = null) { try { @event.StateId = GrainId; @event.Version = this.State.Version + 1; @event.Timestamp = DateTime.Now; using (var ms = new MemoryStream()) { Serializer.Serialize(ms, @event); var bytes = ms.ToArray(); var result = await EventStorage.InsertAsync(@event, bytes, uniqueId, SendEventToMQ); if (result) { @event.Apply(this.State); await EventInsertAfterHandle(@event, bytes, mqHashKey : mqHashKey); RaiseEventAfter(@event, bytes); return(true); } } } catch (Exception ex) { this.GetLogger("Event_Raise").Log(LogCodes.EventRaiseError, Orleans.Runtime.Severity.Error, $"applay event {@event.TypeCode} error, eventId={@event.Version}", null, ex); throw ex; } return(false); }