Utils: Code cleanup

This commit is contained in:
2024-02-20 16:38:18 +01:00
parent c82e8de724
commit f8ee478a9e

View File

@ -11,8 +11,6 @@ using Elwig.Dialogs;
using System.Text; using System.Text;
using System.Numerics; using System.Numerics;
using Elwig.Models.Entities; using Elwig.Models.Entities;
using System.IO;
using ScottPlot.TickGenerators.TimeUnits;
using Elwig.Helpers.Billing; using Elwig.Helpers.Billing;
namespace Elwig.Helpers { namespace Elwig.Helpers {
@ -63,7 +61,7 @@ namespace Elwig.Helpers {
return PhoneNrTypes.Where(t => t.Key == type).Select(t => t.Value).FirstOrDefault(type); return PhoneNrTypes.Where(t => t.Key == type).Select(t => t.Value).FirstOrDefault(type);
} }
private static readonly ushort[] Crc16ModbusTable = { private static readonly ushort[] Crc16ModbusTable = [
0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241,
0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440, 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440,
0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40,
@ -96,7 +94,7 @@ namespace Elwig.Helpers {
0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41, 0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41,
0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641, 0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641,
0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040, 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040,
}; ];
public static SerialPort OpenSerialConnection(string connection) { public static SerialPort OpenSerialConnection(string connection) {
var m = SerialRegex.Match(connection); var m = SerialRegex.Match(connection);
@ -329,7 +327,7 @@ namespace Elwig.Helpers {
public static (string, string?) SplitName(string fullName, string? familyName) { public static (string, string?) SplitName(string fullName, string? familyName) {
if (familyName == null || familyName == "") return (fullName, null); if (familyName == null || familyName == "") return (fullName, null);
var p0 = fullName.ToLower().IndexOf(familyName.ToLower()); var p0 = fullName.IndexOf(familyName, StringComparison.CurrentCultureIgnoreCase);
if (p0 == -1) return (fullName, null); if (p0 == -1) return (fullName, null);
var p1 = fullName.IndexOf(" und "); var p1 = fullName.IndexOf(" und ");
var p2 = fullName.ToLower().LastIndexOf(" und "); var p2 = fullName.ToLower().LastIndexOf(" und ");
@ -348,9 +346,9 @@ namespace Elwig.Helpers {
} }
public static IEnumerable<IEnumerable<T>> Permutate<T>(IEnumerable<T> input, IEnumerable<T>? forced = null) { public static IEnumerable<IEnumerable<T>> Permutate<T>(IEnumerable<T> input, IEnumerable<T>? forced = null) {
HashSet<IEnumerable<T>> output = new(); HashSet<IEnumerable<T>> output = [];
for (int i = 0; i < Math.Pow(2, input.Count()); i++) { for (int i = 0; i < Math.Pow(2, input.Count()); i++) {
List<T> t = new(); List<T> t = [];
for (int j = 0; j < 30; j++) { for (int j = 0; j < 30; j++) {
var e = input.ElementAtOrDefault(j); var e = input.ElementAtOrDefault(j);
if (e != null && ((forced?.Contains(e) ?? false) || (i & (1 << j)) != 0)) { if (e != null && ((forced?.Contains(e) ?? false) || (i & (1 << j)) != 0)) {