Skip to content

Commit 8a708da

Browse files
authored
Merge pull request #57 from solomoto-dev/#46_smart_event_adapters
#46 smart event adapters
2 parents d166497 + ef8dd12 commit 8a708da

78 files changed

Lines changed: 1342 additions & 230 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AkkaClusterTests/AkkaClusterTests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@
8585
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
8686
<Private>True</Private>
8787
</Reference>
88-
<Reference Include="nunit.framework, Version=3.0.5797.27534, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
89-
<HintPath>..\packages\NUnit.3.0.0\lib\net45\nunit.framework.dll</HintPath>
88+
<Reference Include="nunit.framework, Version=3.4.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
89+
<HintPath>..\packages\NUnit.3.4.1\lib\net45\nunit.framework.dll</HintPath>
9090
<Private>True</Private>
9191
</Reference>
9292
<Reference Include="System" />

AkkaClusterTests/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<package id="Google.ProtocolBuffers" version="2.4.1.555" targetFramework="net461" />
1010
<package id="Helios" version="2.1.2" targetFramework="net461" />
1111
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net461" />
12-
<package id="NUnit" version="3.0.0" targetFramework="net461" />
12+
<package id="NUnit" version="3.4.1" targetFramework="net461" />
1313
<package id="System.Collections" version="4.0.11" targetFramework="net461" />
1414
<package id="System.Collections.Immutable" version="1.1.36" targetFramework="net461" />
1515
<package id="System.Diagnostics.Debug" version="4.0.11" targetFramework="net461" />

GridDomain.Common/GridDomain.Common.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,19 @@
6565
<Compile Include="DateTimeStrategyHolder.cs" />
6666
<Compile Include="ExceptionExtensions.cs" />
6767
<Compile Include="IContainerConfiguration.cs" />
68+
<Compile Include="LegacyWireSerializer.cs" />
6869
<Compile Include="MemberNameExtractor.cs" />
6970
<Compile Include="Properties\AssemblyInfo.cs" />
7071
<Compile Include="TasksExtensions.cs" />
7172
</ItemGroup>
7273
<ItemGroup>
7374
<None Include="packages.config" />
7475
</ItemGroup>
76+
<ItemGroup>
77+
<Content Include="LegacyBinaries\LegacyWire_0.0.6.dll">
78+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
79+
</Content>
80+
</ItemGroup>
7581
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
7682
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
7783
Other similar extension points exist, see Microsoft.Common.targets.
37.5 KB
Binary file not shown.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System;
2+
using System.Globalization;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Reflection;
6+
7+
namespace GridDomain.Common
8+
{
9+
public class LegacyWireSerializer
10+
{
11+
private readonly object _serializer;
12+
private readonly MethodInfo _serializeMethod;
13+
private readonly MethodInfo _deserializeMethod;
14+
15+
public LegacyWireSerializer()
16+
{
17+
var path = Path.Combine(Path.GetDirectoryName(Assembly.GetAssembly(typeof(LegacyWireSerializer)).Location),
18+
@"LegacyBinaries\LegacyWire_0.0.6.dll");
19+
20+
if (!File.Exists(path))
21+
throw new CannotFindLegacyWireLibraryException();
22+
23+
var assembly = Assembly.LoadFile(path);
24+
25+
var options = CreateByConstructor(assembly, "Wire.SerializerOptions", new object[] { true,null,false,null});
26+
_serializer = CreateByConstructor(assembly, "Wire.Serializer", new [] {options});
27+
28+
_serializeMethod = _serializer.GetType().GetMethod("Serialize", new [] {typeof(object), typeof(Stream)});
29+
if(_serializeMethod == null)
30+
throw new MissingMethodException("Cannot find serialize method for legacy wire");
31+
32+
_deserializeMethod = _serializer.GetType().GetMethods().FirstOrDefault(m => m.Name == "Deserialize" & !m.IsGenericMethod);
33+
if (_deserializeMethod == null)
34+
throw new MissingMethodException("Cannot find deserialize method for legacy wire");
35+
}
36+
37+
private static object CreateByConstructor(Assembly assembly, string typeName, object[] parameters)
38+
{
39+
return assembly.CreateInstance(typeName,
40+
true,
41+
BindingFlags.Public | BindingFlags.Instance,
42+
null,
43+
parameters,
44+
CultureInfo.CurrentCulture,
45+
null);
46+
}
47+
48+
public object Deserialize(byte[] payload, Type type)
49+
{
50+
using (var stream = new MemoryStream(payload))
51+
return _deserializeMethod.Invoke(_serializer, new object[] { stream});
52+
}
53+
54+
public byte[] Serialize(object obj)
55+
{
56+
using (var stream = new MemoryStream())
57+
{
58+
_serializeMethod.Invoke(_serializer,new object[] { obj, stream});
59+
return stream.ToArray();
60+
}
61+
}
62+
}
63+
64+
public class CannotFindLegacyWireLibraryException : Exception
65+
{
66+
}
67+
}

GridDomain.Domain.Tests/CommandsExecution/SampleDomainCommandExecutionTests.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ namespace GridDomain.Tests.CommandsExecution
1111
{
1212
public class SampleDomainCommandExecutionTests : ExtendedNodeCommandTest
1313
{
14-
protected override TimeSpan Timeout => Debugger.IsAttached
15-
? TimeSpan.FromMinutes(10)
16-
: TimeSpan.FromSeconds(5);
17-
14+
protected override TimeSpan Timeout => TimeSpan.FromSeconds(5);
1815
protected override IContainerConfiguration CreateConfiguration()
1916
{
2017
return new SampleDomainContainerConfiguration();

GridDomain.Domain.Tests/EventsUpgrade/BalanceChangedDomainEventAdapter1.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System.Collections.Generic;
2-
using GridDomain.EventSourcing.DomainEventAdapters;
2+
using GridDomain.EventSourcing.Adapters;
33
using GridDomain.Tests.EventsUpgrade.Domain.Events;
44

55
namespace GridDomain.Tests.EventsUpgrade

GridDomain.Domain.Tests/EventsUpgrade/Chain/DomainEventUpdater1.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System.Collections.Generic;
2-
using GridDomain.EventSourcing.DomainEventAdapters;
2+
using GridDomain.EventSourcing.Adapters;
33
using GridDomain.Tests.EventsUpgrade.Events;
44

55
namespace GridDomain.Tests.EventsUpgrade.Chain

GridDomain.Domain.Tests/EventsUpgrade/Chain/DomainEventUpdater2.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System.Collections.Generic;
2-
using GridDomain.EventSourcing.DomainEventAdapters;
2+
using GridDomain.EventSourcing.Adapters;
33
using GridDomain.Tests.EventsUpgrade.Events;
44

55
namespace GridDomain.Tests.EventsUpgrade.Chain

GridDomain.Domain.Tests/EventsUpgrade/Chain/DomainEventUpdater3.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System.Collections.Generic;
2-
using GridDomain.EventSourcing.DomainEventAdapters;
2+
using GridDomain.EventSourcing.Adapters;
33
using GridDomain.Tests.EventsUpgrade.Events;
44

55
namespace GridDomain.Tests.EventsUpgrade.Chain

0 commit comments

Comments
 (0)