Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added ._.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
/WpfApp/obj
/App.WPF
/WpfApp/bin/Debug/net8.0-windows
/._.gitignore
82 changes: 35 additions & 47 deletions App.Cmd/ViewModels/SaveViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using App.Core.Models;
using App.Core.Services;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Reflection;
using System.Text.RegularExpressions;
Expand All @@ -15,6 +16,7 @@ public partial class SaveViewModel
private readonly LoggerService? loggerService;
private readonly CopyService? copyService;
private readonly DisplayService displayService;
private ThreadManagerService threadManagerService = new();

[GeneratedRegex(@"^\d+;\d+$")]
private static partial Regex MyRegex();
Expand All @@ -32,7 +34,8 @@ public SaveViewModel()
};

loggerService = new();
copyService = new(stateManagerService);
copyService = new();
copyService.stateManagerService = stateManagerService;
displayService = new();

saveService = new()
Expand All @@ -46,21 +49,12 @@ public SaveViewModel()
saveService.ListStateManager = listState;
}




public enum TypeOfSave
{
Sequential,
Complete
}


/// <summary>
/// Method to get the user choice
/// </summary>
/// <param name="UserEntry"></param>
/// <returns></returns>
public bool UserChoice(int UserEntry)
{
saveService!.ListSaveModel = ListSaveModel;
Expand Down Expand Up @@ -215,7 +209,7 @@ public bool UserChoice(int UserEntry)

saveService!.CreateSave( InPath, OutPath, type, SaveName);

stateManagerService!.UpdateStateFile();
//stateManagerService!.UpdateStateFile();
ListSaveModel = saveService.ListSaveModel;
listState = stateManagerService!.listStateModel!;

Expand Down Expand Up @@ -262,57 +256,45 @@ public bool UserChoice(int UserEntry)
{
if (!saveService!.IsSoftwareRunning())
{

List<SaveModel> list = new List<SaveModel>();
string[] parts = UserChoice.Split(';');
int z1 = int.Parse(parts[0]);
int z2 = int.Parse(parts[1]);
DisplayService.SetForegroundColor("Green", $"Save {z1} is running");

saveService!.ExecuteSave(ListSaveModel[z1]);
DisplayService.SetForegroundColor("Green", $"Save {z1} Executed");
Thread.Sleep(1000);
DisplayService.SetForegroundColor("Green", $"Save {z2} is running");
saveService!.ExecuteSave(ListSaveModel[z2]);
DisplayService.SetForegroundColor("Green", $"Save {z2} Executed");
Thread.Sleep(1000);


Console.WriteLine();
list.Add(ListSaveModel[z1]);
list.Add(ListSaveModel[z2]);
saveService!.ExecuteSave(list, threadManagerService);
}
else
{
DisplayService.SetBackForeColor("Black", "DarkRed", "Software is running save cannot be executed...");
System.Threading.Thread.Sleep(1500);
}

}
else
{
//TODO : Ajouter un try catch pour la gestion des entrées de l'utilisateur
if (!saveService!.IsSoftwareRunning())
{
List<SaveModel> list = new List<SaveModel>();

string[] parts = UserChoice.Split('-');
int min = int.Parse(parts[0]);
int max = int.Parse(parts[1]);
for (int x = min; x <= max; x++)
{
DisplayService.SetForegroundColor("Green", $"Save {x} is running");
saveService!.ExecuteSave(ListSaveModel[x]);
DisplayService.SetForegroundColor("Green", $"Save {x} Executed");
Thread.Sleep(1000);
list.Add(ListSaveModel[x]);
}

saveService!.ExecuteSave(list, threadManagerService);
}
else
{
DisplayService.SetBackForeColor("Black", "DarkRed", "Software is running save cannot be executed...");
System.Threading.Thread.Sleep(1500);
}


}
//return true;
}
}

catch (ArgumentOutOfRangeException)
{
//TODO : Quand save est vide
Expand Down Expand Up @@ -355,15 +337,21 @@ public bool UserChoice(int UserEntry)
}
}

private void SaveViewModel_CopyPaused(object? sender, EventArgs e)
{
Console.WriteLine("Save Paused");
}



private void SaveViewModel_CopyStopped(object? sender, EventArgs e)
{
Console.WriteLine("Save Stopped");
}

public void ShowLogs()
{
//Method to show the logs

loggerService.OpenLogFile();
loggerService?.OpenLogFile();
}

/// <summary>
Expand All @@ -384,17 +372,17 @@ public void ShowSavesSchedule()
{
FileInfo fileInfo = new("saves.json");

if (fileInfo.Length > 0)
{
string json = File.ReadAllText("saves.json");
ListSaveModel = JsonConvert.DeserializeObject<ObservableCollection<SaveModel>>(json) ?? [];
if (fileInfo.Length > 0)
{
string json = File.ReadAllText("saves.json");
ListSaveModel = JsonConvert.DeserializeObject<ObservableCollection<SaveModel>>(json) ?? [];
}
else
{
// Fichier vide, initialiser la liste sans désérialiser
ListSaveModel = [];
}
}
else
{
// Fichier vide, initialiser la liste sans désérialiser
ListSaveModel = [];
}
}
else
{
// Créer le fichier s'il n'existe pas
Expand All @@ -406,7 +394,7 @@ public void ShowSavesSchedule()
foreach (SaveModel item in ListSaveModel)
{

Console.WriteLine($"{i} "+saveService!.ShowInfo(item));
Console.WriteLine($"{i} "+saveService!.ShowInfo(item) + threadManagerService.AreThreadsRunning(i));
i++;
}

Expand Down
15 changes: 0 additions & 15 deletions App.Core/Models/ConfigModel.cs

This file was deleted.

5 changes: 4 additions & 1 deletion App.Core/Models/CopyModel.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@


using System.ComponentModel;

namespace App.Core.Models
{
public class CopyModel
public class CopyModel : INotifyPropertyChanged
{
public string SourcePath { get; set; } = string.Empty; // Path of the source file
public string TargetPath { get; set; } = string.Empty; // Path of the target file

public event PropertyChangedEventHandler? PropertyChanged;
}
}
8 changes: 6 additions & 2 deletions App.Core/Models/LoggerModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace App.Core.Models
using System.ComponentModel;

namespace App.Core.Models
{
public class LoggerModel
public class LoggerModel : INotifyPropertyChanged
{
public string Name { get; set; } = string.Empty; // Name of the save
public string FileSource { get; set; } = string.Empty; // Path of the source file
Expand All @@ -9,5 +11,7 @@ public class LoggerModel
public string FileTransferTime { get; set; } = string.Empty; // Time of the transfer
public string FileEncryptionTime { get; set; } = string.Empty; // Time of the encryption
public DateTime Time { get; set; } = DateTime.Now; // Date of the save

public event PropertyChangedEventHandler? PropertyChanged;
}
}
39 changes: 32 additions & 7 deletions App.Core/Models/SaveModel.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
namespace App.Core.Models
using System;
using System.ComponentModel;

namespace App.Core.Models
{
public class SaveModel
public class SaveModel : INotifyPropertyChanged
{
public string InPath { get; set; } = ""; // Path of the source file
public string OutPath { get; set; } = ""; // Path of the target file
public string Type { get; set; } = ""; // Type of the save // false = Complete, true = Sequentiel
public string SaveName { get; set; } = "" ; // Name of the save
private int _percentage;

public string InPath { get; set; } = ""; // Path of the source file
public string OutPath { get; set; } = ""; // Path of the target file
public string Type { get; set; } = ""; // Type of the save (false = Complete, true = Sequential)
public string SaveName { get; set; } = ""; // Name of the save
public string EncryptChoice { get; set; } = "";
public DateTime Date { get; } = DateTime.Now; // Date of the save
public DateTime Date { get; } = DateTime.Now; // Date of the save

public float percentage
{
get { return _percentage; }
set
{
if (_percentage != value)
{
_percentage = (int)value;
OnPropertyChanged(nameof(percentage));
}
}
}

public event PropertyChangedEventHandler? PropertyChanged;

protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
7 changes: 5 additions & 2 deletions App.Core/Models/StateManagerModel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace App.Core.Models
using System.ComponentModel;

namespace App.Core.Models
{

public class StateManagerModel
public class StateManagerModel : INotifyPropertyChanged
{
public string SaveName { get; set; } = string.Empty; // Name of the save
public string SourceFilePath { get; set; } = string.Empty; // Path of the source file
Expand All @@ -12,5 +14,6 @@ public class StateManagerModel
public long NbFilesLeftToDo { get; set; } = 0; // Number of files left to copy
public float Progression { get; set; } = 0; // Progression of the save

public event PropertyChangedEventHandler? PropertyChanged;
}
}
Loading