diff --git a/Platform/Platform.Helpers/ILGeneratorExtensions.cs b/Platform/Platform.Helpers/ILGeneratorExtensions.cs index d76d220d..1ed4a556 100644 --- a/Platform/Platform.Helpers/ILGeneratorExtensions.cs +++ b/Platform/Platform.Helpers/ILGeneratorExtensions.cs @@ -14,13 +14,9 @@ public static void EmitJumpTo(this ILGenerator il, Label label) public static void EmitCall(this ILGenerator il, MethodInfo method) { if (method.IsFinal || !method.IsVirtual) - { il.EmitCall(OpCodes.Call, method, null); - } else - { il.EmitCall(OpCodes.Callvirt, method, null); - } } public static void EmitLiteralLoad(this ILGenerator il, int value) diff --git a/Platform/Platform.Helpers/RandomExtensions.cs b/Platform/Platform.Helpers/RandomExtensions.cs index 35be96d7..c4d8cd0b 100644 --- a/Platform/Platform.Helpers/RandomExtensions.cs +++ b/Platform/Platform.Helpers/RandomExtensions.cs @@ -4,17 +4,7 @@ namespace Platform.Helpers { public static class RandomExtensions { - public static ulong NextUInt64(this Random rnd) - { - return rnd.NextUInt64(UInt64.MaxValue); - } - - public static ulong NextUInt64(this Random rnd, ulong maxValue) - { - return rnd.NextUInt64(UInt64.MinValue, maxValue); - } - - public static ulong NextUInt64(this Random rnd, ulong minValue, ulong maxValue) + public static ulong NextUInt64(this Random rnd, ulong minValue = ulong.MinValue, ulong maxValue = ulong.MaxValue) { if (minValue >= maxValue) return minValue; diff --git a/Platform/Platform.Helpers/SerializationHelpers.cs b/Platform/Platform.Helpers/SerializationHelpers.cs index 8578e7cf..188026d1 100644 --- a/Platform/Platform.Helpers/SerializationHelpers.cs +++ b/Platform/Platform.Helpers/SerializationHelpers.cs @@ -17,31 +17,22 @@ static XmlSerializer GetOrAddXmlSerializer() public static T DeserializeFromXml(string xmlString) { - var serializer = GetOrAddXmlSerializer(); using (var reader = new StringReader(xmlString)) - return (T)serializer.Deserialize(reader); + return (T)GetOrAddXmlSerializer().Deserialize(reader); } public static void SerializeToFile(string path, T obj) { - var serializer = GetOrAddXmlSerializer(); using (var fileStream = File.Open(path, FileMode.Create)) - { - serializer.Serialize(fileStream, obj); - fileStream.Flush(); - } + GetOrAddXmlSerializer().Serialize(fileStream, obj); } public static string SerializeAsXmlString(T obj) { - var serializer = GetOrAddXmlSerializer(); var sb = new StringBuilder(); using (var writer = new StringWriter(sb)) - { - serializer.Serialize(writer, obj); - writer.Flush(); - return sb.ToString(); - } + GetOrAddXmlSerializer().Serialize(writer, obj); + return sb.ToString(); } } } diff --git a/Platform/Platform.Helpers/project.json b/Platform/Platform.Helpers/project.json index 6e4427dc..128bc2ea 100644 --- a/Platform/Platform.Helpers/project.json +++ b/Platform/Platform.Helpers/project.json @@ -1,5 +1,5 @@ { - "version": "0.0.7-*", + "version": "0.0.8-*", "description": "LinksPlatform's Platform.Helpers Class Library", "authors": [ "Konstantin Diachenko" ], "tags": [ "Helpers", "Utilities", "Extensions" ], diff --git a/Platform/Platform.Memory/HeapResizableDirectMemory.cs b/Platform/Platform.Memory/HeapResizableDirectMemory.cs index 0b15c3a2..47475078 100644 --- a/Platform/Platform.Memory/HeapResizableDirectMemory.cs +++ b/Platform/Platform.Memory/HeapResizableDirectMemory.cs @@ -1,5 +1,5 @@ using System; -using Platform.WindowsAPI; +using System.Runtime.InteropServices; namespace Platform.Memory { @@ -8,7 +8,7 @@ namespace Platform.Memory /// /// /// TODO: Реализовать вариант с Virtual Memory - /// TODO: После использования WinApi подумать над реализацией под Mono + /// TODO: Test on Unix /// public unsafe class HeapResizableDirectMemory : ResizableDirectMemoryBase { @@ -30,7 +30,10 @@ public HeapResizableDirectMemory() protected override void OnReservedCapacityChanged(long oldReservedCapacity, long newReservedCapacity) { - Pointer = Pointer == null ? Kernel32.HeapAlloc(newReservedCapacity) : Kernel32.HeapReAlloc(Pointer, newReservedCapacity); + // + Pointer = Pointer == null + ? Marshal.AllocHGlobal(new IntPtr(newReservedCapacity)).ToPointer() + : Marshal.ReAllocHGlobal(new IntPtr(Pointer), new IntPtr(newReservedCapacity)).ToPointer(); } #endregion @@ -39,7 +42,7 @@ protected override void OnReservedCapacityChanged(long oldReservedCapacity, long protected override void DisposePointer(void* pointer, long size) { - Kernel32.HeapFree(pointer); + Marshal.FreeHGlobal(new IntPtr(pointer)); } protected override void EnsureNotDisposed() diff --git a/Platform/Platform.Memory/project.json b/Platform/Platform.Memory/project.json index 6b06f3de..09f71a88 100644 --- a/Platform/Platform.Memory/project.json +++ b/Platform/Platform.Memory/project.json @@ -1,5 +1,5 @@ { - "version": "0.0.8-*", + "version": "0.0.9-*", "description": "LinksPlatform's Platform.Memory Class Library", "authors": [ "Konstantin Diachenko" ], "tags": [ "Memory Mapped Files", "Storage", "Memory" ], @@ -11,8 +11,7 @@ "compilationOptions": { "allowUnsafe": true }, "dependencies": { - "Platform.Helpers": "0.0.7-*", - "Platform.WindowsAPI": "0.0.5-*" + "Platform.Helpers": "0.0.8-*" }, "frameworks": { diff --git a/Platform/Platform.Sandbox/NetParser.cs b/Platform/Platform.Sandbox/NetParser.cs index 6adf3849..f4d7046d 100644 --- a/Platform/Platform.Sandbox/NetParser.cs +++ b/Platform/Platform.Sandbox/NetParser.cs @@ -3,6 +3,9 @@ namespace Platform.Sandbox { + /// + /// Use PEG instead. + /// public class NetParser { const string StatementTermPart = @"((?\w+)|""(?[^""]+)""):"; diff --git a/Platform/Platform.Tests/Data.Core/LinksMemoryManagerTests.cs b/Platform/Platform.Tests/Data.Core/LinksMemoryManagerTests.cs index 8c6e16c0..41fade1d 100644 --- a/Platform/Platform.Tests/Data.Core/LinksMemoryManagerTests.cs +++ b/Platform/Platform.Tests/Data.Core/LinksMemoryManagerTests.cs @@ -5,31 +5,31 @@ namespace Platform.Tests.Data.Core { - public class LinksMemoryManagerTests + public static class LinksMemoryManagerTests { [Fact] - public void BasicMemoryTest() + public static void BasicFileMappedMemoryTest() { var tempFilename = Path.GetTempFileName(); using (var memoryManager = new LinksMemoryManager(tempFilename)) - { - var link = memoryManager.AllocateLink(); - memoryManager.FreeLink(link); - } + memoryManager.TestBasicMemoryOperations(); File.Delete(tempFilename); } [Fact] - public void HeapMemorySupportTest() + public static void BasicHeapMemoryTest() { using (var memory = new HeapResizableDirectMemory(LinksMemoryManager.DefaultLinksSizeStep)) using (var memoryManager = new LinksMemoryManager(memory, LinksMemoryManager.DefaultLinksSizeStep)) - { - var link = memoryManager.AllocateLink(); - memoryManager.FreeLink(link); - } + memoryManager.TestBasicMemoryOperations(); + } + + private static void TestBasicMemoryOperations(this ILinksMemoryManager memoryManager) + { + var link = memoryManager.AllocateLink(); + memoryManager.FreeLink(link); } } } diff --git a/Platform/Platform.Tests/Helpers/MathHelpersTests.cs b/Platform/Platform.Tests/Helpers/MathHelpersTests.cs new file mode 100644 index 00000000..cf4cdedf --- /dev/null +++ b/Platform/Platform.Tests/Helpers/MathHelpersTests.cs @@ -0,0 +1,18 @@ +using Platform.Helpers; +using Xunit; + +namespace Platform.Tests.Helpers +{ + public class MathHelpersTests + { + [Theory] + [InlineData(00, -1)] // 0000 0000 (none, -1) + [InlineData(01, 00)] // 0000 0001 (first, 0) + [InlineData(08, 03)] // 0000 1000 (forth, 3) + [InlineData(88, 03)] // 0101 1000 (forth, 3) + public void GetLowestBitPosition(ulong value, int expectedPosition) + { + Assert.True(MathHelpers.GetLowestBitPosition(value) == expectedPosition); + } + } +} diff --git a/Platform/Platform.Tests/Helpers/SerializationHelpersTests.cs b/Platform/Platform.Tests/Helpers/SerializationHelpersTests.cs new file mode 100644 index 00000000..1b4e520c --- /dev/null +++ b/Platform/Platform.Tests/Helpers/SerializationHelpersTests.cs @@ -0,0 +1,28 @@ +using System.IO; +using Platform.Helpers; +using Xunit; + +namespace Platform.Tests.Helpers +{ + public class SerializationHelpersTests + { + [Fact] + public void SerializeToFileTest() + { + var tempFilename = Path.GetTempFileName(); + + SerializationHelpers.SerializeToFile(tempFilename, new object()); + + Assert.True(File.ReadAllText(tempFilename) == "\r\n"); + + File.Delete(tempFilename); + } + + [Fact] + public void SerializeAsXmlStringTest() + { + var serializedObject = SerializationHelpers.SerializeAsXmlString(new object()); + Assert.True(serializedObject == "\r\n"); + } + } +} diff --git a/Platform/Platform.Tests/project.json b/Platform/Platform.Tests/project.json index a95894ea..9b976934 100644 --- a/Platform/Platform.Tests/project.json +++ b/Platform/Platform.Tests/project.json @@ -1,5 +1,5 @@ { - "version": "0.0.8-*", + "version": "0.0.9-*", "description": "LinksPlatform's Platform.Tests Class Library", "authors": [ "Konstantin Diachenko" ], "tags": [ "LinksPlatform", "Tests" ], @@ -19,7 +19,7 @@ "xunit": "2.1.0", "xunit.runner.dnx": "2.1.0-rc1-build204", "Platform.Data.Core": "0.0.7-*", - "Platform.Helpers": "0.0.7-*" + "Platform.Helpers": "0.0.8-*" }, "frameworks": { diff --git a/Platform/Platform.dotnet.sln.DotSettings b/Platform/Platform.dotnet.sln.DotSettings index c68307ba..4a911566 100644 --- a/Platform/Platform.dotnet.sln.DotSettings +++ b/Platform/Platform.dotnet.sln.DotSettings @@ -1,3 +1,4 @@  CLI - CSV \ No newline at end of file + CSV + IL \ No newline at end of file