using ImageCatalog_2.Commands; using ImageCatalog_2.Services; using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; using Microsoft.Extensions.Logging; namespace ImageCatalog_2 { public class DataModel : ViewModelBase { public ICommand TestCommand { get; } public ICommand AsyncTestCommand { get; } public ICommand AsyncCancelOperationCommand { get; } public ICommand ProcessImagesCommand { get; } private readonly ITestService _service; private readonly ILogger _logger; public DataModel(ITestService testService, ILogger logger) { _service = testService; _logger = logger; TestCommand = new RelayCommand(Test); AsyncTestCommand = new AsyncCommand(TestAsync); AsyncCancelOperationCommand = new AsyncCommand(CancelOperation); ProcessImagesCommand = new AsyncCommand(ProcessImages); } private CancellationTokenSource? _mainToken; public CancellationTokenSource? MainToken { get => _mainToken; set { _mainToken = value; NotifyPropertyChanged(); } } private string _sourcePath; public string SourcePath { get => _sourcePath; set { _sourcePath = value; NotifyPropertyChanged(); } } private string _destinationPath; public string DestinationPath { get => _destinationPath; set { _destinationPath = value; NotifyPropertyChanged(); } } private string _horizontalText; public string HorizontalText { get => _horizontalText; set { _horizontalText = value; NotifyPropertyChanged(); } } private string _verticalText; public string VerticalText { get => _verticalText; set { _verticalText = value; NotifyPropertyChanged(); } } private bool _overwriteImages; public bool OverwriteImages { get => _overwriteImages; set { _overwriteImages = value; NotifyPropertyChanged(); } } private bool _uiEnabled = true; public bool UiEnabled { get => _uiEnabled; set { _uiEnabled = value; NotifyPropertyChanged(); } } public bool UiDisabled => !_uiEnabled; private string _speedCounter = "-"; public string SpeedCounter { get => _speedCounter; set { _speedCounter = value; NotifyPropertyChanged(); } } private void Test(object parameter) { Debug.WriteLine("Yep"); this.UiEnabled = !this.UiEnabled; } private async Task TestAsync() { Debug.WriteLine("Yep c"); } private async Task ProcessImages() { } private async Task CancelOperation() { try { await MainToken?.CancelAsync(); UiEnabled = true; } catch (Exception e) { _logger.LogError(e.Message, "Error canceling the token"); _logger.LogInformation("Ignora questo errore"); } } } }