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 CanHandle(IContainerDocument containerDocument) { if (containerDocument is null) { throw new ArgumentNullException(nameof(containerDocument)); } return(GetHandleMethod(containerDocument) is not null); }
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()))); }
public IEnumerable <IDocumentExpander> GetExpanders(IContainerDocument document, bool includeOptional) { if (document is null) { throw new ArgumentNullException(nameof(document)); } return(serviceProvider .GetServices <IDocumentExpander>() .Where(s => (includeOptional || s.Optional == includeOptional) && s.CanExpand(document))); }
public IEnumerable <IDocumentSubscription> GetSubscriptions(IContainerDocument document) { if (document is null) { throw new ArgumentNullException(nameof(document)); } return(serviceProvider .GetServices <IDocumentSubscription>() .Where(s => s.CanHandle(document))); }
public override async Task HandleAsync(IContainerDocument containerDocument, DocumentSubscriptionEvent subscriptionEvent) { if (containerDocument is null) { throw new ArgumentNullException(nameof(containerDocument)); } var broadcastCommandType = (subscriptionEvent switch { DocumentSubscriptionEvent.Create => typeof(BroadcastDocumentCreateCommand <>), DocumentSubscriptionEvent.Update => typeof(BroadcastDocumentUpdateCommand <>), DocumentSubscriptionEvent.Delete => typeof(BroadcastDocumentDeleteCommand <>), _ => null })?.MakeGenericType(containerDocument.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()}"); }
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); });
private string GetLookupKey(IContainerDocument document) => $"{this.GetType()}|{document.GetType()}";
protected void AssertContainerDocumentMetadata(IContainerDocument containerDocument) { Assert.NotNull(containerDocument); Assert.NotNull(containerDocument.ETag); Assert.NotNull(containerDocument.Timestamp); }
public static BroadcastMessage.Item ToBroadcastMessageItem(this IContainerDocument containerDocument) => containerDocument is null ? throw new NullReferenceException() : new BroadcastMessage.Item()
public override bool CanHandle(IContainerDocument containerDocument) { return(true); }
internal static Task <IDisposable> LockAsync(this IDurableOrchestrationContext functionContext, IContainerDocument containerDocument) => functionContext.LockAsync(containerDocument.GetEntityId());
public IEnumerable <IDocumentSubscription> GetSubscriptions(IContainerDocument containerDocument) => Enumerable.Empty <IDocumentSubscription>();
public IEnumerable <IDocumentExpander> GetExpanders(IContainerDocument containerDocument, bool includeOptional) => Enumerable.Empty <IDocumentExpander>();