Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DefineConstants>TRACE;DEBUG;NET_CLIENT;ASYNC</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
Expand All @@ -34,8 +36,33 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual event aggregator project has been updated to 4.6, why not this proj?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This project targets .NET Client Profile framework that has been discontinued (see HERE)

<HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Threading.Tasks.Extensions, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop, Version=1.0.168.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO, Version=2.6.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.1.1.10\lib\net40\System.IO.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net" />
<Reference Include="System.Runtime, Version=2.6.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.1.1.10\lib\net40\System.Runtime.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Threading.Tasks, Version=2.6.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.1.1.10\lib\net40\System.Threading.Tasks.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -54,9 +81,17 @@
<Compile Include="Samples\BasicSample.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
4 changes: 2 additions & 2 deletions EventAggregator.Net.SampleUsage/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ static void Main(string[] args)
{

BasicSample.Run();

#if ASYNC
AsyncSample.Run();

#endif


Console.WriteLine("");
Expand Down
18 changes: 12 additions & 6 deletions EventAggregator.Net.SampleUsage/Samples/AsyncSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

namespace EventAggregatorNet.SampleUsage.Samples
{
#if ASYNC
public class AsyncSample
{
public static void Run()
{
var config = new EventAggregator.Config
{
// Make the marshaler run in the background thread
DefaultThreadMarshaler = action => Task.Factory.StartNew(action),
DefaultThreadAsyncMarshaler = async action => await Task.Factory.StartNew(action),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need the async/await pair. Task.Factory.StartNew will never throw (and the only difference async/await will make is that Run() will end up in the call stack of an exception)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be renamed back and the marshal param removed from the async send message overloads

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the async/await pair. The DefaultThreadMarshaler is still there I just added the async one as Action<> can not be awaited.

};

var eventAggregationManager = new EventAggregator(config);
Expand All @@ -24,13 +25,18 @@ public static void Run()
}


public class LongRunningHandler : IListener<SampleEventMessage>
public class LongRunningHandler : IListenerAsync<SampleEventMessage>
{
public void Handle(SampleEventMessage message)
public async Task Handle(SampleEventMessage message)
{
"LongRunningHandler - Received event".Log();
Thread.Sleep(1000);
"LongRunningHandler - Done with work".Log();
await Task.Factory.StartNew(() =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could instead write this as:

"LongRunningHandler - Received event".Log();
await TaskEx.Delay(1000);
"LongRunningHandler - Done with work".Log();

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

{
"LongRunningHandler - Received event".Log();
Thread.Sleep(1000);

"LongRunningHandler - Done with work".Log();
});
}
}
#endif
}
15 changes: 15 additions & 0 deletions EventAggregator.Net.SampleUsage/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.10.0" newVersion="2.6.10.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.10.0" newVersion="2.6.10.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
3 changes: 3 additions & 0 deletions EventAggregator.Net.SampleUsage/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EventAggregator.Net" version="0.1" />
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="net4-client" />
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net4-client" />
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net4-client" />
</packages>
48 changes: 38 additions & 10 deletions EventAggregator.Tests/EventAggregator.Net.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -10,17 +11,21 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>EventAggregatorNet.Tests</RootNamespace>
<AssemblyName>EventAggregatorNet.Tests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DefineConstants>TRACE;DEBUG;UNWRAP_EX;ASYNC</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -29,16 +34,36 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="xunit">
<HintPath>..\packages\xunit.1.8.0.1545\lib\xunit.dll</HintPath>
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.assert, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.core, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.execution.desktop, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\EventAggregator\EventAggregator.cs">
<Link>EventAggregator.cs</Link>
</Compile>
<Compile Include="..\EventAggregator\EventAggregatorExtensions.cs">
<Link>EventAggregatorExtensions.cs</Link>
</Compile>
<Compile Include="MessageInheritanceTests.cs" />
<Compile Include="SendMessageWithBaseTypeTests.cs" />
<Compile Include="EventAggregatorExtensionTests.cs" />
Expand All @@ -47,18 +72,21 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SomeMessage.cs" />
<Compile Include="SomeMessageHandler.cs" />
<Compile Include="TestHelpers\SpecificationExtensions.cs" />
<Compile Include="SpecExtensions\xUnitSpecificationExtensions.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EventAggregator\EventAggregator.Net.csproj">
<Project>{5DE30455-5DB4-418B-B655-5D903DF6966A}</Project>
<Name>EventAggregator.Net</Name>
</ProjectReference>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
44 changes: 40 additions & 4 deletions EventAggregator.Tests/EventAggregatorExtensionTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Xunit;
using System.Threading.Tasks;
using Xunit;

namespace EventAggregatorNet.Tests
{
Expand All @@ -16,8 +17,7 @@ public void Can_use_delegate_to_subscribe_to_message()
messageTrapped.ShouldNotBeNull();
}


[Fact]
[Fact]
public void Can_use_unsubscribe_from_delegate_handler()
{
var eventAggregator = new EventAggregator();
Expand All @@ -29,5 +29,41 @@ public void Can_use_unsubscribe_from_delegate_handler()

messageTrapped.ShouldBeNull();
}
}

#if ASYNC
[Fact]
public async Task Can_use_delegate_to_subscribe_to_message_async()
{
var eventAggregator = new EventAggregator();
SomeMessage messageTrapped = null;

eventAggregator.AddListenerAction<SomeMessage>(async msg =>
{
await Task.Delay(500);
messageTrapped = msg;
});
await eventAggregator.SendMessageAsync<SomeMessage>();

messageTrapped.ShouldNotBeNull();
}

[Fact]
public async Task Can_use_unsubscribe_from_delegate_handler_async()
{
var eventAggregator = new EventAggregator();
SomeMessage messageTrapped = null;

var disposable = eventAggregator.AddListenerAction<SomeMessage>(async msg =>
{
await Task.Delay(500);
messageTrapped = msg;
});
disposable.Dispose();
await eventAggregator.SendMessageAsync<SomeMessage>();

messageTrapped.ShouldBeNull();
}
#endif
}

}
Loading