V10: fix build warnings in Web.BackOffice (#12479)

* Run code cleanup

* Start manual run

* Finish dotnet format + manual cleanup

* Fix up after merge

* Fix substrings changed to [..]

Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk>
Co-authored-by: Zeegaan <nge@umbraco.dk>
This commit is contained in:
Nikolaj Geisle
2022-06-20 08:37:17 +02:00
committed by GitHub
parent 7688c61621
commit e762fa91bc
234 changed files with 28037 additions and 27527 deletions

View File

@@ -1,5 +1,3 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@@ -11,154 +9,146 @@ using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Web.Common.Attributes;
using Umbraco.Cms.Web.Common.Authorization;
using Umbraco.Cms.Web.Common.DependencyInjection;
using Constants = Umbraco.Cms.Core.Constants;
namespace Umbraco.Cms.Web.BackOffice.Controllers
namespace Umbraco.Cms.Web.BackOffice.Controllers;
/// <summary>
/// Backoffice controller supporting the dashboard for viewing logs with some simple graphs & filtering
/// </summary>
[PluginController(Constants.Web.Mvc.BackOfficeApiArea)]
[Authorize(Policy = AuthorizationPolicies.SectionAccessSettings)]
public class LogViewerController : BackOfficeNotificationsController
{
/// <summary>
/// Backoffice controller supporting the dashboard for viewing logs with some simple graphs & filtering
/// </summary>
[PluginController(Constants.Web.Mvc.BackOfficeApiArea)]
[Authorize(Policy = AuthorizationPolicies.SectionAccessSettings)]
private readonly ILogLevelLoader _logLevelLoader;
private readonly ILogViewer _logViewer;
public class LogViewerController : BackOfficeNotificationsController
[Obsolete]
public LogViewerController(ILogViewer logViewer)
: this(logViewer, StaticServiceProvider.Instance.GetRequiredService<ILogLevelLoader>())
{
private readonly ILogViewer _logViewer;
private readonly ILogLevelLoader _logLevelLoader;
[Obsolete]
public LogViewerController(ILogViewer logViewer)
: this(logViewer, StaticServiceProvider.Instance.GetRequiredService<ILogLevelLoader>())
{
}
[ActivatorUtilitiesConstructor]
public LogViewerController(ILogViewer logViewer, ILogLevelLoader logLevelLoader)
{
_logViewer = logViewer ?? throw new ArgumentNullException(nameof(logViewer));
_logLevelLoader = logLevelLoader ?? throw new ArgumentNullException(nameof(logLevelLoader));
}
private bool CanViewLogs(LogTimePeriod logTimePeriod)
{
//Can the interface deal with Large Files
if (_logViewer.CanHandleLargeLogs)
return true;
//Interface CheckCanOpenLogs
return _logViewer.CheckCanOpenLogs(logTimePeriod);
}
[HttpGet]
public bool GetCanViewLogs([FromQuery] DateTime? startDate = null,[FromQuery] DateTime? endDate = null)
{
var logTimePeriod = GetTimePeriod(startDate, endDate);
return CanViewLogs(logTimePeriod);
}
[HttpGet]
public ActionResult<int> GetNumberOfErrors([FromQuery] DateTime? startDate = null,[FromQuery] DateTime? endDate = null)
{
var logTimePeriod = GetTimePeriod(startDate, endDate);
//We will need to stop the request if trying to do this on a 1GB file
if (CanViewLogs(logTimePeriod) == false)
{
return ValidationProblem("Unable to view logs, due to size");
}
return _logViewer.GetNumberOfErrors(logTimePeriod);
}
[HttpGet]
public ActionResult<LogLevelCounts> GetLogLevelCounts([FromQuery] DateTime? startDate = null,[FromQuery] DateTime? endDate = null)
{
var logTimePeriod = GetTimePeriod(startDate, endDate);
//We will need to stop the request if trying to do this on a 1GB file
if (CanViewLogs(logTimePeriod) == false)
{
return ValidationProblem("Unable to view logs, due to size");
}
return _logViewer.GetLogLevelCounts(logTimePeriod);
}
[HttpGet]
public ActionResult<IEnumerable<LogTemplate>> GetMessageTemplates([FromQuery] DateTime? startDate = null,[FromQuery] DateTime? endDate = null)
{
var logTimePeriod = GetTimePeriod(startDate, endDate);
//We will need to stop the request if trying to do this on a 1GB file
if (CanViewLogs(logTimePeriod) == false)
{
return ValidationProblem("Unable to view logs, due to size");
}
return new ActionResult<IEnumerable<LogTemplate>>(_logViewer.GetMessageTemplates(logTimePeriod));
}
[HttpGet]
public ActionResult<PagedResult<LogMessage>> GetLogs(string orderDirection = "Descending", int pageNumber = 1, string? filterExpression = null, [FromQuery(Name = "logLevels[]")]string[]? logLevels = null, [FromQuery]DateTime? startDate = null, [FromQuery]DateTime? endDate = null)
{
var logTimePeriod = GetTimePeriod(startDate, endDate);
//We will need to stop the request if trying to do this on a 1GB file
if (CanViewLogs(logTimePeriod) == false)
{
return ValidationProblem("Unable to view logs, due to size");
}
var direction = orderDirection == "Descending" ? Direction.Descending : Direction.Ascending;
return _logViewer.GetLogs(logTimePeriod, filterExpression: filterExpression, pageNumber: pageNumber, orderDirection: direction, logLevels: logLevels);
}
private static LogTimePeriod GetTimePeriod(DateTime? startDate, DateTime? endDate)
{
if (startDate == null || endDate == null)
{
var now = DateTime.Now;
if (startDate == null)
{
startDate = now.AddDays(-1);
}
if (endDate == null)
{
endDate = now;
}
}
return new LogTimePeriod(startDate.Value, endDate.Value);
}
[HttpGet]
public IEnumerable<SavedLogSearch>? GetSavedSearches()
{
return _logViewer.GetSavedSearches();
}
[HttpPost]
public IEnumerable<SavedLogSearch>? PostSavedSearch(SavedLogSearch item)
{
return _logViewer.AddSavedSearch(item.Name, item.Query);
}
[HttpPost]
public IEnumerable<SavedLogSearch>? DeleteSavedSearch(SavedLogSearch item)
{
return _logViewer.DeleteSavedSearch(item.Name, item.Query);
}
[HttpGet]
public ReadOnlyDictionary<string, LogEventLevel?> GetLogLevels()
{
return _logLevelLoader.GetLogLevelsFromSinks();
}
[Obsolete("Please use GetLogLevels() instead. Scheduled for removal in V11.")]
[HttpGet]
public string GetLogLevel()
{
return _logViewer.GetLogLevel();
}
}
[ActivatorUtilitiesConstructor]
public LogViewerController(ILogViewer logViewer, ILogLevelLoader logLevelLoader)
{
_logViewer = logViewer ?? throw new ArgumentNullException(nameof(logViewer));
_logLevelLoader = logLevelLoader ?? throw new ArgumentNullException(nameof(logLevelLoader));
}
private bool CanViewLogs(LogTimePeriod logTimePeriod)
{
//Can the interface deal with Large Files
if (_logViewer.CanHandleLargeLogs)
{
return true;
}
//Interface CheckCanOpenLogs
return _logViewer.CheckCanOpenLogs(logTimePeriod);
}
[HttpGet]
public bool GetCanViewLogs([FromQuery] DateTime? startDate = null, [FromQuery] DateTime? endDate = null)
{
LogTimePeriod logTimePeriod = GetTimePeriod(startDate, endDate);
return CanViewLogs(logTimePeriod);
}
[HttpGet]
public ActionResult<int> GetNumberOfErrors([FromQuery] DateTime? startDate = null,
[FromQuery] DateTime? endDate = null)
{
LogTimePeriod logTimePeriod = GetTimePeriod(startDate, endDate);
//We will need to stop the request if trying to do this on a 1GB file
if (CanViewLogs(logTimePeriod) == false)
{
return ValidationProblem("Unable to view logs, due to size");
}
return _logViewer.GetNumberOfErrors(logTimePeriod);
}
[HttpGet]
public ActionResult<LogLevelCounts> GetLogLevelCounts([FromQuery] DateTime? startDate = null,
[FromQuery] DateTime? endDate = null)
{
LogTimePeriod logTimePeriod = GetTimePeriod(startDate, endDate);
//We will need to stop the request if trying to do this on a 1GB file
if (CanViewLogs(logTimePeriod) == false)
{
return ValidationProblem("Unable to view logs, due to size");
}
return _logViewer.GetLogLevelCounts(logTimePeriod);
}
[HttpGet]
public ActionResult<IEnumerable<LogTemplate>> GetMessageTemplates([FromQuery] DateTime? startDate = null,
[FromQuery] DateTime? endDate = null)
{
LogTimePeriod logTimePeriod = GetTimePeriod(startDate, endDate);
//We will need to stop the request if trying to do this on a 1GB file
if (CanViewLogs(logTimePeriod) == false)
{
return ValidationProblem("Unable to view logs, due to size");
}
return new ActionResult<IEnumerable<LogTemplate>>(_logViewer.GetMessageTemplates(logTimePeriod));
}
[HttpGet]
public ActionResult<PagedResult<LogMessage>> GetLogs(string orderDirection = "Descending", int pageNumber = 1,
string? filterExpression = null, [FromQuery(Name = "logLevels[]")] string[]? logLevels = null,
[FromQuery] DateTime? startDate = null, [FromQuery] DateTime? endDate = null)
{
LogTimePeriod logTimePeriod = GetTimePeriod(startDate, endDate);
//We will need to stop the request if trying to do this on a 1GB file
if (CanViewLogs(logTimePeriod) == false)
{
return ValidationProblem("Unable to view logs, due to size");
}
Direction direction = orderDirection == "Descending" ? Direction.Descending : Direction.Ascending;
return _logViewer.GetLogs(logTimePeriod, filterExpression: filterExpression, pageNumber: pageNumber,
orderDirection: direction, logLevels: logLevels);
}
private static LogTimePeriod GetTimePeriod(DateTime? startDate, DateTime? endDate)
{
if (startDate == null || endDate == null)
{
DateTime now = DateTime.Now;
if (startDate == null)
{
startDate = now.AddDays(-1);
}
if (endDate == null)
{
endDate = now;
}
}
return new LogTimePeriod(startDate.Value, endDate.Value);
}
[HttpGet]
public IEnumerable<SavedLogSearch>? GetSavedSearches() => _logViewer.GetSavedSearches();
[HttpPost]
public IEnumerable<SavedLogSearch>? PostSavedSearch(SavedLogSearch item) =>
_logViewer.AddSavedSearch(item.Name, item.Query);
[HttpPost]
public IEnumerable<SavedLogSearch>? DeleteSavedSearch(SavedLogSearch item) =>
_logViewer.DeleteSavedSearch(item.Name, item.Query);
[HttpGet]
public ReadOnlyDictionary<string, LogEventLevel?> GetLogLevels() => _logLevelLoader.GetLogLevelsFromSinks();
[Obsolete("Please use GetLogLevels() instead. Scheduled for removal in V11.")]
[HttpGet]
public string GetLogLevel() => _logViewer.GetLogLevel();
}