private MethodInfo GetHandleMethod(IContainerDocument containerDocument) => HandleMethodCache .GetOrAdd(GetType(), _ => new ConcurrentDictionary <Type, MethodInfo>()) .GetOrAdd(containerDocument.GetType(), containerDocumentType => { var subscriberInterface = typeof(IDocumentSubscription <>) .MakeGenericType(containerDocument.GetType()); if (subscriberInterface.IsAssignableFrom(GetType())) { return(subscriberInterface.GetMethod(nameof(HandleAsync), new Type[] { containerDocument.GetType(), typeof(DocumentSubscriptionEvent) })); } return(null); });
public virtual async Task ExpandAsync(IContainerDocument document) { if (document is null) { throw new ArgumentNullException(nameof(document)); } if (CanExpand(document)) { var stopwatch = Stopwatch.StartNew(); var expandMethod = expandMethods.GetOrAdd(GetLookupKey(document), _ => typeof(IDocumentExpander <>).MakeGenericType(document.GetType()).GetMethod(nameof(ExpandAsync), new Type[] { document.GetType() })); var expandTask = (Task)expandMethod.Invoke(this, new object[] { document }); await expandTask.ConfigureAwait(false); if (!expandMetric.TrackValue(stopwatch.ElapsedMilliseconds, this.GetType().Name, document.GetType().Name)) { telemetryClient.TrackTrace($"Data series or dimension cap was reached for metric {expandMetric.Identifier.MetricId}.", SeverityLevel.Error); } } else { throw new NotImplementedException($"Missing document expander implementation IDocumentExpander<{document.GetType().Name}> at {GetType()}"); } }
public virtual bool CanExpand(IContainerDocument document) { if (document is null) { throw new ArgumentNullException(nameof(document)); } return(expandableDocumentTypes.GetOrAdd(GetLookupKey(document), _ => typeof(IDocumentExpander <>).MakeGenericType(document.GetType()).IsAssignableFrom(GetType()))); }
private string GetLookupKey(IContainerDocument document) => $"{this.GetType()}|{document.GetType()}";
public virtual Task HandleAsync(IContainerDocument containerDocument, DocumentSubscriptionEvent subscriptionEvent) { if (containerDocument is null) { throw new ArgumentNullException(nameof(containerDocument)); } if (CanHandle(containerDocument)) { return((Task)GetHandleMethod(containerDocument).Invoke(this, new object[] { containerDocument, subscriptionEvent })); } throw new NotImplementedException($"Missing document subscription implementation IDocumentSubscription<{containerDocument.GetType().Name}> at {GetType()}"); }