public MetricsEntryResult RunMetricsCheck(string text, string metricName) { if (text == null) { throw new ArgumentNullException(nameof(text), "Text cannot be null"); } if (metricName == null) { throw new ArgumentNullException(nameof(metricName), "Metric name cannot be null"); } MetricCaller mc = _options.Value.Callers.Single(metric => metric.Name == metricName); if (mc == null) { throw new ArgumentNullException(nameof(metricName), $"There is no metric with such name: {metricName}"); } MetricsEntryResult metricsEntryResult = null; using (IServiceScope scope = _scopeFactory.CreateScope()) { metricsEntryResult = RunCheck(scope, mc, text); } if (metricsEntryResult == null) { throw new ArgumentNullException(nameof(metricsEntryResult), "Metric must return MetricEntryResult"); } return(metricsEntryResult); }
public IMetricsBuilder AddMetrics <T>(string name) where T : IMetric { if (name == null) { throw new ArgumentNullException(nameof(name), "Name cannot be null"); } MetricCaller mr = new MetricCaller(name, service => ActivatorUtilities.GetServiceOrCreateInstance <T>(service)); return(AddMetrics(mr)); }
private MetricsEntryResult RunCheck(IServiceScope scope, MetricCaller caller, string text) { IMetric metric = caller.Factory(scope.ServiceProvider); if (text == null) { throw new ArgumentNullException($"{nameof(text)}", "Stream argument should be provided"); } MetricsEntryResult result = metric.CheckMetric(text); return(result); }
public IMetricsBuilder AddMetrics(MetricCaller caller) { if (caller == null) { throw new ArgumentNullException(nameof(caller), "Caller object cannot be null"); } _services.Configure <MetricsServiceOptions>(options => { options.Callers.Add(caller); }); return(this); }