Added viewmodel
This commit is contained in:
parent
a1c950734a
commit
efbc9f91db
6 changed files with 1541 additions and 1267 deletions
37
imagecatalog/DataModel.cs
Normal file
37
imagecatalog/DataModel.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
2600
imagecatalog/MainForm.Designer.cs
generated
2600
imagecatalog/MainForm.Designer.cs
generated
File diff suppressed because it is too large
Load diff
|
|
@ -11,6 +11,7 @@ using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using CatalogVbLib;
|
using CatalogVbLib;
|
||||||
|
using ImageCatalog_2;
|
||||||
using ImageCatalog_2.Services;
|
using ImageCatalog_2.Services;
|
||||||
using MaddoShared;
|
using MaddoShared;
|
||||||
using Microsoft.VisualBasic;
|
using Microsoft.VisualBasic;
|
||||||
|
|
@ -23,13 +24,23 @@ namespace ImageCatalog
|
||||||
|
|
||||||
public partial class MainForm
|
public partial class MainForm
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public DataModel Model { get; set; }
|
||||||
|
|
||||||
private readonly ITestService _service;
|
private readonly ITestService _service;
|
||||||
|
|
||||||
public MainForm(ITestService testService)
|
public MainForm(ITestService testService)
|
||||||
{
|
{
|
||||||
_service = testService;
|
_service = testService;
|
||||||
|
|
||||||
|
Model = new DataModel();
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
bindingSource1.DataSource = Model;
|
||||||
|
|
||||||
|
BindControls();
|
||||||
|
|
||||||
_Button3.Name = "Button3";
|
_Button3.Name = "Button3";
|
||||||
_Button2.Name = "Button2";
|
_Button2.Name = "Button2";
|
||||||
_Button8.Name = "Button8";
|
_Button8.Name = "Button8";
|
||||||
|
|
@ -52,6 +63,12 @@ namespace ImageCatalog
|
||||||
UiUpdateEvent += OnUiUpdateEvent;
|
UiUpdateEvent += OnUiUpdateEvent;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void BindControls()
|
||||||
|
{
|
||||||
|
//txtSorgente.DataBindings.Add(new Binding("Text", SourcePath, ""));
|
||||||
|
}
|
||||||
|
|
||||||
private event EventHandler<Tuple<string, int>> UiUpdateEvent;
|
private event EventHandler<Tuple<string, int>> UiUpdateEvent;
|
||||||
|
|
||||||
delegate void SetTextCallback(Label target, string text);
|
delegate void SetTextCallback(Label target, string text);
|
||||||
|
|
@ -107,8 +124,9 @@ namespace ImageCatalog
|
||||||
|
|
||||||
private void setDefaults()
|
private void setDefaults()
|
||||||
{
|
{
|
||||||
txtSorgente.Text = "";
|
//txtSorgente.Text = "";
|
||||||
txtDestinazione.Text = "";
|
Model.SourcePath = string.Empty;
|
||||||
|
Model.DestinationPath = string.Empty;
|
||||||
TextBox3.Text = "tn_";
|
TextBox3.Text = "tn_";
|
||||||
TextBox4.Text = "";
|
TextBox4.Text = "";
|
||||||
TextBox5.Text = "350";
|
TextBox5.Text = "350";
|
||||||
|
|
@ -191,14 +209,14 @@ namespace ImageCatalog
|
||||||
|
|
||||||
private void FixPaths()
|
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);
|
minThreads = Conversions.ToInteger(TextBox8.Text);
|
||||||
if (rdbNuovoMetodo.Checked)
|
if (rdbNuovoMetodo.Checked)
|
||||||
{
|
{
|
||||||
setPicSettings(txtSorgente.Text, txtDestinazione.Text);
|
setPicSettings(Model.SourcePath, Model.DestinationPath);
|
||||||
ProgressBar1.Minimum = 0;
|
ProgressBar1.Minimum = 0;
|
||||||
ProgressBar1.Step = 1;
|
ProgressBar1.Step = 1;
|
||||||
ProgressBar1.Value = 0;
|
ProgressBar1.Value = 0;
|
||||||
|
|
@ -256,7 +274,7 @@ namespace ImageCatalog
|
||||||
ContaImmaginiThread = 0;
|
ContaImmaginiThread = 0;
|
||||||
|
|
||||||
// creaImmaginiWithThreadMod(txtSorgente.Text, txtDestinazione.Text)
|
// creaImmaginiWithThreadMod(txtSorgente.Text, txtDestinazione.Text)
|
||||||
creaimmaginiWithThreadDict(txtSorgente.Text, txtDestinazione.Text);
|
creaimmaginiWithThreadDict(Model.SourcePath, Model.DestinationPath);
|
||||||
ThreadPoolWorkItem ThAttivo = null;
|
ThreadPoolWorkItem ThAttivo = null;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
/* TODO ERROR: Skipped DefineDirectiveTrivia */
|
/* TODO ERROR: Skipped DefineDirectiveTrivia */
|
||||||
|
|
@ -295,7 +313,7 @@ namespace ImageCatalog
|
||||||
MyPool.StopThreadPool();
|
MyPool.StopThreadPool();
|
||||||
MyPool.StartThreadPool(minThreads, maxThreads);
|
MyPool.StartThreadPool(minThreads, maxThreads);
|
||||||
ContaImmaginiThread = 0;
|
ContaImmaginiThread = 0;
|
||||||
CreaImmaginiWithThread(txtSorgente.Text, txtDestinazione.Text);
|
CreaImmaginiWithThread(Model.SourcePath, Model.DestinationPath);
|
||||||
ThreadPoolWorkItem ThAttivo = null;
|
ThreadPoolWorkItem ThAttivo = null;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (i != ContaImmaginiThread)
|
while (i != ContaImmaginiThread)
|
||||||
|
|
@ -357,10 +375,10 @@ namespace ImageCatalog
|
||||||
|
|
||||||
private void Button2_Click(object sender, EventArgs e)
|
private void Button2_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var dialogResult = SelectFolder(txtSorgente.Text);
|
var dialogResult = SelectFolder(Model.SourcePath);
|
||||||
if (!string.IsNullOrWhiteSpace(dialogResult))
|
if (!string.IsNullOrWhiteSpace(dialogResult))
|
||||||
{
|
{
|
||||||
txtSorgente.Text = dialogResult;
|
Model.SourcePath = dialogResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
//CommonOpenFileDialog dialog = new CommonOpenFileDialog();
|
//CommonOpenFileDialog dialog = new CommonOpenFileDialog();
|
||||||
|
|
@ -393,10 +411,10 @@ namespace ImageCatalog
|
||||||
|
|
||||||
private void Button3_Click(object sender, EventArgs e)
|
private void Button3_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var dialogResult = SelectFolder(txtDestinazione.Text);
|
var dialogResult = SelectFolder(Model.DestinationPath);
|
||||||
if (!string.IsNullOrWhiteSpace(dialogResult))
|
if (!string.IsNullOrWhiteSpace(dialogResult))
|
||||||
{
|
{
|
||||||
txtDestinazione.Text = dialogResult;
|
Model.DestinationPath = dialogResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
//var DirSearch = new FolderBrowserDialog();
|
//var DirSearch = new FolderBrowserDialog();
|
||||||
|
|
@ -448,8 +466,8 @@ namespace ImageCatalog
|
||||||
{
|
{
|
||||||
string IlNome = SaveFileDlg.FileName;
|
string IlNome = SaveFileDlg.FileName;
|
||||||
Module1.SetupIni.NomeFileSetup = IlNome;
|
Module1.SetupIni.NomeFileSetup = IlNome;
|
||||||
Module1.SetupIni.AggiornaParametro("DirSorgente", txtSorgente.Text);
|
Module1.SetupIni.AggiornaParametro("DirSorgente", Model.SourcePath);
|
||||||
Module1.SetupIni.AggiornaParametro("DirDestinazione", txtDestinazione.Text);
|
Module1.SetupIni.AggiornaParametro("DirDestinazione", Model.DestinationPath);
|
||||||
Module1.SetupIni.AggiornaParametro("DirSottoDirectory", chkAggiornaSottodirectory.Checked);
|
Module1.SetupIni.AggiornaParametro("DirSottoDirectory", chkAggiornaSottodirectory.Checked);
|
||||||
Module1.SetupIni.AggiornaParametro("DirDividiDestinazione", chkCreaSottocartelle.Checked);
|
Module1.SetupIni.AggiornaParametro("DirDividiDestinazione", chkCreaSottocartelle.Checked);
|
||||||
Module1.SetupIni.AggiornaParametro("DirDividiNumFile", txtFilePerCartella.Text);
|
Module1.SetupIni.AggiornaParametro("DirDividiNumFile", txtFilePerCartella.Text);
|
||||||
|
|
@ -530,8 +548,8 @@ namespace ImageCatalog
|
||||||
string IlNome = openFileDialog.FileName;
|
string IlNome = openFileDialog.FileName;
|
||||||
Module1.SetupIni.NomeFileSetup = IlNome;
|
Module1.SetupIni.NomeFileSetup = IlNome;
|
||||||
Module1.SetupIni.CaricaParametriSetup();
|
Module1.SetupIni.CaricaParametriSetup();
|
||||||
txtSorgente.Text = Module1.SetupIni.LeggiParametroString("DirSorgente");
|
Model.SourcePath = Module1.SetupIni.LeggiParametroString("DirSorgente");
|
||||||
txtDestinazione.Text = Module1.SetupIni.LeggiParametroString("DirDestinazione");
|
Model.DestinationPath = Module1.SetupIni.LeggiParametroString("DirDestinazione");
|
||||||
chkAggiornaSottodirectory.Checked = Module1.SetupIni.LeggiParametroBoolean("DirSottoDirectory");
|
chkAggiornaSottodirectory.Checked = Module1.SetupIni.LeggiParametroBoolean("DirSottoDirectory");
|
||||||
chkCreaSottocartelle.Checked = Module1.SetupIni.LeggiParametroBoolean("DirDividiDestinazione");
|
chkCreaSottocartelle.Checked = Module1.SetupIni.LeggiParametroBoolean("DirDividiDestinazione");
|
||||||
txtFilePerCartella.Text = Module1.SetupIni.LeggiParametroString("DirDividiNumFile");
|
txtFilePerCartella.Text = Module1.SetupIni.LeggiParametroString("DirDividiNumFile");
|
||||||
|
|
@ -626,8 +644,8 @@ namespace ImageCatalog
|
||||||
var SourceDir = new DirectoryInfo(SourcePath);
|
var SourceDir = new DirectoryInfo(SourcePath);
|
||||||
var DestDirStart = new DirectoryInfo(DestPath);
|
var DestDirStart = new DirectoryInfo(DestPath);
|
||||||
DirectoryInfo DestDir = null;
|
DirectoryInfo DestDir = null;
|
||||||
PicSettings.DirectorySorgente = txtSorgente.Text;
|
PicSettings.DirectorySorgente = SourcePath;
|
||||||
PicSettings.DirectoryDestinazione = txtDestinazione.Text;
|
PicSettings.DirectoryDestinazione = Model.DestinationPath;
|
||||||
|
|
||||||
// PicSettings.DestDir = DestDir
|
// PicSettings.DestDir = DestDir
|
||||||
// PicSettings.SourceDir = SourceDir
|
// PicSettings.SourceDir = SourceDir
|
||||||
|
|
@ -1213,8 +1231,8 @@ namespace ImageCatalog
|
||||||
|
|
||||||
Application.DoEvents();
|
Application.DoEvents();
|
||||||
var ClsCreaImmagine = new CreaImmagineSeparateThread();
|
var ClsCreaImmagine = new CreaImmagineSeparateThread();
|
||||||
ClsCreaImmagine.DirectorySorgente = txtSorgente.Text;
|
ClsCreaImmagine.DirectorySorgente = SourcePath;
|
||||||
ClsCreaImmagine.DirectoryDestinazione = txtDestinazione.Text;
|
ClsCreaImmagine.DirectoryDestinazione = Model.DestinationPath;
|
||||||
ClsCreaImmagine.DestDir = DestDir;
|
ClsCreaImmagine.DestDir = DestDir;
|
||||||
ClsCreaImmagine.SourceDir = SourceDir;
|
ClsCreaImmagine.SourceDir = SourceDir;
|
||||||
ClsCreaImmagine.DestDirStart = DestDirStart;
|
ClsCreaImmagine.DestDirStart = DestDirStart;
|
||||||
|
|
@ -1531,7 +1549,7 @@ namespace ImageCatalog
|
||||||
lblFotoTotaliNum.Text = "0";
|
lblFotoTotaliNum.Text = "0";
|
||||||
Label18.Text = "0";
|
Label18.Text = "0";
|
||||||
Label43.Text = "-s";
|
Label43.Text = "-s";
|
||||||
setPicSettings(txtSorgente.Text, txtDestinazione.Text);
|
setPicSettings(Model.SourcePath, Model.DestinationPath);
|
||||||
ProgressBar1.Minimum = 0;
|
ProgressBar1.Minimum = 0;
|
||||||
ProgressBar1.Step = 1;
|
ProgressBar1.Step = 1;
|
||||||
ProgressBar1.Value = 0;
|
ProgressBar1.Value = 0;
|
||||||
|
|
@ -1545,8 +1563,8 @@ namespace ImageCatalog
|
||||||
imageCreationOptions.SuffissoCartelle = txtSuffissoCartelle.Text;
|
imageCreationOptions.SuffissoCartelle = txtSuffissoCartelle.Text;
|
||||||
imageCreationOptions.CifreContatore = Conversions.ToInteger(txtCifreContatore.Text);
|
imageCreationOptions.CifreContatore = Conversions.ToInteger(txtCifreContatore.Text);
|
||||||
imageCreationOptions.NumerazioneType = GetNumerazioneEnum();
|
imageCreationOptions.NumerazioneType = GetNumerazioneEnum();
|
||||||
imageCreationOptions.SourcePath = txtSorgente.Text;
|
imageCreationOptions.SourcePath = Model.SourcePath;
|
||||||
imageCreationOptions.DestinationPath = txtDestinazione.Text;
|
imageCreationOptions.DestinationPath = Model.DestinationPath;
|
||||||
imageCreationOptions.MaxThreads = Conversions.ToInteger(TextBox7.Text);
|
imageCreationOptions.MaxThreads = Conversions.ToInteger(TextBox7.Text);
|
||||||
imageCreationOptions.ChunksSize = Conversions.ToInteger(TextBox8.Text);
|
imageCreationOptions.ChunksSize = Conversions.ToInteger(TextBox8.Text);
|
||||||
imageCreationOptions.LinearExecution = rdbVecchioMetodo.Checked;
|
imageCreationOptions.LinearExecution = rdbVecchioMetodo.Checked;
|
||||||
|
|
@ -1611,8 +1629,8 @@ namespace ImageCatalog
|
||||||
imageCreationOptions.SuffissoCartelle = txtSuffissoCartelle.Text;
|
imageCreationOptions.SuffissoCartelle = txtSuffissoCartelle.Text;
|
||||||
imageCreationOptions.CifreContatore = Conversions.ToInteger(txtCifreContatore.Text);
|
imageCreationOptions.CifreContatore = Conversions.ToInteger(txtCifreContatore.Text);
|
||||||
imageCreationOptions.NumerazioneType = GetNumerazioneEnum();
|
imageCreationOptions.NumerazioneType = GetNumerazioneEnum();
|
||||||
imageCreationOptions.SourcePath = txtSorgente.Text;
|
imageCreationOptions.SourcePath = Model.SourcePath;
|
||||||
imageCreationOptions.DestinationPath = txtDestinazione.Text;
|
imageCreationOptions.DestinationPath = Model.DestinationPath;
|
||||||
await imgStf.CreaImmaginiParallel(imageCreationOptions, _results, UiUpdateEvent);
|
await imgStf.CreaImmaginiParallel(imageCreationOptions, _results, UiUpdateEvent);
|
||||||
|
|
||||||
// Await CreaImmaginiParallel(txtSorgente.Text, txtDestinazione.Text)
|
// Await CreaImmaginiParallel(txtSorgente.Text, txtDestinazione.Text)
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,16 @@
|
||||||
<resheader name="writer">
|
<resheader name="writer">
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</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">
|
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
<value>17, 17</value>
|
<value>17, 17</value>
|
||||||
</metadata>
|
</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>
|
</root>
|
||||||
10
imagecatalog/Properties/DataSources/DataModel.datasource
Normal file
10
imagecatalog/Properties/DataSources/DataModel.datasource
Normal 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>
|
||||||
26
imagecatalog/ViewModelBase.cs
Normal file
26
imagecatalog/ViewModelBase.cs
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue