public object GetViewModel()
        {
            WebTransferStatisticalDataAggregator.WebTransferAggregation Deserialize(string src)
            {
                return(JsonSerializer.Create()
                       .Deserialize <WebTransferStatisticalDataAggregator.WebTransferAggregation>(new JsonTextReader(new StringReader(src))));
            }

            var count = GetCount();

            var callCount       = new int[count];
            var requestLengths  = new long[count];
            var responseLengths = new long[count];

            foreach (var item in _timeLine)
            {
                var i    = GetIndex(item);
                var data = Deserialize(item.Data);
                callCount[i]       = data.CallCount;
                requestLengths[i]  = data.RequestLengths;
                responseLengths[i] = data.ResponseLengths;
            }

            return(new
            {
                DataType = "WebTransfer",
                Start = _startTime,
                End = _endTime,
                TimeWindow = _timeWindow.ToString(),
                Resolution = _resolution.ToString(),
                CallCount = callCount,
                RequestLengths = requestLengths,
                ResponseLengths = responseLengths,
            });
        }
        public async Task <IEnumerable <Aggregation> > LoadAggregatedUsageAsync(string dataType, TimeResolution resolution, DateTime startTime, DateTime endTimeExclusive,
                                                                                CancellationToken cancellation)
        {
            var aggregations = new List <Aggregation>();

            using (var ctx = new MsSqlDataContext(ConnectionString, DataOptions, CancellationToken.None))
            {
                await ctx.ExecuteReaderAsync(LoadAggregatedUsageScript, cmd =>
                {
                    cmd.Parameters.AddRange(new[]
                    {
                        ctx.CreateParameter("@DataType", DbType.String, dataType),
                        ctx.CreateParameter("@Resolution", DbType.String, resolution.ToString()),
                        ctx.CreateParameter("@StartTime", DbType.DateTime2, startTime),
                        ctx.CreateParameter("@EndTimeExclusive", DbType.DateTime2, endTimeExclusive),
                    });
                }, async (reader, cancel) => {
                    while (await reader.ReadAsync(cancel))
                    {
                        aggregations.Add(GetAggregationFromReader(reader));
                    }
                    return(true);
                }).ConfigureAwait(false);
            }
            return(aggregations);
        }
Beispiel #3
0
        public object GetViewModel()
        {
            WebHookAggregation Deserialize(string src)
            {
                return(JsonSerializer.Create()
                       .Deserialize <WebHookAggregation>(new JsonTextReader(new StringReader(src))));
            }

            var count = GetCount();

            var callCount       = new int[count];
            var requestLengths  = new long[count];
            var responseLengths = new long[count];
            var status100       = new int[count];
            var status200       = new int[count];
            var status300       = new int[count];
            var status400       = new int[count];
            var status500       = new int[count];

            foreach (var item in _timeLine)
            {
                var i    = GetIndex(item);
                var data = Deserialize(item.Data);
                callCount[i]       = data.CallCount;
                requestLengths[i]  = data.RequestLengths;
                responseLengths[i] = data.ResponseLengths;
                status100[i]       = data.StatusCounts[0];
                status200[i]       = data.StatusCounts[1];
                status300[i]       = data.StatusCounts[2];
                status400[i]       = data.StatusCounts[3];
                status500[i]       = data.StatusCounts[4];
            }

            return(new
            {
                DataType = "WebHook",
                Start = _startTime,
                End = _endTime,
                TimeWindow = _timeWindow.ToString(),
                Resolution = _resolution.ToString(),
                CallCount = callCount,
                RequestLengths = requestLengths,
                ResponseLengths = responseLengths,
                Status100 = status100,
                Status200 = status200,
                Status300 = status300,
                Status400 = status400,
                Status500 = status500,
            });
        }
 public async Task CleanupAggregationsAsync(string dataType, TimeResolution resolution, DateTime retentionTime,
                                            CancellationToken cancellation)
 {
     using (var ctx = new MsSqlDataContext(ConnectionString, DataOptions, CancellationToken.None))
     {
         await ctx.ExecuteNonQueryAsync(CleanupAggregationsScript, cmd =>
         {
             cmd.Parameters.AddRange(new[]
             {
                 ctx.CreateParameter("@DataType", DbType.String, dataType),
                 ctx.CreateParameter("@Resolution", DbType.AnsiString, resolution.ToString()),
                 ctx.CreateParameter("@RetentionTime", SqlDbType.DateTime2, retentionTime),
             });
         }).ConfigureAwait(false);
     }
 }