Catalog/imagecatalog/MainForm.cs

548 lines
18 KiB
C#
Raw Normal View History

2021-03-04 10:44:09 +01:00
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
2025-07-08 14:35:27 +02:00
using System.ComponentModel;
2021-03-04 10:44:09 +01:00
using System.Drawing;
using System.Drawing.Text;
using System.IO;
using System.Linq;
2024-10-14 19:57:24 +02:00
using System.Reflection;
2021-03-04 10:44:09 +01:00
using System.Runtime.InteropServices;
using System.Text;
2021-03-04 10:44:09 +01:00
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
2024-10-14 22:55:52 +02:00
using ImageCatalog_2;
2024-10-14 22:18:03 +02:00
using ImageCatalog_2.Services;
2021-03-04 10:44:09 +01:00
using MaddoShared;
using Microsoft.Extensions.Logging;
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
namespace ImageCatalog;
public partial class MainForm
2021-03-04 10:44:09 +01:00
{
private readonly DataModel Model;
2025-07-29 10:34:23 +02:00
2025-07-28 09:00:07 +02:00
private readonly ILogger<MainForm> _logger;
private readonly ImageCreationStuff _imageCreationService;
2021-03-04 10:44:09 +01:00
2025-07-28 09:15:45 +02:00
private readonly ParametriSetup _parametriSetup;
2025-07-28 10:22:08 +02:00
private readonly PicSettings _picSettings;
2025-07-29 10:34:23 +02:00
public MainForm(DataModel model, ImageCreationStuff imageCreationStuff, PicSettings picSettings,
ParametriSetup parametriSetup, ILogger<MainForm> logger)
2021-03-04 10:44:09 +01:00
{
Model = model;
2025-07-28 09:00:07 +02:00
_imageCreationService = imageCreationStuff;
2025-07-28 09:15:45 +02:00
_parametriSetup = parametriSetup;
2025-07-28 10:22:08 +02:00
_picSettings = picSettings;
2025-07-28 09:00:07 +02:00
_logger = logger;
_logger.LogDebug("Start");
InitializeComponent();
BindControls();
2026-02-04 19:48:03 +01:00
// Subscribe to DataModel events
Model.SelectSourceFolderRequested += OnSelectSourceFolderRequested;
Model.SelectDestinationFolderRequested += OnSelectDestinationFolderRequested;
Model.SelectLogoFileRequested += OnSelectLogoFileRequested;
Model.SaveSettingsRequested += OnSaveSettingsRequested;
Model.LoadSettingsRequested += OnLoadSettingsRequested;
Model.SelectColorRequested += OnSelectColorRequested;
2025-07-28 09:00:07 +02:00
var version = Assembly.GetExecutingAssembly().GetName().Version;
_Label27.Text = $"Version: {version.Major}.{version.Minor}.{version.Build}.{version.Revision}";
2025-09-19 09:53:31 +02:00
_results = [];
2025-07-28 09:00:07 +02:00
UiUpdateEvent += OnUiUpdateEvent;
}
2024-10-14 22:55:52 +02:00
2025-07-28 09:00:07 +02:00
protected void BindControls()
{
2026-02-04 19:48:03 +01:00
// 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);
2025-07-28 09:00:07 +02:00
}
2024-10-14 22:18:03 +02:00
2025-07-28 09:00:07 +02:00
private event EventHandler<Tuple<string, int>> UiUpdateEvent;
2025-07-23 17:16:06 +02:00
2025-07-28 09:00:07 +02:00
delegate void SetTextCallback(Label target, string text);
2024-10-14 22:55:52 +02:00
2025-07-28 09:00:07 +02:00
private void SetText(Label target, string text)
{
if (InvokeRequired)
2024-10-14 22:55:52 +02:00
{
2025-07-29 11:07:49 +02:00
var d = new SetTextCallback(SetText);
2025-07-28 09:00:07 +02:00
this.Invoke(d, new object[] { target, text });
2024-10-14 22:55:52 +02:00
}
2025-07-28 09:00:07 +02:00
else
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
target.Text = text;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
}
2025-09-19 09:53:31 +02:00
private delegate void SetProgressCallback(ProgressBar target, int amount, int maximum);
2025-07-28 09:00:07 +02:00
private void SetProgress(ProgressBar target, int amount, int maximum)
{
if (InvokeRequired)
2021-03-04 10:44:09 +01:00
{
2025-07-29 10:34:23 +02:00
var d = new SetProgressCallback(SetProgress);
2025-07-28 09:00:07 +02:00
this.Invoke(d, new object[] { target, amount, maximum });
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
else
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
target.Maximum = maximum;
target.Value = amount;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
private void OnUiUpdateEvent(object sender, Tuple<string, int> args)
{
SetProgress(ProgressBar1, _results.Count, args.Item2);
SetText(Label18, _results.Count.ToString());
SetText(Label10, args.Item1);
SetText(lblFotoTotaliNum, args.Item2.ToString());
}
2025-07-29 11:10:54 +02:00
2025-07-28 09:00:07 +02:00
private ConcurrentBag<string> _results;
2021-03-04 10:44:09 +01:00
2025-07-28 14:45:03 +02:00
private void SetDefaults()
2025-07-28 09:00:07 +02:00
{
2026-02-04 22:10:16 +01:00
// Bind ComboBoxes to Model using proper data binding
2026-02-04 19:48:03 +01:00
ComboBox1.DataSource = new List<string>(Model.VerticalPositions);
2026-02-04 22:10:16 +01:00
ComboBox1.DataBindings.Add(new Binding("SelectedItem", bindingSource1, nameof(Model.VerticalPosition),
false, DataSourceUpdateMode.OnPropertyChanged));
2026-02-04 19:48:03 +01:00
ComboBox2.DataSource = new List<string>(Model.HorizontalAlignments);
2026-02-04 22:10:16 +01:00
ComboBox2.DataBindings.Add(new Binding("SelectedItem", bindingSource1, nameof(Model.HorizontalAlignment),
false, DataSourceUpdateMode.OnPropertyChanged));
2026-02-04 19:48:03 +01:00
ComboBox3.DataSource = new List<string>(Model.AvailableFonts);
2026-02-04 22:10:16 +01:00
ComboBox3.DataBindings.Add(new Binding("SelectedItem", bindingSource1, nameof(Model.FontName),
false, DataSourceUpdateMode.OnPropertyChanged));
2026-02-04 19:48:03 +01:00
ComboBox4.DataSource = new List<string>(Model.HorizontalAlignments);
2026-02-04 22:10:16 +01:00
ComboBox4.DataBindings.Add(new Binding("SelectedItem", bindingSource1, nameof(Model.LogoHorizontalPosition),
false, DataSourceUpdateMode.OnPropertyChanged));
2026-02-04 19:48:03 +01:00
ComboBox5.DataSource = new List<string> { "Alto", "Centro", "Basso" };
2026-02-04 22:10:16 +01:00
ComboBox5.DataBindings.Add(new Binding("SelectedItem", bindingSource1, nameof(Model.LogoVerticalPosition),
false, DataSourceUpdateMode.OnPropertyChanged));
2026-02-04 21:12:27 +01:00
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
private void Form1_Load(object sender, EventArgs e)
{
bindingSource1.DataSource = Model;
Application.EnableVisualStyles();
2025-07-28 14:45:03 +02:00
SetDefaults();
2025-07-29 10:34:23 +02:00
2025-07-28 09:00:07 +02:00
_logger.LogInformation("Programma Avviato");
}
private void FixPaths()
{
Model.SourcePath = FixPath(Model.SourcePath);
Model.DestinationPath = FixPath(Model.DestinationPath);
}
private string FixPath(string path)
{
if (string.IsNullOrWhiteSpace(path))
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
return string.Empty;
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// Trim leading/trailing quotes
path = path.Trim().Trim('"');
2025-07-28 09:00:07 +02:00
// Normalize directory separators
path = path.Replace('/', Path.DirectorySeparatorChar)
.Replace('\\', Path.DirectorySeparatorChar);
2025-07-28 09:00:07 +02:00
// Remove trailing separators then add one back
path = path.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar;
2025-07-28 09:00:07 +02:00
return path;
}
2025-07-28 09:00:07 +02:00
private void lockUI()
{
Model.UiEnabled = false;
//TabControl1.Enabled = false;
//Button5.Enabled = false;
//Button6.Enabled = false;
//btnCreaCatalogoAsync.Enabled = false;
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
private void unlockUI()
{
Model.UiEnabled = true;
//TabControl1.Enabled = true;
//Button5.Enabled = true;
//Button6.Enabled = true;
//btnCreaCatalogoAsync.Enabled = true;
}
private string CalcTime(DateTime timeStart, DateTime timeStop, int numFoto)
{
long timediffH, timediffS;
long timediffM;
2025-07-29 10:34:23 +02:00
2025-07-28 09:00:07 +02:00
TimeSpan timeDiff = timeStop - timeStart;
timediffM = (int)timeDiff.TotalMinutes;
timediffS = (int)timeDiff.TotalSeconds;
timediffH = (int)timeDiff.TotalHours;
2025-07-29 10:34:23 +02:00
2025-07-28 09:00:07 +02:00
// timediffM = DateAndTime.DateDiff(DateInterval.Minute, timeStart, timeStop);
// timediffS = DateAndTime.DateDiff(DateInterval.Second, timeStart, timeStop);
// timediffH = DateAndTime.DateDiff(DateInterval.Hour, timeStart, timeStop);
2025-07-29 10:34:23 +02:00
2025-07-28 09:00:07 +02:00
double fotoSec = numFoto / (double)timediffS;
double fotoMin = numFoto / (double)timediffM;
double fotoOra = numFoto / (double)timediffH;
string s = "S: " + timediffS.ToString() + "; F/s: " +
fotoSec.ToString(
"0.000"); // + " F/m: " + fotoMin.ToString("0.00") + " F/h: " + fotoOra.ToString("0.00")
return s;
}
private string SelectFolder(string startingFolder)
{
var dialog = new FolderBrowserDialog();
dialog.InitialDirectory = startingFolder;
if (dialog.ShowDialog() != DialogResult.OK) return string.Empty;
2025-07-29 10:34:23 +02:00
2026-02-04 19:48:03 +01:00
return FixPath(dialog.SelectedPath);
2025-07-28 09:00:07 +02:00
}
2026-02-04 19:48:03 +01:00
private void OnSelectSourceFolderRequested(object sender, EventArgs e)
2025-07-28 09:00:07 +02:00
{
var dialogResult = SelectFolder(Model.SourcePath);
if (!string.IsNullOrWhiteSpace(dialogResult))
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
Model.SourcePath = dialogResult;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
}
2026-02-04 19:48:03 +01:00
private void OnSelectDestinationFolderRequested(object sender, EventArgs e)
2025-07-28 09:00:07 +02:00
{
var dialogResult = SelectFolder(Model.DestinationPath);
if (!string.IsNullOrWhiteSpace(dialogResult))
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
Model.DestinationPath = dialogResult;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
}
2026-02-04 19:48:03 +01:00
private void OnSelectLogoFileRequested(object sender, EventArgs e)
2025-07-28 09:00:07 +02:00
{
2026-02-04 19:48:03 +01:00
var dialog = new OpenFileDialog();
dialog.Filter = "Image Files|*.jpg;*.jpeg;*.png;*.bmp;*.gif";
if (Model.LogoFile.Length > 0)
2021-03-04 10:44:09 +01:00
{
2026-02-04 19:48:03 +01:00
dialog.FileName = Model.LogoFile;
2021-03-04 10:44:09 +01:00
}
2026-02-04 19:48:03 +01:00
if (dialog.ShowDialog() == DialogResult.OK)
2025-07-28 14:45:03 +02:00
{
2026-02-04 19:48:03 +01:00
Model.LogoFile = dialog.FileName;
UpdateLogoPictureBox(Model.LogoFile);
2025-07-28 14:45:03 +02:00
}
2026-02-04 19:48:03 +01:00
}
2025-07-28 14:45:03 +02:00
2026-02-04 19:48:03 +01:00
private async void OnSaveSettingsRequested(object sender, string e)
{
var saveDialog = new SaveFileDialog
{
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);
2025-07-28 09:00:07 +02:00
}
2021-03-04 10:44:09 +01:00
2026-02-04 19:48:03 +01:00
private async void OnLoadSettingsRequested(object sender, string e)
2025-07-28 09:00:07 +02:00
{
2026-02-04 19:48:03 +01:00
var openDialog = new OpenFileDialog
{
Filter = "Setup (*.xml)|*.xml|All valid files (*.*)|*.*",
FilterIndex = 0,
RestoreDirectory = true
};
if (openDialog.ShowDialog() != DialogResult.OK) return;
2026-02-04 22:10:16 +01:00
try
2025-09-19 09:53:31 +02:00
{
2026-02-04 22:10:16 +01:00
await Model.LoadSettingsFromFileAsync(openDialog.FileName);
// Explicitly ensure UI is enabled after loading
Model.UiEnabled = true;
// Update logo preview if logo file exists
if (File.Exists(Model.LogoFile))
{
UpdateLogoPictureBox(Model.LogoFile);
}
2026-02-04 19:48:03 +01:00
2026-02-04 22:10:16 +01:00
Text = "Image Catalog - " + Path.GetFileName(openDialog.FileName);
_logger.LogInformation($"Settings loaded successfully from {openDialog.FileName}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error loading settings");
MessageBox.Show($"Error loading settings: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
2026-02-04 19:48:03 +01:00
}
private void OnSelectColorRequested(object sender, EventArgs e)
{
var colorDialog = new ColorDialog
{
AllowFullOpen = true
};
if (!string.IsNullOrWhiteSpace(Model.TextColorRGB))
2021-03-04 10:44:09 +01:00
{
2026-02-04 19:48:03 +01:00
try
{
colorDialog.Color = ColorTranslator.FromHtml(Model.TextColorRGB);
}
catch
{
// Invalid color, use default
}
2025-09-19 09:53:31 +02:00
}
2026-02-04 19:48:03 +01:00
if (colorDialog.ShowDialog() == DialogResult.OK)
2025-09-19 09:53:31 +02:00
{
2026-02-04 19:48:03 +01:00
Model.TextColorRGB = ColorTranslator.ToHtml(colorDialog.Color);
TextBox34.BackColor = colorDialog.Color;
2025-09-19 09:53:31 +02:00
}
2026-02-04 19:48:03 +01:00
}
2025-09-19 09:53:31 +02:00
2026-02-04 19:48:03 +01:00
private void UpdateLogoPictureBox(string logoPath)
{
try
2025-09-19 09:53:31 +02:00
{
2026-02-04 19:48:03 +01:00
PictureBox1.Image = Image.FromFile(logoPath);
2025-09-19 09:53:31 +02:00
if (PictureBox1.Image.Height >= PictureBox1.Image.Width)
2021-03-04 10:44:09 +01:00
{
2025-09-19 09:53:31 +02:00
PictureBox1.Height = 160;
2026-02-04 19:48:03 +01:00
PictureBox1.Width = (int)(160 * PictureBox1.Image.Width / (double)PictureBox1.Image.Height);
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
else
2021-03-04 10:44:09 +01:00
{
2026-02-04 19:48:03 +01:00
PictureBox1.Width = 160;
PictureBox1.Height = (int)(160 * PictureBox1.Image.Height / (double)PictureBox1.Image.Width);
2021-03-04 10:44:09 +01:00
}
2025-09-19 09:53:31 +02:00
}
2026-02-04 19:48:03 +01:00
catch
{
// Image loading failed, ignore
}
2025-07-28 09:00:07 +02:00
}
2021-03-04 10:44:09 +01:00
2025-07-28 10:22:08 +02:00
private void SetPicSettings(string SourcePath, string DestPath)
2025-07-28 09:00:07 +02:00
{
2025-07-28 10:22:08 +02:00
_picSettings.DirectorySorgente = SourcePath;
2026-02-04 19:48:03 +01:00
_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;
2026-02-04 22:10:16 +01:00
_picSettings.Codice = Model.BigPhotoSuffix;
2026-02-04 19:48:03 +01:00
// 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
2025-07-28 10:22:08 +02:00
_picSettings.TestoFirmaStart = Model.HorizontalText;
2025-07-28 10:34:03 +02:00
_picSettings.TestoFirmaStartV = Model.VerticalText;
2026-02-04 19:48:03 +01:00
// 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;
2026-02-04 22:10:16 +01:00
// Thumbnail text options from Model
_picSettings.AggiungiScritteMiniature = Model.AddTextToThumbnails;
_picSettings.AggTempoGaraMin = Model.AddRaceTimeToThumbnails;
_picSettings.AggNumTempMin = Model.AddNumberAndTimeToThumbnails;
2025-07-28 09:00:07 +02:00
}
private void setLabel18Text(string text)
{
if (Label18.InvokeRequired)
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
Label18.Invoke(new Action<string>(setLabel18Text), text);
}
else
{
Label18.Text = text;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
private NumerazioneType GetNumerazioneEnum()
{
NumerazioneType numerazioneType;
if (rdbNumProgressiva.Checked)
{
2026-02-04 19:48:03 +01:00
numerazioneType = NumerazioneType.Progressiva;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
else
{
numerazioneType = NumerazioneType.Files;
2021-03-04 10:44:09 +01:00
}
2026-02-04 19:48:03 +01:00
return numerazioneType;
2025-07-28 09:00:07 +02:00
}
2021-03-04 11:25:40 +01:00
2025-07-28 09:00:07 +02:00
private async void Button1_Click(object sender, EventArgs e)
{
_logger.LogInformation("Avvio elaborazione...");
lockUI();
2025-07-29 11:10:54 +02:00
2025-07-29 11:07:49 +02:00
Model.MainToken?.Dispose();
Model.MainToken = new CancellationTokenSource();
var token = Model.MainToken.Token;
2025-07-29 10:34:23 +02:00
2025-07-28 09:00:07 +02:00
// timeStart = TimeOfDay
FixPaths();
Label10.Text = "Elaborazione in corso...";
lblFotoTotaliNum.Text = "0";
Label18.Text = "0";
2025-07-29 11:07:49 +02:00
Model.SpeedCounter = "-f/m";
2025-07-28 10:22:08 +02:00
SetPicSettings(Model.SourcePath, Model.DestinationPath);
2025-07-28 09:00:07 +02:00
ProgressBar1.Minimum = 0;
ProgressBar1.Step = 1;
ProgressBar1.Value = 0;
var imageCreationOptions = new ImageCreationStuff.Options
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
AggiornaSottodirectory = chkAggiornaSottodirectory.Checked,
CreaSottocartelle = chkCreaSottocartelle.Checked,
FilePerCartella = int.Parse(txtFilePerCartella.Text),
SuffissoCartelle = txtSuffissoCartelle.Text,
CifreContatore = int.Parse(txtCifreContatore.Text),
NumerazioneType = GetNumerazioneEnum(),
SourcePath = Model.SourcePath,
DestinationPath = Model.DestinationPath,
2025-09-19 09:53:31 +02:00
MaxThreads = Model.ThreadsCount,
ChunksSize = Model.ChunkSize,
2025-07-28 09:00:07 +02:00
LinearExecution = rdbVecchioMetodo.Checked
};
try
{
_results = [];
_currentAmount = 0;
_previousAmount = 0;
timer1.Tick += Timer1OnTick;
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
timer1.Interval = 1000 * 60;
timer1.Enabled = true;
2021-03-04 10:44:09 +01:00
2025-09-19 09:53:31 +02:00
var time =
2025-07-29 10:34:23 +02:00
await _imageCreationService.CreaCatalogoParallel(imageCreationOptions, _results, UiUpdateEvent, token);
Model.SpeedCounter = time;
2025-07-28 09:00:07 +02:00
timer1.Enabled = false;
}
catch (OperationCanceledException operationCanceledException)
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
_logger.LogInformation("Operazione Cancellata");
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
finally
{
2025-07-29 11:07:49 +02:00
Model.MainToken?.Dispose();
Model.MainToken = null;
2025-07-28 09:00:07 +02:00
timer1.Tick -= Timer1OnTick;
}
Label10.Text = "Finito";
unlockUI();
}
private int _currentAmount = 0;
private int _previousAmount = 0;
private void Timer1OnTick(object sender, EventArgs e)
{
_previousAmount = _currentAmount;
_currentAmount = _results.Count;
int diff = _currentAmount - _previousAmount;
2025-07-29 10:34:23 +02:00
Model.SpeedCounter = $"{diff} f/m";
2025-07-28 09:00:07 +02:00
}
}
public class PicInfo
{
public DirectoryInfo DirSource, DirDest, DirDestStart;
public string NomeImmagine;
public PicInfo(DirectoryInfo Dir_Source, DirectoryInfo Dir_Dest, DirectoryInfo Dir_DestStart,
string Nome_Immagine)
{
DirSource = Dir_Source;
DirDest = Dir_Dest;
DirDestStart = Dir_DestStart;
NomeImmagine = Nome_Immagine;
2021-03-04 10:44:09 +01:00
}
}