Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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
            });
        }
Exemplo n.º 4
0
        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;
            }
        }