public ResourceTracker(IEnumerable <IResourceMeter> resourceMeters, TimeSpan trackingInterval, TimeSpan operationTimeout, ResourceLog resourceLog, TimeSpan logInterval, Func <IEnumerable <ResourceUse>, UseLevel> aggregationFunc, int maxTransientExceptions = 5) { ArgumentValidator.ThrowIfNull("resourceMeters", resourceMeters); ArgumentValidator.ThrowIfInvalidValue <IEnumerable <IResourceMeter> >("resourceMeters", resourceMeters, (IEnumerable <IResourceMeter> meters) => meters.Any <IResourceMeter>()); ArgumentValidator.ThrowIfNull("resourceLog", resourceLog); ArgumentValidator.ThrowIfInvalidValue <TimeSpan>("logInterval", logInterval, (TimeSpan timeout) => timeout > TimeSpan.Zero); ArgumentValidator.ThrowIfInvalidValue <TimeSpan>("operationTimeout", operationTimeout, (TimeSpan timeout) => timeout > TimeSpan.Zero); ArgumentValidator.ThrowIfInvalidValue <TimeSpan>("trackingInterval", trackingInterval, (TimeSpan interval) => interval > TimeSpan.Zero); ArgumentValidator.ThrowIfZeroOrNegative("maxTransientExceptions", maxTransientExceptions); if (aggregationFunc != null) { this.aggregationFunc = aggregationFunc; } this.operationTimeout = operationTimeout; this.trackingInterval = trackingInterval; this.resourceLog = resourceLog; this.logInterval = logInterval; this.isTracking = false; this.resourceMeters = resourceMeters; this.currentResourseUses = new List <ResourceUse> { new ResourceUse(this.AggregateResourceUse.Resource, UseLevel.Low, UseLevel.Low) }; this.lastUpdateTime = DateTime.MinValue; foreach (IResourceMeter resourceMeter in resourceMeters) { if (resourceMeter != null) { if (this.resourceTrackingOperations.ContainsKey(resourceMeter.Resource)) { throw new ArgumentException(string.Format("Duplicate Resource Meter for {0} : {1}", resourceMeter.Resource.Name, resourceMeter.Resource.InstanceName), "resourceMeters"); } DelegatingInfoCollector executionInfo = new DelegatingInfoCollector(new List <IExecutionInfo> { new ExecutionTimeInfo() }); ResourceTrackingOperation value = new ResourceTrackingOperation(resourceMeter, executionInfo, maxTransientExceptions); this.resourceTrackingOperations.Add(resourceMeter.Resource, value); } } }
public ResourceTrackingOperation(IResourceMeter resourceMeter, IExecutionInfo executionInfo, int maxTransientExceptions = 5) : base(ResourceTrackingOperation.GetDebugInfo(resourceMeter), ResourceTrackingOperation.GetResourceTrackingAction(resourceMeter), executionInfo, maxTransientExceptions) { this.resourceMeter = resourceMeter; }