Added viewmodel

This commit is contained in:
MaddoScientisto 2024-10-14 22:55:52 +02:00
commit efbc9f91db
6 changed files with 1541 additions and 1267 deletions

View file

@ -11,6 +11,7 @@ using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using CatalogVbLib;
using ImageCatalog_2;
using ImageCatalog_2.Services;
using MaddoShared;
using Microsoft.VisualBasic;
@ -23,13 +24,23 @@ namespace ImageCatalog
public partial class MainForm
{
public DataModel Model { get; set; }
private readonly ITestService _service;
public MainForm(ITestService testService)
{
_service = testService;
Model = new DataModel();
InitializeComponent();
bindingSource1.DataSource = Model;
BindControls();
_Button3.Name = "Button3";
_Button2.Name = "Button2";
_Button8.Name = "Button8";
@ -52,6 +63,12 @@ namespace ImageCatalog
UiUpdateEvent += OnUiUpdateEvent;
}
protected void BindControls()
{
//txtSorgente.DataBindings.Add(new Binding("Text", SourcePath, ""));
}
private event EventHandler<Tuple<string, int>> UiUpdateEvent;
delegate void SetTextCallback(Label target, string text);
@ -107,8 +124,9 @@ namespace ImageCatalog
private void setDefaults()
{
txtSorgente.Text = "";
txtDestinazione.Text = "";
//txtSorgente.Text = "";
Model.SourcePath = string.Empty;
Model.DestinationPath = string.Empty;
TextBox3.Text = "tn_";
TextBox4.Text = "";
TextBox5.Text = "350";
@ -191,14 +209,14 @@ namespace ImageCatalog
private void FixPaths()
{
if (txtSorgente.Text.EndsWith(@"\") == false)
if (Model.SourcePath.EndsWith(@"\") == false)
{
txtSorgente.Text += @"\";
Model.SourcePath += @"\";
}
if (txtDestinazione.Text.EndsWith(@"\") == false)
if (Model.DestinationPath.EndsWith(@"\") == false)
{
txtDestinazione.Text += @"\";
Model.DestinationPath += @"\";
}
}
@ -233,7 +251,7 @@ namespace ImageCatalog
minThreads = Conversions.ToInteger(TextBox8.Text);
if (rdbNuovoMetodo.Checked)
{
setPicSettings(txtSorgente.Text, txtDestinazione.Text);
setPicSettings(Model.SourcePath, Model.DestinationPath);
ProgressBar1.Minimum = 0;
ProgressBar1.Step = 1;
ProgressBar1.Value = 0;
@ -256,7 +274,7 @@ namespace ImageCatalog
ContaImmaginiThread = 0;
// creaImmaginiWithThreadMod(txtSorgente.Text, txtDestinazione.Text)
creaimmaginiWithThreadDict(txtSorgente.Text, txtDestinazione.Text);
creaimmaginiWithThreadDict(Model.SourcePath, Model.DestinationPath);
ThreadPoolWorkItem ThAttivo = null;
int i = 0;
/* TODO ERROR: Skipped DefineDirectiveTrivia */
@ -295,7 +313,7 @@ namespace ImageCatalog
MyPool.StopThreadPool();
MyPool.StartThreadPool(minThreads, maxThreads);
ContaImmaginiThread = 0;
CreaImmaginiWithThread(txtSorgente.Text, txtDestinazione.Text);
CreaImmaginiWithThread(Model.SourcePath, Model.DestinationPath);
ThreadPoolWorkItem ThAttivo = null;
int i = 0;
while (i != ContaImmaginiThread)
@ -357,10 +375,10 @@ namespace ImageCatalog
private void Button2_Click(object sender, EventArgs e)
{
var dialogResult = SelectFolder(txtSorgente.Text);
var dialogResult = SelectFolder(Model.SourcePath);
if (!string.IsNullOrWhiteSpace(dialogResult))
{
txtSorgente.Text = dialogResult;
Model.SourcePath = dialogResult;
}
//CommonOpenFileDialog dialog = new CommonOpenFileDialog();
@ -393,10 +411,10 @@ namespace ImageCatalog
private void Button3_Click(object sender, EventArgs e)
{
var dialogResult = SelectFolder(txtDestinazione.Text);
var dialogResult = SelectFolder(Model.DestinationPath);
if (!string.IsNullOrWhiteSpace(dialogResult))
{
txtDestinazione.Text = dialogResult;
Model.DestinationPath = dialogResult;
}
//var DirSearch = new FolderBrowserDialog();
@ -448,8 +466,8 @@ namespace ImageCatalog
{
string IlNome = SaveFileDlg.FileName;
Module1.SetupIni.NomeFileSetup = IlNome;
Module1.SetupIni.AggiornaParametro("DirSorgente", txtSorgente.Text);
Module1.SetupIni.AggiornaParametro("DirDestinazione", txtDestinazione.Text);
Module1.SetupIni.AggiornaParametro("DirSorgente", Model.SourcePath);
Module1.SetupIni.AggiornaParametro("DirDestinazione", Model.DestinationPath);
Module1.SetupIni.AggiornaParametro("DirSottoDirectory", chkAggiornaSottodirectory.Checked);
Module1.SetupIni.AggiornaParametro("DirDividiDestinazione", chkCreaSottocartelle.Checked);
Module1.SetupIni.AggiornaParametro("DirDividiNumFile", txtFilePerCartella.Text);
@ -530,8 +548,8 @@ namespace ImageCatalog
string IlNome = openFileDialog.FileName;
Module1.SetupIni.NomeFileSetup = IlNome;
Module1.SetupIni.CaricaParametriSetup();
txtSorgente.Text = Module1.SetupIni.LeggiParametroString("DirSorgente");
txtDestinazione.Text = Module1.SetupIni.LeggiParametroString("DirDestinazione");
Model.SourcePath = Module1.SetupIni.LeggiParametroString("DirSorgente");
Model.DestinationPath = Module1.SetupIni.LeggiParametroString("DirDestinazione");
chkAggiornaSottodirectory.Checked = Module1.SetupIni.LeggiParametroBoolean("DirSottoDirectory");
chkCreaSottocartelle.Checked = Module1.SetupIni.LeggiParametroBoolean("DirDividiDestinazione");
txtFilePerCartella.Text = Module1.SetupIni.LeggiParametroString("DirDividiNumFile");
@ -626,8 +644,8 @@ namespace ImageCatalog
var SourceDir = new DirectoryInfo(SourcePath);
var DestDirStart = new DirectoryInfo(DestPath);
DirectoryInfo DestDir = null;
PicSettings.DirectorySorgente = txtSorgente.Text;
PicSettings.DirectoryDestinazione = txtDestinazione.Text;
PicSettings.DirectorySorgente = SourcePath;
PicSettings.DirectoryDestinazione = Model.DestinationPath;
// PicSettings.DestDir = DestDir
// PicSettings.SourceDir = SourceDir
@ -1213,8 +1231,8 @@ namespace ImageCatalog
Application.DoEvents();
var ClsCreaImmagine = new CreaImmagineSeparateThread();
ClsCreaImmagine.DirectorySorgente = txtSorgente.Text;
ClsCreaImmagine.DirectoryDestinazione = txtDestinazione.Text;
ClsCreaImmagine.DirectorySorgente = SourcePath;
ClsCreaImmagine.DirectoryDestinazione = Model.DestinationPath;
ClsCreaImmagine.DestDir = DestDir;
ClsCreaImmagine.SourceDir = SourceDir;
ClsCreaImmagine.DestDirStart = DestDirStart;
@ -1531,7 +1549,7 @@ namespace ImageCatalog
lblFotoTotaliNum.Text = "0";
Label18.Text = "0";
Label43.Text = "-s";
setPicSettings(txtSorgente.Text, txtDestinazione.Text);
setPicSettings(Model.SourcePath, Model.DestinationPath);
ProgressBar1.Minimum = 0;
ProgressBar1.Step = 1;
ProgressBar1.Value = 0;
@ -1545,8 +1563,8 @@ namespace ImageCatalog
imageCreationOptions.SuffissoCartelle = txtSuffissoCartelle.Text;
imageCreationOptions.CifreContatore = Conversions.ToInteger(txtCifreContatore.Text);
imageCreationOptions.NumerazioneType = GetNumerazioneEnum();
imageCreationOptions.SourcePath = txtSorgente.Text;
imageCreationOptions.DestinationPath = txtDestinazione.Text;
imageCreationOptions.SourcePath = Model.SourcePath;
imageCreationOptions.DestinationPath = Model.DestinationPath;
imageCreationOptions.MaxThreads = Conversions.ToInteger(TextBox7.Text);
imageCreationOptions.ChunksSize = Conversions.ToInteger(TextBox8.Text);
imageCreationOptions.LinearExecution = rdbVecchioMetodo.Checked;
@ -1611,8 +1629,8 @@ namespace ImageCatalog
imageCreationOptions.SuffissoCartelle = txtSuffissoCartelle.Text;
imageCreationOptions.CifreContatore = Conversions.ToInteger(txtCifreContatore.Text);
imageCreationOptions.NumerazioneType = GetNumerazioneEnum();
imageCreationOptions.SourcePath = txtSorgente.Text;
imageCreationOptions.DestinationPath = txtDestinazione.Text;
imageCreationOptions.SourcePath = Model.SourcePath;
imageCreationOptions.DestinationPath = Model.DestinationPath;
await imgStf.CreaImmaginiParallel(imageCreationOptions, _results, UiUpdateEvent);
// Await CreaImmaginiParallel(txtSorgente.Text, txtDestinazione.Text)