netframework support and some fixes

This commit is contained in:
Timerix22 2022-03-13 23:16:33 +03:00
parent 3c1d92d79a
commit a5c071b1d5
15 changed files with 101 additions and 48 deletions

14
.gitignore vendored
View File

@ -1,11 +1,21 @@
*.user # Build results
[Bb]in/ [Bb]in/
.bin/ .bin/
[Dd]ebug/
[Rr]elease/
[Rr]eleases/
[Oo]bj/ [Oo]bj/
[Oo]ut/ [Oo]ut/
[Ll]og/ [Ll]og/
[Ll]ogs/ [Ll]ogs/
# IDE files
.vs/ .vs/
.vscode/
.vshistory/ .vshistory/
.idea/ .idea/
.vscode/ .editorconfig
*.user
#backups
.old*/

View File

@ -1,18 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFrameworks>net6.0;net48</TargetFrameworks>
<LangVersion>preview</LangVersion>
<ImplicitUsings>false</ImplicitUsings> <ImplicitUsings>false</ImplicitUsings>
<Nullable>disable</Nullable> <Nullable>disable</Nullable>
<DebugType>portable</DebugType> <DebugType>portable</DebugType>
<AssemblyName>DTLib</AssemblyName> <AssemblyName>DTLib</AssemblyName>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> <!--xxhash uses arithmetic overflow-->
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly> <ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<Configurations>Debug;Release;Release-net48</Configurations>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <PropertyGroup Condition=" '$(Configuration)' == 'Release-net48' ">
<Compile Remove="Experimental\**" /> <TargetFramework>net48</TargetFramework>
<EmbeddedResource Remove="Experimental\**" /> </PropertyGroup>
<None Remove="Experimental\**" /> <ItemGroup Condition=" '$(TargetFramework)' == 'net48' ">
<Reference Include="System.Net" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Dynamic" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)' != 'Debug' ">
<Compile Remove="Experimental\**" />
<EmbeddedResource Remove="Experimental\**" />
<None Remove="Experimental\**" />
<Compile Remove="Dtsod\V30\**" />
<EmbeddedResource Remove="Dtsod\V30\**" />
<None Remove="Dtsod\V30\**" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Experimental\Tester.cs" /> <Compile Include="Experimental\Tester.cs" />

View File

@ -0,0 +1,17 @@
namespace DTLib.Dtsod;
public class DtsodBuilder
{
private StringBuilder b = new();
public DtsodBuilder AddProperty(string key, dynamic value)
{
return this;
}
public string BuildToString() => b.ToString();
public DtsodV23 Build() => new DtsodV23(BuildToString());
}

View File

@ -290,7 +290,7 @@ public class DtsodV22 : Dictionary<string, DtsodV22.ValueStruct>, IDtsod
break; break;
default: default:
throw new Exception($"Dtsod.Parse.ReadValue() error: value <{stringValue}> has wrong type"); throw new Exception($"Dtsod.Parse.ReadValue() error: value <{stringValue}> has wrong type");
}; }
} }
// short; long; int // short; long; int
else else
@ -310,7 +310,7 @@ public class DtsodV22 : Dictionary<string, DtsodV22.ValueStruct>, IDtsod
break; break;
} }
break; break;
}; }
} }
StringBuilder defaultValueBuilder = new(); StringBuilder defaultValueBuilder = new();
@ -344,7 +344,7 @@ public class DtsodV22 : Dictionary<string, DtsodV22.ValueStruct>, IDtsod
case ValueTypes.List: case ValueTypes.List:
isList = true; isList = true;
break; break;
}; }
outType = type; outType = type;
return value; return value;
// строка, начинающаяся с # будет считаться комментом // строка, начинающаяся с # будет считаться комментом

View File

@ -1,6 +1,4 @@
using System.Globalization; using System.Globalization;
using System.IO;
using System.Linq.Expressions;
namespace DTLib.Dtsod; namespace DTLib.Dtsod;
@ -12,7 +10,7 @@ namespace DTLib.Dtsod;
public class DtsodV23 : DtsodDict<string, dynamic>, IDtsod public class DtsodV23 : DtsodDict<string, dynamic>, IDtsod
{ {
public DtsodVersion Version { get; } = DtsodVersion.V30; public DtsodVersion Version { get; } = DtsodVersion.V23;
public IDictionary<string, dynamic> ToDictionary() => this; public IDictionary<string, dynamic> ToDictionary() => this;
public DtsodV23() : base() {} public DtsodV23() : base() {}

View File

@ -4,6 +4,8 @@ public enum DtsodVersion : byte
{ {
V21 = 21, V21 = 21,
V22 = 22, V22 = 22,
V23 = 23, V23 = 23
V30 = 30 #if DEBUG
,V30 = 30
#endif
} }

View File

@ -8,7 +8,9 @@ public static class DtsodVersionConverter
DtsodVersion.V21 => new DtsodV21(src.ToDictionary()), DtsodVersion.V21 => new DtsodV21(src.ToDictionary()),
DtsodVersion.V22 => throw new NotImplementedException("Converting dtsods to V22 isn't implemented"), DtsodVersion.V22 => throw new NotImplementedException("Converting dtsods to V22 isn't implemented"),
DtsodVersion.V23 => new DtsodV23(src.ToDictionary()), DtsodVersion.V23 => new DtsodV23(src.ToDictionary()),
#if DEBUG
DtsodVersion.V30 => new DtsodV30(src.ToDictionary()), DtsodVersion.V30 => new DtsodV30(src.ToDictionary()),
#endif
_ => throw new Exception($"DtsodVersionConverter.Convert() error: unknown target version <{targetVersion}>"), _ => throw new Exception($"DtsodVersionConverter.Convert() error: unknown target version <{targetVersion}>"),
}; };
} }

View File

@ -260,7 +260,7 @@ public class DtsodV30 : DtsodDict<string, dynamic>, IDtsod
StringBuilder b = new(); StringBuilder b = new();
foreach (KeyValuePair<string, dynamic> pair in dtsod) foreach (KeyValuePair<string, dynamic> pair in dtsod)
{ {
SerializeObject(pair.Key, pair.Value);
} }
void SerializeObject(string name, dynamic inst) void SerializeObject(string name, dynamic inst)

View File

@ -110,5 +110,5 @@ public class TypeHelper
: Type.GetType(str, false) : Type.GetType(str, false)
?? throw new Exception($"DtsodV30.Deserialize.ParseType() error: type {str} doesn't exists") ?? throw new Exception($"DtsodV30.Deserialize.ParseType() error: type {str} doesn't exists")
}; };
static internal T As<T>(object inst) where T : class => inst as T; internal static T As<T>(object inst) where T : class => inst as T;
} }

View File

@ -1,4 +1,5 @@
using System.Diagnostics; using System.Diagnostics;
using System.Globalization;
namespace DTLib.Experimental; namespace DTLib.Experimental;
@ -12,6 +13,6 @@ public static class Tester
operation(); operation();
clock.Stop(); clock.Stop();
double time=(double)(clock.ElapsedTicks)/Stopwatch.Frequency/repeats; double time=(double)(clock.ElapsedTicks)/Stopwatch.Frequency/repeats;
LogNoTime("y",$"operation ","b",op_name,"y"," lasted ","b",time.ToString(),"y"," seconds"); LogNoTime("y",$"operation ","b",op_name,"y"," lasted ","b",time.ToString(CultureInfo.InvariantCulture),"y"," seconds");
} }
} }

View File

@ -1,21 +1,25 @@
namespace DTLib.Filesystem; namespace DTLib.Filesystem;
static public class Path public static class Path
{ {
static public readonly char Sep = OperatingSystem.IsWindows() ? '\\' : '/'; public static readonly char Sep = Environment.OSVersion.Platform == PlatformID.Win32NT ? '\\' : '/';
public static string CorrectSeparator(string path) public static string CorrectSeparator(this string path)
{ {
if (Sep == '\\') if (Sep == '\\')
{ {
if (path.Contains('/')) if (path.Contains('/'))
path = path.Replace('/', '\\'); path = path.Replace('/', '\\');
} }
else if (Sep == '/') else
{ {
if (path.Contains('\\')) if (path.Contains('\\'))
path = path.Replace('\\', '/'); path = path.Replace('\\', '/');
} }
return path; return path;
} }
// replaces wrong characters to use string as path
public static string NormalizeAsPath(this string str) =>
str.Replace(':', '-').Replace(' ', '_');
} }

View File

@ -1,4 +1,6 @@
namespace DTLib.Loggers; using System.Globalization;
namespace DTLib.Loggers;
// вывод лога в консоль и файл // вывод лога в консоль и файл
public class AsyncLogger : BaseLogger public class AsyncLogger : BaseLogger
@ -12,8 +14,8 @@ public class AsyncLogger : BaseLogger
{ {
lock (statelocker) if (!IsEnabled) return; lock (statelocker) if (!IsEnabled) return;
// добавление даты // добавление даты
if (msg.Length == 1) msg[0] = "[" + DateTime.Now.ToString() + "]: " + msg[0]; if (msg.Length == 1) msg[0] = "[" + DateTime.Now.ToString(CultureInfo.InvariantCulture) + "]: " + msg[0];
else msg[1] = "[" + DateTime.Now.ToString() + "]: " + msg[1]; else msg[1] = "[" + DateTime.Now.ToString(CultureInfo.InvariantCulture) + "]: " + msg[1];
// перенос строки // перенос строки
msg[msg.Length - 1] += '\n'; msg[msg.Length - 1] += '\n';
// вывод в консоль // вывод в консоль

View File

@ -2,13 +2,13 @@
public abstract class BaseLogger public abstract class BaseLogger
{ {
public string Logfile { get; init; }
public BaseLogger() { } public BaseLogger() { }
public BaseLogger(string logfile) => (Logfile, WriteToFile) = (logfile,true); public BaseLogger(string logfile) => (Logfile, WriteToFile) = (logfile,true);
public BaseLogger(string dir, string programName) public BaseLogger(string dir, string programName)
: this($"{dir}\\{programName}_{DateTime.Now}.log".Replace(':', '-').Replace(' ', '_')) { } : this($"{dir}\\{programName}_{DateTime.Now}.log".Replace(':', '-').Replace(' ', '_')) { }
public string Logfile { get; init; }
public bool IsEnabled { get; private set; } = false; public bool IsEnabled { get; private set; } = false;
public bool WriteToFile { get; private set; } = false; public bool WriteToFile { get; private set; } = false;
protected readonly object statelocker = new(); protected readonly object statelocker = new();

View File

@ -1,4 +1,6 @@
namespace DTLib.Loggers; using System.Globalization;
namespace DTLib.Loggers;
// вывод лога в консоль и файл // вывод лога в консоль и файл
public class DefaultLogger : BaseLogger public class DefaultLogger : BaseLogger
@ -10,15 +12,15 @@ public class DefaultLogger : BaseLogger
public override void Log(params string[] msg) public override void Log(params string[] msg)
{ {
lock (Logfile) if (!IsEnabled) return; lock (statelocker) if (!IsEnabled) return;
if (msg.Length == 1) msg[0] = "[" + DateTime.Now.ToString() + "]: " + msg[0]; if (msg.Length == 1) msg[0] = "[" + DateTime.Now.ToString(CultureInfo.InvariantCulture) + "]: " + msg[0];
else msg[1] = "[" + DateTime.Now.ToString() + "]: " + msg[1]; else msg[1] = "[" + DateTime.Now.ToString(CultureInfo.InvariantCulture) + "]: " + msg[1];
LogNoTime(msg); LogNoTime(msg);
} }
public void LogNoTime(params string[] msg) public void LogNoTime(params string[] msg)
{ {
lock (Logfile) if (!IsEnabled) return; lock (statelocker) if (!IsEnabled) return;
msg[msg.Length - 1] += '\n'; msg[msg.Length - 1] += '\n';
ColoredConsole.Write(msg); ColoredConsole.Write(msg);
if (WriteToFile) if (WriteToFile)