Initial commit

This commit is contained in:
Mark J Price 2022-09-19 10:50:44 +01:00
parent 5d934d40d6
commit 8831f9b0d5
24 changed files with 282 additions and 4 deletions

View file

@ -15,7 +15,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WorkingWithJson", "WorkingW
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ch09Ex02SerializingShapes", "Ch09Ex02SerializingShapes\Ch09Ex02SerializingShapes.csproj", "{27FA94CC-1856-4512-9D09-0214CF846311}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkingWithRandomAccess", "WorkingWithRandomAccess\WorkingWithRandomAccess.csproj", "{EFC99F8A-CB39-48BB-A70D-5D7DB0A001D6}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WorkingWithRandomAccess", "WorkingWithRandomAccess\WorkingWithRandomAccess.csproj", "{EFC99F8A-CB39-48BB-A70D-5D7DB0A001D6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkingWithTarArchives", "WorkingWithTarArchives\WorkingWithTarArchives.csproj", "{CD1DB489-9656-4D00-ABCA-8EA975F8BE0D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -51,6 +53,10 @@ Global
{EFC99F8A-CB39-48BB-A70D-5D7DB0A001D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EFC99F8A-CB39-48BB-A70D-5D7DB0A001D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EFC99F8A-CB39-48BB-A70D-5D7DB0A001D6}.Release|Any CPU.Build.0 = Release|Any CPU
{CD1DB489-9656-4D00-ABCA-8EA975F8BE0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CD1DB489-9656-4D00-ABCA-8EA975F8BE0D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CD1DB489-9656-4D00-ABCA-8EA975F8BE0D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CD1DB489-9656-4D00-ABCA-8EA975F8BE0D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View file

@ -0,0 +1,26 @@
partial class Program
{
static void WriteError(string message)
{
ConsoleColor previousColor = ForegroundColor;
ForegroundColor = ConsoleColor.Red;
WriteLine($"FAIL: {message}");
ForegroundColor = previousColor;
}
static void WriteWarning(string message)
{
ConsoleColor previousColor = ForegroundColor;
ForegroundColor = ConsoleColor.DarkYellow;
WriteLine($"WARN: {message}");
ForegroundColor = previousColor;
}
static void WriteInformation(string message)
{
ConsoleColor previousColor = ForegroundColor;
ForegroundColor = ConsoleColor.Blue;
WriteLine($"INFO: {message}");
ForegroundColor = previousColor;
}
}

View file

@ -0,0 +1,65 @@
using System.Formats.Tar; // TarFile
try
{
string current = Environment.CurrentDirectory;
WriteInformation($"Current directory: {current}");
string sourceDirectory = Path.Combine(current, "images");
string destinationDirectory = Path.Combine(current, "extracted");
string tarFile = Path.Combine(current, "images-archive.tar");
if (!Directory.Exists(sourceDirectory))
{
WriteError($"The {sourceDirectory} directory must exist. Please create it and add some files to it.");
return;
}
if (File.Exists(tarFile))
{
// If the Tar archive file already exists then we must delete it.
File.Delete(tarFile);
WriteWarning($"{tarFile} already existed so it was deleted.");
}
WriteInformation(
$"Archiving directory: {sourceDirectory}\n To .tar file: {tarFile}");
TarFile.CreateFromDirectory(
sourceDirectoryName: sourceDirectory,
destinationFileName: tarFile,
includeBaseDirectory: true);
WriteInformation($"Does {tarFile} exist? {File.Exists(tarFile)}.");
if (!Directory.Exists(destinationDirectory))
{
// If the destination directory does not exist then we must create
// it before extracting a Tar archive to it.
Directory.CreateDirectory(destinationDirectory);
WriteWarning($"{destinationDirectory} did not exist so it was created.");
}
WriteInformation(
$"Extracting archive: {tarFile}\n To directory: {destinationDirectory}");
TarFile.ExtractToDirectory(
sourceFileName: tarFile,
destinationDirectoryName: destinationDirectory,
overwriteFiles: true);
if (Directory.Exists(destinationDirectory))
{
foreach (string dir in Directory.GetDirectories(destinationDirectory))
{
WriteInformation(
$"Extracted directory {dir} containing these files: " +
string.Join(',', Directory.EnumerateFiles(dir)
.Select(file => Path.GetFileName(file))));
}
}
}
catch (Exception ex)
{
WriteError(ex.Message);
}

View file

@ -0,0 +1,45 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Using Include="System.Console" Static="true" />
</ItemGroup>
<ItemGroup>
<Folder Include="images\" />
</ItemGroup>
<ItemGroup>
<None Update="images\category1.jpeg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="images\category2.jpeg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="images\category3.jpeg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="images\category4.jpeg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="images\category5.jpeg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="images\category6.jpeg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="images\category7.jpeg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="images\category8.jpeg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

View file

@ -9,15 +9,15 @@
{
"path": "WorkingWithEncodings"
},
{
"path": "WorkingWithRandomAccess"
},
{
"path": "WorkingWithSerialization"
},
{
"path": "WorkingWithJson"
},
{
"path": "WorkingWithTarArchives"
},
{
"path": "Ch09Ex02SerializingShapes"
}

View file

@ -0,0 +1,26 @@
partial class Program
{
static void WriteError(string message)
{
ConsoleColor previousColor = ForegroundColor;
ForegroundColor = ConsoleColor.Red;
WriteLine($"FAIL: {message}");
ForegroundColor = previousColor;
}
static void WriteWarning(string message)
{
ConsoleColor previousColor = ForegroundColor;
ForegroundColor = ConsoleColor.DarkYellow;
WriteLine($"WARN: {message}");
ForegroundColor = previousColor;
}
static void WriteInformation(string message)
{
ConsoleColor previousColor = ForegroundColor;
ForegroundColor = ConsoleColor.Blue;
WriteLine($"INFO: {message}");
ForegroundColor = previousColor;
}
}

View file

@ -0,0 +1,65 @@
using System.Formats.Tar; // TarFile
try
{
string current = Environment.CurrentDirectory;
WriteInformation($"Current directory: {current}");
string sourceDirectory = Path.Combine(current, "images");
string destinationDirectory = Path.Combine(current, "extracted");
string tarFile = Path.Combine(current, "images-archive.tar");
if (!Directory.Exists(sourceDirectory))
{
WriteError($"The {sourceDirectory} directory must exist. Please create it and add some files to it.");
return;
}
if (File.Exists(tarFile))
{
// If the Tar archive file already exists then we must delete it.
File.Delete(tarFile);
WriteWarning($"{tarFile} already existed so it was deleted.");
}
WriteInformation(
$"Archiving directory: {sourceDirectory}\n To .tar file: {tarFile}");
TarFile.CreateFromDirectory(
sourceDirectoryName: sourceDirectory,
destinationFileName: tarFile,
includeBaseDirectory: true);
WriteInformation($"Does {tarFile} exist? {File.Exists(tarFile)}.");
if (!Directory.Exists(destinationDirectory))
{
// If the destination directory does not exist then we must create
// it before extracting a Tar archive to it.
Directory.CreateDirectory(destinationDirectory);
WriteWarning($"{destinationDirectory} did not exist so it was created.");
}
WriteInformation(
$"Extracting archive: {tarFile}\n To directory: {destinationDirectory}");
TarFile.ExtractToDirectory(
sourceFileName: tarFile,
destinationDirectoryName: destinationDirectory,
overwriteFiles: true);
if (Directory.Exists(destinationDirectory))
{
foreach (string dir in Directory.GetDirectories(destinationDirectory))
{
WriteInformation(
$"Extracted directory {dir} containing these files: " +
string.Join(',', Directory.EnumerateFiles(dir)
.Select(file => Path.GetFileName(file))));
}
}
}
catch (Exception ex)
{
WriteError(ex.Message);
}

View file

@ -0,0 +1,45 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Using Include="System.Console" Static="true" />
</ItemGroup>
<ItemGroup>
<Folder Include="images\" />
</ItemGroup>
<ItemGroup>
<None Update="images\category1.jpeg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="images\category2.jpeg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="images\category3.jpeg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="images\category4.jpeg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="images\category5.jpeg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="images\category6.jpeg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="images\category7.jpeg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="images\category8.jpeg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB