public async Task WriteDataAsync(IStatisticalDataRecord data, CancellationToken cancellation)
 {
     using (var ctx = new MsSqlDataContext(ConnectionString, DataOptions, CancellationToken.None))
     {
         await ctx.ExecuteNonQueryAsync(WriteDataScript, cmd =>
         {
             var now = DateTime.UtcNow;
             cmd.Parameters.AddRange(new[]
             {
                 ctx.CreateParameter("@DataType", SqlDbType.NVarChar, 50, data.DataType),
                 ctx.CreateParameter("@WrittenTime", SqlDbType.DateTime2, now),
                 ctx.CreateParameter("@CreationTime", SqlDbType.DateTime2, data.CreationTime ?? now),
                 ctx.CreateParameter("@Duration", SqlDbType.BigInt, (object)data.Duration?.Ticks ?? DBNull.Value),
                 ctx.CreateParameter("@RequestLength", SqlDbType.BigInt, (object)data.RequestLength ?? DBNull.Value),
                 ctx.CreateParameter("@ResponseLength", SqlDbType.BigInt, (object)data.ResponseLength ?? DBNull.Value),
                 ctx.CreateParameter("@ResponseStatusCode", SqlDbType.Int, (object)data.ResponseStatusCode ?? DBNull.Value),
                 ctx.CreateParameter("@Url", SqlDbType.NVarChar, 1000, (object)data.Url ?? DBNull.Value),
                 ctx.CreateParameter("@TargetId", SqlDbType.Int, (object)data.TargetId ?? DBNull.Value),
                 ctx.CreateParameter("@ContentId", SqlDbType.Int, (object)data.ContentId ?? DBNull.Value),
                 ctx.CreateParameter("@EventName", SqlDbType.NVarChar, 50, (object)data.EventName ?? DBNull.Value),
                 ctx.CreateParameter("@ErrorMessage", SqlDbType.NVarChar, 500, (object)data.ErrorMessage ?? DBNull.Value),
                 ctx.CreateParameter("@GeneralData", SqlDbType.NVarChar, (object)data.GeneralData ?? DBNull.Value),
             });
         }).ConfigureAwait(false);
     }
 }
Esempio n. 2
0
 public ApiUsageListItemViewModel(IStatisticalDataRecord record)
 {
     CreationTime       = record.CreationTime ?? DateTime.MinValue;
     Duration           = record.Duration ?? TimeSpan.Zero;
     RequestLength      = record.RequestLength ?? 0;
     ResponseLength     = record.ResponseLength ?? 0;
     ResponseStatusCode = record.ResponseStatusCode ?? 0;
     Url = record.Url;
 }
Esempio n. 3
0
        public void Aggregate(IStatisticalDataRecord data)
        {
            _aggregation.CallCount++;
            _aggregation.RequestLengths  += data.RequestLength ?? 0;
            _aggregation.ResponseLengths += data.ResponseLength ?? 0;
            var leadDigit = (data.ResponseStatusCode ?? 0) / 100 - 1;

            if (leadDigit >= 0 && leadDigit < 5)
            {
                _aggregation.StatusCounts[leadDigit]++;
            }
        }
Esempio n. 4
0
        public WebHookUsageListItemViewModel(IStatisticalDataRecord record)
        {
            var isPermitted = IsPermitted(record.ContentId);

            CreationTime       = record.CreationTime ?? DateTime.MinValue;
            Duration           = record.Duration ?? TimeSpan.Zero;
            RequestLength      = record.RequestLength ?? 0;
            ResponseLength     = record.ResponseLength ?? 0;
            ResponseStatusCode = record.ResponseStatusCode ?? 0;
            Url          = record.Url;
            WebHookId    = record.TargetId ?? 0;
            ContentId    = record.ContentId ?? 0;
            EventName    = record.EventName;
            ErrorMessage = record.ErrorMessage;
            Payload      = isPermitted ? record.GeneralData : null;
        }
Esempio n. 5
0
 private IStatisticalDataRecord CloneRecord(IStatisticalDataRecord record)
 {
     return(new StatisticalDataRecord
     {
         Id = record.Id,
         DataType = record.DataType,
         WrittenTime = record.WrittenTime,
         CreationTime = record.CreationTime,
         Duration = record.Duration,
         RequestLength = record.RequestLength,
         ResponseLength = record.ResponseLength,
         ResponseStatusCode = record.ResponseStatusCode,
         Url = record.Url,
         TargetId = record.TargetId,
         ContentId = record.ContentId,
         EventName = record.EventName,
         ErrorMessage = record.ErrorMessage,
         GeneralData = record.GeneralData
     });
 }
Esempio n. 6
0
        public STT.Task WriteDataAsync(IStatisticalDataRecord data, CancellationToken cancel)
        {
            var now = DateTime.UtcNow;

            Storage.Add(new StatisticalDataRecord
            {
                Id                 = GetNextId(),
                DataType           = data.DataType,
                WrittenTime        = now,
                CreationTime       = data.CreationTime ?? now,
                Duration           = data.Duration,
                RequestLength      = data.RequestLength,
                ResponseLength     = data.ResponseLength,
                ResponseStatusCode = data.ResponseStatusCode,
                Url                = data.Url,
                TargetId           = data.TargetId,
                ContentId          = data.ContentId,
                EventName          = data.EventName,
                ErrorMessage       = data.ErrorMessage,
                GeneralData        = data.GeneralData
            });

            return(System.Threading.Tasks.Task.CompletedTask);
        }
 public void Aggregate(IStatisticalDataRecord data)
 {
     _aggregation.CallCount++;
     _aggregation.RequestLengths  += data.RequestLength ?? 0;
     _aggregation.ResponseLengths += data.ResponseLength ?? 0;
 }
 public Task WriteDataAsync(IStatisticalDataRecord data, CancellationToken cancel)
 {
     return(Task.CompletedTask);
 }