private async Task <DataSubscription> SubscribeToAttribute(string socketId, DataSubscription subscription) { var series = GrainClient.GrainFactory.GetGrain <IAttributeSeriesGrain>(SeriesIdHelper.ToAttributeSeriesId(subscription.Entity, subscription.Attribute)); subscription.Observer = new SeriesObserver(socketId, this); var observerRef = await GrainClient.GrainFactory.CreateObjectReference <ISeriesObserver>(subscription.Observer); await series.Subscribe(observerRef); return(subscription); }
public async Task <IEnumerable <AggregatedDataRange> > GetAggregatedAttributeData(Guid entity, Guid attribute, int aggregationSeconds, [FromQuery] long minTimeSecondsUtc, [FromQuery] long maxTimeSecondsUtc) { var timeRange = new TimeRange(minTimeSecondsUtc, maxTimeSecondsUtc); IAttributeSeriesGrain series = GrainClient.GrainFactory.GetGrain <IAttributeSeriesGrain>(SeriesIdHelper.ToAttributeSeriesId(entity, attribute)); var data = await series.GetAggregatedData(timeRange, aggregationSeconds); return(data); }
private async Task <FetchAggregatedAttributeDataResponse> ReceiveFetchAggregatedAttributeDataRequest(FetchAggregatedAttributeDataRequest request) { var series = GrainClient.GrainFactory.GetGrain <IAttributeSeriesGrain>(SeriesIdHelper.ToAttributeSeriesId(request.EntityGuid, request.AttributeGuid)); var dataRanges = await series.GetAggregatedData(request.TimeRange, request.AggregationSeconds).ConfigureAwait(false); return(new FetchAggregatedAttributeDataResponse { ActionId = request.ActionId, MessageClass = OutgoingMessageClass.Response, ResponseType = ResponseType.FetchAggregatedAttributeData, Ranges = dataRanges, Succeeded = true }); }
private async Task UnsubscribeFromAttribute(DataSubscription subscription) { var series = GrainClient.GrainFactory.GetGrain <IAttributeSeriesGrain>(SeriesIdHelper.ToCalculationSeriesId(subscription.Entity, subscription.Attribute)); var observerRef = await GrainClient.GrainFactory.CreateObjectReference <ISeriesObserver>(subscription.Observer); await series.Unsubscribe(observerRef); }
public async Task AddData(AggregatedDataRange aggregatedRange) { try { using (_tripCounterFactory.Create("SourceSeriesGrain.AddData")) { _logger.LogDebug($"Preparing to add data"); var seriesMapping = await _mapProvider.GetSeriesModelMapping(_dataSource, _sourceName); IAttributeSeriesGrain series = GrainClient.GrainFactory.GetGrain <IAttributeSeriesGrain>(SeriesIdHelper.ToAttributeSeriesId(seriesMapping.Entity, seriesMapping.Attribute)); await series.ReceiveData(aggregatedRange); } } catch (Exception exception) { _logger.LogError(new EventId(105), exception, "Error when adding aggregated data"); throw; } }