Migration to MVVM

This commit is contained in:
MaddoScientisto 2026-02-04 19:48:03 +01:00
commit 1db874ce77
6 changed files with 946 additions and 575 deletions

View file

@ -4,6 +4,7 @@ using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing.Text;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -15,25 +16,55 @@ namespace ImageCatalog_2
public class DataModel : ViewModelBase
{
public ICommand TestCommand { get; }
public ICommand AsyncTestCommand { get; }
public ICommand AsyncCancelOperationCommand { get; }
public ICommand ProcessImagesCommand { get; }
public ICommand SelectSourceFolderCommand { get; }
public ICommand SelectDestinationFolderCommand { get; }
public ICommand SelectLogoFileCommand { get; }
public ICommand SaveSettingsCommand { get; }
public ICommand LoadSettingsCommand { get; }
public ICommand SelectColorCommand { get; }
private readonly ITestService _service;
private readonly ILogger<DataModel> _logger;
private readonly ISettingsService _settingsService;
public DataModel(ITestService testService, ILogger<DataModel> logger)
// ComboBox collections
public List<string> AvailableFonts { get; }
public List<string> VerticalPositions { get; } = new() { "Alto", "Centro", "Basso" };
public List<string> HorizontalAlignments { get; } = new() { "Sinistra", "Centro", "Destra" };
public DataModel(ITestService testService, ISettingsService settingsService, ILogger<DataModel> logger)
{
_service = testService;
_logger = logger;
_settingsService = settingsService;
TestCommand = new RelayCommand(Test);
AsyncTestCommand = new AsyncCommand(TestAsync);
AsyncCancelOperationCommand = new AsyncCommand(CancelOperation);
ProcessImagesCommand = new AsyncCommand(ProcessImages);
SelectSourceFolderCommand = new RelayCommand(SelectSourceFolder);
SelectDestinationFolderCommand = new RelayCommand(SelectDestinationFolder);
SelectLogoFileCommand = new RelayCommand(SelectLogoFile);
SaveSettingsCommand = new RelayCommand(SaveSettings);
LoadSettingsCommand = new RelayCommand(LoadSettings);
SelectColorCommand = new RelayCommand(SelectColor);
// Load available fonts
AvailableFonts = LoadAvailableFonts();
}
private List<string> LoadAvailableFonts()
{
var fonts = new List<string>();
using (var installedFonts = new InstalledFontCollection())
{
fonts.AddRange(installedFonts.Families.Select(f => f.Name));
}
return fonts;
}
private CancellationTokenSource? _mainToken;
@ -158,6 +189,546 @@ namespace ImageCatalog_2
}
}
// Thumbnail settings
private string _thumbnailPrefix = "tn_";
public string ThumbnailPrefix
{
get => _thumbnailPrefix;
set
{
_thumbnailPrefix = value;
NotifyPropertyChanged();
}
}
private int _thumbnailHeight = 350;
public int ThumbnailHeight
{
get => _thumbnailHeight;
set
{
_thumbnailHeight = value;
NotifyPropertyChanged();
}
}
private int _thumbnailWidth = 350;
public int ThumbnailWidth
{
get => _thumbnailWidth;
set
{
_thumbnailWidth = value;
NotifyPropertyChanged();
}
}
// Big photo settings
private int _photoBigHeight = 2240;
public int PhotoBigHeight
{
get => _photoBigHeight;
set
{
_photoBigHeight = value;
NotifyPropertyChanged();
}
}
private int _photoBigWidth = 2240;
public int PhotoBigWidth
{
get => _photoBigWidth;
set
{
_photoBigWidth = value;
NotifyPropertyChanged();
}
}
// Font settings
private int _fontSize = 20;
public int FontSize
{
get => _fontSize;
set
{
_fontSize = value;
NotifyPropertyChanged();
}
}
private int _fontSizeThumbnail = 50;
public int FontSizeThumbnail
{
get => _fontSizeThumbnail;
set
{
_fontSizeThumbnail = value;
NotifyPropertyChanged();
}
}
private string _fontName = "Arial";
public string FontName
{
get => _fontName;
set
{
_fontName = value;
NotifyPropertyChanged();
}
}
private bool _fontBold = false;
public bool FontBold
{
get => _fontBold;
set
{
_fontBold = value;
NotifyPropertyChanged();
}
}
// Text settings
private int _textTransparency = 0;
public int TextTransparency
{
get => _textTransparency;
set
{
_textTransparency = value;
NotifyPropertyChanged();
}
}
private int _textMargin = 8;
public int TextMargin
{
get => _textMargin;
set
{
_textMargin = value;
NotifyPropertyChanged();
}
}
private string _textColorRGB = "Yellow";
public string TextColorRGB
{
get => _textColorRGB;
set
{
_textColorRGB = value;
NotifyPropertyChanged();
}
}
// Logo/Watermark settings
private string _logoFile = "";
public string LogoFile
{
get => _logoFile;
set
{
_logoFile = value;
NotifyPropertyChanged();
}
}
private int _logoHeight = 430;
public int LogoHeight
{
get => _logoHeight;
set
{
_logoHeight = value;
NotifyPropertyChanged();
}
}
private int _logoWidth = 430;
public int LogoWidth
{
get => _logoWidth;
set
{
_logoWidth = value;
NotifyPropertyChanged();
}
}
private int _logoMargin = 290;
public int LogoMargin
{
get => _logoMargin;
set
{
_logoMargin = value;
NotifyPropertyChanged();
}
}
private int _logoTransparency = 100;
public int LogoTransparency
{
get => _logoTransparency;
set
{
_logoTransparency = value;
NotifyPropertyChanged();
}
}
// Folder division settings
private int _filesPerFolder = 99;
public int FilesPerFolder
{
get => _filesPerFolder;
set
{
_filesPerFolder = value;
NotifyPropertyChanged();
}
}
private string _folderSuffix = "";
public string FolderSuffix
{
get => _folderSuffix;
set
{
_folderSuffix = value;
NotifyPropertyChanged();
}
}
private int _counterDigits = 2;
public int CounterDigits
{
get => _counterDigits;
set
{
_counterDigits = value;
NotifyPropertyChanged();
}
}
// Vertical text settings
private int _verticalTextSize = 20;
public int VerticalTextSize
{
get => _verticalTextSize;
set
{
_verticalTextSize = value;
NotifyPropertyChanged();
}
}
private int _verticalTextMargin = 6;
public int VerticalTextMargin
{
get => _verticalTextMargin;
set
{
_verticalTextMargin = value;
NotifyPropertyChanged();
}
}
// JPEG compression settings
private int _jpegQuality = 85;
public int JpegQuality
{
get => _jpegQuality;
set
{
_jpegQuality = value;
NotifyPropertyChanged();
}
}
private int _jpegQualityThumbnail = 30;
public int JpegQualityThumbnail
{
get => _jpegQualityThumbnail;
set
{
_jpegQualityThumbnail = value;
NotifyPropertyChanged();
}
}
// CheckBox settings
private bool _createThumbnails = true;
public bool CreateThumbnails
{
get => _createThumbnails;
set
{
_createThumbnails = value;
NotifyPropertyChanged();
}
}
private bool _automaticRotation;
public bool AutomaticRotation
{
get => _automaticRotation;
set
{
_automaticRotation = value;
NotifyPropertyChanged();
}
}
private bool _forceJpeg;
public bool ForceJpeg
{
get => _forceJpeg;
set
{
_forceJpeg = value;
NotifyPropertyChanged();
}
}
private bool _updateSubdirectories;
public bool UpdateSubdirectories
{
get => _updateSubdirectories;
set
{
_updateSubdirectories = value;
NotifyPropertyChanged();
}
}
private bool _createSubfolders;
public bool CreateSubfolders
{
get => _createSubfolders;
set
{
_createSubfolders = value;
NotifyPropertyChanged();
}
}
private bool _addTime;
public bool AddTime
{
get => _addTime;
set
{
_addTime = value;
NotifyPropertyChanged();
}
}
private bool _addRaceTime;
public bool AddRaceTime
{
get => _addRaceTime;
set
{
_addRaceTime = value;
NotifyPropertyChanged();
}
}
private bool _addLogo;
public bool AddLogo
{
get => _addLogo;
set
{
_addLogo = value;
NotifyPropertyChanged();
}
}
private bool _keepOriginalDimensions;
public bool KeepOriginalDimensions
{
get => _keepOriginalDimensions;
set
{
_keepOriginalDimensions = value;
NotifyPropertyChanged();
}
}
private bool _showDate;
public bool ShowDate
{
get => _showDate;
set
{
_showDate = value;
NotifyPropertyChanged();
}
}
private bool _showPhotoNumber;
public bool ShowPhotoNumber
{
get => _showPhotoNumber;
set
{
_showPhotoNumber = value;
NotifyPropertyChanged();
}
}
private bool _shutdownSystem;
public bool ShutdownSystem
{
get => _shutdownSystem;
set
{
_shutdownSystem = value;
NotifyPropertyChanged();
}
}
// ComboBox position/alignment settings
private string _verticalPosition = "Basso";
public string VerticalPosition
{
get => _verticalPosition;
set
{
_verticalPosition = value;
NotifyPropertyChanged();
}
}
private string _horizontalAlignment = "Centro";
public string HorizontalAlignment
{
get => _horizontalAlignment;
set
{
_horizontalAlignment = value;
NotifyPropertyChanged();
}
}
private string _logoHorizontalPosition = "Destra";
public string LogoHorizontalPosition
{
get => _logoHorizontalPosition;
set
{
_logoHorizontalPosition = value;
NotifyPropertyChanged();
}
}
private string _logoVerticalPosition = "Basso";
public string LogoVerticalPosition
{
get => _logoVerticalPosition;
set
{
_logoVerticalPosition = value;
NotifyPropertyChanged();
}
}
// RadioButton settings
private bool _useProgressiveNumbering = true;
public bool UseProgressiveNumbering
{
get => _useProgressiveNumbering;
set
{
_useProgressiveNumbering = value;
NotifyPropertyChanged();
}
}
private bool _useFileNumbering;
public bool UseFileNumbering
{
get => _useFileNumbering;
set
{
_useFileNumbering = value;
NotifyPropertyChanged();
}
}
private bool _useParallelProcessing = true;
public bool UseParallelProcessing
{
get => _useParallelProcessing;
set
{
_useParallelProcessing = value;
NotifyPropertyChanged();
}
}
private bool _useSequentialProcessing;
public bool UseSequentialProcessing
{
get => _useSequentialProcessing;
set
{
_useSequentialProcessing = value;
NotifyPropertyChanged();
}
}
// Additional settings that were missing
private bool _addTimeToThumbnails;
public bool AddTimeToThumbnails
{
get => _addTimeToThumbnails;
set
{
_addTimeToThumbnails = value;
NotifyPropertyChanged();
}
}
private bool _showFileNameOnThumbnails;
public bool ShowFileNameOnThumbnails
{
get => _showFileNameOnThumbnails;
set
{
_showFileNameOnThumbnails = value;
NotifyPropertyChanged();
}
}
private DateTime _raceStartDate = DateTime.Now;
public DateTime RaceStartDate
{
get => _raceStartDate;
set
{
_raceStartDate = value;
NotifyPropertyChanged();
}
}
private string _timeLabel = "";
public string TimeLabel
{
get => _timeLabel;
set
{
_timeLabel = value;
NotifyPropertyChanged();
}
}
private void Test(object parameter)
{
Debug.WriteLine("Yep");
@ -187,5 +758,54 @@ namespace ImageCatalog_2
_logger.LogInformation("Ignora questo errore");
}
}
// Note: These commands will trigger events that the View will handle to show dialogs
// since dialogs require UI context
public event EventHandler SelectSourceFolderRequested;
public event EventHandler SelectDestinationFolderRequested;
public event EventHandler SelectLogoFileRequested;
public event EventHandler<string> SaveSettingsRequested;
public event EventHandler<string> LoadSettingsRequested;
public event EventHandler SelectColorRequested;
private void SelectSourceFolder(object parameter)
{
SelectSourceFolderRequested?.Invoke(this, EventArgs.Empty);
}
private void SelectDestinationFolder(object parameter)
{
SelectDestinationFolderRequested?.Invoke(this, EventArgs.Empty);
}
private void SelectLogoFile(object parameter)
{
SelectLogoFileRequested?.Invoke(this, EventArgs.Empty);
}
private void SaveSettings(object parameter)
{
SaveSettingsRequested?.Invoke(this, null);
}
private void LoadSettings(object parameter)
{
LoadSettingsRequested?.Invoke(this, null);
}
private void SelectColor(object parameter)
{
SelectColorRequested?.Invoke(this, EventArgs.Empty);
}
public async Task SaveSettingsToFileAsync(string filePath)
{
await _settingsService.SaveSettingsAsync(filePath, this);
}
public async Task LoadSettingsFromFileAsync(string filePath)
{
await _settingsService.LoadSettingsAsync(filePath, this);
}
}
}

View file

@ -1,4 +1,4 @@
using System;
using System;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.CompilerServices;
@ -221,6 +221,7 @@ namespace ImageCatalog
//
// CheckBox22
//
CheckBox22.DataBindings.Add(new Binding("Checked", bindingSource1, "ShutdownSystem", true, DataSourceUpdateMode.OnPropertyChanged));
CheckBox22.AutoSize = true;
CheckBox22.Location = new Point(1168, 882);
CheckBox22.Margin = new Padding(6, 8, 6, 8);
@ -350,6 +351,7 @@ namespace ImageCatalog
//
// rdbNuovoMetodo
//
rdbNuovoMetodo.DataBindings.Add(new Binding("Checked", bindingSource1, "UseParallelProcessing", true, DataSourceUpdateMode.OnPropertyChanged));
rdbNuovoMetodo.AutoSize = true;
rdbNuovoMetodo.Checked = true;
rdbNuovoMetodo.Location = new Point(18, 69);
@ -363,6 +365,7 @@ namespace ImageCatalog
//
// rdbVecchioMetodo
//
rdbVecchioMetodo.DataBindings.Add(new Binding("Checked", bindingSource1, "UseSequentialProcessing", true, DataSourceUpdateMode.OnPropertyChanged));
rdbVecchioMetodo.AutoSize = true;
rdbVecchioMetodo.Location = new Point(18, 10);
rdbVecchioMetodo.Margin = new Padding(6, 8, 6, 8);
@ -413,6 +416,7 @@ namespace ImageCatalog
//
// chkAggiornaSottodirectory
//
chkAggiornaSottodirectory.DataBindings.Add(new Binding("Checked", bindingSource1, "UpdateSubdirectories", true, DataSourceUpdateMode.OnPropertyChanged));
chkAggiornaSottodirectory.ForeColor = Color.Black;
chkAggiornaSottodirectory.Location = new Point(174, 157);
chkAggiornaSottodirectory.Margin = new Padding(6, 8, 6, 8);
@ -429,7 +433,6 @@ namespace ImageCatalog
_Button3.Size = new Size(52, 50);
_Button3.TabIndex = 6;
_Button3.Text = "...";
_Button3.Click += Button3_Click;
//
// _Button2
//
@ -439,7 +442,6 @@ namespace ImageCatalog
_Button2.Size = new Size(52, 50);
_Button2.TabIndex = 5;
_Button2.Text = "...";
_Button2.Click += Button2_Click;
//
// Label1
//
@ -506,6 +508,7 @@ namespace ImageCatalog
//
// rdbNumFiles
//
rdbNumFiles.DataBindings.Add(new Binding("Checked", bindingSource1, "UseFileNumbering", true, DataSourceUpdateMode.OnPropertyChanged));
rdbNumFiles.ForeColor = Color.Black;
rdbNumFiles.Location = new Point(70, 315);
rdbNumFiles.Margin = new Padding(6, 8, 6, 8);
@ -516,6 +519,7 @@ namespace ImageCatalog
//
// rdbNumProgressiva
//
rdbNumProgressiva.DataBindings.Add(new Binding("Checked", bindingSource1, "UseProgressiveNumbering", true, DataSourceUpdateMode.OnPropertyChanged));
rdbNumProgressiva.Checked = true;
rdbNumProgressiva.ForeColor = Color.Black;
rdbNumProgressiva.Location = new Point(70, 275);
@ -528,6 +532,7 @@ namespace ImageCatalog
//
// txtCifreContatore
//
txtCifreContatore.DataBindings.Add(new Binding("Text", bindingSource1, "CounterDigits", true, DataSourceUpdateMode.OnPropertyChanged));
txtCifreContatore.Location = new Point(278, 216);
txtCifreContatore.Margin = new Padding(6, 8, 6, 8);
txtCifreContatore.Name = "txtCifreContatore";
@ -548,6 +553,7 @@ namespace ImageCatalog
//
// txtSuffissoCartelle
//
txtSuffissoCartelle.DataBindings.Add(new Binding("Text", bindingSource1, "FolderSuffix", true, DataSourceUpdateMode.OnPropertyChanged));
txtSuffissoCartelle.Location = new Point(122, 157);
txtSuffissoCartelle.Margin = new Padding(6, 8, 6, 8);
txtSuffissoCartelle.Name = "txtSuffissoCartelle";
@ -577,6 +583,7 @@ namespace ImageCatalog
//
// chkCreaSottocartelle
//
chkCreaSottocartelle.DataBindings.Add(new Binding("Checked", bindingSource1, "CreateSubfolders", true, DataSourceUpdateMode.OnPropertyChanged));
chkCreaSottocartelle.ForeColor = Color.Black;
chkCreaSottocartelle.Location = new Point(122, 40);
chkCreaSottocartelle.Margin = new Padding(6, 8, 6, 8);
@ -587,6 +594,7 @@ namespace ImageCatalog
//
// txtFilePerCartella
//
txtFilePerCartella.DataBindings.Add(new Binding("Text", bindingSource1, "FilesPerFolder", true, DataSourceUpdateMode.OnPropertyChanged));
txtFilePerCartella.Location = new Point(122, 99);
txtFilePerCartella.Margin = new Padding(6, 8, 6, 8);
txtFilePerCartella.Name = "txtFilePerCartella";
@ -633,6 +641,7 @@ namespace ImageCatalog
//
// chkRotazioneAutomatica
//
chkRotazioneAutomatica.DataBindings.Add(new Binding("Checked", bindingSource1, "AutomaticRotation", true, DataSourceUpdateMode.OnPropertyChanged));
chkRotazioneAutomatica.ForeColor = Color.Black;
chkRotazioneAutomatica.Location = new Point(34, 96);
chkRotazioneAutomatica.Margin = new Padding(6, 8, 6, 8);
@ -643,6 +652,7 @@ namespace ImageCatalog
//
// chkForzaJpg
//
chkForzaJpg.DataBindings.Add(new Binding("Checked", bindingSource1, "ForceJpeg", true, DataSourceUpdateMode.OnPropertyChanged));
chkForzaJpg.Checked = true;
chkForzaJpg.CheckState = CheckState.Checked;
chkForzaJpg.ForeColor = Color.Black;
@ -705,6 +715,7 @@ namespace ImageCatalog
//
// TextBox31
//
TextBox31.DataBindings.Add(new Binding("Text", bindingSource1, "VerticalTextMargin", true, DataSourceUpdateMode.OnPropertyChanged));
TextBox31.Location = new Point(284, 114);
TextBox31.Margin = new Padding(6, 8, 6, 8);
TextBox31.Name = "TextBox31";
@ -713,6 +724,7 @@ namespace ImageCatalog
//
// TextBox30
//
TextBox30.DataBindings.Add(new Binding("Text", bindingSource1, "VerticalTextSize", true, DataSourceUpdateMode.OnPropertyChanged));
TextBox30.Location = new Point(284, 54);
TextBox30.Margin = new Padding(6, 8, 6, 8);
TextBox30.Name = "TextBox30";
@ -734,6 +746,7 @@ namespace ImageCatalog
//
// CheckBox17
//
CheckBox17.DataBindings.Add(new Binding("Checked", bindingSource1, "ShowPhotoNumber", true, DataSourceUpdateMode.OnPropertyChanged));
CheckBox17.AutoSize = true;
CheckBox17.Location = new Point(208, 45);
CheckBox17.Margin = new Padding(6, 8, 6, 8);
@ -745,6 +758,7 @@ namespace ImageCatalog
//
// CheckBox16
//
CheckBox16.DataBindings.Add(new Binding("Checked", bindingSource1, "ShowDate", true, DataSourceUpdateMode.OnPropertyChanged));
CheckBox16.AutoSize = true;
CheckBox16.Location = new Point(13, 46);
CheckBox16.Margin = new Padding(6, 8, 6, 8);
@ -778,6 +792,7 @@ namespace ImageCatalog
//
// TextBox34
//
TextBox34.DataBindings.Add(new Binding("Text", bindingSource1, "TextColorRGB", true, DataSourceUpdateMode.OnPropertyChanged));
TextBox34.Location = new Point(346, 224);
TextBox34.Margin = new Padding(6, 8, 6, 8);
TextBox34.Name = "TextBox34";
@ -794,7 +809,6 @@ namespace ImageCatalog
_Button8.Size = new Size(161, 59);
_Button8.TabIndex = 35;
_Button8.Text = "Scegli...";
_Button8.Click += Button8_Click;
//
// Label36
//
@ -809,6 +823,7 @@ namespace ImageCatalog
//
// TextBox25
//
TextBox25.DataBindings.Add(new Binding("Text", bindingSource1, "FontSizeThumbnail", true, DataSourceUpdateMode.OnPropertyChanged));
TextBox25.Location = new Point(346, 146);
TextBox25.Margin = new Padding(6, 8, 6, 8);
TextBox25.Name = "TextBox25";
@ -829,6 +844,7 @@ namespace ImageCatalog
//
// ComboBox3
//
ComboBox3.DataBindings.Add(new Binding("Text", bindingSource1, "FontName", true, DataSourceUpdateMode.OnPropertyChanged));
ComboBox3.Location = new Point(208, 19);
ComboBox3.Margin = new Padding(6, 8, 6, 8);
ComboBox3.Name = "ComboBox3";
@ -838,6 +854,7 @@ namespace ImageCatalog
//
// TextBox11
//
TextBox11.DataBindings.Add(new Binding("Text", bindingSource1, "FontSize", true, DataSourceUpdateMode.OnPropertyChanged));
TextBox11.Location = new Point(346, 86);
TextBox11.Margin = new Padding(6, 8, 6, 8);
TextBox11.Name = "TextBox11";
@ -870,6 +887,7 @@ namespace ImageCatalog
//
// CheckBox3
//
CheckBox3.DataBindings.Add(new Binding("Checked", bindingSource1, "FontBold", true, DataSourceUpdateMode.OnPropertyChanged));
CheckBox3.ForeColor = Color.Black;
CheckBox3.Location = new Point(486, 19);
CheckBox3.Margin = new Padding(6, 8, 6, 8);
@ -957,6 +975,7 @@ namespace ImageCatalog
//
// CheckBox8
//
CheckBox8.DataBindings.Add(new Binding("Checked", bindingSource1, "AddTime", true, DataSourceUpdateMode.OnPropertyChanged));
CheckBox8.ForeColor = Color.Black;
CheckBox8.Location = new Point(156, 384);
CheckBox8.Margin = new Padding(6, 8, 6, 8);
@ -967,6 +986,7 @@ namespace ImageCatalog
//
// TextBox9
//
TextBox9.DataBindings.Add(new Binding("Text", bindingSource1, "TextTransparency", true, DataSourceUpdateMode.OnPropertyChanged));
TextBox9.Location = new Point(260, 266);
TextBox9.Margin = new Padding(6, 8, 6, 8);
TextBox9.Name = "TextBox9";
@ -976,6 +996,7 @@ namespace ImageCatalog
//
// CheckBox7
//
CheckBox7.DataBindings.Add(new Binding("Checked", bindingSource1, "AddRaceTime", true, DataSourceUpdateMode.OnPropertyChanged));
CheckBox7.ForeColor = Color.Black;
CheckBox7.Location = new Point(294, 384);
CheckBox7.Margin = new Padding(6, 8, 6, 8);
@ -1028,6 +1049,7 @@ namespace ImageCatalog
//
// ComboBox1
//
ComboBox1.DataBindings.Add(new Binding("Text", bindingSource1, "VerticalPosition", true, DataSourceUpdateMode.OnPropertyChanged));
ComboBox1.Location = new Point(156, 325);
ComboBox1.Margin = new Padding(6, 8, 6, 8);
ComboBox1.Name = "ComboBox1";
@ -1037,6 +1059,7 @@ namespace ImageCatalog
//
// ComboBox2
//
ComboBox2.DataBindings.Add(new Binding("Text", bindingSource1, "HorizontalAlignment", true, DataSourceUpdateMode.OnPropertyChanged));
ComboBox2.Location = new Point(814, 325);
ComboBox2.Margin = new Padding(6, 8, 6, 8);
ComboBox2.Name = "ComboBox2";
@ -1057,6 +1080,7 @@ namespace ImageCatalog
//
// TextBox12
//
TextBox12.DataBindings.Add(new Binding("Text", bindingSource1, "TextMargin", true, DataSourceUpdateMode.OnPropertyChanged));
TextBox12.Location = new Point(814, 266);
TextBox12.Margin = new Padding(6, 8, 6, 8);
TextBox12.Name = "TextBox12";
@ -1120,6 +1144,7 @@ namespace ImageCatalog
//
// TextBox32
//
TextBox32.DataBindings.Add(new Binding("Text", bindingSource1, "JpegQuality", true, DataSourceUpdateMode.OnPropertyChanged));
TextBox32.Location = new Point(156, 197);
TextBox32.Margin = new Padding(6, 8, 6, 8);
TextBox32.Name = "TextBox32";
@ -1160,6 +1185,7 @@ namespace ImageCatalog
//
// TextBox27
//
TextBox27.DataBindings.Add(new Binding("Text", bindingSource1, "PhotoBigWidth", true, DataSourceUpdateMode.OnPropertyChanged));
TextBox27.Location = new Point(156, 59);
TextBox27.Margin = new Padding(6, 8, 6, 8);
TextBox27.Name = "TextBox27";
@ -1180,6 +1206,7 @@ namespace ImageCatalog
//
// TextBox28
//
TextBox28.DataBindings.Add(new Binding("Text", bindingSource1, "PhotoBigHeight", true, DataSourceUpdateMode.OnPropertyChanged));
TextBox28.Location = new Point(156, 118);
TextBox28.Margin = new Padding(6, 8, 6, 8);
TextBox28.Name = "TextBox28";
@ -1189,6 +1216,7 @@ namespace ImageCatalog
//
// CheckBox15
//
CheckBox15.DataBindings.Add(new Binding("Checked", bindingSource1, "KeepOriginalDimensions", true, DataSourceUpdateMode.OnPropertyChanged));
CheckBox15.Checked = true;
CheckBox15.CheckState = CheckState.Checked;
CheckBox15.ForeColor = Color.Black;
@ -1234,7 +1262,6 @@ namespace ImageCatalog
_CheckBox18.TabIndex = 36;
_CheckBox18.Text = "Numero foto";
_CheckBox18.UseVisualStyleBackColor = true;
_CheckBox18.CheckedChanged += CheckBox18_CheckedChanged;
//
// _CheckBox4
//
@ -1245,7 +1272,6 @@ namespace ImageCatalog
_CheckBox4.Size = new Size(226, 42);
_CheckBox4.TabIndex = 34;
_CheckBox4.Text = "Aggiungi scritta";
_CheckBox4.CheckedChanged += CheckBox4_CheckedChanged;
//
// _CheckBox12
//
@ -1256,7 +1282,6 @@ namespace ImageCatalog
_CheckBox12.Size = new Size(226, 51);
_CheckBox12.TabIndex = 35;
_CheckBox12.Text = "Aggiungi orario";
_CheckBox12.CheckedChanged += CheckBox12_CheckedChanged;
//
// GroupBox1
//
@ -1292,6 +1317,7 @@ namespace ImageCatalog
//
// TextBox33
//
TextBox33.DataBindings.Add(new Binding("Text", bindingSource1, "JpegQualityThumbnail", true, DataSourceUpdateMode.OnPropertyChanged));
TextBox33.Location = new Point(528, 99);
TextBox33.Margin = new Padding(6, 8, 6, 8);
TextBox33.Name = "TextBox33";
@ -1384,6 +1410,7 @@ namespace ImageCatalog
//
// TextBox5
//
TextBox5.DataBindings.Add(new Binding("Text", bindingSource1, "ThumbnailWidth", true, DataSourceUpdateMode.OnPropertyChanged));
TextBox5.Location = new Point(156, 157);
TextBox5.Margin = new Padding(6, 8, 6, 8);
TextBox5.Name = "TextBox5";
@ -1404,6 +1431,7 @@ namespace ImageCatalog
//
// TextBox6
//
TextBox6.DataBindings.Add(new Binding("Text", bindingSource1, "ThumbnailHeight", true, DataSourceUpdateMode.OnPropertyChanged));
TextBox6.Location = new Point(156, 216);
TextBox6.Margin = new Padding(6, 8, 6, 8);
TextBox6.Name = "TextBox6";
@ -1424,6 +1452,7 @@ namespace ImageCatalog
//
// TextBox3
//
TextBox3.DataBindings.Add(new Binding("Text", bindingSource1, "ThumbnailPrefix", true, DataSourceUpdateMode.OnPropertyChanged));
TextBox3.Location = new Point(156, 99);
TextBox3.Margin = new Padding(6, 8, 6, 8);
TextBox3.Name = "TextBox3";
@ -1433,6 +1462,7 @@ namespace ImageCatalog
//
// CheckBox1
//
CheckBox1.DataBindings.Add(new Binding("Checked", bindingSource1, "CreateThumbnails", true, DataSourceUpdateMode.OnPropertyChanged));
CheckBox1.ForeColor = Color.Black;
CheckBox1.Location = new Point(156, 40);
CheckBox1.Margin = new Padding(6, 8, 6, 8);
@ -1505,11 +1535,10 @@ namespace ImageCatalog
_PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
_PictureBox1.TabIndex = 43;
_PictureBox1.TabStop = false;
_PictureBox1.MouseMove += PictureBox1_MouseMove;
_PictureBox1.MouseUp += PictureBox1_MouseUp;
//
// ComboBox5
//
ComboBox5.DataBindings.Add(new Binding("Text", bindingSource1, "LogoVerticalPosition", true, DataSourceUpdateMode.OnPropertyChanged));
ComboBox5.Location = new Point(312, 413);
ComboBox5.Margin = new Padding(6, 8, 6, 8);
ComboBox5.Name = "ComboBox5";
@ -1519,6 +1548,7 @@ namespace ImageCatalog
//
// ComboBox4
//
ComboBox4.DataBindings.Add(new Binding("Text", bindingSource1, "LogoHorizontalPosition", true, DataSourceUpdateMode.OnPropertyChanged));
ComboBox4.Location = new Point(312, 355);
ComboBox4.Margin = new Padding(6, 8, 6, 8);
ComboBox4.Name = "ComboBox4";
@ -1528,6 +1558,7 @@ namespace ImageCatalog
//
// TextBox19
//
TextBox19.DataBindings.Add(new Binding("Text", bindingSource1, "LogoTransparency", true, DataSourceUpdateMode.OnPropertyChanged));
TextBox19.Location = new Point(312, 237);
TextBox19.Margin = new Padding(6, 8, 6, 8);
TextBox19.Name = "TextBox19";
@ -1548,6 +1579,7 @@ namespace ImageCatalog
//
// CheckBox5
//
CheckBox5.DataBindings.Add(new Binding("Checked", bindingSource1, "AddLogo", true, DataSourceUpdateMode.OnPropertyChanged));
CheckBox5.ForeColor = Color.Black;
CheckBox5.Location = new Point(0, 64);
CheckBox5.Margin = new Padding(6, 8, 6, 8);
@ -1558,6 +1590,7 @@ namespace ImageCatalog
//
// TextBox15
//
TextBox15.DataBindings.Add(new Binding("Text", bindingSource1, "LogoHeight", true, DataSourceUpdateMode.OnPropertyChanged));
TextBox15.Location = new Point(312, 178);
TextBox15.Margin = new Padding(6, 8, 6, 8);
TextBox15.Name = "TextBox15";
@ -1567,6 +1600,7 @@ namespace ImageCatalog
//
// TextBox14
//
TextBox14.DataBindings.Add(new Binding("Text", bindingSource1, "LogoWidth", true, DataSourceUpdateMode.OnPropertyChanged));
TextBox14.Location = new Point(312, 118);
TextBox14.Margin = new Padding(6, 8, 6, 8);
TextBox14.Name = "TextBox14";
@ -1588,6 +1622,7 @@ namespace ImageCatalog
//
// TextBox16
//
TextBox16.DataBindings.Add(new Binding("Text", bindingSource1, "LogoMargin", true, DataSourceUpdateMode.OnPropertyChanged));
TextBox16.Location = new Point(312, 296);
TextBox16.Margin = new Padding(6, 8, 6, 8);
TextBox16.Name = "TextBox16";
@ -1639,10 +1674,10 @@ namespace ImageCatalog
_Button4.Size = new Size(52, 50);
_Button4.TabIndex = 8;
_Button4.Text = "...";
_Button4.Click += Button4_Click;
//
// TextBox10
//
TextBox10.DataBindings.Add(new Binding("Text", bindingSource1, "LogoFile", true, DataSourceUpdateMode.OnPropertyChanged));
TextBox10.Location = new Point(312, 59);
TextBox10.Margin = new Padding(6, 8, 6, 8);
TextBox10.Name = "TextBox10";
@ -1695,7 +1730,6 @@ namespace ImageCatalog
_Label27.TabIndex = 62;
_Label27.Text = "Versione 2.2 2021";
_Label27.TextAlign = ContentAlignment.MiddleRight;
_Label27.Click += Label27_Click;
//
// _Button7
//
@ -1719,7 +1753,6 @@ namespace ImageCatalog
_Button5.Size = new Size(416, 78);
_Button5.TabIndex = 60;
_Button5.Text = "Salva impostazioni";
_Button5.Click += Button5_Click;
//
// Label20
//
@ -1785,7 +1818,6 @@ namespace ImageCatalog
_Button6.Size = new Size(416, 78);
_Button6.TabIndex = 54;
_Button6.Text = "Carica impostazioni";
_Button6.Click += Button6_Click;
//
// _btnCreaCatalogoAsync
//
@ -1894,16 +1926,7 @@ namespace ImageCatalog
[MethodImpl(MethodImplOptions.Synchronized)]
set
{
if (_Button3 != null)
{
_Button3.Click -= Button3_Click;
}
_Button3 = value;
if (_Button3 != null)
{
_Button3.Click += Button3_Click;
}
}
}
@ -1920,16 +1943,7 @@ namespace ImageCatalog
[MethodImpl(MethodImplOptions.Synchronized)]
set
{
if (_Button2 != null)
{
_Button2.Click -= Button2_Click;
}
_Button2 = value;
if (_Button2 != null)
{
_Button2.Click += Button2_Click;
}
}
}
@ -1975,16 +1989,7 @@ namespace ImageCatalog
[MethodImpl(MethodImplOptions.Synchronized)]
set
{
if (_Button8 != null)
{
_Button8.Click -= Button8_Click;
}
_Button8 = value;
if (_Button8 != null)
{
_Button8.Click += Button8_Click;
}
}
}
@ -2040,16 +2045,7 @@ namespace ImageCatalog
[MethodImpl(MethodImplOptions.Synchronized)]
set
{
if (_CheckBox18 != null)
{
_CheckBox18.CheckedChanged -= CheckBox18_CheckedChanged;
}
_CheckBox18 = value;
if (_CheckBox18 != null)
{
_CheckBox18.CheckedChanged += CheckBox18_CheckedChanged;
}
}
}
@ -2066,16 +2062,7 @@ namespace ImageCatalog
[MethodImpl(MethodImplOptions.Synchronized)]
set
{
if (_CheckBox4 != null)
{
_CheckBox4.CheckedChanged -= CheckBox4_CheckedChanged;
}
_CheckBox4 = value;
if (_CheckBox4 != null)
{
_CheckBox4.CheckedChanged += CheckBox4_CheckedChanged;
}
}
}
@ -2092,16 +2079,7 @@ namespace ImageCatalog
[MethodImpl(MethodImplOptions.Synchronized)]
set
{
if (_CheckBox12 != null)
{
_CheckBox12.CheckedChanged -= CheckBox12_CheckedChanged;
}
_CheckBox12 = value;
if (_CheckBox12 != null)
{
_CheckBox12.CheckedChanged += CheckBox12_CheckedChanged;
}
}
}
@ -2137,18 +2115,7 @@ namespace ImageCatalog
[MethodImpl(MethodImplOptions.Synchronized)]
set
{
if (_PictureBox1 != null)
{
_PictureBox1.MouseMove -= PictureBox1_MouseMove;
_PictureBox1.MouseUp -= PictureBox1_MouseUp;
}
_PictureBox1 = value;
if (_PictureBox1 != null)
{
_PictureBox1.MouseMove += PictureBox1_MouseMove;
_PictureBox1.MouseUp += PictureBox1_MouseUp;
}
}
}
@ -2177,16 +2144,7 @@ namespace ImageCatalog
[MethodImpl(MethodImplOptions.Synchronized)]
set
{
if (_Button4 != null)
{
_Button4.Click -= Button4_Click;
}
_Button4 = value;
if (_Button4 != null)
{
_Button4.Click += Button4_Click;
}
}
}
@ -2207,16 +2165,7 @@ namespace ImageCatalog
[MethodImpl(MethodImplOptions.Synchronized)]
set
{
if (_Label27 != null)
{
_Label27.Click -= Label27_Click;
}
_Label27 = value;
if (_Label27 != null)
{
_Label27.Click += Label27_Click;
}
}
}
@ -2235,16 +2184,7 @@ namespace ImageCatalog
[MethodImpl(MethodImplOptions.Synchronized)]
set
{
if (_Button5 != null)
{
_Button5.Click -= Button5_Click;
}
_Button5 = value;
if (_Button5 != null)
{
_Button5.Click += Button5_Click;
}
}
}
@ -2291,16 +2231,7 @@ namespace ImageCatalog
[MethodImpl(MethodImplOptions.Synchronized)]
set
{
if (_Button6 != null)
{
_Button6.Click -= Button6_Click;
}
_Button6 = value;
if (_Button6 != null)
{
_Button6.Click += Button6_Click;
}
}
}

View file

@ -37,29 +37,20 @@ public partial class MainForm
_imageCreationService = imageCreationStuff;
_parametriSetup = parametriSetup;
_picSettings = picSettings;
_logger = logger;
_logger.LogDebug("Start");
InitializeComponent();
BindControls();
_Button3.Name = "Button3";
_Button2.Name = "Button2";
_Button8.Name = "Button8";
_CheckBox18.Name = "CheckBox18";
_CheckBox4.Name = "CheckBox4";
_CheckBox12.Name = "CheckBox12";
_PictureBox1.Name = "PictureBox1";
_Button4.Name = "Button4";
_Label27.Name = "Label27";
_Button7.Name = "Button7";
_Button5.Name = "Button5";
//_btnCreaCatalogo.Name = "btnCreaCatalogo";
_Button6.Name = "Button6";
_btnCreaCatalogoAsync.Name = "btnCreaCatalogoAsync";
// Subscribe to DataModel events
Model.SelectSourceFolderRequested += OnSelectSourceFolderRequested;
Model.SelectDestinationFolderRequested += OnSelectDestinationFolderRequested;
Model.SelectLogoFileRequested += OnSelectLogoFileRequested;
Model.SaveSettingsRequested += OnSaveSettingsRequested;
Model.LoadSettingsRequested += OnLoadSettingsRequested;
Model.SelectColorRequested += OnSelectColorRequested;
var version = Assembly.GetExecutingAssembly().GetName().Version;
_Label27.Text = $"Version: {version.Major}.{version.Minor}.{version.Build}.{version.Revision}";
@ -70,7 +61,13 @@ public partial class MainForm
protected void BindControls()
{
//txtSorgente.DataBindings.Add(new Binding("Text", SourcePath, ""));
// Wire up buttons to ViewModel commands
_Button2.Click += (s, e) => Model.SelectSourceFolderCommand.Execute(null);
_Button3.Click += (s, e) => Model.SelectDestinationFolderCommand.Execute(null);
_Button4.Click += (s, e) => Model.SelectLogoFileCommand.Execute(null);
_Button5.Click += (s, e) => Model.SaveSettingsCommand.Execute(null);
_Button6.Click += (s, e) => Model.LoadSettingsCommand.Execute(null);
_Button8.Click += (s, e) => Model.SelectColorCommand.Execute(null);
}
private event EventHandler<Tuple<string, int>> UiUpdateEvent;
@ -114,80 +111,25 @@ public partial class MainForm
SetText(lblFotoTotaliNum, args.Item2.ToString());
}
private bool _waterSelectColor = false;
private ConcurrentBag<string> _results;
private void SetDefaults()
{
//txtSorgente.Text = "";
Model.SourcePath = string.Empty;
Model.DestinationPath = string.Empty;
TextBox3.Text = "tn_";
Model.HorizontalText = "";
TextBox5.Text = "350";
TextBox6.Text = "350";
TextBox27.Text = "2240";
TextBox28.Text = "2240";
TextBox9.Text = "0";
TextBox11.Text = "20";
TextBox12.Text = "8";
// TextBox13.Text = ""
TextBox10.Text = "";
TextBox14.Text = "430";
TextBox15.Text = "430";
TextBox16.Text = "290";
txtFilePerCartella.Text = "99";
TextBox19.Text = "100";
txtSuffissoCartelle.Text = "";
txtCifreContatore.Text = "2";
TextBox25.Text = "50";
TextBox26.Text = "";
Model.ThreadsCount = 10;
Model.ChunkSize = 100;
TextBox34.Text = "Yellow";
TextBox30.Text = "20";
TextBox31.Text = "6";
TextBox32.Text = "85";
TextBox33.Text = "30";
ComboBox1.Items.Add("Alto");
ComboBox1.Items.Add("Basso");
ComboBox1.SelectedIndex = 1;
ComboBox2.Items.Add("Sinistra");
ComboBox2.Items.Add("Centro");
ComboBox2.Items.Add("Destra");
ComboBox2.SelectedIndex = 1;
// Model defaults are already set in DataModel constructor, just bind ComboBoxes
ComboBox1.DataSource = new List<string>(Model.VerticalPositions);
ComboBox1.SelectedItem = Model.VerticalPosition;
ComboBox2.DataSource = new List<string>(Model.HorizontalAlignments);
ComboBox2.SelectedItem = Model.HorizontalAlignment;
// Create a obejct of InstalledFontCollection
var InstalledFonts = new InstalledFontCollection();
// Gets the array of FontFamily objects associated with this FontCollection.
var fontfamilies = InstalledFonts.Families;
ComboBox3.DataSource = new List<string>(Model.AvailableFonts);
ComboBox3.SelectedItem = Model.FontName;
// Populates font combobox with the font name
foreach (FontFamily fontFamily in fontfamilies)
ComboBox3.Items.Add(fontFamily.Name);
ComboBox3.Text = ComboBox3.Items[0].ToString();
// ComboBox3.Items.Add("Arial")
// ComboBox3.Items.Add("Arial Black")
// ComboBox3.Items.Add("Arial Narrow")
// ComboBox3.Items.Add("Comic Sans MS")
// ComboBox3.Items.Add("Courier New")
// ComboBox3.Items.Add("System")
// ComboBox3.Items.Add("Times New Roman")
// ComboBox3.Items.Add("Verdana")
// ComboBox3.Items.Add("Wingdings")
// ComboBox3.SelectedIndex = 7
ComboBox4.Items.Add("Sinistra");
ComboBox4.Items.Add("Centro");
ComboBox4.Items.Add("Destra");
ComboBox4.SelectedIndex = 2;
ComboBox5.Items.Add("Alto");
ComboBox5.Items.Add("Centro");
ComboBox5.Items.Add("Basso");
ComboBox5.SelectedIndex = 2;
ComboBox4.DataSource = new List<string>(Model.HorizontalAlignments);
ComboBox4.SelectedItem = Model.LogoHorizontalPosition;
ComboBox5.DataSource = new List<string> { "Alto", "Centro", "Basso" };
ComboBox5.SelectedItem = Model.LogoVerticalPosition;
}
@ -274,12 +216,10 @@ public partial class MainForm
dialog.InitialDirectory = startingFolder;
if (dialog.ShowDialog() != DialogResult.OK) return string.Empty;
var directoryScelta = FixPath(dialog.SelectedPath); // dialog.FileName;
return directoryScelta;
return FixPath(dialog.SelectedPath);
}
private void Button2_Click(object sender, EventArgs e)
private void OnSelectSourceFolderRequested(object sender, EventArgs e)
{
var dialogResult = SelectFolder(Model.SourcePath);
if (!string.IsNullOrWhiteSpace(dialogResult))
@ -288,7 +228,7 @@ public partial class MainForm
}
}
private void Button3_Click(object sender, EventArgs e)
private void OnSelectDestinationFolderRequested(object sender, EventArgs e)
{
var dialogResult = SelectFolder(Model.DestinationPath);
if (!string.IsNullOrWhiteSpace(dialogResult))
@ -297,283 +237,174 @@ public partial class MainForm
}
}
private void Button5_Click(object sender, EventArgs e)
private void OnSelectLogoFileRequested(object sender, EventArgs e)
{
var SaveFileDlg = new SaveFileDialog();
// SaveFileDlg.InitialDirectory = "c:\"
SaveFileDlg.Filter = "Setup (*.xml)|*.xml|All valid files (*.*)|*.*";
SaveFileDlg.FilterIndex = 0;
SaveFileDlg.RestoreDirectory = true;
if (DialogResult.OK != SaveFileDlg.ShowDialog()) return;
var ilNome = SaveFileDlg.FileName;
_parametriSetup.NomeFileSetup = ilNome;
_parametriSetup.AggiornaParametro("DirSorgente", Model.SourcePath);
_parametriSetup.AggiornaParametro("DirDestinazione", Model.DestinationPath);
_parametriSetup.AggiornaParametro("DirSottoDirectory", chkAggiornaSottodirectory.Checked);
_parametriSetup.AggiornaParametro("DirDividiDestinazione", chkCreaSottocartelle.Checked);
_parametriSetup.AggiornaParametro("DirDividiNumFile", txtFilePerCartella.Text);
_parametriSetup.AggiornaParametro("DirDividiSuffisso", txtSuffissoCartelle.Text);
_parametriSetup.AggiornaParametro("DirDividiNumCifre", txtCifreContatore.Text);
if (rdbNumProgressiva.Checked == true)
var dialog = new OpenFileDialog();
dialog.Filter = "Image Files|*.jpg;*.jpeg;*.png;*.bmp;*.gif";
if (Model.LogoFile.Length > 0)
{
_parametriSetup.AggiornaParametro("DirDividiTipoNumerazione", "Progressiva");
dialog.FileName = Model.LogoFile;
}
else
if (dialog.ShowDialog() == DialogResult.OK)
{
_parametriSetup.AggiornaParametro("DirDividiTipoNumerazione", "Files");
Model.LogoFile = dialog.FileName;
UpdateLogoPictureBox(Model.LogoFile);
}
_parametriSetup.AggiornaParametro("MiniatureCrea", CheckBox1.Checked);
_parametriSetup.AggiornaParametro("MiniatureSuffisso", TextBox3.Text);
_parametriSetup.AggiornaParametro("MiniatureAltezza", TextBox5.Text);
_parametriSetup.AggiornaParametro("MiniatureLarghezza", TextBox6.Text);
_parametriSetup.AggiornaParametro("MiniatureAddScritta", RadioButton3.Checked);
_parametriSetup.AggiornaParametro("MiniatureAddOrario", RadioButton4.Checked);
_parametriSetup.AggiornaParametro("FotoAltezza", TextBox27.Text);
_parametriSetup.AggiornaParametro("FotoLarghezza", TextBox28.Text);
// SetupIni.AggiornaParametro("FotoCodice", TextBox13.Text)
// SetupIni.AggiornaParametro("FotoDimOriginali", CheckBox2.Checked)
_parametriSetup.AggiornaParametro("FontDimensione", TextBox11.Text);
_parametriSetup.AggiornaParametro("FontDimensioneMiniatura", TextBox25.Text);
_parametriSetup.AggiornaParametro("FontBold", CheckBox3.Checked);
_parametriSetup.AggiornaParametro("FontNome", ComboBox3.Text);
_parametriSetup.AggiornaParametro("TestoTesto", Model.HorizontalText);
_parametriSetup.AggiornaParametro("TestoTrasparente", TextBox9.Text);
_parametriSetup.AggiornaParametro("TestoMargine", TextBox12.Text);
_parametriSetup.AggiornaParametro("TestoPosizione", ComboBox1.Text);
_parametriSetup.AggiornaParametro("TestoAllineamento", ComboBox2.Text);
_parametriSetup.AggiornaParametro("MarchioFile", TextBox10.Text);
_parametriSetup.AggiornaParametro("MarchioAltezza", TextBox14.Text);
_parametriSetup.AggiornaParametro("MarchioLarghezza", TextBox15.Text);
_parametriSetup.AggiornaParametro("MarchioMargine", TextBox16.Text);
_parametriSetup.AggiornaParametro("MarchioAllOrizzontale", ComboBox4.Text);
_parametriSetup.AggiornaParametro("MarchioAllVerticale", ComboBox5.Text);
_parametriSetup.AggiornaParametro("MarchioTrasparenza", TextBox19.Text);
_parametriSetup.AggiornaParametro("MarchioAggiungi", CheckBox5.Checked);
_parametriSetup.AggiornaParametro("TempoGara", CheckBox7.Checked);
_parametriSetup.AggiornaParametro("Orario", CheckBox8.Checked);
_parametriSetup.AggiornaParametro("EtichettaOrario", TextBox18.Text);
_parametriSetup.AggiornaParametro("GeneraleForzaJpg", chkForzaJpg.Checked);
_parametriSetup.AggiornaParametro("GeneraleRotazioneAutomatica", chkRotazioneAutomatica.Checked);
_parametriSetup.AggiornaParametro("GrandezzaVerticale", TextBox30.Text);
_parametriSetup.AggiornaParametro("MargineVerticale", TextBox31.Text);
_parametriSetup.AggiornaParametro("DimensioniOriginali", CheckBox15.Checked);
_parametriSetup.AggiornaParametro("TestoVerticale", Model.VerticalText);
_parametriSetup.AggiornaParametro("NomeMiniatura", RadioButton6.Checked);
_parametriSetup.AggiornaParametro("DataFoto", CheckBox16.Checked);
_parametriSetup.AggiornaParametro("NumeroFoto", CheckBox17.Checked);
_parametriSetup.AggiornaParametro("ColoreTestoRGB", TextBox34.Text);
_parametriSetup.AggiornaParametro("TempoSmall", RadioButton5.Checked);
_parametriSetup.AggiornaParametro("NumTempoSmall", RadioButton7.Checked);
_parametriSetup.AggiornaParametro("CompressioneJpeg", TextBox32.Text);
_parametriSetup.AggiornaParametro("CompressioneJpegMiniatura", TextBox33.Text);
// 2021
_parametriSetup.AggiornaParametro("ChunkSize", Model.ChunkSize.ToString());
_parametriSetup.AggiornaParametro("ThreadsCount", Model.ThreadsCount.ToString());
_parametriSetup.AggiornaParametro("OverwriteImages", Model.OverwriteImages);
_parametriSetup.SalvaParametriSetup();
Text = "Image Catalog - " + LeggiSoloNomeFile(ilNome);
}
private void Button6_Click(object sender, EventArgs e)
private async void OnSaveSettingsRequested(object sender, string e)
{
var openFileDialog = new OpenFileDialog();
// openFileDialog.InitialDirectory = TextBox1.Text
openFileDialog.Filter = "Setup (*.xml)|*.xml|All valid files (*.*)|*.*";
openFileDialog.FilterIndex = 0;
openFileDialog.RestoreDirectory = true;
if (DialogResult.OK != openFileDialog.ShowDialog()) return;
var ilNome = openFileDialog.FileName;
_parametriSetup.NomeFileSetup = ilNome;
_parametriSetup.CaricaParametriSetup();
Model.SourcePath = _parametriSetup.LeggiParametroString("DirSorgente");
Model.DestinationPath = _parametriSetup.LeggiParametroString("DirDestinazione");
chkAggiornaSottodirectory.Checked = _parametriSetup.LeggiParametroBoolean("DirSottoDirectory");
chkCreaSottocartelle.Checked = _parametriSetup.LeggiParametroBoolean("DirDividiDestinazione");
txtFilePerCartella.Text = _parametriSetup.LeggiParametroString("DirDividiNumFile");
txtSuffissoCartelle.Text = _parametriSetup.LeggiParametroString("DirDividiSuffisso");
txtCifreContatore.Text = _parametriSetup.LeggiParametroString("DirDividiNumCifre");
string TestoTemp = _parametriSetup.LeggiParametroString("DirDividiTipoNumerazione");
if (TestoTemp.ToUpper() == "PROGRESSIVA")
var saveDialog = new SaveFileDialog
{
rdbNumProgressiva.Checked = true;
}
else
Filter = "Setup (*.xml)|*.xml|All valid files (*.*)|*.*",
FilterIndex = 0,
RestoreDirectory = true
};
if (saveDialog.ShowDialog() != DialogResult.OK) return;
await Model.SaveSettingsToFileAsync(saveDialog.FileName);
Text = "Image Catalog - " + Path.GetFileName(saveDialog.FileName);
}
private async void OnLoadSettingsRequested(object sender, string e)
{
var openDialog = new OpenFileDialog
{
rdbNumFiles.Checked = true;
Filter = "Setup (*.xml)|*.xml|All valid files (*.*)|*.*",
FilterIndex = 0,
RestoreDirectory = true
};
if (openDialog.ShowDialog() != DialogResult.OK) return;
await Model.LoadSettingsFromFileAsync(openDialog.FileName);
// Update logo preview if logo file exists
if (File.Exists(Model.LogoFile))
{
UpdateLogoPictureBox(Model.LogoFile);
}
CheckBox1.Checked = _parametriSetup.LeggiParametroBoolean("MiniatureCrea");
TextBox3.Text = _parametriSetup.LeggiParametroString("MiniatureSuffisso");
TextBox5.Text = _parametriSetup.LeggiParametroString("MiniatureAltezza");
TextBox6.Text = _parametriSetup.LeggiParametroString("MiniatureLarghezza");
RadioButton3.Checked = _parametriSetup.LeggiParametroBoolean("MiniatureAddScritta");
RadioButton4.Checked = _parametriSetup.LeggiParametroBoolean("MiniatureAddOrario");
TextBox27.Text = _parametriSetup.LeggiParametroString("FotoAltezza");
TextBox28.Text = _parametriSetup.LeggiParametroString("FotoLarghezza");
// TextBox13.Text = SetupIni.LeggiParametroString("FotoCodice")
// CheckBox2.Checked = SetupIni.LeggiParametroBoolean("FotoDimOriginali")
Text = "Image Catalog - " + Path.GetFileName(openDialog.FileName);
}
TextBox11.Text = _parametriSetup.LeggiParametroString("FontDimensione");
TextBox25.Text = _parametriSetup.LeggiParametroString("FontDimensioneMiniatura");
CheckBox3.Checked = _parametriSetup.LeggiParametroBoolean("FontBold");
ComboBox3.Text = _parametriSetup.LeggiParametroString("FontNome");
if (string.IsNullOrEmpty(TextBox25.Text))
private void OnSelectColorRequested(object sender, EventArgs e)
{
var colorDialog = new ColorDialog
{
TextBox25.Text = "0";
AllowFullOpen = true
};
if (!string.IsNullOrWhiteSpace(Model.TextColorRGB))
{
try
{
colorDialog.Color = ColorTranslator.FromHtml(Model.TextColorRGB);
}
catch
{
// Invalid color, use default
}
}
Model.HorizontalText = _parametriSetup.LeggiParametroString("TestoTesto");
TextBox9.Text = _parametriSetup.LeggiParametroString("TestoTrasparente");
TextBox12.Text = _parametriSetup.LeggiParametroString("TestoMargine");
ComboBox1.Text = _parametriSetup.LeggiParametroString("TestoPosizione");
ComboBox2.Text = _parametriSetup.LeggiParametroString("TestoAllineamento");
TextBox10.Text = _parametriSetup.LeggiParametroString("MarchioFile");
TextBox14.Text = _parametriSetup.LeggiParametroString("MarchioAltezza");
TextBox15.Text = _parametriSetup.LeggiParametroString("MarchioLarghezza");
TextBox16.Text = _parametriSetup.LeggiParametroString("MarchioMargine");
ComboBox4.Text = _parametriSetup.LeggiParametroString("MarchioAllOrizzontale");
ComboBox5.Text = _parametriSetup.LeggiParametroString("MarchioAllVerticale");
TextBox19.Text = _parametriSetup.LeggiParametroString("MarchioTrasparenza");
CheckBox5.Checked = _parametriSetup.LeggiParametroBoolean("MarchioAggiungi");
CheckBox7.Checked = _parametriSetup.LeggiParametroBoolean("TempoGara");
CheckBox8.Checked = _parametriSetup.LeggiParametroBoolean("Orario");
TextBox18.Text = _parametriSetup.LeggiParametroString("EtichettaOrario");
chkForzaJpg.Checked = _parametriSetup.LeggiParametroBoolean("GeneraleForzaJpg");
chkRotazioneAutomatica.Checked = _parametriSetup.LeggiParametroBoolean("GeneraleRotazioneAutomatica");
TextBox30.Text = _parametriSetup.LeggiParametroString("GrandezzaVerticale");
TextBox31.Text = _parametriSetup.LeggiParametroString("MargineVerticale");
CheckBox15.Checked = _parametriSetup.LeggiParametroBoolean("DimensioniOriginali");
Model.VerticalText = _parametriSetup.LeggiParametroString("TestoVerticale");
RadioButton6.Checked = _parametriSetup.LeggiParametroBoolean("NomeMiniatura");
CheckBox16.Checked = _parametriSetup.LeggiParametroBoolean("DataFoto");
CheckBox17.Checked = _parametriSetup.LeggiParametroBoolean("NumeroFoto");
RadioButton5.Checked = _parametriSetup.LeggiParametroBoolean("TempoSmall");
RadioButton7.Checked = _parametriSetup.LeggiParametroBoolean("NumTempoSmall");
TextBox32.Text = _parametriSetup.LeggiParametroString("CompressioneJpeg");
TextBox33.Text = _parametriSetup.LeggiParametroString("CompressioneJpegMiniatura");
TextBox34.Text = _parametriSetup.LeggiParametroString("ColoreTestoRGB");
Model.OverwriteImages = _parametriSetup.LeggiParametroBoolean("OverwriteImages");
if (File.Exists(TextBox10.Text))
if (colorDialog.ShowDialog() == DialogResult.OK)
{
PictureBox1.Image = Image.FromFile(TextBox10.Text);
Model.TextColorRGB = ColorTranslator.ToHtml(colorDialog.Color);
TextBox34.BackColor = colorDialog.Color;
}
}
private void UpdateLogoPictureBox(string logoPath)
{
try
{
PictureBox1.Image = Image.FromFile(logoPath);
if (PictureBox1.Image.Height >= PictureBox1.Image.Width)
{
PictureBox1.Height = 160;
PictureBox1.Width =
(int)(160 * PictureBox1.Image.Width / (double)PictureBox1.Image.Height);
PictureBox1.Width = (int)(160 * PictureBox1.Image.Width / (double)PictureBox1.Image.Height);
}
else
{
PictureBox1.Width = 224;
PictureBox1.Height =
(int)(224 * PictureBox1.Image.Height / (double)PictureBox1.Image.Width);
PictureBox1.Width = 160;
PictureBox1.Height = (int)(160 * PictureBox1.Image.Height / (double)PictureBox1.Image.Width);
}
}
Text = "Image Catalog - " + LeggiSoloNomeFile(ilNome);
// 2021
Model.ChunkSize = _parametriSetup.LeggiParametro("ChunkSize", Model.ChunkSize);
Model.ThreadsCount = _parametriSetup.LeggiParametro("ThreadsCount", Model.ThreadsCount);
// if (int.TryParse(_parametriSetup.LeggiParametroString("ChunkSize"), out var chunkSize))
// {
// Model.ChunkSize = chunkSize;
// }
// if (int.TryParse(_parametriSetup.LeggiParametroString("ThreadsCount"), out var threadsCount))
// {
// Model.ThreadsCount = threadsCount;
// }
// Model.ChunkSize = int.Parse(_parametriSetup.LeggiParametroString("ChunkSize"));
// Model.ThreadsCount = int.Parse(_parametriSetup.LeggiParametroString("ThreadsCount"));
catch
{
// Image loading failed, ignore
}
}
private void SetPicSettings(string SourcePath, string DestPath)
{
var SourceDir = new DirectoryInfo(SourcePath);
var DestDirStart = new DirectoryInfo(DestPath);
DirectoryInfo DestDir = null;
_picSettings.DirectorySorgente = SourcePath;
_picSettings.DirectoryDestinazione = Model.DestinationPath;
// _picSettings.DestDir = DestDir
// _picSettings.SourceDir = SourceDir
// _picSettings.DestDirStart = DestDirStart
_picSettings.DimStandard = int.Parse(TextBox11.Text);
_picSettings.DimStandardMiniatura = int.Parse(TextBox25.Text);
_picSettings.UsaOrarioMiniatura = CheckBox12.Checked;
_picSettings.UsaOrarioTestoApplicare = CheckBox8.Checked;
_picSettings.UsaTempoGaraTestoApplicare = CheckBox7.Checked;
_picSettings.UsaRotazioneAutomatica = chkRotazioneAutomatica.Checked;
_picSettings.UsaForzaJpg = chkForzaJpg.Checked;
if (CheckBox17.Checked)
{
_picSettings.TestoNome = true;
}
else
{
_picSettings.TestoNome = false;
}
if (CheckBox16.Checked)
{
_picSettings.NomeData = true;
}
else
{
_picSettings.NomeData = false;
}
_picSettings.DirectoryDestinazione = DestPath;
// Font and text settings from Model
_picSettings.DimStandard = Model.FontSize;
_picSettings.DimStandardMiniatura = Model.FontSizeThumbnail;
_picSettings.IlFont = Model.FontName;
_picSettings.Grassetto = Model.FontBold;
_picSettings.Posizione = Model.VerticalPosition;
_picSettings.Allineamento = Model.HorizontalAlignment;
_picSettings.Trasparenza = Model.TextTransparency;
_picSettings.Margine = Model.TextMargin;
_picSettings.FontColoreRGB = ColorTranslator.FromHtml(Model.TextColorRGB);
// Thumbnail settings from Model
_picSettings.AltezzaSmall = Model.ThumbnailHeight;
_picSettings.LarghezzaSmall = Model.ThumbnailWidth;
_picSettings.Suffisso = Model.ThumbnailPrefix;
_picSettings.CreaMiniature = Model.CreateThumbnails;
_picSettings.JpegQualityMin = Model.JpegQualityThumbnail;
_picSettings.DimMin = Model.FontSizeThumbnail;
// Big photo settings from Model
_picSettings.AltezzaBig = Model.PhotoBigHeight;
_picSettings.LarghezzaBig = Model.PhotoBigWidth;
_picSettings.FotoGrandeDimOrigina = Model.KeepOriginalDimensions;
_picSettings.JpegQuality = Model.JpegQuality;
// Logo settings from Model
_picSettings.LogoAggiungi = Model.AddLogo;
_picSettings.LogoNomeFile = Model.LogoFile;
_picSettings.LogoAltezza = Model.LogoHeight;
_picSettings.LogoLarghezza = Model.LogoWidth;
_picSettings.LogoMargine = Model.LogoMargin.ToString();
_picSettings.LogoTrasparenza = Model.LogoTransparency.ToString();
_picSettings.LogoPosizioneH = Model.LogoHorizontalPosition;
_picSettings.LogoPosizioneV = Model.LogoVerticalPosition;
// Text content from Model
_picSettings.TestoFirmaStart = Model.HorizontalText;
_picSettings.TestoFirmaStartV = Model.VerticalText;
_picSettings.DataPartenza = DateTimePicker1.Value;
_picSettings.TestoOrario = TextBox18.Text;
_picSettings.AltezzaSmall = int.Parse(TextBox6.Text);
_picSettings.LarghezzaSmall = int.Parse(TextBox5.Text);
_picSettings.CreaMiniature = CheckBox1.Checked;
// Vertical text settings from Model
_picSettings.DimVert = Model.VerticalTextSize;
_picSettings.MargVert = Model.VerticalTextMargin;
// Boolean flags from Model
_picSettings.UsaRotazioneAutomatica = Model.AutomaticRotation;
_picSettings.UsaForzaJpg = Model.ForceJpeg;
_picSettings.TestoNome = Model.ShowPhotoNumber;
_picSettings.NomeData = Model.ShowDate;
_picSettings.UsaOrarioTestoApplicare = Model.AddTime;
_picSettings.UsaTempoGaraTestoApplicare = Model.AddRaceTime;
_picSettings.OverwriteFiles = Model.OverwriteImages;
// Additional settings from Model
_picSettings.UsaOrarioMiniatura = Model.AddTimeToThumbnails;
_picSettings.DataPartenza = Model.RaceStartDate;
_picSettings.TestoOrario = Model.TimeLabel;
_picSettings.TestoMin = Model.ShowFileNameOnThumbnails;
// Controls that still need binding (TODO: move to Model)
_picSettings.AggiungiScritteMiniature = RadioButton3.Checked;
_picSettings.AggTempoGaraMin = RadioButton5.Checked;
_picSettings.AggNumTempMin = RadioButton7.Checked;
_picSettings.DimVert = int.Parse(TextBox30.Text);
_picSettings.MargVert = int.Parse(TextBox31.Text);
// _picSettings.NomeFileChild = childFile.Name
_picSettings.Suffisso = TextBox3.Text;
// _picSettings.Codice = TextBox13.Text
_picSettings.Trasparenza = int.Parse(TextBox9.Text);
_picSettings.IlFont = ComboBox3.SelectedItem.ToString();
_picSettings.Grassetto = CheckBox3.Checked;
_picSettings.Posizione = ComboBox1.SelectedItem.ToString();
_picSettings.Allineamento = ComboBox2.SelectedItem.ToString();
_picSettings.Margine = int.Parse(TextBox12.Text);
_picSettings.LogoAltezza = int.Parse(TextBox14.Text);
_picSettings.LogoLarghezza = int.Parse(TextBox15.Text);
_picSettings.FontColoreRGB = ColorTranslator.FromHtml(TextBox34.Text);
_picSettings.LogoAggiungi = CheckBox5.Checked;
_picSettings.LogoNomeFile = TextBox10.Text;
_picSettings.LogoTrasparenza = TextBox19.Text;
_picSettings.LogoMargine = TextBox16.Text;
_picSettings.LogoPosizioneH = ComboBox4.Text;
_picSettings.LogoPosizioneV = ComboBox5.Text;
_picSettings.FotoGrandeDimOrigina = CheckBox15.Checked;
_picSettings.AltezzaBig = int.Parse(TextBox27.Text);
_picSettings.LarghezzaBig = int.Parse(TextBox28.Text);
_picSettings.DimMin = int.Parse(TextBox25.Text);
_picSettings.TestoMin = RadioButton6.Checked;
_picSettings.JpegQuality = int.Parse(TextBox32.Text);
_picSettings.JpegQualityMin = int.Parse(TextBox33.Text);
_picSettings.OverwriteFiles = Model.OverwriteImages;
}
private void setLabel18Text(string text)
@ -593,132 +424,16 @@ public partial class MainForm
NumerazioneType numerazioneType;
if (rdbNumProgressiva.Checked)
{
numerazioneType = NumerazioneType.Progressiva; // FileHelper.numerazione.Progressiva
numerazioneType = NumerazioneType.Progressiva;
}
else
{
numerazioneType = NumerazioneType.Files;
} // FileHelper.numerazione.Files
}
return numerazioneType;
}
private void Button4_Click(object sender, EventArgs e)
{
var openFileDialog = new OpenFileDialog();
// openFileDialog.InitialDirectory = TextBox1.Text
openFileDialog.Filter = "Immagini jpg (*.jpg)|*.jpg|Immagini gif (*.gif)|*.gif|Tutti i file (*.*)|*.*";
if (TextBox10.Text.Length > 0)
{
openFileDialog.FileName = TextBox10.Text;
}
openFileDialog.FilterIndex = 0;
openFileDialog.RestoreDirectory = true;
if (DialogResult.OK == openFileDialog.ShowDialog())
{
TextBox10.Text = openFileDialog.FileName;
PictureBox1.Image = Image.FromFile(TextBox10.Text);
if (PictureBox1.Image.Height >= PictureBox1.Image.Width)
{
PictureBox1.Height = 160;
PictureBox1.Width =
(int)(160 * PictureBox1.Image.Width / (double)PictureBox1.Image.Height);
}
else
{
PictureBox1.Width = 224;
PictureBox1.Height =
(int)(224 * PictureBox1.Image.Height / (double)PictureBox1.Image.Width);
}
}
}
private string LeggiSoloNomeFile(string FileName)
{
string Testo = FileName;
string Risposta = "";
var Nomi = Testo.Split(new char[] { '\\' });
if (Nomi.Length > 1)
{
Risposta = Nomi[Nomi.Length - 1];
}
return Risposta;
}
private void PictureBox1_MouseMove(object sender, MouseEventArgs e)
{
// GetColor()
// GetPixelColor(PictureBox1.PointToScreen(e.Location)).ToArgb.ToString("X8")
}
private void PictureBox1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
_waterSelectColor = true;
}
else
{
_waterSelectColor = false;
}
}
private Color[] GetPixelColor(Point screenLocation)
{
// Dim bm As New Bitmap(1, 1, Imaging.PixelFormat.Format24bppRgb)
// Dim g As Graphics = Graphics.FromImage(bm)
// g.CopyFromScreen(screenLocation, New Point(0, 0), New Size(1, 1))
// Dim result As Color = bm.GetPixel(0, 0)
// g.Dispose()
// bm.Dispose()
// Return result
return null;
}
private void Button8_Click(object sender, EventArgs e)
{
var MyDialog = new ColorDialog();
MyDialog.AllowFullOpen = true;
// If TextBox22.Text.Length > 0 And TextBox23.Text.Length > 0 And TextBox24.Text.Length > 0 Then
// If CType(TextBox22.Text, Integer) >= 0 And CType(TextBox23.Text, Integer) >= 0 And CType(TextBox24.Text, Integer) >= 0 Then
// MyDialog.Color = Color.FromArgb(0, CType(TextBox22.Text, Integer), CType(TextBox23.Text, Integer), CType(TextBox24.Text, Integer))
// End If
// End If
if (MyDialog.ShowDialog() == DialogResult.OK)
{
// TextBox22.Text = MyDialog.Color.R.ToString
// TextBox23.Text = MyDialog.Color.G.ToString
// TextBox24.Text = MyDialog.Color.B.ToString
TextBox34.Text = ColorTranslator.ToHtml(MyDialog.Color);
TextBox34.BackColor = MyDialog.Color;
}
}
private void CheckBox18_CheckedChanged(object sender, EventArgs e)
{
CheckBox4.Checked = false;
CheckBox12.Checked = false;
}
private void CheckBox4_CheckedChanged(object sender, EventArgs e)
{
CheckBox18.Checked = false;
}
private void CheckBox12_CheckedChanged(object sender, EventArgs e)
{
CheckBox18.Checked = false;
}
private void Label27_Click(object sender, EventArgs e)
{
}
//private CancellationTokenSource? _mainToken;
private async void Button1_Click(object sender, EventArgs e)
{
@ -796,11 +511,6 @@ public partial class MainForm
int diff = _currentAmount - _previousAmount;
Model.SpeedCounter = $"{diff} f/m";
}
private void UpdateCounter(string text)
{
Label10.Invoke(new Action(() => Label10.Text = text));
}
}
public class PicInfo

View file

@ -81,6 +81,7 @@ static class Program
{
// Register your services here
services.AddTransient<ITestService, TestService>();
services.AddTransient<ISettingsService, SettingsService>();
services.AddTransient<DataModel>();

View file

@ -0,0 +1,10 @@
using System.Threading.Tasks;
namespace ImageCatalog_2.Services
{
public interface ISettingsService
{
Task SaveSettingsAsync(string filePath, object settings);
Task LoadSettingsAsync(string filePath, object settings);
}
}

View file

@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using ImageCatalog;
namespace ImageCatalog_2.Services
{
/// <summary>
/// Modern settings service that uses reflection to automatically save/load all properties
/// </summary>
public class SettingsService : ISettingsService
{
private readonly ParametriSetup _parametriSetup;
public SettingsService(ParametriSetup parametriSetup)
{
_parametriSetup = parametriSetup;
}
public Task SaveSettingsAsync(string filePath, object settings)
{
return Task.Run(() =>
{
_parametriSetup.NomeFileSetup = filePath;
// Use reflection to get all properties and save them
var properties = settings.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)
.Where(p => p.CanRead && IsSerializableType(p.PropertyType));
foreach (var prop in properties)
{
var value = prop.GetValue(settings);
_parametriSetup.AggiornaParametro(prop.Name, value);
}
_parametriSetup.SalvaParametriSetup();
});
}
public Task LoadSettingsAsync(string filePath, object settings)
{
return Task.Run(() =>
{
_parametriSetup.NomeFileSetup = filePath;
_parametriSetup.CaricaParametriSetup();
// Use reflection to get all properties and load them
var properties = settings.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)
.Where(p => p.CanWrite && IsSerializableType(p.PropertyType));
foreach (var prop in properties)
{
try
{
object value;
if (prop.PropertyType == typeof(string))
{
value = _parametriSetup.LeggiParametroString(prop.Name);
}
else if (prop.PropertyType == typeof(bool))
{
value = _parametriSetup.LeggiParametroBoolean(prop.Name);
}
else if (prop.PropertyType == typeof(int))
{
value = _parametriSetup.LeggiParametro<int>(prop.Name, (int)(prop.GetValue(settings) ?? 0));
}
else if (prop.PropertyType == typeof(double))
{
value = _parametriSetup.LeggiParametro<double>(prop.Name, (double)(prop.GetValue(settings) ?? 0.0));
}
else
{
continue; // Skip unsupported types
}
prop.SetValue(settings, value);
}
catch
{
// Skip properties that can't be loaded
}
}
});
}
private bool IsSerializableType(Type type)
{
return type == typeof(string) ||
type == typeof(int) ||
type == typeof(bool) ||
type == typeof(double) ||
type == typeof(float) ||
type == typeof(decimal);
}
}
}