netframework support and some fixes
This commit is contained in:
parent
3c1d92d79a
commit
a5c071b1d5
14
.gitignore
vendored
14
.gitignore
vendored
@ -1,11 +1,21 @@
|
||||
*.user
|
||||
# Build results
|
||||
[Bb]in/
|
||||
.bin/
|
||||
[Dd]ebug/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
[Oo]bj/
|
||||
[Oo]ut/
|
||||
[Ll]og/
|
||||
[Ll]ogs/
|
||||
|
||||
# IDE files
|
||||
.vs/
|
||||
.vscode/
|
||||
.vshistory/
|
||||
.idea/
|
||||
.vscode/
|
||||
.editorconfig
|
||||
*.user
|
||||
|
||||
#backups
|
||||
.old*/
|
||||
@ -1,18 +1,33 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<TargetFrameworks>net6.0;net48</TargetFrameworks>
|
||||
<LangVersion>preview</LangVersion>
|
||||
<ImplicitUsings>false</ImplicitUsings>
|
||||
<Nullable>disable</Nullable>
|
||||
<DebugType>portable</DebugType>
|
||||
<AssemblyName>DTLib</AssemblyName>
|
||||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
|
||||
<!--xxhash uses arithmetic overflow-->
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
|
||||
<Configurations>Debug;Release;Release-net48</Configurations>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release-net48' ">
|
||||
<TargetFramework>net48</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<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>
|
||||
<Compile Include="Experimental\Tester.cs" />
|
||||
|
||||
17
DTLib/Dtsod/DtsodBuilder.cs
Normal file
17
DTLib/Dtsod/DtsodBuilder.cs
Normal 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());
|
||||
}
|
||||
@ -290,7 +290,7 @@ public class DtsodV22 : Dictionary<string, DtsodV22.ValueStruct>, IDtsod
|
||||
break;
|
||||
default:
|
||||
throw new Exception($"Dtsod.Parse.ReadValue() error: value <{stringValue}> has wrong type");
|
||||
};
|
||||
}
|
||||
}
|
||||
// short; long; int
|
||||
else
|
||||
@ -310,7 +310,7 @@ public class DtsodV22 : Dictionary<string, DtsodV22.ValueStruct>, IDtsod
|
||||
break;
|
||||
}
|
||||
break;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder defaultValueBuilder = new();
|
||||
@ -344,7 +344,7 @@ public class DtsodV22 : Dictionary<string, DtsodV22.ValueStruct>, IDtsod
|
||||
case ValueTypes.List:
|
||||
isList = true;
|
||||
break;
|
||||
};
|
||||
}
|
||||
outType = type;
|
||||
return value;
|
||||
// строка, начинающаяся с # будет считаться комментом
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace DTLib.Dtsod;
|
||||
|
||||
@ -12,7 +10,7 @@ namespace DTLib.Dtsod;
|
||||
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 DtsodV23() : base() {}
|
||||
|
||||
@ -4,6 +4,8 @@ public enum DtsodVersion : byte
|
||||
{
|
||||
V21 = 21,
|
||||
V22 = 22,
|
||||
V23 = 23,
|
||||
V30 = 30
|
||||
V23 = 23
|
||||
#if DEBUG
|
||||
,V30 = 30
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -8,7 +8,9 @@ public static class DtsodVersionConverter
|
||||
DtsodVersion.V21 => new DtsodV21(src.ToDictionary()),
|
||||
DtsodVersion.V22 => throw new NotImplementedException("Converting dtsods to V22 isn't implemented"),
|
||||
DtsodVersion.V23 => new DtsodV23(src.ToDictionary()),
|
||||
#if DEBUG
|
||||
DtsodVersion.V30 => new DtsodV30(src.ToDictionary()),
|
||||
#endif
|
||||
_ => throw new Exception($"DtsodVersionConverter.Convert() error: unknown target version <{targetVersion}>"),
|
||||
};
|
||||
}
|
||||
|
||||
@ -260,7 +260,7 @@ public class DtsodV30 : DtsodDict<string, dynamic>, IDtsod
|
||||
StringBuilder b = new();
|
||||
foreach (KeyValuePair<string, dynamic> pair in dtsod)
|
||||
{
|
||||
|
||||
SerializeObject(pair.Key, pair.Value);
|
||||
}
|
||||
|
||||
void SerializeObject(string name, dynamic inst)
|
||||
|
||||
@ -110,5 +110,5 @@ public class TypeHelper
|
||||
: Type.GetType(str, false)
|
||||
?? 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;
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
|
||||
namespace DTLib.Experimental;
|
||||
|
||||
@ -12,6 +13,6 @@ public static class Tester
|
||||
operation();
|
||||
clock.Stop();
|
||||
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");
|
||||
}
|
||||
}
|
||||
@ -1,21 +1,25 @@
|
||||
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 (path.Contains('/'))
|
||||
path = path.Replace('/', '\\');
|
||||
}
|
||||
else if (Sep == '/')
|
||||
else
|
||||
{
|
||||
if (path.Contains('\\'))
|
||||
path = path.Replace('\\', '/');
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
// replaces wrong characters to use string as path
|
||||
public static string NormalizeAsPath(this string str) =>
|
||||
str.Replace(':', '-').Replace(' ', '_');
|
||||
}
|
||||
@ -1,4 +1,6 @@
|
||||
namespace DTLib.Loggers;
|
||||
using System.Globalization;
|
||||
|
||||
namespace DTLib.Loggers;
|
||||
|
||||
// вывод лога в консоль и файл
|
||||
public class AsyncLogger : BaseLogger
|
||||
@ -12,8 +14,8 @@ public class AsyncLogger : BaseLogger
|
||||
{
|
||||
lock (statelocker) if (!IsEnabled) return;
|
||||
// добавление даты
|
||||
if (msg.Length == 1) msg[0] = "[" + DateTime.Now.ToString() + "]: " + msg[0];
|
||||
else msg[1] = "[" + DateTime.Now.ToString() + "]: " + msg[1];
|
||||
if (msg.Length == 1) msg[0] = "[" + DateTime.Now.ToString(CultureInfo.InvariantCulture) + "]: " + msg[0];
|
||||
else msg[1] = "[" + DateTime.Now.ToString(CultureInfo.InvariantCulture) + "]: " + msg[1];
|
||||
// перенос строки
|
||||
msg[msg.Length - 1] += '\n';
|
||||
// вывод в консоль
|
||||
|
||||
@ -2,13 +2,13 @@
|
||||
|
||||
public abstract class BaseLogger
|
||||
{
|
||||
public string Logfile { get; init; }
|
||||
public BaseLogger() { }
|
||||
public BaseLogger(string logfile) => (Logfile, WriteToFile) = (logfile,true);
|
||||
public BaseLogger(string dir, string programName)
|
||||
: this($"{dir}\\{programName}_{DateTime.Now}.log".Replace(':', '-').Replace(' ', '_')) { }
|
||||
|
||||
|
||||
public string Logfile { get; init; }
|
||||
public bool IsEnabled { get; private set; } = false;
|
||||
public bool WriteToFile { get; private set; } = false;
|
||||
protected readonly object statelocker = new();
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
namespace DTLib.Loggers;
|
||||
using System.Globalization;
|
||||
|
||||
namespace DTLib.Loggers;
|
||||
|
||||
// вывод лога в консоль и файл
|
||||
public class DefaultLogger : BaseLogger
|
||||
@ -10,15 +12,15 @@ public class DefaultLogger : BaseLogger
|
||||
|
||||
public override void Log(params string[] msg)
|
||||
{
|
||||
lock (Logfile) if (!IsEnabled) return;
|
||||
if (msg.Length == 1) msg[0] = "[" + DateTime.Now.ToString() + "]: " + msg[0];
|
||||
else msg[1] = "[" + DateTime.Now.ToString() + "]: " + msg[1];
|
||||
lock (statelocker) if (!IsEnabled) return;
|
||||
if (msg.Length == 1) msg[0] = "[" + DateTime.Now.ToString(CultureInfo.InvariantCulture) + "]: " + msg[0];
|
||||
else msg[1] = "[" + DateTime.Now.ToString(CultureInfo.InvariantCulture) + "]: " + msg[1];
|
||||
LogNoTime(msg);
|
||||
}
|
||||
|
||||
public void LogNoTime(params string[] msg)
|
||||
{
|
||||
lock (Logfile) if (!IsEnabled) return;
|
||||
lock (statelocker) if (!IsEnabled) return;
|
||||
msg[msg.Length - 1] += '\n';
|
||||
ColoredConsole.Write(msg);
|
||||
if (WriteToFile)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user