Skip to content

Commit

Permalink
Apply code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollo3zehn committed Mar 15, 2024
1 parent 077dcd4 commit 16836f2
Show file tree
Hide file tree
Showing 73 changed files with 445 additions and 741 deletions.
10 changes: 5 additions & 5 deletions src/Nexus.UI/Charts/Chart.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public Chart()
{
_dotNetHelper = DotNetObjectReference.Create(this);

_timeAxisConfigs = new[]
{
_timeAxisConfigs =
[
/* nanoseconds */
new TimeAxisConfig(TimeSpan.FromSeconds(100e-9), ".fffffff", TriggerPeriod.Second, "HH:mm.ss", "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss.fffffff"),

Expand Down Expand Up @@ -101,19 +101,19 @@ public Chart()

/* years */
new TimeAxisConfig(TimeSpan.FromDays(365), "yyyy", TriggerPeriod.Year, default, default, "yyyy-MM-dd"),
};
];

_timeAxisConfig = _timeAxisConfigs.First();

_colors = new[] {
_colors = [
new SKColor(0, 114, 189),
new SKColor(217, 83, 25),
new SKColor(237, 177, 32),
new SKColor(126, 47, 142),
new SKColor(119, 172, 48),
new SKColor(77, 190, 238),
new SKColor(162, 20, 47)
};
];
}

[Inject]
Expand Down
14 changes: 7 additions & 7 deletions src/Nexus.UI/Core/AppState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class AppState : INotifyPropertyChanged
private ViewState _viewState = ViewState.Normal;
private ExportParameters _exportParameters = default!;
private readonly INexusClient _client;
private readonly List<(DateTime, Exception)> _errors = new();
private readonly Dictionary<string, Dictionary<EditModeItem, string?>> _editModeCatalogMap = new();
private readonly List<(DateTime, Exception)> _errors = [];
private readonly Dictionary<string, Dictionary<EditModeItem, string?>> _editModeCatalogMap = [];
private bool _beginAtZero;
private string? _searchString;
private const string GROUP_KEY = "groups";
Expand Down Expand Up @@ -176,7 +176,7 @@ public string? SearchString
}
}

public ObservableCollection<JobViewModel> Jobs { get; set; } = new ObservableCollection<JobViewModel>();
public ObservableCollection<JobViewModel> Jobs { get; set; } = [];

public void AddJob(JobViewModel job)
{
Expand Down Expand Up @@ -232,7 +232,7 @@ public void AddError(Exception error, ISnackbar? snackbar)

public void AddEditModeCatalog(string catalogId)
{
_editModeCatalogMap.Add(catalogId, new Dictionary<EditModeItem, string?>());
_editModeCatalogMap.Add(catalogId, []);
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(EditModeCatalogMap)));
}

Expand All @@ -258,7 +258,7 @@ public async Task SaveAndRemoveEditModeCatalogAsync(string catalogId, ISnackbar
resources = resourcesNode.AsArray();

else
resources = new JsonArray();
resources = [];

overrides["Resources"] = resources;

Expand All @@ -283,7 +283,7 @@ public async Task SaveAndRemoveEditModeCatalogAsync(string catalogId, ISnackbar
properties = propertiesNode.AsObject();

else
properties = new JsonObject();
properties = [];

resource["Properties"] = properties;

Expand Down Expand Up @@ -351,7 +351,7 @@ public async Task SaveAndRemoveEditModeCatalogAsync(string catalogId, ISnackbar

if (!success)
{
group = new List<CatalogItemViewModel>();
group = [];
catalogItemsMap[groupName] = group;
}

Expand Down
10 changes: 5 additions & 5 deletions src/Nexus.UI/Core/NexusDemoClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public Task<ResourceCatalog> GetAsync(string catalogId, CancellationToken cancel
var resource1 = new Resource(
Id: "temperature",
Properties: properties1,
Representations: new List<Representation>() { new Representation(NexusDataType.FLOAT64, TimeSpan.FromMinutes(1), default) }
Representations: new List<Representation>() { new(NexusDataType.FLOAT64, TimeSpan.FromMinutes(1), default) }
);

var properties2 = new Dictionary<string, JsonElement>()
Expand All @@ -85,7 +85,7 @@ public Task<ResourceCatalog> GetAsync(string catalogId, CancellationToken cancel
var resource2 = new Resource(
Id: "wind_speed",
Properties: properties2,
Representations: new List<Representation>() { new Representation(NexusDataType.FLOAT64, TimeSpan.FromMinutes(1), default) }
Representations: new List<Representation>() { new(NexusDataType.FLOAT64, TimeSpan.FromMinutes(1), default) }
);

var resources = new List<Resource>() { resource1, resource2 };
Expand Down Expand Up @@ -188,12 +188,12 @@ We hope you enjoy it!
PackageReferenceId: Guid.NewGuid()
);

return Task.FromResult((IReadOnlyList<CatalogInfo>)new List<CatalogInfo>() { catalogInfo });
return Task.FromResult((IReadOnlyList<CatalogInfo>)[catalogInfo]);
}

else
{
return Task.FromResult((IReadOnlyList<CatalogInfo>)new List<CatalogInfo>() { });
return Task.FromResult((IReadOnlyList<CatalogInfo>)[]);
}
}

Expand Down Expand Up @@ -539,6 +539,6 @@ public Task<IReadOnlyList<ExtensionDescription>> GetDescriptionsAsync(Cancellati
AdditionalInformation: additionalInformation
);

return Task.FromResult((IReadOnlyList<ExtensionDescription>)new List<ExtensionDescription>() { description });
return Task.FromResult((IReadOnlyList<ExtensionDescription>)[description]);
}
}
15 changes: 9 additions & 6 deletions src/Nexus.UI/Core/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public record ResourcePathParseResult(
TimeSpan? BasePeriod
);

public static class Utilities
public static partial class Utilities
{
public static string ToSpaceFilledCatalogId(string catalogId)
=> catalogId.TrimStart('/').Replace("/", " / ");
Expand All @@ -26,11 +26,11 @@ public static string EscapeDataString(string catalogId)

// keep in sync with DataModelExtensions ...
private const int NS_PER_TICK = 100;
private static readonly long[] _nanoseconds = new[] { (long)1e0, (long)1e3, (long)1e6, (long)1e9, (long)60e9, (long)3600e9, (long)86400e9 };
private static readonly int[] _quotients = new[] { 1000, 1000, 1000, 60, 60, 24, 1 };
private static readonly string[] _postFixes = new[] { "ns", "us", "ms", "s", "min", "h", "d" };
private static readonly long[] _nanoseconds = [(long)1e0, (long)1e3, (long)1e6, (long)1e9, (long)60e9, (long)3600e9, (long)86400e9];
private static readonly int[] _quotients = [1000, 1000, 1000, 60, 60, 24, 1];
private static readonly string[] _postFixes = ["ns", "us", "ms", "s", "min", "h", "d"];
// ... except this line
private static readonly Regex _unitStringEvaluator = new(@"^\s*([0-9]+)[\s_]*([a-zA-Z]+)\s*$", RegexOptions.Compiled);
private static readonly Regex _unitStringEvaluator = UnitStringEvaluator();

public static string ToUnitString(this TimeSpan samplePeriod, bool withUnderScore = false)
{
Expand Down Expand Up @@ -155,7 +155,7 @@ public static void ParseResourcePath(
var matches = _matchSingleParametersExpression
.Matches(parseResult.Parameters);

if (matches.Any())
if (matches.Count != 0)
{
parameters = new ReadOnlyDictionary<string, string>(matches
.Select(match => (match.Groups[1].Value, match.Groups[2].Value))
Expand Down Expand Up @@ -331,4 +331,7 @@ private static JsonElement GetJsonObjectFromPath(this JsonElement root, Span<str

return default;
}

[GeneratedRegex(@"^\s*([0-9]+)[\s_]*([a-zA-Z]+)\s*$", RegexOptions.Compiled)]
private static partial Regex UnitStringEvaluator();
}
6 changes: 3 additions & 3 deletions src/Nexus.UI/Pages/ChartTest.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ public ChartTest()

var lineSeries = new LineSeries[]
{
new LineSeries(
new(
"Wind speed",
"m/s",
TimeSpan.FromMilliseconds(500),
Enumerable.Range(0, 60*2).Select(value => value / 4.0).ToArray()),

new LineSeries(
new(
"Temperature",
"°C",
TimeSpan.FromSeconds(1),
Enumerable.Range(0, 60).Select(value => random.NextDouble() * 10 - 5).ToArray()),

new LineSeries(
new(
"Pressure",
"mbar",
TimeSpan.FromSeconds(1),
Expand Down
11 changes: 3 additions & 8 deletions src/Nexus.UI/Services/NexusAuthenticationStateProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@

namespace Nexus.UI.Services;

public class NexusAuthenticationStateProvider : AuthenticationStateProvider
public class NexusAuthenticationStateProvider(INexusClient client) : AuthenticationStateProvider
{
private readonly INexusClient _client;

public NexusAuthenticationStateProvider(INexusClient client)
{
_client = client;
}
private readonly INexusClient _client = client;

public override async Task<AuthenticationState> GetAuthenticationStateAsync()
{
Expand All @@ -26,7 +21,7 @@ public override async Task<AuthenticationState> GetAuthenticationStateAsync()

var claims = new List<Claim>
{
new Claim(NAME_CLAIM, meResponse.User.Name)
new(NAME_CLAIM, meResponse.User.Name)
};

if (meResponse.IsAdmin)
Expand Down
6 changes: 3 additions & 3 deletions src/Nexus.UI/Services/TypeFaceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ namespace Nexus.UI.Services;

public class TypeFaceService
{
private readonly Dictionary<string, SKTypeface> _typeFaces = new();
private readonly Dictionary<string, SKTypeface> _typeFaces = [];

public SKTypeface GetTTF(string ttfName)
{
if (_typeFaces.ContainsKey(ttfName))
return _typeFaces[ttfName];
if (_typeFaces.TryGetValue(ttfName, out var value))
return value;

else if (LoadTypeFace(ttfName))
return _typeFaces[ttfName];
Expand Down
18 changes: 6 additions & 12 deletions src/Nexus.UI/ViewModels/CatalogItemSelectionViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@

namespace Nexus.UI.ViewModels;

public class CatalogItemSelectionViewModel
public class CatalogItemSelectionViewModel(
CatalogItemViewModel baseItem,
IDictionary<string, string>? parameters)
{
public CatalogItemSelectionViewModel(
CatalogItemViewModel baseItem,
IDictionary<string, string>? parameters)
{
BaseItem = baseItem;
Parameters = parameters;
}

public CatalogItemViewModel BaseItem { get; }
public IDictionary<string, string>? Parameters { get; }
public List<RepresentationKind> Kinds { get; } = new List<RepresentationKind>();
public CatalogItemViewModel BaseItem { get; } = baseItem;
public IDictionary<string, string>? Parameters { get; } = parameters;
public List<RepresentationKind> Kinds { get; } = [];

public string GetResourcePath(RepresentationKind kind, TimeSpan samplePeriod)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Nexus.UI/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class SettingsViewModel : INotifyPropertyChanged
private readonly AppState _appState;
private readonly INexusClient _client;
private readonly IJSInProcessRuntime _jsRuntime;
private List<CatalogItemSelectionViewModel> _selectedCatalogItems = new();
private List<CatalogItemSelectionViewModel> _selectedCatalogItems = [];

public SettingsViewModel(AppState appState, IJSInProcessRuntime jsRuntime, INexusClient client)
{
Expand Down Expand Up @@ -209,7 +209,7 @@ public void ToggleCatalogItemSelection(CatalogItemSelectionViewModel selection)

if (reference is null)
{
if (CanModifySamplePeriod && !_selectedCatalogItems.Any())
if (CanModifySamplePeriod && _selectedCatalogItems.Count == 0)
SamplePeriod = new Period(selection.BaseItem.Representation.SamplePeriod);

EnsureDefaultRepresentationKind(selection);
Expand Down Expand Up @@ -244,7 +244,7 @@ private void EnsureDefaultRepresentationKind(CatalogItemSelectionViewModel selec
var baseItem = selectedItem.BaseItem;
var baseSamplePeriod = baseItem.Representation.SamplePeriod;

if (!selectedItem.Kinds.Any())
if (selectedItem.Kinds.Count == 0)
{
if (SamplePeriod.Value < baseSamplePeriod)
selectedItem.Kinds.Add(RepresentationKind.Resampled);
Expand All @@ -268,7 +268,7 @@ private async Task InitializeAsync()
.Where(description => description.AdditionalInformation.GetStringValue(Constants.DATA_WRITER_LABEL_KEY) is not null)
.ToList();

if (writerDescriptions.Any())
if (writerDescriptions.Count != 0)
{
string? actualFileType = default;

Expand Down
11 changes: 3 additions & 8 deletions src/Nexus/API/ArtifactsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,12 @@ namespace Nexus.Controllers;
[ApiController]
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/[controller]")]
internal class ArtifactsController : ControllerBase
internal class ArtifactsController(
IDatabaseService databaseService) : ControllerBase
{
// GET /api/artifacts/{artifactId}

public IDatabaseService _databaseService;

public ArtifactsController(
IDatabaseService databaseService)
{
_databaseService = databaseService;
}
public IDatabaseService _databaseService = databaseService;

/// <summary>
/// Gets the specified artifact.
Expand Down
21 changes: 7 additions & 14 deletions src/Nexus/API/CatalogsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ namespace Nexus.Controllers;
[ApiController]
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/[controller]")]
internal class CatalogsController : ControllerBase
internal class CatalogsController(
AppState appState,
IDatabaseService databaseService,
IDataControllerService dataControllerService) : ControllerBase
{
// POST /api/catalogs/search-items
// GET /api/catalogs/{catalogId}
Expand All @@ -38,19 +41,9 @@ internal class CatalogsController : ControllerBase
// GET /api/catalogs/{catalogId}/metadata
// PUT /api/catalogs/{catalogId}/metadata

private readonly AppState _appState;
private readonly IDatabaseService _databaseService;
private readonly IDataControllerService _dataControllerService;

public CatalogsController(
AppState appState,
IDatabaseService databaseService,
IDataControllerService dataControllerService)
{
_appState = appState;
_databaseService = databaseService;
_dataControllerService = dataControllerService;
}
private readonly AppState _appState = appState;
private readonly IDatabaseService _databaseService = databaseService;
private readonly IDataControllerService _dataControllerService = dataControllerService;

/// <summary>
/// Searches for the given resource paths and returns the corresponding catalog items.
Expand Down
11 changes: 3 additions & 8 deletions src/Nexus/API/DataController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,12 @@ namespace Nexus.Controllers;
[ApiController]
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/[controller]")]
internal class DataController : ControllerBase
internal class DataController(
IDataService dataService) : ControllerBase
{
// GET /api/data

private readonly IDataService _dataService;

public DataController(
IDataService dataService)
{
_dataService = dataService;
}
private readonly IDataService _dataService = dataService;

/// <summary>
/// Gets the requested data.
Expand Down
Loading

0 comments on commit 16836f2

Please sign in to comment.