/// <summary> Gets report statistic. </summary> /// <param name="request"> The request. </param> /// <returns> The report statistic. </returns> private async Task <ReportStatResult> GetReportStatistic(GetReportStatistics request) { ReportIncludeItemTypes reportRowType = ReportHelper.GetRowType(request.IncludeItemTypes); QueryResult <BaseItem> queryResult = await GetQueryResult(request).ConfigureAwait(false); ReportStatBuilder reportBuilder = new ReportStatBuilder(_libraryManager); ReportStatResult reportResult = reportBuilder.GetResult(queryResult.Items, ReportHelper.GetRowType(request.IncludeItemTypes), request.TopItems ?? 5); reportResult.TotalRecordCount = reportResult.Groups.Count(); return(reportResult); }
/// <summary> Gets the given request. </summary> /// <param name="request"> The request. </param> /// <returns> A Task<object> </returns> public async Task <object> Get(GetReportDownload request) { if (string.IsNullOrEmpty(request.IncludeItemTypes)) { return(null); } request.DisplayType = "Export"; ReportViewType reportViewType = ReportHelper.GetReportViewType(request.ReportView); var headers = new Dictionary <string, string>(); string fileExtension = "csv"; string contentType = "text/plain;charset='utf-8'"; switch (request.ExportType) { case ReportExportType.CSV: break; case ReportExportType.Excel: contentType = "application/vnd.ms-excel"; fileExtension = "xls"; break; } var filename = "ReportExport." + fileExtension; headers["Content-Disposition"] = string.Format("attachment; filename=\"{0}\"", filename); headers["Content-Encoding"] = "UTF-8"; var user = !string.IsNullOrWhiteSpace(request.UserId) ? _userManager.GetUserById(request.UserId) : null; ReportResult result = null; switch (reportViewType) { case ReportViewType.ReportData: ReportIncludeItemTypes reportRowType = ReportHelper.GetRowType(request.IncludeItemTypes); ReportBuilder dataBuilder = new ReportBuilder(_libraryManager); QueryResult <BaseItem> queryResult = await GetQueryResult(request, user).ConfigureAwait(false); result = dataBuilder.GetResult(queryResult.Items, request); result.TotalRecordCount = queryResult.TotalRecordCount; break; case ReportViewType.ReportActivities: result = GetReportActivities(request); break; } string returnResult = string.Empty; switch (request.ExportType) { case ReportExportType.CSV: returnResult = new ReportExport().ExportToCsv(result); break; case ReportExportType.Excel: returnResult = new ReportExport().ExportToExcel(result); break; } return(ResultFactory.GetResult(returnResult, contentType, headers)); }
/// <summary> Gets the headers. </summary> /// <typeparam name="H"> Type of the header. </typeparam> /// <param name="request"> The request. </param> /// <returns> The headers. </returns> /// <seealso cref="M:MediaBrowser.Api.Reports.ReportBuilderBase.GetHeaders{H}(H)"/> protected internal override List <ReportHeader> GetHeaders <H>(H request) { ReportIncludeItemTypes reportRowType = ReportHelper.GetRowType(request.IncludeItemTypes); return(this.GetHeaders <BaseItem>(request, () => this.GetDefaultHeaderMetadata(reportRowType), (hm) => this.GetOption(hm))); }