// end of accessor public TimeZone TimeZone ////////////////////////////////////////////////////////////////////// /// <summary>searches through the evententries to /// find the original event</summary> /// <param name="original">The original event to find</param> /// <returns> </returns> ////////////////////////////////////////////////////////////////////// public EventEntry FindEvent(OriginalEvent original) { // first try the internal cache foreach (EventEntry entry in this.Entries) { if (entry.SelfUri.ToString() == original.Href) { return(entry); } } // did not find it in the cache. Need to call the server to get it. CalendarService calService = this.Service as CalendarService; if (calService != null) { EventQuery query = new EventQuery(original.Href); EventFeed newFeed = (EventFeed)calService.Query(query); if (newFeed != null && newFeed.Entries != null) { Tracing.Assert(newFeed.Entries.Count == 1, "There should be just one entry returned"); return(newFeed.Entries[0] as EventEntry); } } return(null); }
public async ValueTask <BaseProposedEvent> Transform( OriginalEvent originalEvent, CancellationToken cancellationToken ) { var httpEvent = new HttpEvent( originalEvent.EventDetails.EventType, originalEvent.EventDetails.Stream, Encoding.UTF8.GetString(originalEvent.Data) ); try { var response = await _client.PostAsync( "", new ByteArrayContent(JsonSerializer.SerializeToUtf8Bytes(httpEvent)), cancellationToken ).ConfigureAwait(false); if (!response.IsSuccessStatusCode) { throw new HttpRequestException($"Transformation request failed: {response.ReasonPhrase}"); } if (response.StatusCode == HttpStatusCode.NoContent) { return(new IgnoredEvent( originalEvent.EventDetails, originalEvent.Position, originalEvent.SequenceNumber )); } HttpEvent httpResponse = (await JsonSerializer.DeserializeAsync <HttpEvent>( await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false), cancellationToken: cancellationToken ).ConfigureAwait(false)) !; return(new ProposedEvent( originalEvent.EventDetails with { EventType = httpResponse.EventType, Stream = httpResponse.StreamName }, Encoding.UTF8.GetBytes(httpResponse.Payload), originalEvent.Metadata, originalEvent.Position, originalEvent.SequenceNumber )); } catch (OperationCanceledException) { return(new NoEvent(originalEvent.EventDetails, originalEvent.Position, originalEvent.SequenceNumber)); } }
internal JournalEvent ExecuteEvent(string eventName, string json) { var rawEvent = new OriginalEvent { EventName = eventName, Source = json }; BeforeEvent?.Invoke(this, rawEvent); if (rawEvent.Ignore) { return(null); } if (_cache.Value.TryGetValue(eventName, out var eventCacheItem)) { JournalEvent @event = null; try { @event = (JournalEvent)eventCacheItem.Execute.Invoke(null, new object[] { json, this }); } catch (Exception exception) { LogJournalException(new JournalRecordException(json, exception)); } if (@event != null) { AllEvents?.Invoke(this, new ProcessedEvent { EventName = eventCacheItem.Name, EventType = eventCacheItem.Type, Event = @event }); } return(@event); } LogJournalWarning(new JournalEventNotFoundException(eventName, json)); return(null); }
public static ValueTask <ProposedEvent> Default( OriginalEvent originalEvent, CancellationToken _ ) => new(
private void OnApiBeforeEvent(object sender, OriginalEvent e) => Dispatcher?.Invoke(() => _journal.Add(e.Source));