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

37
imagecatalog/DataModel.cs Normal file
View file

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ImageCatalog_2
{
public class DataModel : ViewModelBase
{
private string _sourcePath;
public string SourcePath
{
get => _sourcePath;
set
{
_sourcePath = value;
NotifyPropertyChanged();
}
}
private string _destinationPath;
public string DestinationPath
{
get => _destinationPath;
set
{
_destinationPath = value;
NotifyPropertyChanged();
}
}
}
}

File diff suppressed because it is too large Load diff

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)

View file

@ -117,7 +117,16 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="bindingSource1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>586, 17</value>
</metadata>
<metadata name="dataModelBindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>120, 17</value>
</metadata>
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="dataModelBindingSource1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>349, 17</value>
</metadata>
</root>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is automatically generated by Visual Studio. It is
used to store generic object data source configuration information.
Renaming the file extension or editing the content of this file may
cause the file to be unrecognizable by the program.
-->
<GenericObjectDataSource DisplayName="DataModel" Version="1.0" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
<TypeInfo>ImageCatalog_2.DataModel, ImageCatalog 2, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null</TypeInfo>
</GenericObjectDataSource>

View file

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace ImageCatalog_2
{
public class ViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;
// This method is called by the Set accessor of each property.
// The CallerMemberName attribute that is applied to the optional propertyName
// parameter causes the property name of the caller to be substituted as an argument.
protected void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}