Conversione a c# + threads
This commit is contained in:
parent
abe5a40f2e
commit
d133917283
24 changed files with 2649 additions and 642 deletions
27
Catalog.sln
27
Catalog.sln
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26403.3
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.31005.135
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "ImageCatalog 2", "imagecatalog\ImageCatalog 2.vbproj", "{8D3AA2B0-8F06-4A61-9CAD-B920EB1A8E9C}"
|
||||
EndProject
|
||||
|
|
@ -15,6 +15,8 @@ Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "CatalogVbLib", "CatalogVbLi
|
|||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Libraries", "Libraries", "{A3D50937-74F6-4DC8-8D89-B534B484C0F9}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MaddoShared", "MaddoShared\MaddoShared.csproj", "{AEBFE9E3-277C-4A7B-8448-145D1B11998B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
|
@ -28,6 +30,7 @@ Global
|
|||
{8D3AA2B0-8F06-4A61-9CAD-B920EB1A8E9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8D3AA2B0-8F06-4A61-9CAD-B920EB1A8E9C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8D3AA2B0-8F06-4A61-9CAD-B920EB1A8E9C}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{8D3AA2B0-8F06-4A61-9CAD-B920EB1A8E9C}.Debug|x64.Build.0 = Debug|x64
|
||||
{8D3AA2B0-8F06-4A61-9CAD-B920EB1A8E9C}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{8D3AA2B0-8F06-4A61-9CAD-B920EB1A8E9C}.Debug|x86.Build.0 = Debug|x86
|
||||
{8D3AA2B0-8F06-4A61-9CAD-B920EB1A8E9C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
|
|
@ -39,6 +42,7 @@ Global
|
|||
{D11ED7B0-93E8-4F38-A142-EED72D7EE8B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D11ED7B0-93E8-4F38-A142-EED72D7EE8B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D11ED7B0-93E8-4F38-A142-EED72D7EE8B5}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{D11ED7B0-93E8-4F38-A142-EED72D7EE8B5}.Debug|x64.Build.0 = Debug|x64
|
||||
{D11ED7B0-93E8-4F38-A142-EED72D7EE8B5}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{D11ED7B0-93E8-4F38-A142-EED72D7EE8B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D11ED7B0-93E8-4F38-A142-EED72D7EE8B5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
|
|
@ -68,14 +72,33 @@ Global
|
|||
{44465926-240D-473F-90B8-786BA4384406}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{44465926-240D-473F-90B8-786BA4384406}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{44465926-240D-473F-90B8-786BA4384406}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{44465926-240D-473F-90B8-786BA4384406}.Debug|x64.Build.0 = Debug|x64
|
||||
{44465926-240D-473F-90B8-786BA4384406}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{44465926-240D-473F-90B8-786BA4384406}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{44465926-240D-473F-90B8-786BA4384406}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{44465926-240D-473F-90B8-786BA4384406}.Release|x64.ActiveCfg = Release|x64
|
||||
{44465926-240D-473F-90B8-786BA4384406}.Release|x64.Build.0 = Release|x64
|
||||
{44465926-240D-473F-90B8-786BA4384406}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{AEBFE9E3-277C-4A7B-8448-145D1B11998B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{AEBFE9E3-277C-4A7B-8448-145D1B11998B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AEBFE9E3-277C-4A7B-8448-145D1B11998B}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{AEBFE9E3-277C-4A7B-8448-145D1B11998B}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{AEBFE9E3-277C-4A7B-8448-145D1B11998B}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{AEBFE9E3-277C-4A7B-8448-145D1B11998B}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{AEBFE9E3-277C-4A7B-8448-145D1B11998B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AEBFE9E3-277C-4A7B-8448-145D1B11998B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{AEBFE9E3-277C-4A7B-8448-145D1B11998B}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{AEBFE9E3-277C-4A7B-8448-145D1B11998B}.Release|x64.Build.0 = Release|Any CPU
|
||||
{AEBFE9E3-277C-4A7B-8448-145D1B11998B}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{AEBFE9E3-277C-4A7B-8448-145D1B11998B}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{AEBFE9E3-277C-4A7B-8448-145D1B11998B} = {A3D50937-74F6-4DC8-8D89-B534B484C0F9}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {0E3ABC63-8601-4DAC-AFEA-33F3E8E36757}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
|||
|
|
@ -68,9 +68,24 @@
|
|||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Ben.Demystifier, Version=0.3.0.0, Culture=neutral, PublicKeyToken=a6d206e05440431a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Ben.Demystifier.0.3.0\lib\net45\Ben.Demystifier.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Collections.Immutable, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Collections.Immutable.5.0.0\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Reflection.Metadata, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Reflection.Metadata.5.0.0\lib\portable-net45+win8\System.Reflection.Metadata.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\netstandard1.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Windows" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
|
|
@ -92,6 +107,7 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="Class1.vb" />
|
||||
<Compile Include="ExifReader.vb" />
|
||||
<Compile Include="ImageCreator.vb" />
|
||||
<Compile Include="My Project\AssemblyInfo.vb" />
|
||||
<Compile Include="My Project\Application.Designer.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
|
|
@ -127,6 +143,7 @@
|
|||
<CustomToolNamespace>My</CustomToolNamespace>
|
||||
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
|
||||
</None>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
Imports System.IO
|
||||
Imports System.Drawing
|
||||
Imports System.IO
|
||||
Imports System.Drawing.Drawing2D
|
||||
Imports System.Drawing.Imaging
|
||||
Imports System.Windows.Forms
|
||||
'Imports System.Threading
|
||||
|
||||
Public Class ImageCreator
|
||||
#Region "dichiarazioni"
|
||||
|
||||
|
||||
|
||||
Private FotoRuotaADestra As Boolean = False
|
||||
Private FotoRuotaASinistra As Boolean = False
|
||||
|
|
@ -61,56 +63,63 @@ Public Class ImageCreator
|
|||
|
||||
Public Sub New(ByVal file As FileInfo, ByVal destination As DirectoryInfo)
|
||||
Me.WorkFile = file
|
||||
me.DestDir = destination
|
||||
Me.DestDir = destination
|
||||
|
||||
End Sub
|
||||
|
||||
Public Sub CreaImmagineThread(ByVal Info As String)
|
||||
#If Not Debug Then
|
||||
|
||||
Try
|
||||
#End If
|
||||
|
||||
preparaVariabili()
|
||||
'Dim g As System.Drawing.Image = System.Drawing.Image.FromFile(Path.Combine(SourceDir.FullName, NomeFileChild))
|
||||
Dim g As System.Drawing.Image = System.Drawing.Image.FromFile(WorkFile.FullName)
|
||||
Using g As Image = Image.FromFile(WorkFile.FullName)
|
||||
|
||||
' Imposta testo extra
|
||||
impostaTestoExtra(g)
|
||||
|
||||
' Ruota l'immagine in base ai dati EXIF
|
||||
Rotation(g)
|
||||
|
||||
' Forza jpeg se è selezionata l'opzione
|
||||
Dim thisFormat As System.Drawing.Imaging.ImageFormat = g.RawFormat
|
||||
If PicSettings.UsaForzaJpg = True Then thisFormat = System.Drawing.Imaging.ImageFormat.Jpeg
|
||||
|
||||
prepareThumbnailSize(g)
|
||||
'Dim g As System.Drawing.Image = System.Drawing.Image.FromFile(WorkFile.FullName)
|
||||
|
||||
Dim imgOutputBig As New Bitmap(g, thumbSizeBig.Width, thumbSizeBig.Height)
|
||||
imgOutputBig.SetResolution(g.HorizontalResolution, g.VerticalResolution)
|
||||
' Imposta testo extra
|
||||
impostaTestoExtra(g)
|
||||
|
||||
' Crea le miniature
|
||||
creaMiniature(g, imgOutputBig, thisFormat)
|
||||
' Ruota l'immagine in base ai dati EXIF
|
||||
Rotation(g)
|
||||
|
||||
aggiungiTesto(g, imgOutputBig)
|
||||
' Forza jpeg se è selezionata l'opzione
|
||||
Dim thisFormat As System.Drawing.Imaging.ImageFormat = g.RawFormat
|
||||
If PicSettings.UsaForzaJpg = True Then thisFormat = System.Drawing.Imaging.ImageFormat.Jpeg
|
||||
|
||||
aggiungiLogo(imgOutputBig)
|
||||
prepareThumbnailSize(g)
|
||||
|
||||
salvaFoto(imgOutputBig, thumbSizeBig, nomeFileBig, nomeFileSmall, thumbSizeSmall, thisFormat)
|
||||
Dim imgOutputBig As New Bitmap(g, thumbSizeBig.Width, thumbSizeBig.Height)
|
||||
imgOutputBig.SetResolution(g.HorizontalResolution, g.VerticalResolution)
|
||||
|
||||
g.Dispose()
|
||||
' Crea le miniature
|
||||
creaMiniature(g, imgOutputBig, thisFormat)
|
||||
|
||||
aggiungiTesto(g, imgOutputBig)
|
||||
|
||||
aggiungiLogo(imgOutputBig)
|
||||
|
||||
salvaFoto(imgOutputBig, thumbSizeBig, nomeFileBig, nomeFileSmall, thumbSizeSmall, thisFormat)
|
||||
End Using
|
||||
'g.Dispose()
|
||||
|
||||
GC.Collect()
|
||||
|
||||
PicSettings.mainForm.stepProgressBar()
|
||||
#If Not Debug Then
|
||||
Catch ex As Exception
|
||||
'PicSettings.mainForm.stepProgressBar()
|
||||
|
||||
|
||||
MessageBox.Show(ex.Message)
|
||||
Catch ex As Exception
|
||||
Dim e = ex.Demystify()
|
||||
Console.WriteLine(e)
|
||||
Console.WriteLine(e.Message)
|
||||
Console.WriteLine(e.StackTrace)
|
||||
'MessageBox.Show(ex.Message)
|
||||
|
||||
|
||||
End Try
|
||||
#End If
|
||||
|
||||
|
||||
|
||||
End Sub
|
||||
8
CatalogVbLib/packages.config
Normal file
8
CatalogVbLib/packages.config
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Ben.Demystifier" version="0.3.0" targetFramework="net45" />
|
||||
<package id="System.Collections.Immutable" version="5.0.0" targetFramework="net45" />
|
||||
<package id="System.Reflection.Metadata" version="5.0.0" targetFramework="net45" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.3" targetFramework="net45" />
|
||||
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net45" />
|
||||
</packages>
|
||||
27
MaddoShared/FileData.cs
Normal file
27
MaddoShared/FileData.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MaddoShared
|
||||
{
|
||||
public class FileData
|
||||
{
|
||||
/// <summary>
|
||||
/// Il file originale
|
||||
/// </summary>
|
||||
public FileInfo File { get; set; }
|
||||
/// <summary>
|
||||
/// La cartella di destinazione
|
||||
/// </summary>
|
||||
public DirectoryInfo Directory { get; set; }
|
||||
|
||||
public FileData(FileInfo newFile, DirectoryInfo newDirectory)
|
||||
{
|
||||
this.File = newFile;
|
||||
this.Directory = newDirectory;
|
||||
}
|
||||
}
|
||||
}
|
||||
116
MaddoShared/FileHelperSharp.cs
Normal file
116
MaddoShared/FileHelperSharp.cs
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MaddoShared
|
||||
{
|
||||
public class FileHelperOptions
|
||||
{
|
||||
public bool SeparateFiles { get; set; }
|
||||
public NumerazioneType NumerationType { get; set; }
|
||||
public int CounterSize { get; set; }
|
||||
public string Suffix { get; set; }
|
||||
public int FilesPerFolder { get; set; }
|
||||
}
|
||||
public enum NumerazioneType
|
||||
{
|
||||
Progressiva,
|
||||
Files
|
||||
}
|
||||
public class FileHelperSharp
|
||||
{
|
||||
|
||||
public List<FileData> GetFilesRecursive(DirectoryInfo root, DirectoryInfo destRoot, string filter, FileHelperOptions options)
|
||||
{
|
||||
ConcurrentDictionary<FileInfo, DirectoryInfo> dirSourceDest = new ConcurrentDictionary<FileInfo, DirectoryInfo>();
|
||||
List<FileInfo> result = new List<FileInfo>();
|
||||
|
||||
// Dim stack As New Stack(Of DirectoryInfo)
|
||||
Stack<KeyValuePair<DirectoryInfo, DirectoryInfo>> stack = new Stack<KeyValuePair<DirectoryInfo, DirectoryInfo>>();
|
||||
|
||||
|
||||
|
||||
KeyValuePair<DirectoryInfo, DirectoryInfo> pair = new KeyValuePair<DirectoryInfo, DirectoryInfo>();
|
||||
|
||||
|
||||
// stack.Push(root)
|
||||
stack.Push(new KeyValuePair<DirectoryInfo, DirectoryInfo>(root, destRoot));
|
||||
|
||||
while ((stack.Count > 0))
|
||||
{
|
||||
KeyValuePair<DirectoryInfo, DirectoryInfo> curDirKV = stack.Pop();
|
||||
// curDirKP = stack.Pop()
|
||||
DirectoryInfo dir = curDirKV.Key;
|
||||
DirectoryInfo dDir = curDirKV.Value;
|
||||
try
|
||||
{
|
||||
// result.AddRange(dir.GetFiles(filter, SearchOption.TopDirectoryOnly))
|
||||
// dividere file qui
|
||||
if (options.FilesPerFolder > 0 & options.SeparateFiles)
|
||||
AppendDictionaryConcurrent(dirSourceDest, DividiFilesInDirConcurrent(dir, dDir, options, filter));
|
||||
else
|
||||
AppendDictionaryConcurrent(dirSourceDest, DividiFilesInDirConcurrent(dir, dDir, options, filter));
|
||||
|
||||
foreach (DirectoryInfo subDirectory in dir.GetDirectories())
|
||||
stack.Push(new KeyValuePair<DirectoryInfo, DirectoryInfo>(subDirectory, new DirectoryInfo(Path.Combine(dDir.FullName, subDirectory.Name))));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// TODO ERROR
|
||||
}
|
||||
}
|
||||
|
||||
List<FileData> resultData = new List<FileData>();
|
||||
resultData.AddRange(from p in dirSourceDest
|
||||
select new FileData(p.Key, p.Value));
|
||||
return resultData;
|
||||
}
|
||||
|
||||
public ConcurrentDictionary<FileInfo, DirectoryInfo> AppendDictionaryConcurrent(ConcurrentDictionary<FileInfo, DirectoryInfo> dictA, ConcurrentDictionary<FileInfo, DirectoryInfo> dictB)
|
||||
{
|
||||
foreach (KeyValuePair<FileInfo, DirectoryInfo> pair in dictB)
|
||||
dictA.TryAdd(pair.Key, pair.Value);
|
||||
return dictA;
|
||||
}
|
||||
|
||||
|
||||
private ConcurrentDictionary<FileInfo, DirectoryInfo> DividiFilesInDirConcurrent(DirectoryInfo dir, DirectoryInfo dirDest, FileHelperOptions options, string filter)
|
||||
{
|
||||
//int filesCount = dir.GetFiles(Filter).Length;
|
||||
int contaFilePerDir = 0;
|
||||
int contaDirPerDir = 0;
|
||||
string tempText;// = string.Empty;
|
||||
ConcurrentDictionary<FileInfo, DirectoryInfo> foldersDict = new ConcurrentDictionary<FileInfo, DirectoryInfo>();
|
||||
|
||||
DirectoryInfo destDir;
|
||||
destDir = new DirectoryInfo(Path.Combine(dirDest.FullName));
|
||||
foreach (FileInfo file in dir.GetFiles(filter))
|
||||
{
|
||||
contaFilePerDir += 1;
|
||||
|
||||
if (contaFilePerDir == (contaDirPerDir * options.FilesPerFolder) + 1)
|
||||
{
|
||||
contaDirPerDir += 1;
|
||||
|
||||
tempText = options.NumerationType == NumerazioneType.Progressiva ? contaDirPerDir.ToString() : (contaDirPerDir * options.FilesPerFolder).ToString();
|
||||
int i;
|
||||
for (i = 1; i <= (options.CounterSize - tempText.Length); i++)
|
||||
tempText = "0" + tempText;
|
||||
destDir = new DirectoryInfo(Path.Combine(dirDest.FullName, options.Suffix + tempText));
|
||||
}
|
||||
|
||||
if (!destDir.Exists)
|
||||
destDir.Create();
|
||||
|
||||
foldersDict.TryAdd(file, destDir);
|
||||
}
|
||||
|
||||
return foldersDict;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
200
MaddoShared/ImageCreationStuff.cs
Normal file
200
MaddoShared/ImageCreationStuff.cs
Normal file
|
|
@ -0,0 +1,200 @@
|
|||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using CatalogVbLib;
|
||||
using Dasync.Collections;
|
||||
|
||||
namespace MaddoShared
|
||||
{
|
||||
public class ImageCreationStuff
|
||||
{
|
||||
public class Options
|
||||
{
|
||||
public bool AggiornaSottodirectory { get; set; }
|
||||
public bool CreaSottocartelle { get; set; }
|
||||
|
||||
public int FilePerCartella { get; set; }
|
||||
public string SuffissoCartelle { get; set; }
|
||||
public int CifreContatore { get; set; }
|
||||
public NumerazioneType NumerazioneType { get; set; }
|
||||
public string SourcePath { get; set; }
|
||||
public string DestinationPath { get; set; }
|
||||
|
||||
public int MaxThreads { get; set; }
|
||||
public int ChunksSize { get; set; }
|
||||
public bool LinearExecution { get; set; }
|
||||
}
|
||||
|
||||
public async Task<string> CreaCatalogoParallel(Options options)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
// todo immagini counter
|
||||
//todo set label
|
||||
await CreaImmaginiParallel(options);
|
||||
|
||||
// todo set finito label
|
||||
stopwatch.Stop();
|
||||
|
||||
return $"{stopwatch.Elapsed.Hours}h {stopwatch.Elapsed.Minutes}m ${stopwatch.Elapsed.Seconds}s ({stopwatch.Elapsed.TotalSeconds}s)";
|
||||
|
||||
|
||||
}
|
||||
|
||||
public async Task CreaImmaginiParallel(Options options)
|
||||
{
|
||||
var dataToProcess = new List<FileData>();
|
||||
if (options.AggiornaSottodirectory && options.CreaSottocartelle)
|
||||
{
|
||||
var helper = new FileHelperSharp();
|
||||
dataToProcess = helper.GetFilesRecursive(new DirectoryInfo(options.SourcePath), new DirectoryInfo(options.DestinationPath),
|
||||
"*.jpg", new FileHelperOptions()
|
||||
{
|
||||
FilesPerFolder = options.FilePerCartella,
|
||||
Suffix = options.SuffissoCartelle,
|
||||
CounterSize = options.CifreContatore,
|
||||
NumerationType = options.NumerazioneType
|
||||
});
|
||||
}
|
||||
else if (!options.CreaSottocartelle)
|
||||
{
|
||||
var files = Directory.EnumerateFiles(options.SourcePath, "*.jpg",
|
||||
options.AggiornaSottodirectory
|
||||
? SearchOption.AllDirectories
|
||||
: SearchOption.TopDirectoryOnly);
|
||||
|
||||
dataToProcess = files.Select(x =>
|
||||
{
|
||||
var fInfo = new FileInfo(x);
|
||||
var filePath = fInfo.DirectoryName;
|
||||
var trimmedSourcePath = options.SourcePath.TrimEnd('\\');
|
||||
var newFilePath = fInfo.FullName.Replace(trimmedSourcePath, "").TrimStart('\\');
|
||||
newFilePath = Path.Combine(options.DestinationPath, newFilePath);
|
||||
|
||||
var destFolderPath = new FileInfo(newFilePath).DirectoryName;
|
||||
var destFolderInfo = new DirectoryInfo(destFolderPath);
|
||||
destFolderInfo.EnsureDirectoryExists();
|
||||
|
||||
return new FileData(fInfo, new DirectoryInfo(new FileInfo(newFilePath).DirectoryName));
|
||||
}).ToList();
|
||||
|
||||
//// TODO
|
||||
//dataToProcess =
|
||||
// (from f in Directory.EnumerateFiles(options.SourcePath, "*.jpg",
|
||||
// options.AggiornaSottodirectory
|
||||
// ? SearchOption.AllDirectories
|
||||
// : SearchOption.TopDirectoryOnly)
|
||||
// select new FileData(new FileInfo(f),
|
||||
// new DirectoryInfo(options.DestinationPath.PathCombine(
|
||||
// new FileInfo(f).DirectoryName.Replace(options.SourcePath.TrimEnd(new char[] {'\\'}), "")
|
||||
// )
|
||||
// )
|
||||
// )
|
||||
// )
|
||||
// .ToList();
|
||||
}
|
||||
|
||||
var threads = options.MaxThreads == 0 ? Environment.ProcessorCount * 2 : options.MaxThreads;
|
||||
var scheduler = new ConcurrentExclusiveSchedulerPair(TaskScheduler.Default, threads)
|
||||
.ConcurrentScheduler;
|
||||
|
||||
//var allTasks = new List<Task>();
|
||||
var test = from d in dataToProcess
|
||||
select Task.Factory.StartNew(async () =>
|
||||
{
|
||||
await new ImageCreatorSharp(d.File, d.Directory).CreaImmagineThread(d.File.Name);
|
||||
|
||||
//var imgC = new ImageCreatorSharp(d.File, d.Directory);
|
||||
//imgC.CreaImmagineThread(d.File.Name);
|
||||
//imgC = null;
|
||||
}, CancellationToken.None, TaskCreationOptions.None, scheduler);
|
||||
if (options.LinearExecution)
|
||||
{
|
||||
foreach (var task in test)
|
||||
{
|
||||
await task;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (options.ChunksSize == 0)
|
||||
{
|
||||
|
||||
|
||||
var opts = new ParallelOptions() { MaxDegreeOfParallelism = threads };
|
||||
await dataToProcess.ParallelForEachAsync(async fileData =>
|
||||
{
|
||||
await new ImageCreatorSharp(fileData.File, fileData.Directory).CreaImmagineThread(fileData.File.Name);
|
||||
}, maxDegreeOfParallelism: threads);
|
||||
|
||||
|
||||
//var throttler = new SemaphoreSlim(initialCount: threads);
|
||||
//foreach (var fileData in dataToProcess)
|
||||
//{
|
||||
// await throttler.WaitAsync();
|
||||
// allTasks.Add(Task.Factory.StartNew(() => {
|
||||
// try
|
||||
// {
|
||||
// new ImageCreatorSharp(fileData.File, fileData.Directory).CreaImmagineThread(
|
||||
// fileData.File.Name);
|
||||
// }
|
||||
// finally
|
||||
// {
|
||||
// throttler.Release();
|
||||
// }
|
||||
// }, CancellationToken.None, TaskCreationOptions.None, scheduler));
|
||||
//}
|
||||
|
||||
//await Task.WhenAll(test);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
var asdf = SplitList(dataToProcess.ToList(), dataToProcess.Count() / options.ChunksSize).ToList();
|
||||
//var sadf = asdf[0];
|
||||
|
||||
//var sadf1 = asdf[1];
|
||||
|
||||
foreach (var sdaf in asdf)
|
||||
{
|
||||
await sdaf.ParallelForEachAsync(async fileData =>
|
||||
{
|
||||
await new ImageCreatorSharp(fileData.File, fileData.Directory).CreaImmagineThread(fileData.File.Name);
|
||||
}, maxDegreeOfParallelism: threads);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//foreach (var chunk in asdf)
|
||||
//{
|
||||
// await Task.WhenAll(chunk);
|
||||
// GC.Collect();
|
||||
// //GC.WaitForPendingFinalizers();
|
||||
// //GC.Collect();
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//foreach (var task in test)
|
||||
//{
|
||||
// await task;
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
public static IEnumerable<List<T>> SplitList<T>(List<T> bigList, int nSize = 3)
|
||||
{
|
||||
for (int i = 0; i < bigList.Count; i += nSize)
|
||||
{
|
||||
yield return bigList.GetRange(i, Math.Min(nSize, bigList.Count - i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1021
MaddoShared/ImageCreatorSharp.cs
Normal file
1021
MaddoShared/ImageCreatorSharp.cs
Normal file
File diff suppressed because it is too large
Load diff
101
MaddoShared/MaddoShared.csproj
Normal file
101
MaddoShared/MaddoShared.csproj
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{AEBFE9E3-277C-4A7B-8448-145D1B11998B}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>MaddoShared</RootNamespace>
|
||||
<AssemblyName>MaddoShared</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="AsyncEnumerable, Version=4.0.2.0, Culture=neutral, PublicKeyToken=0426b068161bd1d1, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\AsyncEnumerator.4.0.2\lib\net461\AsyncEnumerable.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Ben.Demystifier, Version=0.3.0.0, Culture=neutral, PublicKeyToken=a6d206e05440431a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Ben.Demystifier.0.3.0\lib\net45\Ben.Demystifier.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.5.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SixLabors.ImageSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d998eea7b14cab13, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SixLabors.ImageSharp.1.0.3\lib\net472\SixLabors.ImageSharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Collections.Immutable, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Collections.Immutable.5.0.0\lib\net461\System.Collections.Immutable.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Reflection.Metadata, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Reflection.Metadata.5.0.0\lib\net461\System.Reflection.Metadata.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Z.ExtensionMethods, Version=2.1.1.0, Culture=neutral, PublicKeyToken=59b66d028979105b, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Z.ExtensionMethods.2.1.1\lib\net45\Z.ExtensionMethods.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ImageCreationStuff.cs" />
|
||||
<Compile Include="ImageCreatorSharp.cs" />
|
||||
<Compile Include="ThreadingHelper.cs" />
|
||||
<Compile Include="FileData.cs" />
|
||||
<Compile Include="FileHelperSharp.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CatalogVbLib\CatalogVbLib.vbproj">
|
||||
<Project>{44465926-240d-473f-90b8-786ba4384406}</Project>
|
||||
<Name>CatalogVbLib</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
36
MaddoShared/Properties/AssemblyInfo.cs
Normal file
36
MaddoShared/Properties/AssemblyInfo.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("MaddoShared")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("MaddoShared")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2021")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("aebfe9e3-277c-4a7b-8448-145d1b11998b")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
60
MaddoShared/ThreadingHelper.cs
Normal file
60
MaddoShared/ThreadingHelper.cs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MaddoShared
|
||||
{
|
||||
public static class ThreadingHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Starts the given tasks and waits for them to complete. This will run, at most, the specified number of tasks in parallel.
|
||||
/// <para>NOTE: If one of the given tasks has already been started, an exception will be thrown.</para>
|
||||
/// </summary>
|
||||
/// <param name="tasksToRun">The tasks to run.</param>
|
||||
/// <param name="maxTasksToRunInParallel">The maximum number of tasks to run in parallel.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
public static void StartAndWaitAllThrottled(IEnumerable<Task> tasksToRun, int maxTasksToRunInParallel, CancellationToken cancellationToken = new CancellationToken())
|
||||
{
|
||||
StartAndWaitAllThrottled(tasksToRun, maxTasksToRunInParallel, -1, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts the given tasks and waits for them to complete. This will run, at most, the specified number of tasks in parallel.
|
||||
/// <para>NOTE: If one of the given tasks has already been started, an exception will be thrown.</para>
|
||||
/// </summary>
|
||||
/// <param name="tasksToRun">The tasks to run.</param>
|
||||
/// <param name="maxTasksToRunInParallel">The maximum number of tasks to run in parallel.</param>
|
||||
/// <param name="timeoutInMilliseconds">The maximum milliseconds we should allow the max tasks to run in parallel before allowing another task to start. Specify -1 to wait indefinitely.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
public static void StartAndWaitAllThrottled(IEnumerable<Task> tasksToRun, int maxTasksToRunInParallel, int timeoutInMilliseconds, CancellationToken cancellationToken = new CancellationToken())
|
||||
{
|
||||
// Convert to a list of tasks so that we don't enumerate over it multiple times needlessly.
|
||||
var tasks = tasksToRun.ToList();
|
||||
|
||||
using (var throttler = new SemaphoreSlim(maxTasksToRunInParallel))
|
||||
{
|
||||
var postTaskTasks = new List<Task>();
|
||||
|
||||
// Have each task notify the throttler when it completes so that it decrements the number of tasks currently running.
|
||||
tasks.ForEach(t => postTaskTasks.Add(t.ContinueWith(tsk => throttler.Release())));
|
||||
|
||||
// Start running each task.
|
||||
foreach (var task in tasks)
|
||||
{
|
||||
// Increment the number of tasks currently running and wait if too many are running.
|
||||
throttler.Wait(timeoutInMilliseconds, cancellationToken);
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
task.Start();
|
||||
}
|
||||
|
||||
// Wait for all of the provided tasks to complete.
|
||||
// We wait on the list of "post" tasks instead of the original tasks, otherwise there is a potential race condition where the throttler's using block is exited before some Tasks have had their "post" action completed, which references the throttler, resulting in an exception due to accessing a disposed object.
|
||||
Task.WaitAll(postTaskTasks.ToArray(), cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
19
MaddoShared/app.config
Normal file
19
MaddoShared/app.config
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
15
MaddoShared/packages.config
Normal file
15
MaddoShared/packages.config
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="AsyncEnumerator" version="4.0.2" targetFramework="net472" />
|
||||
<package id="Ben.Demystifier" version="0.3.0" targetFramework="net472" />
|
||||
<package id="Microsoft.Bcl.AsyncInterfaces" version="5.0.0" targetFramework="net472" />
|
||||
<package id="SixLabors.ImageSharp" version="1.0.3" targetFramework="net472" />
|
||||
<package id="System.Buffers" version="4.5.1" targetFramework="net472" />
|
||||
<package id="System.Collections.Immutable" version="5.0.0" targetFramework="net472" />
|
||||
<package id="System.Memory" version="4.5.4" targetFramework="net472" />
|
||||
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net472" />
|
||||
<package id="System.Reflection.Metadata" version="5.0.0" targetFramework="net472" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="5.0.0" targetFramework="net472" />
|
||||
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net472" />
|
||||
<package id="Z.ExtensionMethods" version="2.1.1" targetFramework="net472" />
|
||||
</packages>
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
Imports System.IO
|
||||
Imports System.Collections.Concurrent
|
||||
Imports System.IO
|
||||
Imports System.Collections.Generic
|
||||
Imports MaddoShared
|
||||
|
||||
Public Class FileHelper
|
||||
'Private dirSourceDest As Dictionary(Of FileInfo, DirectoryInfo)
|
||||
|
|
@ -28,7 +30,7 @@ Public Class FileHelper
|
|||
Me.filesPerFolder = filesPerFolder
|
||||
Me.suffix = suffix
|
||||
Me.counterSize = counterSize
|
||||
me.numerationType = numerationType
|
||||
Me.numerationType = numerationType
|
||||
Me.separateFiles = True
|
||||
End Sub
|
||||
|
||||
|
|
@ -37,7 +39,7 @@ Public Class FileHelper
|
|||
''' </summary>
|
||||
''' <remarks></remarks>
|
||||
Public Sub New()
|
||||
me.separateFiles = False
|
||||
Me.separateFiles = False
|
||||
End Sub
|
||||
|
||||
|
||||
|
|
@ -77,13 +79,71 @@ Public Class FileHelper
|
|||
|
||||
Next
|
||||
Catch ex As Exception
|
||||
|
||||
Dim e As Exception = ex.Demystify()
|
||||
Console.WriteLine(e)
|
||||
Console.WriteLine(e.Message)
|
||||
Console.WriteLine(e.StackTrace)
|
||||
End Try
|
||||
Loop
|
||||
|
||||
Return dirSourceDest
|
||||
End Function
|
||||
|
||||
'Public Class FileData
|
||||
' Public File As FileInfo
|
||||
' Public Directory As DirectoryInfo
|
||||
' Public Sub New(newFile As FileInfo, newDirectory As DirectoryInfo)
|
||||
' File = newFile
|
||||
' Directory = newDirectory
|
||||
' End Sub
|
||||
'End Class
|
||||
|
||||
'Public Function GetFilesRecursiveParallel(ByVal root As DirectoryInfo, ByVal destRoot As DirectoryInfo, ByVal filter As String) As List(Of FileData)
|
||||
|
||||
|
||||
' Dim dirSourceDest As New ConcurrentDictionary(Of FileInfo, DirectoryInfo)
|
||||
' Dim result As New List(Of FileInfo)
|
||||
|
||||
' 'Dim stack As New Stack(Of DirectoryInfo)
|
||||
' Dim stack As New Stack(Of KeyValuePair(Of DirectoryInfo, DirectoryInfo))
|
||||
|
||||
|
||||
' Me.filter = filter
|
||||
' Dim pair As New KeyValuePair(Of DirectoryInfo, DirectoryInfo)
|
||||
|
||||
|
||||
' 'stack.Push(root)
|
||||
' stack.Push(New KeyValuePair(Of DirectoryInfo, DirectoryInfo)(root, destRoot))
|
||||
|
||||
' Do While (stack.Count > 0)
|
||||
' Dim curDirKV As KeyValuePair(Of DirectoryInfo, DirectoryInfo) = stack.Pop
|
||||
' 'curDirKP = stack.Pop()
|
||||
' Dim dir As DirectoryInfo = curDirKV.Key
|
||||
' Dim dDir As DirectoryInfo = curDirKV.Value
|
||||
' Try
|
||||
' 'result.AddRange(dir.GetFiles(filter, SearchOption.TopDirectoryOnly))
|
||||
' ' dividere file qui
|
||||
' If filesPerFolder > 0 And separateFiles Then
|
||||
' AppendDictionaryConcurrent(dirSourceDest, DividiFilesInDirConcurrent(dir, dDir))
|
||||
' Else
|
||||
' AppendDictionaryConcurrent(dirSourceDest, DividiFilesInDirConcurrent(dir, dDir))
|
||||
' End If
|
||||
|
||||
' For Each subDirectory As DirectoryInfo In dir.GetDirectories
|
||||
' stack.Push(New KeyValuePair(Of DirectoryInfo, DirectoryInfo)(subDirectory, New DirectoryInfo(Path.Combine(dDir.FullName, subDirectory.Name))))
|
||||
|
||||
' Next
|
||||
' Catch ex As Exception
|
||||
' ' TODO: FARE QUALCOSA
|
||||
' End Try
|
||||
' Loop
|
||||
|
||||
' Dim resultData As New List(Of FileData)
|
||||
' resultData.AddRange(From p In dirSourceDest Select New FileData(p.Key, p.Value))
|
||||
' Return resultData
|
||||
' 'Return dirSourceDest
|
||||
'End Function
|
||||
|
||||
Public Function appendDictionary(ByVal dictA As Dictionary(Of FileInfo, DirectoryInfo), ByVal dictB As Dictionary(Of FileInfo, DirectoryInfo)) As Dictionary(Of FileInfo, DirectoryInfo)
|
||||
For Each pair As KeyValuePair(Of FileInfo, DirectoryInfo) In dictB
|
||||
dictA.Add(pair.Key, pair.Value)
|
||||
|
|
@ -91,6 +151,14 @@ Public Class FileHelper
|
|||
Return dictA
|
||||
End Function
|
||||
|
||||
'Public Function AppendDictionaryConcurrent(ByVal dictA As ConcurrentDictionary(Of FileInfo, DirectoryInfo), ByVal dictB As ConcurrentDictionary(Of FileInfo, DirectoryInfo)) As ConcurrentDictionary(Of FileInfo, DirectoryInfo)
|
||||
' For Each pair As KeyValuePair(Of FileInfo, DirectoryInfo) In dictB
|
||||
' dictA.TryAdd(pair.Key, pair.Value)
|
||||
' 'dictA.Add(pair.Key, pair.Value)
|
||||
' Next
|
||||
' Return dictA
|
||||
'End Function
|
||||
|
||||
Public Function getAllFilesInDir(dir As DirectoryInfo, dirDest As DirectoryInfo) As Dictionary(Of FileInfo, DirectoryInfo)
|
||||
Dim dict As New Dictionary(Of FileInfo, DirectoryInfo)
|
||||
For Each File As FileInfo In dir.GetFiles(filter)
|
||||
|
|
@ -140,4 +208,45 @@ Public Class FileHelper
|
|||
|
||||
Return foldersDict
|
||||
End Function
|
||||
|
||||
Private Function DividiFilesInDirConcurrent(dir As DirectoryInfo, dirDest As DirectoryInfo) As ConcurrentDictionary(Of FileInfo, DirectoryInfo)
|
||||
Dim filesCount As Integer = dir.GetFiles(filter).Count
|
||||
Dim contaFilePerDir As Integer = 0
|
||||
Dim contaDirPerDir As Integer = 0
|
||||
Dim tempText As String = String.Empty
|
||||
Dim foldersDict As New ConcurrentDictionary(Of FileInfo, DirectoryInfo)
|
||||
|
||||
Dim destDir As DirectoryInfo
|
||||
destDir = New DirectoryInfo(Path.Combine(dirDest.FullName))
|
||||
For Each file As FileInfo In dir.GetFiles(filter)
|
||||
|
||||
contaFilePerDir += 1
|
||||
|
||||
If contaFilePerDir = (contaDirPerDir * filesPerFolder) + 1 Then
|
||||
contaDirPerDir += 1
|
||||
|
||||
If numerationType = numerazione.Progressiva Then
|
||||
tempText = contaDirPerDir.ToString
|
||||
Else
|
||||
tempText = (contaDirPerDir * filesPerFolder).ToString
|
||||
End If
|
||||
Dim i As Integer
|
||||
For i = 1 To (counterSize - tempText.Length)
|
||||
tempText = "0" & tempText
|
||||
Next
|
||||
destDir = New DirectoryInfo(Path.Combine(dirDest.FullName, suffix + tempText))
|
||||
|
||||
|
||||
|
||||
End If
|
||||
|
||||
If Not destDir.Exists Then
|
||||
destDir.Create()
|
||||
End If
|
||||
|
||||
foldersDict.TryAdd(file, destDir)
|
||||
Next
|
||||
|
||||
Return foldersDict
|
||||
End Function
|
||||
End Class
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ Imports System.Drawing.Drawing2D
|
|||
Imports System.Drawing.Imaging
|
||||
Imports System.Threading
|
||||
Imports System.Collections.Generic
|
||||
Imports CatalogVbLib
|
||||
|
||||
Public Delegate Sub XyThreadAddold(ByVal Info As String)
|
||||
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@
|
|||
<SccLocalPath>SAK</SccLocalPath>
|
||||
<SccAuxPath>SAK</SccAuxPath>
|
||||
<SccProvider>SAK</SccProvider>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
<PublishUrl>http://localhost/ImageCatalog/</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Web</InstallFrom>
|
||||
|
|
@ -54,8 +56,6 @@
|
|||
<ApplicationVersion>1.8.0.%2a</ApplicationVersion>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<OutputPath>bin\</OutputPath>
|
||||
|
|
@ -169,10 +169,19 @@
|
|||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Ben.Demystifier, Version=0.3.0.0, Culture=neutral, PublicKeyToken=a6d206e05440431a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Ben.Demystifier.0.3.0\lib\net45\Ben.Demystifier.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualBasic.PowerPacks.Vs, Version=10.0.0.0" />
|
||||
<Reference Include="System">
|
||||
<Name>System</Name>
|
||||
</Reference>
|
||||
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Collections.Immutable, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Collections.Immutable.5.0.0\lib\net461\System.Collections.Immutable.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
<Private>True</Private>
|
||||
|
|
@ -185,6 +194,22 @@
|
|||
<Name>System.Drawing</Name>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Reflection.Metadata, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Reflection.Metadata.5.0.0\lib\net461\System.Reflection.Metadata.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Windows.Forms">
|
||||
<Name>System.Windows.Forms</Name>
|
||||
</Reference>
|
||||
|
|
@ -207,7 +232,6 @@
|
|||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="FileHelper.vb" />
|
||||
<Compile Include="ImageCreator.vb" />
|
||||
<Compile Include="CreaImmagineSeparateMultiCore.vb" />
|
||||
<Compile Include="CreaImmagineSeparateThread.vb" />
|
||||
<Compile Include="ExifReader.vb">
|
||||
|
|
@ -260,6 +284,7 @@
|
|||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
|
||||
</None>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
|
|
@ -296,6 +321,16 @@
|
|||
<ItemGroup>
|
||||
<Folder Include="Sorgenti\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CatalogVbLib\CatalogVbLib.vbproj">
|
||||
<Project>{44465926-240d-473f-90b8-786ba4384406}</Project>
|
||||
<Name>CatalogVbLib</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\MaddoShared\MaddoShared.csproj">
|
||||
<Project>{aebfe9e3-277c-4a7b-8448-145d1b11998b}</Project>
|
||||
<Name>MaddoShared</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.VisualBasic.targets" />
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>
|
||||
|
|
|
|||
28
imagecatalog/MainForm.Designer.vb
generated
28
imagecatalog/MainForm.Designer.vb
generated
|
|
@ -160,6 +160,7 @@ Partial Class MainForm
|
|||
Me.Label10 = New System.Windows.Forms.Label()
|
||||
Me.btnCreaCatalogo = New System.Windows.Forms.Button()
|
||||
Me.Button6 = New System.Windows.Forms.Button()
|
||||
Me.btnCreaCatalogoAsync = New System.Windows.Forms.Button()
|
||||
Me.TabControl1.SuspendLayout()
|
||||
Me.TabPage5.SuspendLayout()
|
||||
Me.GroupBox11.SuspendLayout()
|
||||
|
|
@ -289,9 +290,9 @@ Partial Class MainForm
|
|||
Me.Label8.AutoSize = True
|
||||
Me.Label8.Location = New System.Drawing.Point(64, 26)
|
||||
Me.Label8.Name = "Label8"
|
||||
Me.Label8.Size = New System.Drawing.Size(61, 13)
|
||||
Me.Label8.Size = New System.Drawing.Size(111, 13)
|
||||
Me.Label8.TabIndex = 3
|
||||
Me.Label8.Text = "Min Thread"
|
||||
Me.Label8.Text = "Chunk Size (0 = MAX)"
|
||||
'
|
||||
'TextBox8
|
||||
'
|
||||
|
|
@ -299,16 +300,16 @@ Partial Class MainForm
|
|||
Me.TextBox8.Name = "TextBox8"
|
||||
Me.TextBox8.Size = New System.Drawing.Size(47, 20)
|
||||
Me.TextBox8.TabIndex = 2
|
||||
Me.TextBox8.Text = "4"
|
||||
Me.TextBox8.Text = "0"
|
||||
'
|
||||
'Label7
|
||||
'
|
||||
Me.Label7.AutoSize = True
|
||||
Me.Label7.Location = New System.Drawing.Point(61, 48)
|
||||
Me.Label7.Name = "Label7"
|
||||
Me.Label7.Size = New System.Drawing.Size(64, 13)
|
||||
Me.Label7.Size = New System.Drawing.Size(108, 13)
|
||||
Me.Label7.TabIndex = 1
|
||||
Me.Label7.Text = "Max Thread"
|
||||
Me.Label7.Text = "Threads (0 = CPU *2)"
|
||||
'
|
||||
'TextBox7
|
||||
'
|
||||
|
|
@ -316,7 +317,7 @@ Partial Class MainForm
|
|||
Me.TextBox7.Name = "TextBox7"
|
||||
Me.TextBox7.Size = New System.Drawing.Size(47, 20)
|
||||
Me.TextBox7.TabIndex = 0
|
||||
Me.TextBox7.Text = "4"
|
||||
Me.TextBox7.Text = "0"
|
||||
'
|
||||
'GroupBox3
|
||||
'
|
||||
|
|
@ -1493,7 +1494,7 @@ Partial Class MainForm
|
|||
Me.Label27.Name = "Label27"
|
||||
Me.Label27.Size = New System.Drawing.Size(140, 20)
|
||||
Me.Label27.TabIndex = 62
|
||||
Me.Label27.Text = "Versione 2.1 2019"
|
||||
Me.Label27.Text = "Versione 2.2 2021"
|
||||
Me.Label27.TextAlign = System.Drawing.ContentAlignment.MiddleRight
|
||||
'
|
||||
'Button7
|
||||
|
|
@ -1568,7 +1569,7 @@ Partial Class MainForm
|
|||
Me.btnCreaCatalogo.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
|
||||
Me.btnCreaCatalogo.Location = New System.Drawing.Point(539, 77)
|
||||
Me.btnCreaCatalogo.Name = "btnCreaCatalogo"
|
||||
Me.btnCreaCatalogo.Size = New System.Drawing.Size(192, 39)
|
||||
Me.btnCreaCatalogo.Size = New System.Drawing.Size(102, 39)
|
||||
Me.btnCreaCatalogo.TabIndex = 53
|
||||
Me.btnCreaCatalogo.Text = "crea catalogo"
|
||||
'
|
||||
|
|
@ -1581,11 +1582,21 @@ Partial Class MainForm
|
|||
Me.Button6.TabIndex = 54
|
||||
Me.Button6.Text = "Carica impostazioni"
|
||||
'
|
||||
'btnCreaCatalogoAsync
|
||||
'
|
||||
Me.btnCreaCatalogoAsync.Location = New System.Drawing.Point(647, 78)
|
||||
Me.btnCreaCatalogoAsync.Name = "btnCreaCatalogoAsync"
|
||||
Me.btnCreaCatalogoAsync.Size = New System.Drawing.Size(84, 38)
|
||||
Me.btnCreaCatalogoAsync.TabIndex = 68
|
||||
Me.btnCreaCatalogoAsync.Text = "Crea 2"
|
||||
Me.btnCreaCatalogoAsync.UseVisualStyleBackColor = True
|
||||
'
|
||||
'MainForm
|
||||
'
|
||||
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
|
||||
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
|
||||
Me.ClientSize = New System.Drawing.Size(739, 401)
|
||||
Me.Controls.Add(Me.btnCreaCatalogoAsync)
|
||||
Me.Controls.Add(Me.ProgressBar1)
|
||||
Me.Controls.Add(Me.CheckBox22)
|
||||
Me.Controls.Add(Me.Label43)
|
||||
|
|
@ -1783,4 +1794,5 @@ Partial Class MainForm
|
|||
Friend WithEvents rdbVecchioMetodo As System.Windows.Forms.RadioButton
|
||||
Friend WithEvents CheckBox2 As System.Windows.Forms.CheckBox
|
||||
Friend WithEvents chkSovrascriviFile As System.Windows.Forms.CheckBox
|
||||
Friend WithEvents btnCreaCatalogoAsync As Button
|
||||
End Class
|
||||
|
|
|
|||
|
|
@ -1,9 +1,14 @@
|
|||
Imports System.IO
|
||||
Imports System.Collections.Concurrent
|
||||
Imports System.IO
|
||||
Imports System.Drawing.Drawing2D
|
||||
Imports System.Drawing.Imaging
|
||||
Imports System.Threading
|
||||
Imports System.Collections.Generic
|
||||
Imports System.Drawing.Text
|
||||
Imports System.Runtime.InteropServices
|
||||
Imports System.Threading.Tasks
|
||||
Imports CatalogVbLib
|
||||
Imports MaddoShared
|
||||
|
||||
Public Delegate Sub XyThreadAdd(ByVal Info As String)
|
||||
|
||||
|
|
@ -97,12 +102,20 @@ Public Class MainForm
|
|||
ComboBox5.Items.Add("Basso")
|
||||
ComboBox5.SelectedIndex = 2
|
||||
End Sub
|
||||
<DllImport("kernel32.dll", SetLastError:=True)>
|
||||
Private Shared Function AllocConsole() As Boolean
|
||||
|
||||
End Function
|
||||
|
||||
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||
Application.EnableVisualStyles()
|
||||
|
||||
setDefaults()
|
||||
#If Not DEBUG Then
|
||||
AllocConsole()
|
||||
#End If
|
||||
|
||||
Console.WriteLine("Programma avviato")
|
||||
End Sub
|
||||
|
||||
Private Sub FixPaths()
|
||||
|
|
@ -160,6 +173,7 @@ Public Class MainForm
|
|||
End If
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub creaCatalogoThread()
|
||||
Dim timeStart As Date = TimeOfDay
|
||||
MyPool.StopThreadPool()
|
||||
|
|
@ -878,7 +892,7 @@ Public Class MainForm
|
|||
|
||||
|
||||
|
||||
Dim ClsCreaImmagine As New ImageCreator(childFile.Name, SourceDir, DestDir, DestDirStart)
|
||||
Dim ClsCreaImmagine As New ImageCreatorSharp(childFile.Name, SourceDir, DestDir, DestDirStart)
|
||||
' ClsCreaImmagine.NomeFileChild = childFile.Name
|
||||
' ClsCreaImmagine.DestDir = DestDir
|
||||
' ClsCreaImmagine.SourceDir = SourceDir
|
||||
|
|
@ -898,7 +912,7 @@ Public Class MainForm
|
|||
End Sub
|
||||
|
||||
Private Function getNumerazione() As Integer
|
||||
dim numerazione As Integer
|
||||
Dim numerazione As Integer
|
||||
If rdbNumProgressiva.Checked Then
|
||||
numerazione = FileHelper.numerazione.Progressiva
|
||||
Else
|
||||
|
|
@ -907,6 +921,16 @@ Public Class MainForm
|
|||
Return numerazione
|
||||
End Function
|
||||
|
||||
Private Function GetNumerazioneEnum() As NumerazioneType
|
||||
Dim numerazioneType As NumerazioneType
|
||||
If rdbNumProgressiva.Checked Then
|
||||
numerazioneType = NumerazioneType.Progressiva ' FileHelper.numerazione.Progressiva
|
||||
Else
|
||||
numerazioneType = NumerazioneType.Files ' FileHelper.numerazione.Files
|
||||
End If
|
||||
Return numerazioneType
|
||||
End Function
|
||||
|
||||
Private Sub creaimmaginiWithThreadDict(ByVal SourcePath As String, ByVal DestPath As String)
|
||||
Dim dirSourceDest As Dictionary(Of FileInfo, DirectoryInfo) = New Dictionary(Of FileInfo, DirectoryInfo)
|
||||
If chkAggiornaSottodirectory.Checked And chkCreaSottocartelle.Checked Then
|
||||
|
|
@ -922,12 +946,12 @@ Public Class MainForm
|
|||
|
||||
Dim pair As KeyValuePair(Of FileInfo, DirectoryInfo)
|
||||
For Each pair In dirSourceDest
|
||||
|
||||
setLabel10Text("File: " & pair.Key.Name)
|
||||
Dim b As String = (CType(Label18.Text, Integer) + 1).ToString
|
||||
|
||||
Dim ClsCreaImmagine As New ImageCreator(pair.Key, pair.Value)
|
||||
Dim ClsCreaImmagine As New ImageCreatorSharp(pair.Key, pair.Value)
|
||||
ContaImmaginiThread += 1
|
||||
|
||||
MyPool.InsertWorkItem(pair.Key.Name, New XyThreadAdd(AddressOf ClsCreaImmagine.CreaImmagineThread), New Object(0) {pair.Key.Name}, True)
|
||||
|
||||
Next
|
||||
|
|
@ -1312,7 +1336,157 @@ Public Class MainForm
|
|||
CheckBox18.Checked = False
|
||||
End Sub
|
||||
|
||||
Private Sub Label27_Click(sender As Object, e As EventArgs) Handles Label27.Click
|
||||
|
||||
End Sub
|
||||
|
||||
Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles btnCreaCatalogoAsync.Click
|
||||
lockUI()
|
||||
'Dim timeStart As Date
|
||||
'Dim timeStop As Date
|
||||
|
||||
'timeStart = TimeOfDay
|
||||
FixPaths()
|
||||
Label10.Text = "Elaborazione in corso..."
|
||||
lblFotoTotaliNum.Text = "0"
|
||||
Label18.Text = "0"
|
||||
Label43.Text = "-s"
|
||||
|
||||
setPicSettings(txtSorgente.Text, txtDestinazione.Text)
|
||||
ProgressBar1.Minimum = 0
|
||||
ProgressBar1.Step = 1
|
||||
ProgressBar1.Value = 0
|
||||
|
||||
'Await CreaCatalogoParallel()
|
||||
Dim imgStf As ImageCreationStuff = New ImageCreationStuff()
|
||||
|
||||
Dim imageCreationOptions As ImageCreationStuff.Options = New ImageCreationStuff.Options()
|
||||
With imageCreationOptions
|
||||
.AggiornaSottodirectory = chkAggiornaSottodirectory.Checked
|
||||
.CreaSottocartelle = chkCreaSottocartelle.Checked
|
||||
.FilePerCartella = CInt(txtFilePerCartella.Text)
|
||||
.SuffissoCartelle = txtSuffissoCartelle.Text
|
||||
.CifreContatore = CInt(txtCifreContatore.Text)
|
||||
.NumerazioneType = GetNumerazioneEnum()
|
||||
.SourcePath = txtSorgente.Text
|
||||
.DestinationPath = txtDestinazione.Text
|
||||
.MaxThreads = CInt(TextBox7.Text)
|
||||
.ChunksSize = CInt(TextBox8.Text)
|
||||
.LinearExecution = rdbVecchioMetodo.Checked
|
||||
End With
|
||||
|
||||
Dim time As String = Await imgStf.CreaCatalogoParallel(imageCreationOptions)
|
||||
Label43.Text = time
|
||||
Label10.Text = "Finito"
|
||||
unlockUI()
|
||||
|
||||
End Sub
|
||||
Private Sub UpdateCounter(text As String)
|
||||
Label10.Invoke(Sub()
|
||||
Label10.Text = text
|
||||
|
||||
End Sub)
|
||||
End Sub
|
||||
Private Async Function CreaCatalogoParallel() As Task
|
||||
Dim timeStart As Date = TimeOfDay
|
||||
ContaImmaginiThread = 0
|
||||
setLabel10Text("Elaborazione in corso...")
|
||||
Dim imgStf As ImageCreationStuff = New ImageCreationStuff()
|
||||
|
||||
Dim imageCreationOptions As ImageCreationStuff.Options = New ImageCreationStuff.Options()
|
||||
With imageCreationOptions
|
||||
.AggiornaSottodirectory = chkAggiornaSottodirectory.Checked
|
||||
.CreaSottocartelle = chkCreaSottocartelle.Checked
|
||||
.FilePerCartella = CInt(txtFilePerCartella.Text)
|
||||
.SuffissoCartelle = txtSuffissoCartelle.Text
|
||||
.CifreContatore = CInt(txtCifreContatore.Text)
|
||||
.NumerazioneType = GetNumerazioneEnum()
|
||||
.SourcePath = txtSorgente.Text
|
||||
.DestinationPath = txtDestinazione.Text
|
||||
End With
|
||||
|
||||
Await imgStf.CreaImmaginiParallel(imageCreationOptions)
|
||||
|
||||
'Await CreaImmaginiParallel(txtSorgente.Text, txtDestinazione.Text)
|
||||
|
||||
setLabel10Text("Finito")
|
||||
Dim timeStop As Date = TimeOfDay
|
||||
setLabel43Text(CalcTime(timeStart, timeStop, ContaImmaginiThread))
|
||||
End Function
|
||||
|
||||
'Private Async Function CreaImmaginiParallel(ByVal SourcePath As String, ByVal DestPath As String) As Task
|
||||
' Dim dataToProcess As List(Of FileData) = New List(Of FileData)
|
||||
|
||||
' 'Dim dirSourceDest As Dictionary(Of FileInfo, DirectoryInfo) = New Dictionary(Of FileInfo, DirectoryInfo)
|
||||
' If chkAggiornaSottodirectory.Checked And chkCreaSottocartelle.Checked Then
|
||||
|
||||
' Dim helperSharp As New FileHelperSharp()
|
||||
|
||||
' 'Dim helper As New FileHelper(CInt(txtFilePerCartella.Text), txtSuffissoCartelle.Text, CInt(txtCifreContatore.Text), getNumerazione())
|
||||
' 'getfilesrecursive
|
||||
|
||||
' Dim fileHelperOptions As FileHelperOptions = New FileHelperOptions()
|
||||
' fileHelperOptions.FilesPerFolder = CInt(txtFilePerCartella.Text)
|
||||
' fileHelperOptions.Suffix = txtSuffissoCartelle.Text
|
||||
' fileHelperOptions.CounterSize = CInt(txtCifreContatore.Text)
|
||||
' fileHelperOptions.NumerationType = GetNumerazioneEnum()
|
||||
|
||||
' dataToProcess = helperSharp.GetFilesRecursive(New DirectoryInfo(SourcePath), New DirectoryInfo(DestPath), "*.jpg", fileHelperOptions)
|
||||
|
||||
' 'dataToProcess = helper.GetFilesRecursiveParallel(New DirectoryInfo(SourcePath), New DirectoryInfo(DestPath), "*.jpg")
|
||||
' ElseIf chkAggiornaSottodirectory.Checked And Not chkCreaSottocartelle.Checked Then
|
||||
' ' TODO manca tutto?!?!?!?
|
||||
' End If
|
||||
|
||||
' Dim scheduler As TaskScheduler = New ConcurrentExclusiveSchedulerPair(TaskScheduler.Default, Environment.ProcessorCount * 2).ConcurrentScheduler
|
||||
|
||||
' Dim test As IEnumerable(Of Task) = From d In dataToProcess Select Task.Factory.StartNew(Sub()
|
||||
' 'setLabel10Text("File: " & p.File.Name)
|
||||
|
||||
' Dim b As String = (CType(Label18.Text, Integer) + 1).ToString
|
||||
|
||||
' Dim clsCreaImmagine As New ImageCreator(d.File, d.Directory)
|
||||
|
||||
' clsCreaImmagine.CreaImmagineThread(d.File.Name)
|
||||
|
||||
' ContaImmaginiThread += 1
|
||||
' UpdateCounter(ContaImmaginiThread & " " & d.File.Name)
|
||||
' End Sub, CancellationToken.None, TaskCreationOptions.LongRunning, scheduler) 'TODO Cancellation Token
|
||||
|
||||
' 'ThreadingHelper.StartAndWaitAllThrottled(test, CType(TextBox7.Text, Integer))
|
||||
|
||||
' Await Task.WhenAll(test)
|
||||
|
||||
' '= getDirsDict(SourcePath, DestPath)
|
||||
' 'Parallel.ForEach(dataToProcess,
|
||||
' ' Sub(p, state)
|
||||
' ' 'setLabel10Text("File: " & p.File.Name)
|
||||
|
||||
' ' Dim b As String = (CType(Label18.Text, Integer) + 1).ToString
|
||||
|
||||
' ' Dim clsCreaImmagine As New ImageCreator(p.File, p.Directory)
|
||||
|
||||
' ' clsCreaImmagine.CreaImmagineThread(p.File.Name)
|
||||
|
||||
' ' ContaImmaginiThread += 1
|
||||
' ' UpdateCounter(ContaImmaginiThread & " " & p.File.Name)
|
||||
' ' 'MyPool.InsertWorkItem(p.File.Name, New XyThreadAdd(AddressOf ClsCreaImmagine.CreaImmagineThread), New Object(0) {p.File.Name}, True)
|
||||
' ' ' TODO: BREAK ON STOP state.stop()
|
||||
|
||||
' ' End Sub)
|
||||
|
||||
' 'Dim pair As KeyValuePair(Of FileInfo, DirectoryInfo)
|
||||
' 'For Each pair In dirSourceDest
|
||||
|
||||
' ' setLabel10Text("File: " & pair.Key.Name)
|
||||
' ' Dim b As String = (CType(Label18.Text, Integer) + 1).ToString
|
||||
|
||||
' ' Dim ClsCreaImmagine As New ImageCreator(pair.Key, pair.Value)
|
||||
' ' ContaImmaginiThread += 1
|
||||
' ' MyPool.InsertWorkItem(pair.Key.Name, New XyThreadAdd(AddressOf ClsCreaImmagine.CreaImmagineThread), New Object(0) {pair.Key.Name}, True)
|
||||
|
||||
' 'Next
|
||||
'End Function
|
||||
End Class
|
||||
|
||||
Public Class PicInfo
|
||||
|
|
|
|||
2
imagecatalog/My Project/Application.Designer.vb
generated
2
imagecatalog/My Project/Application.Designer.vb
generated
|
|
@ -8,7 +8,7 @@
|
|||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict On
|
||||
Option Strict Off
|
||||
Option Explicit On
|
||||
|
||||
|
||||
|
|
|
|||
2
imagecatalog/My Project/Settings.Designer.vb
generated
2
imagecatalog/My Project/Settings.Designer.vb
generated
|
|
@ -8,7 +8,7 @@
|
|||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict On
|
||||
Option Strict Off
|
||||
Option Explicit On
|
||||
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,5 +1,5 @@
|
|||
Option Explicit On
|
||||
Option Strict On
|
||||
Option Strict Off
|
||||
|
||||
Imports System.Threading
|
||||
Imports System.Collections
|
||||
|
|
|
|||
|
|
@ -1,23 +1,36 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<system.diagnostics>
|
||||
<sources>
|
||||
<!-- Questa sezione definisce la configurazione di registrazione per My.Application.Log -->
|
||||
<source name="DefaultSource" switchName="DefaultSwitch">
|
||||
<listeners>
|
||||
<add name="FileLog"/>
|
||||
<add name="FileLog" />
|
||||
<!-- Per scrivere nel log eventi dell'applicazione, rimuovere il commento dalla sezione sottostante -->
|
||||
<!--<add name="EventLog"/>-->
|
||||
</listeners>
|
||||
</source>
|
||||
</sources>
|
||||
<switches>
|
||||
<add name="DefaultSwitch" value="Information"/>
|
||||
<add name="DefaultSwitch" value="Information" />
|
||||
</switches>
|
||||
<sharedListeners>
|
||||
<add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter"/>
|
||||
<add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter" />
|
||||
<!-- Per scrivere nel log eventi dell'applicazione, rimuovere il commento dalla sezione sottostante e sostituire APPLICATION_NAME con il nome dell'applicazione -->
|
||||
<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
|
||||
</sharedListeners>
|
||||
</system.diagnostics>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/></startup></configuration>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /></startup>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
|
|
|
|||
11
imagecatalog/packages.config
Normal file
11
imagecatalog/packages.config
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Ben.Demystifier" version="0.3.0" targetFramework="net472" />
|
||||
<package id="System.Buffers" version="4.5.1" targetFramework="net472" />
|
||||
<package id="System.Collections.Immutable" version="5.0.0" targetFramework="net472" />
|
||||
<package id="System.Memory" version="4.5.4" targetFramework="net472" />
|
||||
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net472" />
|
||||
<package id="System.Reflection.Metadata" version="5.0.0" targetFramework="net472" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.3" targetFramework="net472" />
|
||||
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net472" />
|
||||
</packages>
|
||||
Loading…
Add table
Add a link
Reference in a new issue