Ejemplo n.º 1
0
        private readonly IUserManager _userManager; ///< Manager for user

        #endregion

        #region [Public Methods]

        /// <summary> Gets the given request. </summary>
        /// <param name="request"> The request. </param>
        /// <returns> A Task&lt;object&gt; </returns>
        public async Task <object> Get(GetActivityLogs request)
        {
            request.DisplayType = "Screen";
            ReportResult result = await GetReportActivities(request).ConfigureAwait(false);

            return(ToOptimizedResult(result));
        }
Ejemplo n.º 2
0
        /// <summary> Export to CSV. </summary>
        /// <param name="reportResult"> The report result. </param>
        /// <returns> A string. </returns>
        public string ExportToCsv(ReportResult reportResult)
        {
            StringBuilder returnValue = new StringBuilder();

            returnValue.AppendLine(string.Join(";", reportResult.Headers.Select(s => s.Name.Replace(',', ' ')).ToArray()));

            if (reportResult.IsGrouped)
            {
                foreach (ReportGroup group in reportResult.Groups)
                {
                    foreach (ReportRow row in reportResult.Rows)
                    {
                        returnValue.AppendLine(string.Join(";", row.Columns.Select(s => s.Name.Replace(',', ' ')).ToArray()));
                    }
                }
            }
            else
            {
                foreach (ReportRow row in reportResult.Rows)
                {
                    returnValue.AppendLine(string.Join(";", row.Columns.Select(s => s.Name.Replace(',', ' ')).ToArray()));
                }
            }

            return(returnValue.ToString());
        }
Ejemplo n.º 3
0
        private readonly IUserManager _userManager; ///< Manager for user

        #endregion

        #region [Public Methods]

        /// <summary> Gets the given request. </summary>
        /// <param name="request"> The request. </param>
        /// <returns> A Task&lt;object&gt; </returns>
        public object Get(GetActivityLogs request)
        {
            request.DisplayType = "Screen";
            ReportResult result = GetReportActivities(request);

            return(ToOptimizedResult(result));
        }
Ejemplo n.º 4
0
        public ReportResult GetReportResult(BaseItem[] items, ReportViewType reportRowType, BaseReportRequest request)
        {
            List <HeaderMetadata> headersMetadata = this.GetFilteredReportHeaderMetadata(reportRowType, request);

            var headers = GetReportHeaders(reportRowType, headersMetadata);
            var rows    = GetReportRows(items, headersMetadata);

            ReportResult result = new ReportResult {
                Headers = headers
            };
            HeaderMetadata groupBy = ReportHelper.GetHeaderMetadataType(request.GroupBy);
            int            i       = headers.FindIndex(x => x.FieldName == groupBy);

            if (groupBy != HeaderMetadata.None && i > 0)
            {
                var rowsGroup = rows.SelectMany(x => x.Columns[i].Name.Split(';'), (x, g) => new { Genre = g.Trim(), Rows = x })
                                .GroupBy(x => x.Genre)
                                .OrderBy(x => x.Key)
                                .Select(x => new ReportGroup {
                    Name = x.Key, Rows = x.Select(r => r.Rows).ToList()
                });

                result.Groups    = rowsGroup.ToList();
                result.IsGrouped = true;
            }
            else
            {
                result.Rows      = rows;
                result.IsGrouped = false;
            }

            return(result);
        }
Ejemplo n.º 5
0
		public ReportResult GetReportResult(BaseItem[] items, ReportViewType reportRowType, BaseReportRequest request)
		{
			List<HeaderMetadata> headersMetadata = this.GetFilteredReportHeaderMetadata(reportRowType, request);

			var headers = GetReportHeaders(reportRowType, headersMetadata);
			var rows = GetReportRows(items, headersMetadata);

			ReportResult result = new ReportResult { Headers = headers };
			HeaderMetadata groupBy = ReportHelper.GetHeaderMetadataType(request.GroupBy);
			int i = headers.FindIndex(x => x.FieldName == groupBy);
			if (groupBy != HeaderMetadata.None && i > 0)
			{
				var rowsGroup = rows.SelectMany(x => x.Columns[i].Name.Split(';'), (x, g) => new { Genre = g.Trim(), Rows = x })
					.GroupBy(x => x.Genre)
					.OrderBy(x => x.Key)
					.Select(x => new ReportGroup { Name = x.Key, Rows = x.Select(r => r.Rows).ToList() });

				result.Groups = rowsGroup.ToList();
				result.IsGrouped = true;
			}
			else
			{
				result.Rows = rows;
				result.IsGrouped = false;
			}

			return result;
		}
Ejemplo n.º 6
0
 private static void ExportToExcelRow(ReportResult reportResult,
                                      StringBuilder returnValue,
                                      ReportRow row)
 {
     returnValue.AppendLine("<tr>");
     returnValue.AppendLine(string.Join("", row.Columns.Select(s => string.Format("<td>{0}</td>", s.Name)).ToArray()));
     returnValue.AppendLine("</tr>");
 }
Ejemplo n.º 7
0
        private ReportResult GetReportResult(QueryResult <BaseItem> queryResult)
        {
            var reportResult = new ReportResult();

            // Fill rows and columns

            return(reportResult);
        }
Ejemplo n.º 8
0
        /// <summary> Gets report result. </summary>
        /// <param name="request"> The request. </param>
        /// <returns> The report result. </returns>
        private ReportResult GetReportResult(GetItemReport request, User user)
        {
            ReportBuilder          reportBuilder = new ReportBuilder(_libraryManager);
            QueryResult <BaseItem> queryResult   = GetQueryResult(request, user);
            ReportResult           reportResult  = reportBuilder.GetResult(queryResult.Items, request);

            reportResult.TotalRecordCount = queryResult.TotalRecordCount;

            return(reportResult);
        }
Ejemplo n.º 9
0
        /// <summary> Gets report result. </summary>
        /// <param name="request"> The request. </param>
        /// <returns> The report result. </returns>
        private async Task <ReportResult> GetReportResult(GetItemReport request)
        {
            ReportBuilder          reportBuilder = new ReportBuilder(_libraryManager);
            QueryResult <BaseItem> queryResult   = await GetQueryResult(request).ConfigureAwait(false);

            ReportResult reportResult = reportBuilder.GetResult(queryResult.Items, request);

            reportResult.TotalRecordCount = queryResult.TotalRecordCount;

            return(reportResult);
        }
Ejemplo n.º 10
0
        /// <summary> Gets the given request. </summary>
        /// <param name="request"> The request. </param>
        /// <returns> A Task&lt;object&gt; </returns>
        public async Task <object> Get(GetReportDownload request)
        {
            if (string.IsNullOrEmpty(request.IncludeItemTypes))
            {
                return(null);
            }

            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";

            ReportViewType         reportRowType = ReportHelper.GetRowType(request.IncludeItemTypes);
            ReportBuilder          reportBuilder = new ReportBuilder(_libraryManager);
            QueryResult <BaseItem> queryResult   = await GetQueryResult(request).ConfigureAwait(false);

            ReportResult reportResult = reportBuilder.GetReportResult(queryResult.Items, reportRowType, request);

            reportResult.TotalRecordCount = queryResult.TotalRecordCount;

            string result = string.Empty;

            switch (request.ExportType)
            {
            case ReportExportType.CSV:
                result = new ReportExport().ExportToCsv(reportResult);
                break;

            case ReportExportType.Excel:
                result = new ReportExport().ExportToExcel(reportResult);
                break;
            }

            object ro = ResultFactory.GetResult(result, contentType, headers);

            return(ro);
        }
Ejemplo n.º 11
0
		/// <summary> Export to CSV. </summary>
		/// <param name="reportResult"> The report result. </param>
		/// <returns> A string. </returns>
		public string ExportToCsv(ReportResult reportResult)
		{
			StringBuilder returnValue = new StringBuilder();

			returnValue.AppendLine(string.Join(";", reportResult.Headers.Select(s => s.Name.Replace(',', ' ')).ToArray()));

			if (reportResult.IsGrouped)
				foreach (ReportGroup group in reportResult.Groups)
				{
					foreach (ReportRow row in reportResult.Rows)
					{
						returnValue.AppendLine(string.Join(";", row.Columns.Select(s => s.Name.Replace(',', ' ')).ToArray()));
					}
				}
			else
				foreach (ReportRow row in reportResult.Rows)
				{
					returnValue.AppendLine(string.Join(";", row.Columns.Select(s => s.Name.Replace(',', ' ')).ToArray()));
				}

			return returnValue.ToString();
		}
Ejemplo n.º 12
0
        /// <summary> Gets report result. </summary>
        /// <param name="items"> The items. </param>
        /// <param name="request"> The request. </param>
        /// <returns> The report result. </returns>
        public ReportResult GetResult(BaseItem[] items, IReportsQuery request)
        {
            ReportIncludeItemTypes reportRowType = ReportHelper.GetRowType(request.IncludeItemTypes);
            ReportDisplayType      displayType   = ReportHelper.GetReportDisplayType(request.DisplayType);

            List <ReportOptions <BaseItem> > options = this.GetReportOptions <BaseItem>(request,
                                                                                        () => this.GetDefaultHeaderMetadata(reportRowType),
                                                                                        (hm) => this.GetOption(hm)).Where(x => this.DisplayTypeVisible(x.Header.DisplayType, displayType)).ToList();

            var headers = GetHeaders <BaseItem>(options);
            var rows    = GetReportRows(items, options);

            ReportResult result = new ReportResult {
                Headers = headers
            };
            HeaderMetadata groupBy = ReportHelper.GetHeaderMetadataType(request.GroupBy);
            int            i       = headers.FindIndex(x => x.FieldName == groupBy);

            if (groupBy != HeaderMetadata.None && i >= 0)
            {
                var rowsGroup = rows.SelectMany(x => x.Columns[i].Name.Split(';'), (x, g) => new { Group = g.Trim(), Rows = x })
                                .GroupBy(x => x.Group)
                                .OrderBy(x => x.Key)
                                .Select(x => new ReportGroup {
                    Name = x.Key, Rows = x.Select(r => r.Rows).ToList()
                });

                result.Groups    = rowsGroup.ToList();
                result.IsGrouped = true;
            }
            else
            {
                result.Rows      = rows;
                result.IsGrouped = false;
            }

            return(result);
        }
Ejemplo n.º 13
0
		/// <summary> Export to excel. </summary>
		/// <param name="reportResult"> The report result. </param>
		/// <returns> A string. </returns>
		public string ExportToExcel(ReportResult reportResult)
		{

			string style = @"<style type='text/css'>
							BODY {
									font-family: Arial;
									font-size: 12px;
								}

								TABLE {
									font-family: Arial;
									font-size: 12px;
								}

								A {
									font-family: Arial;
									color: #144A86;
									font-size: 12px;
									cursor: pointer;
									text-decoration: none;
									font-weight: bold;
								}
								DIV {
									font-family: Arial;
									font-size: 12px;
									margin-bottom: 0px;
								}
								P, LI, DIV {
									font-size: 12px;
									margin-bottom: 0px;
								}

								P, UL {
									font-size: 12px;
									margin-bottom: 6px;
									margin-top: 0px;
								}

								H1 {
									font-size: 18pt;
								}

								H2 {
									font-weight: bold;
									font-size: 14pt;
									COLOR: #C0C0C0;
								}

								H3 {
									font-weight: normal;
									font-size: 14pt;
									text-indent: +1em;
								}

								H4 {
									font-size: 10pt;
									font-weight: normal;
								}

								H5 {
									font-size: 10pt;
									font-weight: normal;
									background: #A9A9A9;
									COLOR: white;
									display: inline;
								}

								H6 {
									padding: 2 1 2 5;
									font-size: 11px;
									font-weight: bold;
									text-decoration: none;
									margin-bottom: 1px;
								}

								UL {
									line-height: 1.5em;
									list-style-type: disc;
								}

								OL {
									line-height: 1.5em;
								}

								LI {
									line-height: 1.5em;
								}

								A IMG {
									border: 0;
								}

								table.gridtable {
									color: #333333;
									border-width: 0.1pt;
									border-color: #666666;
									border-collapse: collapse;
								}

								table.gridtable th {
									border-width: 0.1pt;
									padding: 8px;
									border-style: solid;
									border-color: #666666;
									background-color: #dedede;
								}
								table.gridtable tr {
									background-color: #ffffff;
								}
								table.gridtable td {
									border-width: 0.1pt;
									padding: 8px;
									border-style: solid;
									border-color: #666666;
									background-color: #ffffff;
								}
						</style>";

			string Html = @"<!DOCTYPE html>
							<html xmlns='http://www.w3.org/1999/xhtml'>
							<head>
							<meta http-equiv='X-UA-Compatible' content='IE=8, IE=9, IE=10' />
							<meta charset='utf-8'>
							<title>Emby Reports Export</title>";
			Html += "\n" + style + "\n";
			Html += "</head>\n";
			Html += "<body>\n";

			StringBuilder returnValue = new StringBuilder();
			returnValue.AppendLine("<table  class='gridtable'>");
			returnValue.AppendLine("<tr>");
			returnValue.AppendLine(string.Join("", reportResult.Headers.Select(s => string.Format("<th>{0}</th>", s.Name)).ToArray()));
			returnValue.AppendLine("</tr>");
			if (reportResult.IsGrouped)
				foreach (ReportGroup group in reportResult.Groups)
				{
					returnValue.AppendLine("<tr>");
					returnValue.AppendLine("<th scope='rowgroup' colspan='" + reportResult.Headers.Count + "'>" + (string.IsNullOrEmpty(group.Name) ? "&nbsp;" : group.Name) + "</th>");
					returnValue.AppendLine("</tr>");
					foreach (ReportRow row in group.Rows)
					{
						ExportToExcelRow(reportResult, returnValue, row);
					}
					returnValue.AppendLine("<tr>");
					returnValue.AppendLine("<th style='background-color: #ffffff;' scope='rowgroup' colspan='" + reportResult.Headers.Count + "'>" + "&nbsp;" + "</th>");
					returnValue.AppendLine("</tr>");
				}

			else
				foreach (ReportRow row in reportResult.Rows)
				{
					ExportToExcelRow(reportResult, returnValue, row);
				}
			returnValue.AppendLine("</table>");

			Html += returnValue.ToString();
			Html += "</body>";
			Html += "</html>";
			return Html;
		}
Ejemplo n.º 14
0
		private static void ExportToExcelRow(ReportResult reportResult,
			StringBuilder returnValue,
			ReportRow row)
		{
			returnValue.AppendLine("<tr>");
			returnValue.AppendLine(string.Join("", row.Columns.Select(s => string.Format("<td>{0}</td>", s.Name)).ToArray()));
			returnValue.AppendLine("</tr>");
		}
Ejemplo n.º 15
0
        /// <summary> Export to excel. </summary>
        /// <param name="reportResult"> The report result. </param>
        /// <returns> A string. </returns>
        public string ExportToExcel(ReportResult reportResult)
        {
            string style = @"<style type='text/css'>
							BODY {
									font-family: Arial;
									font-size: 12px;
								}

								TABLE {
									font-family: Arial;
									font-size: 12px;
								}

								A {
									font-family: Arial;
									color: #144A86;
									font-size: 12px;
									cursor: pointer;
									text-decoration: none;
									font-weight: bold;
								}
								DIV {
									font-family: Arial;
									font-size: 12px;
									margin-bottom: 0px;
								}
								P, LI, DIV {
									font-size: 12px;
									margin-bottom: 0px;
								}

								P, UL {
									font-size: 12px;
									margin-bottom: 6px;
									margin-top: 0px;
								}

								H1 {
									font-size: 18pt;
								}

								H2 {
									font-weight: bold;
									font-size: 14pt;
									COLOR: #C0C0C0;
								}

								H3 {
									font-weight: normal;
									font-size: 14pt;
									text-indent: +1em;
								}

								H4 {
									font-size: 10pt;
									font-weight: normal;
								}

								H5 {
									font-size: 10pt;
									font-weight: normal;
									background: #A9A9A9;
									COLOR: white;
									display: inline;
								}

								H6 {
									padding: 2 1 2 5;
									font-size: 11px;
									font-weight: bold;
									text-decoration: none;
									margin-bottom: 1px;
								}

								UL {
									line-height: 1.5em;
									list-style-type: disc;
								}

								OL {
									line-height: 1.5em;
								}

								LI {
									line-height: 1.5em;
								}

								A IMG {
									border: 0;
								}

								table.gridtable {
									color: #333333;
									border-width: 0.1pt;
									border-color: #666666;
									border-collapse: collapse;
								}

								table.gridtable th {
									border-width: 0.1pt;
									padding: 8px;
									border-style: solid;
									border-color: #666666;
									background-color: #dedede;
								}
								table.gridtable tr {
									background-color: #ffffff;
								}
								table.gridtable td {
									border-width: 0.1pt;
									padding: 8px;
									border-style: solid;
									border-color: #666666;
									background-color: #ffffff;
								}
						</style>"                        ;

            string Html = @"<!DOCTYPE html>
							<html xmlns='http://www.w3.org/1999/xhtml'>
							<head>
							<meta http-equiv='X-UA-Compatible' content='IE=8, IE=9, IE=10' />
							<meta charset='utf-8'>
							<title>Emby Reports Export</title>"                            ;

            Html += "\n" + style + "\n";
            Html += "</head>\n";
            Html += "<body>\n";

            StringBuilder returnValue = new StringBuilder();

            returnValue.AppendLine("<table  class='gridtable'>");
            returnValue.AppendLine("<tr>");
            returnValue.AppendLine(string.Join("", reportResult.Headers.Select(s => string.Format("<th>{0}</th>", s.Name)).ToArray()));
            returnValue.AppendLine("</tr>");
            if (reportResult.IsGrouped)
            {
                foreach (ReportGroup group in reportResult.Groups)
                {
                    returnValue.AppendLine("<tr>");
                    returnValue.AppendLine("<th scope='rowgroup' colspan='" + reportResult.Headers.Count + "'>" + (string.IsNullOrEmpty(group.Name) ? "&nbsp;" : group.Name) + "</th>");
                    returnValue.AppendLine("</tr>");
                    foreach (ReportRow row in group.Rows)
                    {
                        ExportToExcelRow(reportResult, returnValue, row);
                    }
                    returnValue.AppendLine("<tr>");
                    returnValue.AppendLine("<th style='background-color: #ffffff;' scope='rowgroup' colspan='" + reportResult.Headers.Count + "'>" + "&nbsp;" + "</th>");
                    returnValue.AppendLine("</tr>");
                }
            }

            else
            {
                foreach (ReportRow row in reportResult.Rows)
                {
                    ExportToExcelRow(reportResult, returnValue, row);
                }
            }
            returnValue.AppendLine("</table>");

            Html += returnValue.ToString();
            Html += "</body>";
            Html += "</html>";
            return(Html);
        }
        /// <summary> Gets the given request. </summary>
        /// <param name="request"> The request. </param>
        /// <returns> A Task&lt;object&gt; </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.ReportStatistics:
            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));
        }