Meta - Fixed a bunch of build warnings

This commit is contained in:
Robert committed 2023-10-18 23:13:57 +02:00
1 parent 6921561317
commit 1bd4efbbc5
27 files changed
+199 -149

No files matched your search

@@ -15,7 +15,7 @@ public class LostFocusTextBoxBindingBehavior : Behavior<TextBox>
/// <summary>
/// Gets or sets the value of the binding.
/// </summary>
public static readonly StyledProperty<string> TextProperty = AvaloniaProperty.Register<LostFocusTextBoxBindingBehavior, string>(
public static readonly StyledProperty<string?> TextProperty = AvaloniaProperty.Register<LostFocusTextBoxBindingBehavior, string?>(
"Text", defaultBindingMode: BindingMode.TwoWay);
static LostFocusTextBoxBindingBehavior()
@@ -26,7 +26,7 @@ public class LostFocusTextBoxBindingBehavior : Behavior<TextBox>
/// <summary>
/// Gets or sets the value of the binding.
/// </summary>
public string Text
public string? Text
{
get => GetValue(TextProperty);
set => SetValue(TextProperty, value);
@@ -305,7 +305,7 @@ public class DeviceVisualizer : Control
{
_deviceImage = await Task.Run(() => GetDeviceImage(device));
}
catch (Exception e)
catch (Exception)
{
// ignored
}
@@ -19,32 +19,32 @@ namespace Artemis.UI.Shared.Pagination;
[TemplatePart("PART_PagesView", typeof(StackPanel))]
public partial class Pagination : TemplatedControl
{
private Button? _previousButton;
private Button? _nextButton;
private StackPanel? _pagesView;
/// <inheritdoc />
public Pagination()
{
PropertyChanged += OnPropertyChanged;
}
public Button? PreviousButton { get; set; }
public Button? NextButton { get; set; }
public StackPanel? PagesView { get; set; }
/// <inheritdoc />
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
if (PreviousButton != null)
PreviousButton.Click -= PreviousButtonOnClick;
if (NextButton != null)
NextButton.Click -= NextButtonOnClick;
if (_previousButton != null)
_previousButton.Click -= PreviousButtonOnClick;
if (_nextButton != null)
_nextButton.Click -= NextButtonOnClick;
PreviousButton = e.NameScope.Find<Button>("PART_PreviousButton");
NextButton = e.NameScope.Find<Button>("PART_NextButton");
PagesView = e.NameScope.Find<StackPanel>("PART_PagesView");
_previousButton = e.NameScope.Find<Button>("PART_PreviousButton");
_nextButton = e.NameScope.Find<Button>("PART_NextButton");
_pagesView = e.NameScope.Find<StackPanel>("PART_PagesView");
if (PreviousButton != null)
PreviousButton.Click += PreviousButtonOnClick;
if (NextButton != null)
NextButton.Click += NextButtonOnClick;
if (_previousButton != null)
_previousButton.Click += PreviousButtonOnClick;
if (_nextButton != null)
_nextButton.Click += NextButtonOnClick;
Update();
}
@@ -69,40 +69,40 @@ public partial class Pagination : TemplatedControl
private void Update()
{
if (PagesView == null)
if (_pagesView == null)
return;
List<int> pages = GetPages(Value, Maximum);
// Remove extra children
while (PagesView.Children.Count > pages.Count)
while (_pagesView.Children.Count > pages.Count)
{
PagesView.Children.RemoveAt(PagesView.Children.Count - 1);
_pagesView.Children.RemoveAt(_pagesView.Children.Count - 1);
}
if (PagesView.Children.Count > pages.Count)
PagesView.Children.RemoveRange(0, PagesView.Children.Count - pages.Count);
if (_pagesView.Children.Count > pages.Count)
_pagesView.Children.RemoveRange(0, _pagesView.Children.Count - pages.Count);
// Add/modify children
for (int i = 0; i < pages.Count; i++)
{
int page = pages[i];
// -1 indicates an ellipsis (...)
if (page == -1)
{
if (PagesView.Children.ElementAtOrDefault(i) is not PaginationEllipsis)
if (_pagesView.Children.ElementAtOrDefault(i) is not PaginationEllipsis)
{
if (PagesView.Children.Count - 1 >= i)
PagesView.Children[i] = new PaginationEllipsis();
if (_pagesView.Children.Count - 1 >= i)
_pagesView.Children[i] = new PaginationEllipsis();
else
PagesView.Children.Add(new PaginationEllipsis());
_pagesView.Children.Add(new PaginationEllipsis());
}
}
// Anything else indicates a regular page
else
{
if (PagesView.Children.ElementAtOrDefault(i) is PaginationPage paginationPage)
if (_pagesView.Children.ElementAtOrDefault(i) is PaginationPage paginationPage)
{
paginationPage.Page = page;
paginationPage.Command = ReactiveCommand.Create(() => Value = page);
@@ -110,14 +110,14 @@ public partial class Pagination : TemplatedControl
}
paginationPage = new PaginationPage {Page = page, Command = ReactiveCommand.Create(() => Value = page)};
if (PagesView.Children.Count - 1 >= i)
PagesView.Children[i] = paginationPage;
if (_pagesView.Children.Count - 1 >= i)
_pagesView.Children[i] = paginationPage;
else
PagesView.Children.Add(paginationPage);
_pagesView.Children.Add(paginationPage);
}
}
foreach (Control child in PagesView.Children)
foreach (Control child in _pagesView.Children)
{
if (child is PaginationPage paginationPage)
((IPseudoClasses) paginationPage.Classes).Set(":selected", paginationPage.Page == Value);
@@ -8,10 +8,17 @@ using ReactiveUI;
namespace Artemis.UI.Shared.TagsInput;
/// <summary>
/// Represents an input for tags.
/// </summary>
[TemplatePart("PART_TagInputBox", typeof(TextBox))]
public partial class TagsInput : TemplatedControl
{
public TextBox? TagInputBox { get; set; }
private TextBox? _tagInputBox;
/// <summary>
/// Gets the command that is to be called when removing a tag
/// </summary>
public ICommand RemoveTag { get; }
/// <inheritdoc />
@@ -23,18 +30,18 @@ public partial class TagsInput : TemplatedControl
/// <inheritdoc />
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
if (TagInputBox != null)
if (_tagInputBox != null)
{
TagInputBox.KeyDown -= TagInputBoxOnKeyDown;
TagInputBox.TextChanging -= TagInputBoxOnTextChanging;
_tagInputBox.KeyDown -= TagInputBoxOnKeyDown;
_tagInputBox.TextChanging -= TagInputBoxOnTextChanging;
}
TagInputBox = e.NameScope.Find<TextBox>("PART_TagInputBox");
_tagInputBox = e.NameScope.Find<TextBox>("PART_TagInputBox");
if (TagInputBox != null)
if (_tagInputBox != null)
{
TagInputBox.KeyDown += TagInputBoxOnKeyDown;
TagInputBox.TextChanging += TagInputBoxOnTextChanging;
_tagInputBox.KeyDown += TagInputBoxOnKeyDown;
_tagInputBox.TextChanging += TagInputBoxOnTextChanging;
}
}
@@ -42,21 +49,21 @@ public partial class TagsInput : TemplatedControl
{
Tags.Remove(t);
if (TagInputBox != null)
TagInputBox.IsEnabled = Tags.Count < MaxLength;
if (_tagInputBox != null)
_tagInputBox.IsEnabled = Tags.Count < MaxLength;
}
private void TagInputBoxOnTextChanging(object? sender, TextChangingEventArgs e)
{
if (TagInputBox?.Text == null)
if (_tagInputBox?.Text == null)
return;
TagInputBox.Text = CleanTagRegex().Replace(TagInputBox.Text.ToLower(), "");
_tagInputBox.Text = CleanTagRegex().Replace(_tagInputBox.Text.ToLower(), "");
}
private void TagInputBoxOnKeyDown(object? sender, KeyEventArgs e)
{
if (TagInputBox == null)
if (_tagInputBox == null)
return;
if (e.Key == Key.Space)
@@ -64,13 +71,13 @@ public partial class TagsInput : TemplatedControl
if (e.Key != Key.Enter)
return;
if (string.IsNullOrWhiteSpace(TagInputBox.Text) || Tags.Contains(TagInputBox.Text) || Tags.Count >= MaxLength)
if (string.IsNullOrWhiteSpace(_tagInputBox.Text) || Tags.Contains(_tagInputBox.Text) || Tags.Count >= MaxLength)
return;
Tags.Add(CleanTagRegex().Replace(TagInputBox.Text.ToLower(), ""));
Tags.Add(CleanTagRegex().Replace(_tagInputBox.Text.ToLower(), ""));
TagInputBox.Text = "";
TagInputBox.IsEnabled = Tags.Count < MaxLength;
_tagInputBox.Text = "";
_tagInputBox.IsEnabled = Tags.Count < MaxLength;
}
[GeneratedRegex("[\\s\\-]+")]
@@ -2,6 +2,9 @@ using System;
namespace Artemis.UI.Shared;
/// <summary>
/// Represents errors that occur within the Artemis router.
/// </summary>
public class ArtemisRoutingException : Exception
{
/// <inheritdoc />
@@ -5,50 +5,60 @@ using System.Threading;
using System.Threading.Tasks;
using Artemis.UI.Shared.Utilities;
namespace Artemis.UI.Shared.Extensions
namespace Artemis.UI.Shared.Extensions;
/// <summary>
/// Provides extension methods for the <see cref="HttpClient" /> type.
/// </summary>
public static class HttpClientProgressExtensions
{
public static class HttpClientProgressExtensions
/// <summary>
/// Send a GET request to the specified Uri with an HTTP completion option and a cancellation token as an asynchronous operation.
/// </summary>
/// <param name="client">The HTTP client to use.</param>
/// <param name="requestUrl">The Uri the request is sent to.</param>
/// <param name="destination">The destination stream.</param>
/// <param name="progress">The progress instance to use for progress indication.</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
public static async Task DownloadDataAsync(this HttpClient client, string requestUrl, Stream destination, IProgress<StreamProgress>? progress, CancellationToken cancellationToken)
{
public static async Task DownloadDataAsync(this HttpClient client, string requestUrl, Stream destination, IProgress<StreamProgress>? progress, CancellationToken cancellationToken)
using HttpResponseMessage response = await client.GetAsync(requestUrl, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
response.EnsureSuccessStatusCode();
long? contentLength = response.Content.Headers.ContentLength;
await using Stream download = await response.Content.ReadAsStreamAsync(cancellationToken);
// no progress... no contentLength... very sad
if (progress is null || !contentLength.HasValue)
{
using HttpResponseMessage response = await client.GetAsync(requestUrl, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
response.EnsureSuccessStatusCode();
long? contentLength = response.Content.Headers.ContentLength;
await using Stream download = await response.Content.ReadAsStreamAsync(cancellationToken);
// no progress... no contentLength... very sad
if (progress is null || !contentLength.HasValue)
{
await download.CopyToAsync(destination, cancellationToken);
return;
}
// Such progress and contentLength much reporting Wow!
await download.CopyToAsync(destination, 81920, progress, contentLength, cancellationToken);
await download.CopyToAsync(destination, cancellationToken);
return;
}
static async Task CopyToAsync(this Stream source, Stream destination, int bufferSize, IProgress<StreamProgress> progress, long? contentLength, CancellationToken cancellationToken)
{
if (bufferSize < 0)
throw new ArgumentOutOfRangeException(nameof(bufferSize));
if (source is null)
throw new ArgumentNullException(nameof(source));
if (!source.CanRead)
throw new InvalidOperationException($"'{nameof(source)}' is not readable.");
if (destination == null)
throw new ArgumentNullException(nameof(destination));
if (!destination.CanWrite)
throw new InvalidOperationException($"'{nameof(destination)}' is not writable.");
// Such progress and contentLength much reporting Wow!
await download.CopyToAsync(destination, 81920, progress, contentLength, cancellationToken);
}
byte[] buffer = new byte[bufferSize];
long totalBytesRead = 0;
int bytesRead;
while ((bytesRead = await source.ReadAsync(buffer, 0, buffer.Length, cancellationToken).ConfigureAwait(false)) != 0)
{
await destination.WriteAsync(buffer, 0, bytesRead, cancellationToken).ConfigureAwait(false);
totalBytesRead += bytesRead;
progress?.Report(new StreamProgress(totalBytesRead, contentLength ?? totalBytesRead));
}
private static async Task CopyToAsync(this Stream source, Stream destination, int bufferSize, IProgress<StreamProgress> progress, long? contentLength, CancellationToken cancellationToken)
{
if (bufferSize < 0)
throw new ArgumentOutOfRangeException(nameof(bufferSize));
if (source is null)
throw new ArgumentNullException(nameof(source));
if (!source.CanRead)
throw new InvalidOperationException($"'{nameof(source)}' is not readable.");
if (destination == null)
throw new ArgumentNullException(nameof(destination));
if (!destination.CanWrite)
throw new InvalidOperationException($"'{nameof(destination)}' is not writable.");
byte[] buffer = new byte[bufferSize];
long totalBytesRead = 0;
int bytesRead;
while ((bytesRead = await source.ReadAsync(buffer, 0, buffer.Length, cancellationToken).ConfigureAwait(false)) != 0)
{
await destination.WriteAsync(buffer, 0, bytesRead, cancellationToken).ConfigureAwait(false);
totalBytesRead += bytesRead;
progress?.Report(new StreamProgress(totalBytesRead, contentLength ?? totalBytesRead));
}
}
}
@@ -61,7 +61,10 @@ internal class WindowService : IWindowService
public async Task ShowDialogAsync(object viewModel)
{
Window? parent = GetCurrentWindow();
if (parent == null)
throw new ArtemisSharedUIException("Failed to get the current window.");
string name = viewModel.GetType().FullName!.Split('`')[0].Replace("ViewModel", "View");
Type? type = viewModel.GetType().Assembly.GetType(name);
@@ -100,6 +103,9 @@ internal class WindowService : IWindowService
public async Task<TResult> ShowDialogAsync<TResult>(DialogViewModelBase<TResult> viewModel)
{
Window? parent = GetCurrentWindow();
if (parent == null)
throw new ArtemisSharedUIException("Failed to get the current window.");
string name = viewModel.GetType().FullName!.Split('`')[0].Replace("ViewModel", "View");
Type? type = viewModel.GetType().Assembly.GetType(name);
+3
View File
@@ -18,6 +18,9 @@ public static class UI
{
private static readonly BehaviorSubject<bool> MicaEnabledSubject = new(false);
/// <summary>
/// Gets the background event loop scheduler.
/// </summary>
public static EventLoopScheduler BackgroundScheduler = new(ts => new Thread(ts));
static UI()