Browse Source

Move progress models to Models.Progress

pull/18/head
Ionite 1 year ago
parent
commit
baff351f5c
No known key found for this signature in database
  1. 1
      StabilityMatrix/DesignData/MockFirstLaunchSetupViewModel.cs
  2. 1
      StabilityMatrix/Helper/ArchiveHelper.cs
  3. 1
      StabilityMatrix/Helper/FileHash.cs
  4. 1
      StabilityMatrix/Helper/FileTransfers.cs
  5. 1
      StabilityMatrix/Helper/IPrerequisiteHelper.cs
  6. 42
      StabilityMatrix/Helper/ISnackbarService.cs
  7. 1
      StabilityMatrix/Helper/PrerequisiteHelper.cs
  8. 35
      StabilityMatrix/Helper/SnackbarService.cs
  9. 1
      StabilityMatrix/Models/CheckpointFile.cs
  10. 1
      StabilityMatrix/Models/CheckpointFolder.cs
  11. 1
      StabilityMatrix/Models/Packages/A3WebUI.cs
  12. 1
      StabilityMatrix/Models/Packages/BaseGitPackage.cs
  13. 1
      StabilityMatrix/Models/Packages/BasePackage.cs
  14. 1
      StabilityMatrix/Models/Packages/ComfyUI.cs
  15. 1
      StabilityMatrix/Models/Packages/VladAutomatic.cs
  16. 4
      StabilityMatrix/Models/Progress/ProgressReport.cs
  17. 2
      StabilityMatrix/Models/Progress/ProgressState.cs
  18. 2
      StabilityMatrix/Models/Progress/ProgressType.cs
  19. 29
      StabilityMatrix/Models/TaskResult.cs
  20. 1
      StabilityMatrix/Services/DownloadService.cs
  21. 1
      StabilityMatrix/Services/IDownloadService.cs
  22. 1
      StabilityMatrix/Updater/IUpdateHelper.cs
  23. 1
      StabilityMatrix/Updater/UpdateHelper.cs
  24. 1
      StabilityMatrix/ViewModels/InstallerViewModel.cs
  25. 1
      StabilityMatrix/ViewModels/OneClickInstallViewModel.cs
  26. 1
      StabilityMatrix/ViewModels/PackageManagerViewModel.cs
  27. 1
      StabilityMatrix/ViewModels/RefreshBadgeViewModel.cs
  28. 1
      StabilityMatrix/ViewModels/SelectInstallLocationsViewModel.cs
  29. 1
      StabilityMatrix/ViewModels/SettingsViewModel.cs
  30. 1
      StabilityMatrix/ViewModels/UpdateWindowViewModel.cs

1
StabilityMatrix/DesignData/MockFirstLaunchSetupViewModel.cs

@ -1,4 +1,5 @@
using StabilityMatrix.Models;
using StabilityMatrix.Models.Progress;
using StabilityMatrix.ViewModels;
namespace StabilityMatrix.DesignData;

1
StabilityMatrix/Helper/ArchiveHelper.cs

@ -10,6 +10,7 @@ using NLog;
using SharpCompress.Common;
using SharpCompress.Readers;
using StabilityMatrix.Models;
using StabilityMatrix.Models.Progress;
namespace StabilityMatrix.Helper;

1
StabilityMatrix/Helper/FileHash.cs

@ -5,6 +5,7 @@ using System.Security.Cryptography;
using System.Threading.Tasks;
using Blake3;
using StabilityMatrix.Models;
using StabilityMatrix.Models.Progress;
namespace StabilityMatrix.Helper;

1
StabilityMatrix/Helper/FileTransfers.cs

@ -5,6 +5,7 @@ using System.IO;
using System.Linq;
using System.Threading.Tasks;
using StabilityMatrix.Models;
using StabilityMatrix.Models.Progress;
namespace StabilityMatrix.Helper;

1
StabilityMatrix/Helper/IPrerequisiteHelper.cs

@ -1,6 +1,7 @@
using System;
using System.Threading.Tasks;
using StabilityMatrix.Models;
using StabilityMatrix.Models.Progress;
namespace StabilityMatrix.Helper;

42
StabilityMatrix/Helper/ISnackbarService.cs

@ -1,5 +1,5 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;
using StabilityMatrix.Models;
using Wpf.Ui.Common;
using Wpf.Ui.Controls;
@ -8,34 +8,58 @@ namespace StabilityMatrix.Helper;
public interface ISnackbarService
{
/// <summary>
/// Default timeout for snackbar messages.
/// </summary>
public TimeSpan DefaultTimeout { get; }
/// <summary>
/// Shows a generic error snackbar with the given message.
/// </summary>
/// <param name="title">The title to show in the snackbar.</param>
/// <param name="message">The message to show</param>
/// <param name="appearance">The appearance of the snackbar.</param>
/// <param name="icon">The icon to show in the snackbar.</param>
/// <param name="timeout">Snackbar timeout, defaults to class DefaultTimeout</param>
public Task ShowSnackbarAsync(
string message,
string title = "Error",
string title,
string message,
ControlAppearance appearance = ControlAppearance.Danger,
SymbolRegular icon = SymbolRegular.ErrorCircle24,
int timeoutMilliseconds = 5000);
TimeSpan? timeout = null);
/// <summary>
/// Attempt to run the given task, showing a generic error snackbar if it fails.
/// </summary>
/// <param name="task">The task to run.</param>
/// <param name="title">The title to show in the snackbar.</param>
/// <param name="message">The message to show, default to exception.Message</param>
/// <param name="appearance">The appearance of the snackbar.</param>
/// <param name="icon">The icon to show in the snackbar.</param>
/// <param name="timeout">Snackbar timeout, defaults to class DefaultTimeout</param>
public Task<TaskResult<T>> TryAsync<T>(
Task<T> task,
string message,
string title = "Error",
string? message = null,
ControlAppearance appearance = ControlAppearance.Danger,
SymbolRegular icon = SymbolRegular.ErrorCircle24,
int timeoutMilliseconds = 5000);
TimeSpan? timeout = null);
/// <summary>
/// Attempt to run the given void task, showing a generic error snackbar if it fails.
/// Return a TaskResult with true if the task succeeded, false if it failed.
/// </summary>
/// <param name="task">The task to run.</param>
/// <param name="title">The title to show in the snackbar.</param>
/// <param name="message">The message to show, default to exception.Message</param>
/// <param name="appearance">The appearance of the snackbar.</param>
/// <param name="icon">The icon to show in the snackbar.</param>
/// <param name="timeout">Snackbar timeout, defaults to class DefaultTimeout</param>
Task<TaskResult<bool>> TryAsync(
Task task,
string message,
string title = "Error",
string? message = null,
ControlAppearance appearance = ControlAppearance.Danger,
SymbolRegular icon = SymbolRegular.ErrorCircle24,
int timeoutMilliseconds = 5000);
TimeSpan? timeout = null);
}

1
StabilityMatrix/Helper/PrerequisiteHelper.cs

@ -9,6 +9,7 @@ using Microsoft.Extensions.Logging;
using Microsoft.Win32;
using Octokit;
using StabilityMatrix.Models;
using StabilityMatrix.Models.Progress;
using StabilityMatrix.Python;
using StabilityMatrix.Services;

35
StabilityMatrix/Helper/SnackbarService.cs

@ -17,6 +17,7 @@ public class SnackbarService : ISnackbarService
{
private readonly Wpf.Ui.Contracts.ISnackbarService snackbarService;
private readonly SnackbarViewModel snackbarViewModel;
public TimeSpan DefaultTimeout { get; } = TimeSpan.FromSeconds(5);
public SnackbarService(Wpf.Ui.Contracts.ISnackbarService snackbarService, SnackbarViewModel snackbarViewModel)
{
@ -26,26 +27,29 @@ public class SnackbarService : ISnackbarService
/// <inheritdoc />
public async Task ShowSnackbarAsync(
string message,
string title = "Error",
ControlAppearance appearance = ControlAppearance.Danger,
string title,
string message,
ControlAppearance appearance = ControlAppearance.Danger,
SymbolRegular icon = SymbolRegular.ErrorCircle24,
int timeoutMilliseconds = 5000)
TimeSpan? timeout = null)
{
snackbarService.Timeout = timeoutMilliseconds;
snackbarService.Timeout = (int) (timeout ?? DefaultTimeout).TotalMilliseconds;
await snackbarService.ShowAsync(title, message, new SymbolIcon(icon), appearance);
}
/// <inheritdoc />
public async Task<TaskResult<T>> TryAsync<T>(
Task<T> task,
string message,
ControlAppearance appearance = ControlAppearance.Danger,
Task<T> task,
string title = "Error",
string? message = null,
ControlAppearance appearance = ControlAppearance.Danger,
SymbolRegular icon = SymbolRegular.ErrorCircle24,
int timeoutMilliseconds = 5000)
TimeSpan? timeout = null)
{
try
{
task.wa
await task;
return new TaskResult<T>
{
Result = await task
@ -53,7 +57,7 @@ public class SnackbarService : ISnackbarService
}
catch (Exception e)
{
ShowSnackbarAsync(message, level: level, timeoutMilliseconds: timeoutMilliseconds).SafeFireAndForget();
ShowSnackbarAsync(title, message ?? e.Message, appearance, icon, timeout).SafeFireAndForget();
return new TaskResult<T>
{
Exception = e
@ -63,11 +67,12 @@ public class SnackbarService : ISnackbarService
/// <inheritdoc />
public async Task<TaskResult<bool>> TryAsync(
Task task,
string message,
ControlAppearance appearance = ControlAppearance.Danger,
Task task,
string title = "Error",
string? message = null,
ControlAppearance appearance = ControlAppearance.Danger,
SymbolRegular icon = SymbolRegular.ErrorCircle24,
int timeoutMilliseconds = 5000)
TimeSpan? timeout = null)
{
try
{
@ -79,7 +84,7 @@ public class SnackbarService : ISnackbarService
}
catch (Exception e)
{
ShowSnackbarAsync(message, level: level, timeoutMilliseconds: timeoutMilliseconds);
ShowSnackbarAsync(title, message ?? e.Message, appearance, icon, timeout).SafeFireAndForget();
return new TaskResult<bool>
{
Result = false,

1
StabilityMatrix/Models/CheckpointFile.cs

@ -14,6 +14,7 @@ using CommunityToolkit.Mvvm.Input;
using NLog;
using StabilityMatrix.Extensions;
using StabilityMatrix.Helper;
using StabilityMatrix.Models.Progress;
namespace StabilityMatrix.Models;

1
StabilityMatrix/Models/CheckpointFolder.cs

@ -11,6 +11,7 @@ using CommunityToolkit.Mvvm.Input;
using StabilityMatrix.Extensions;
using StabilityMatrix.Helper;
using StabilityMatrix.Models.FileInterfaces;
using StabilityMatrix.Models.Progress;
using StabilityMatrix.Services;
using StabilityMatrix.ViewModels;

1
StabilityMatrix/Models/Packages/A3WebUI.cs

@ -7,6 +7,7 @@ using System.Text.RegularExpressions;
using System.Threading.Tasks;
using StabilityMatrix.Helper;
using StabilityMatrix.Helper.Cache;
using StabilityMatrix.Models.Progress;
using StabilityMatrix.Services;
namespace StabilityMatrix.Models.Packages;

1
StabilityMatrix/Models/Packages/BaseGitPackage.cs

@ -9,6 +9,7 @@ using NLog;
using Octokit;
using StabilityMatrix.Helper;
using StabilityMatrix.Helper.Cache;
using StabilityMatrix.Models.Progress;
using StabilityMatrix.Python;
using StabilityMatrix.Services;

1
StabilityMatrix/Models/Packages/BasePackage.cs

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Octokit;
using StabilityMatrix.Models.Progress;
namespace StabilityMatrix.Models.Packages;

1
StabilityMatrix/Models/Packages/ComfyUI.cs

@ -8,6 +8,7 @@ using System.Threading.Tasks;
using NLog;
using StabilityMatrix.Helper;
using StabilityMatrix.Helper.Cache;
using StabilityMatrix.Models.Progress;
using StabilityMatrix.Services;
namespace StabilityMatrix.Models.Packages;

1
StabilityMatrix/Models/Packages/VladAutomatic.cs

@ -7,6 +7,7 @@ using System.Text.RegularExpressions;
using System.Threading.Tasks;
using StabilityMatrix.Helper;
using StabilityMatrix.Helper.Cache;
using StabilityMatrix.Models.Progress;
using StabilityMatrix.Services;
namespace StabilityMatrix.Models.Packages;

4
StabilityMatrix/Models/ProgressReport.cs → StabilityMatrix/Models/Progress/ProgressReport.cs

@ -1,6 +1,6 @@
using System;
namespace StabilityMatrix.Models;
namespace StabilityMatrix.Models.Progress;
public record struct ProgressReport
{
@ -63,4 +63,6 @@ public record struct ProgressReport
IsIndeterminate = true;
Type = type;
}
// Implicit conversion from action
}

2
StabilityMatrix/Models/ProgressState.cs → StabilityMatrix/Models/Progress/ProgressState.cs

@ -1,4 +1,4 @@
namespace StabilityMatrix.Models;
namespace StabilityMatrix.Models.Progress;
public enum ProgressState
{

2
StabilityMatrix/Models/ProgressType.cs → StabilityMatrix/Models/Progress/ProgressType.cs

@ -1,4 +1,4 @@
namespace StabilityMatrix.Models;
namespace StabilityMatrix.Models.Progress;
public enum ProgressType
{

29
StabilityMatrix/Models/TaskResult.cs

@ -1,11 +1,34 @@
using System;
using System.Diagnostics.CodeAnalysis;
namespace StabilityMatrix.Models;
public class TaskResult<T>
public readonly record struct TaskResult<T>
{
public T? Result { get; set; }
public Exception? Exception { get; set; }
public readonly T? Result;
public readonly Exception? Exception = null;
[MemberNotNullWhen(true, nameof(Result))]
public bool IsSuccessful => Exception is null && Result != null;
// ReSharper disable once MemberCanBePrivate.Global
private TaskResult(Exception exception)
{
Result = default;
Exception = exception;
}
// ReSharper disable once MemberCanBePrivate.Global
public TaskResult(T? Result)
{
this.Result = Result;
}
public TaskResult<T> FromException(Exception exception) => new(exception: exception);
public void Deconstruct(out T? result, out Exception? exception)
{
result = Result;
exception = Exception;
}
}

1
StabilityMatrix/Services/DownloadService.cs

@ -6,6 +6,7 @@ using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Polly.Contrib.WaitAndRetry;
using StabilityMatrix.Models;
using StabilityMatrix.Models.Progress;
namespace StabilityMatrix.Services;

1
StabilityMatrix/Services/IDownloadService.cs

@ -1,6 +1,7 @@
using System;
using System.Threading.Tasks;
using StabilityMatrix.Models;
using StabilityMatrix.Models.Progress;
namespace StabilityMatrix.Services;

1
StabilityMatrix/Updater/IUpdateHelper.cs

@ -1,6 +1,7 @@
using System;
using System.Threading.Tasks;
using StabilityMatrix.Models;
using StabilityMatrix.Models.Progress;
namespace StabilityMatrix.Updater;

1
StabilityMatrix/Updater/UpdateHelper.cs

@ -11,6 +11,7 @@ using StabilityMatrix.Extensions;
using StabilityMatrix.Helper;
using StabilityMatrix.Models;
using StabilityMatrix.Models.Configs;
using StabilityMatrix.Models.Progress;
using StabilityMatrix.Services;
namespace StabilityMatrix.Updater;

1
StabilityMatrix/ViewModels/InstallerViewModel.cs

@ -13,6 +13,7 @@ using Octokit;
using StabilityMatrix.Helper;
using StabilityMatrix.Models;
using StabilityMatrix.Models.Packages;
using StabilityMatrix.Models.Progress;
using StabilityMatrix.Python;
using StabilityMatrix.Services;
using Wpf.Ui.Contracts;

1
StabilityMatrix/ViewModels/OneClickInstallViewModel.cs

@ -7,6 +7,7 @@ using Microsoft.Extensions.Logging;
using StabilityMatrix.Helper;
using StabilityMatrix.Models;
using StabilityMatrix.Models.Packages;
using StabilityMatrix.Models.Progress;
using StabilityMatrix.Python;
using EventManager = StabilityMatrix.Helper.EventManager;

1
StabilityMatrix/ViewModels/PackageManagerViewModel.cs

@ -10,6 +10,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Extensions.Logging;
using Polly;
using StabilityMatrix.Models.Progress;
using Wpf.Ui.Contracts;
using Wpf.Ui.Controls.ContentDialogControl;
using EventManager = StabilityMatrix.Helper.EventManager;

1
StabilityMatrix/ViewModels/RefreshBadgeViewModel.cs

@ -6,6 +6,7 @@ using CommunityToolkit.Mvvm.Input;
using NLog;
using StabilityMatrix.Controls;
using StabilityMatrix.Models;
using StabilityMatrix.Models.Progress;
using Wpf.Ui.Common;
using Wpf.Ui.Controls;
using Wpf.Ui.Controls.IconElements;

1
StabilityMatrix/ViewModels/SelectInstallLocationsViewModel.cs

@ -12,6 +12,7 @@ using Ookii.Dialogs.Wpf;
using StabilityMatrix.Helper;
using StabilityMatrix.Models;
using StabilityMatrix.Models.FileInterfaces;
using StabilityMatrix.Models.Progress;
using StabilityMatrix.Models.Settings;
namespace StabilityMatrix.ViewModels;

1
StabilityMatrix/ViewModels/SettingsViewModel.cs

@ -23,6 +23,7 @@ using StabilityMatrix.Api;
using StabilityMatrix.Database;
using StabilityMatrix.Helper;
using StabilityMatrix.Models;
using StabilityMatrix.Models.Progress;
using StabilityMatrix.Python;
using Wpf.Ui.Appearance;
using Wpf.Ui.Contracts;

1
StabilityMatrix/ViewModels/UpdateWindowViewModel.cs

@ -7,6 +7,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using StabilityMatrix.Helper;
using StabilityMatrix.Models;
using StabilityMatrix.Models.Progress;
using StabilityMatrix.Updater;
using Wpf.Ui.Controls.Window;

Loading…
Cancel
Save