Skip to content

Commit

Permalink
Update ISO639-3
Browse files Browse the repository at this point in the history
  • Loading branch information
ptr727 committed Feb 20, 2022
1 parent 19af22f commit 050f713
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 90 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ Packages published on [NuGet](https://www.nuget.org/packages/InsaneGenius.Utilit
## Notes

- ISO 639-3 language data is sourced from the [ISO 639-3 Registration Authority](https://iso639-3.sil.org/code_tables/download_tables).
- Download UTF8 format [ISO-639-3 file](https://iso639-3.sil.org/sites/iso639-3/files/downloads/iso-639-3.tab).
- Compile using Visual Studio's built-in [T4 Tool](https://docs.microsoft.com/en-us/visualstudio/modeling/code-generation-and-t4-text-templates).
- Or compile from the CLI using the [Mono T4](https://github.com/mono/t4) tool.
- `wget -O ISO-639-3.tab https://iso639-3.sil.org/sites/iso639-3/files/downloads/iso-639-3.tab`
- `dotnet tool install -g dotnet-t4`
- `t4 --out=ISO-639-3.cs ISO-639-3.tt`
21 changes: 10 additions & 11 deletions Sandbox/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal class Program
// https://jeremylindsayni.wordpress.com/2019/01/01/using-polly-and-flurl-to-improve-your-website/


private static readonly HttpClient GlobalHttpClient = new HttpClient();
private static readonly HttpClient GlobalHttpClient = new();

#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
private static async Task<int> Main(string[] args)
Expand Down Expand Up @@ -75,7 +75,7 @@ private static async Task<int> Main(string[] args)

private static async Task<IEnumerable<NuGetVersion>> GetNuGetPackageVersionsAsync(string packageId)
{
SourceCacheContext cache = new SourceCacheContext();
SourceCacheContext cache = new();
SourceRepository repository = Repository.Factory.GetCoreV3("https://api.nuget.org/v3/index.json");

FindPackageByIdResource resource = await repository.GetResourceAsync<FindPackageByIdResource>();
Expand Down Expand Up @@ -161,13 +161,13 @@ protected override void OutputHandler(DataReceivedEventArgs e)
Pipe.Writer.WriteAsync(Encoding.UTF8.GetBytes(e.Data));
}

protected override void ExitHandler(EventArgs e)
protected override void ExitHandler()
{
// Signal writer pipe that we are done
Pipe.Writer.Complete();

// Call base
base.ExitHandler(e);
base.ExitHandler();
}

private async Task ReadAsync()
Expand Down Expand Up @@ -210,7 +210,7 @@ private async Task ReadAsync()
Pipe.Reader.Complete();
}

private Pipe Pipe = new Pipe();
private Pipe Pipe = new();
}

public class FfProbeProcess : ProcessEx
Expand Down Expand Up @@ -293,11 +293,10 @@ protected override void OutputHandler(DataReceivedEventArgs e)
string footer = e.Data.Trim();
if (footer.Equals("]"))
JsonFooterFound = true;
return;
}
}

private readonly StringBuilder JsonBuffer = new StringBuilder();
private readonly StringBuilder JsonBuffer = new();
private bool JsonHeaderFound = false;
private bool JsonFooterFound = false;
}
Expand All @@ -308,7 +307,7 @@ private static void TestSerilog()
Microsoft.Extensions.Logging.ILogger logger = Microsoft.Extensions.Logging.Abstractions.NullLogger.Instance;

// https://github.com/serilog/serilog-extensions-logging/blob/dev/samples/Sample/Program.cs
LoggerProviderCollection providerCollection = new LoggerProviderCollection();
LoggerProviderCollection providerCollection = new();

Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
Expand All @@ -317,12 +316,12 @@ private static void TestSerilog()
.WriteTo.Providers(providerCollection)
.CreateLogger();

ServiceCollection serviceCollection = new ServiceCollection();
ServiceCollection serviceCollection = new();
serviceCollection.AddSingleton(providerCollection);
serviceCollection.AddSingleton<ILoggerFactory>(sc =>
{
LoggerProviderCollection loggerProviderCollection = sc.GetService<LoggerProviderCollection>();
SerilogLoggerFactory serilogLoggerFactory = new SerilogLoggerFactory(null, true, loggerProviderCollection);
SerilogLoggerFactory serilogLoggerFactory = new(null, true, loggerProviderCollection);
foreach (ILoggerProvider loggerProvider in sc.GetServices<ILoggerProvider>())
serilogLoggerFactory.AddProvider(loggerProvider);
Expand Down Expand Up @@ -354,7 +353,7 @@ private static void TestSerilog1()
.CreateLogger();

// MEL logger factory
LoggerFactory loggerFactory = new LoggerFactory();
LoggerFactory loggerFactory = new();
loggerFactory.AddSerilog(Log.Logger);

// MEL logger
Expand Down
18 changes: 9 additions & 9 deletions Utilities/CommandLineEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ public static string[] ParseArguments(string commandLine)
if (commandLine == null)
throw new ArgumentNullException(nameof(commandLine));

char[] parmChars = commandLine.ToCharArray();
char[] paramChars = commandLine.ToCharArray();
bool inQuote = false;
for (int index = 0; index < parmChars.Length; index++)
for (int index = 0; index < paramChars.Length; index++)
{
if (parmChars[index] == '"')
if (paramChars[index] == '"')
inQuote = !inQuote;
if (!inQuote && parmChars[index] == ' ')
parmChars[index] = '\n';
if (!inQuote && paramChars[index] == ' ')
paramChars[index] = '\n';
}
return new string(parmChars).Split('\n');
return new string(paramChars).Split('\n');
}

public static string[] GetCommandLineArgs()
Expand All @@ -28,9 +28,9 @@ public static string[] GetCommandLineArgs()
string[] args = ParseArguments(Environment.CommandLine);

// Strip the process path from the list of arguments
string[] argsex = new string[args.Length - 1];
Array.Copy(args, 1, argsex, 0, argsex.Length);
return argsex;
string[] argsEx = new string[args.Length - 1];
Array.Copy(args, 1, argsEx, 0, argsEx.Length);
return argsEx;
}
}
}
20 changes: 10 additions & 10 deletions Utilities/FileEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static bool RenameFile(string originalName, string newName)
string newFile = Path.GetFileName(newName);

bool result = false;
for (int retrycount = 0; retrycount < Options.RetryCount; retrycount ++)
for (int retryCount = 0; retryCount < Options.RetryCount; retryCount ++)
{
// Break on cancel
if (Options.Cancel.IsCancellationRequested)
Expand All @@ -140,9 +140,9 @@ public static bool RenameFile(string originalName, string newName)
{
// Retry
if (originalDirectory.Equals(newDirectory, StringComparison.OrdinalIgnoreCase))
LogOptions.Logger.LogInformation("Renaming ({Retrycount} / {OptionsRetryCount}) : {OriginalDirectory} : {OriginalFile} to {NewFile}", retrycount, Options.RetryCount, originalDirectory, originalFile, newFile);
LogOptions.Logger.LogInformation("Renaming ({RetryCount} / {OptionsRetryCount}) : {OriginalDirectory} : {OriginalFile} to {NewFile}", retryCount, Options.RetryCount, originalDirectory, originalFile, newFile);
else
LogOptions.Logger.LogInformation("Renaming ({Retrycount} / {OptionsRetryCount}) : {OriginalName} to {NewName}", retrycount, Options.RetryCount, originalName, newName);
LogOptions.Logger.LogInformation("Renaming ({RetryCount} / {OptionsRetryCount}) : {OriginalName} to {NewName}", retryCount, Options.RetryCount, originalName, newName);
Options.RetryWaitForCancel();
}
catch (Exception e) when (LogOptions.Logger.LogAndHandle(e, MethodBase.GetCurrentMethod().Name))
Expand Down Expand Up @@ -276,8 +276,8 @@ public static bool WaitFileReadAble(string fileName)
// Try to access the file
try
{
FileInfo fileinfo = new FileInfo(fileName);
using FileStream stream = fileinfo.Open(FileMode.Open, FileAccess.Read, FileShare.None);
FileInfo fileInfo = new FileInfo(fileName);
using FileStream stream = fileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.None);
stream.Close();
result = true;
break;
Expand Down Expand Up @@ -522,8 +522,8 @@ public static bool CreateRandomFilledFile(string name, long size)
stream.Seek(0, SeekOrigin.Begin);

// Buffer with random data
const int buffersize = 2 * Format.MiB;
byte[] buffer = new byte[buffersize];
const int bufferSize = 2 * Format.MiB;
byte[] buffer = new byte[bufferSize];
Random rand = new Random();

// Write in buffer chunks
Expand All @@ -533,10 +533,10 @@ public static bool CreateRandomFilledFile(string name, long size)
// Fill buffer with random data
rand.NextBytes(buffer);
// Write
long writesize = Math.Min(remaining, Convert.ToInt64(buffer.Length));
stream.Write(buffer, 0, Convert.ToInt32(writesize));
long writeSize = Math.Min(remaining, Convert.ToInt64(buffer.Length));
stream.Write(buffer, 0, Convert.ToInt32(writeSize));
// Remaining
remaining -= writesize;
remaining -= writeSize;
}

// Close
Expand Down
14 changes: 2 additions & 12 deletions Utilities/Format.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static class Format
// https://en.wikipedia.org/wiki/Kilobyte
// https://stackoverflow.com/questions/281640/how-do-i-get-a-human-readable-file-size-in-bytes-abbreviation-using-net
// https://stackoverflow.com/questions/14488796/does-net-provide-an-easy-way-convert-bytes-to-kb-mb-gb-etc
public static string BytesToKibi(long value, string units)
public static string BytesToKibi(long value, string units = "B")
{
if (value < 0)
return "-" + BytesToKibi(Math.Abs(value));
Expand All @@ -39,12 +39,7 @@ public static string BytesToKibi(long value, string units)
}
private static readonly string[] KibiSuffix = { "", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei" };

public static string BytesToKibi(long value)
{
return BytesToKibi(value, "B");
}

public static string BytesToKilo(long value, string units)
public static string BytesToKilo(long value, string units = "B")
{
if (value < 0)
return "-" + BytesToKilo(Math.Abs(value));
Expand All @@ -57,10 +52,5 @@ public static string BytesToKilo(long value, string units)
return fraction.Equals(truncate) ? $"{Convert.ToInt64(truncate):D}{KiloSuffix[magnitude]}{units}" : $"{fraction:F}{KiloSuffix[magnitude]}{units}";
}
private static readonly string[] KiloSuffix = { "", "K", "M", "G", "T", "P", "E" };

public static string BytesToKilo(long value)
{
return BytesToKilo(value, "B");
}
}
}
Loading

0 comments on commit 050f713

Please sign in to comment.