public async Task <UsageDataTableResult> GetExceptions(Guid telemetryKey, TelemetryItemTypes itemType, int skip , int take, IEnumerable <Tuple <string, bool> > sortBy, ISearch requestSearch , List <string> searchableColumns) { Program program = await this.portalContext.Programs.FirstOrDefaultAsync(x => x.TelemetryKey == telemetryKey).ConfigureAwait(false); if (program == null) { throw new ArgumentException($"Program with key {telemetryKey} does not exist"); } IQueryable <ExceptionInfo> query = this.telemetryContext.Exceptions.Where(x => x.ProgramId == program.Id); int totalCount = await this.telemetryContext.Exceptions.CountAsync(x => x.ProgramId == program.Id).ConfigureAwait(false); if (take == -1) { take = totalCount; } IQueryable <ExceptionInfo> filteredQuery = EntityFilter.Match(query , property => property.Contains(requestSearch.Value) , new List <Expression <Func <ExceptionInfo, string> > >() { { x => x.Sequence }, { x => x.Message }, { x => x.TypeName }, { x => x.ProgramVersion }, { x => x.ParsedStack }, { x => x.UserName }, }); List <ExceptionInfo> ordered = await ApplyOrderingQuery(sortBy, filteredQuery, skip, take).ConfigureAwait(false); List <ExceptionData> result = new List <ExceptionData>(); foreach (ExceptionInfo exception in ordered) { ExceptionData data = new ExceptionData { Timestamp = exception.Timestamp , UserName = exception.UserName , EntryKey = exception.TypeName , Note = exception.Note , ProgramVersion = exception.ProgramVersion , Sequence = exception.Sequence , ErrorMessage = exception.Message , StackTrace = GetStackTrace(exception.ParsedStack) , Properties = exception.TelemetryUnits.Where(x => x.UnitType == TelemetryUnit.UnitTypes.Property).ToDictionary(x => x.Key, x => x.ValueString) , Metrics = exception.TelemetryUnits.Where(x => x.UnitType == TelemetryUnit.UnitTypes.Metric).ToDictionary(x => x.Key, x => x.ValueDouble) }; result.Add(data); } return(new UsageDataTableResult { TotalCount = totalCount, FilteredCount = totalCount, UsageData = result }); }
public async Task <UsageDataTableResult> GetLogs(Guid telemetryKey, int skip, int take, IEnumerable <Tuple <string, bool> > sortBy, string searchPhrase) { Program program = await this.portalContext.Programs.FirstOrDefaultAsync(x => x.TelemetryKey == telemetryKey).ConfigureAwait(false); if (program == null) { throw new ArgumentException($"Program with key {telemetryKey} does not exist"); } IQueryable <LogMessage> query = this.telemetryContext.LogMessages.Where(x => x.ProgramId == program.Id); int totalCount = await this.telemetryContext.LogMessages.CountAsync(x => x.ProgramId == program.Id).ConfigureAwait(false); if (take == -1) { take = totalCount; } IQueryable <LogMessage> filteredQuery = EntityFilter.Match(query , property => property.Contains(searchPhrase) , new List <Expression <Func <LogMessage, string> > >() { { x => x.Sequence }, { x => x.Message }, { x => x.ProgramVersion }, { x => x.UserName }, }); List <LogMessage> ordered = await ApplyOrderingQuery(sortBy, filteredQuery, skip, take).ConfigureAwait(false); List <LogMessageData> result = new List <LogMessageData>(); foreach (LogMessage item in ordered) { LogMessageData data = new LogMessageData { Timestamp = item.Timestamp, UserName = item.UserName, Message = item.Message , ProgramVersion = item.ProgramVersion , Sequence = item.Sequence , LogLevel = item.Level.ToString() }; result.Add(data); } return(new UsageDataTableResult { TotalCount = totalCount, FilteredCount = totalCount, UsageData = result }); }
public async Task <UsageDataTableResult> GetProgramUsageData(Guid telemetryKey, TelemetryItemTypes itemType , int skip, int take, IEnumerable <Tuple <string, bool> > sortBy, ISearch requestSearch , List <string> searchableColumns) { Program program = await this.portalContext.Programs.FirstOrDefaultAsync(x => x.TelemetryKey == telemetryKey).ConfigureAwait(false); if (program == null) { throw new ArgumentException($"Program with key {telemetryKey} does not exist"); } IQueryable <TelemetryDetail> query; int totalCount; if (itemType == TelemetryItemTypes.View) { query = this.telemetryContext.ViewTelemetryDetails.Where(x => x.TelemetrySummary.View.ProgramId == program.Id); totalCount = await this.telemetryContext.ViewTelemetryDetails.CountAsync(x => x.TelemetrySummary.View.ProgramId == program.Id).ConfigureAwait(false); } else { query = this.telemetryContext.EventTelemetryDetails.Where(x => x.TelemetrySummary.Event.ProgramId == program.Id && !string.IsNullOrEmpty(x.TelemetrySummary.Event.Name)); //todo remove this empty string check after dealing with heartbeat data totalCount = await this.telemetryContext.EventTelemetryDetails.CountAsync(x => x.TelemetrySummary.Event.ProgramId == program.Id && !string.IsNullOrEmpty(x.TelemetrySummary.Event.Name)).ConfigureAwait(false); } IQueryable <TelemetryDetail> filteredQuery = EntityFilter.Match(query , property => property.Contains(requestSearch.Value) , new List <Expression <Func <TelemetryDetail, string> > >() { { x => x.Sequence }, { x => x.IpAddress }, { x => x.UserIdentifier }, { x => x.EntryKey }, }); if (take == -1) { take = totalCount; } List <TelemetryDetail> usages = await ApplyOrderingQuery(sortBy, filteredQuery, skip, take).ConfigureAwait(false); List <DataTableTelemetryData> result = new List <DataTableTelemetryData>(); foreach (TelemetryDetail detail in usages) { DataTableTelemetryData data = new DataTableTelemetryData() { Timestamp = detail.Timestamp , UserName = detail.UserIdentifier , IpAddress = detail.IpAddress , EntryKey = detail.EntryKey , ProgramVersion = detail.FileVersion , Sequence = detail.Sequence , Properties = detail.GetTelemetryUnits().Where(x => x.UnitType == TelemetryUnit.UnitTypes.Property).ToDictionary(x => x.Key, x => x.ValueString) , Metrics = detail.GetTelemetryUnits().Where(x => x.UnitType == TelemetryUnit.UnitTypes.Metric).ToDictionary(x => x.Key, x => x.ValueDouble) }; result.Add(data); } return(new UsageDataTableResult { TotalCount = totalCount, FilteredCount = totalCount, UsageData = result }); }