Skip to content

Commit

Permalink
ut'd EventAggregator
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydmiller committed Mar 19, 2013
1 parent 162de6c commit 656a664
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 80 deletions.
1 change: 1 addition & 0 deletions src/Bottles.Services.Tests/Bottles.Services.Tests.csproj
Expand Up @@ -75,6 +75,7 @@
<Compile Include="BottleServiceFinderTester.cs" />
<Compile Include="BottleServiceRunnerTester.cs" />
<Compile Include="BottleServiceTester.cs" />
<Compile Include="Messaging\EventAggregatorTester.cs" />
<Compile Include="Messaging\MessagingHubTester.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestBootstrappers.cs" />
Expand Down
5 changes: 5 additions & 0 deletions src/Bottles.Services/Bottles.Services.csproj
Expand Up @@ -55,14 +55,19 @@
<Compile Include="..\CommonAssemblyInfo.cs">
<Link>Properties\CommonAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Messaging\EventAggregator.cs" />
<Compile Include="Messaging\IListener.cs" />
<Compile Include="Messaging\IRemoteListener.cs" />
<Compile Include="Messaging\MessagingHub.cs" />
<Compile Include="Messaging\RemoteListener.cs" />
<Compile Include="Messaging\ServiceMessage.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="BottleService.cs" />
<Compile Include="BottleServiceFinder.cs" />
<Compile Include="BottleServiceRunner.cs" />
<Compile Include="BottleServiceAggregator.cs" />
<Compile Include="Remote\Classes.cs" />
<Compile Include="Wait.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config">
Expand Down
79 changes: 1 addition & 78 deletions src/Bottles.Services/Remote/Classes.cs
Expand Up @@ -17,25 +17,7 @@ namespace Bottles.Services.Remote
*/


public class CallbackProxy : MarshalByRefObject, IRemoteListener
{
private readonly MessagingHub _listener;

public CallbackProxy(MessagingHub listener)
{
_listener = listener;
}

public void Send(string json)
{
_listener.SendJson(json);
}

public override object InitializeLifetimeService()
{
return null;
}
}

[Serializable]
public class ServicesToRun
Expand Down Expand Up @@ -78,7 +60,7 @@ public class RemoteProxy : MarshalByRefObject
{
public void Start(ServicesToRun services, MarshalByRefObject remoteListener)
{
ServiceListener.Start((IRemoteListener) remoteListener);
EventAggregator.Start((IRemoteListener) remoteListener);

// TODO -- need to run the TopShelf stuff here.
}
Expand Down Expand Up @@ -153,64 +135,5 @@ public void Dispose()
}


public interface IRemoteListener
{
void Send(string json);
}

public static class ServiceListener
{
private static readonly BlockingCollection<object> _messages;
private static IRemoteListener _remoteListener;
private static CancellationTokenSource _cancellationSource;
private static Task _task;

static ServiceListener()
{
_messages = new BlockingCollection<object>(new ConcurrentQueue<object>());
}

public static void Start(IRemoteListener remoteListener)
{
_remoteListener = remoteListener;

_cancellationSource = new CancellationTokenSource();
_task = Task.Factory.StartNew(read, _cancellationSource.Token);
_task.Start();
}

private static void read()
{
foreach (object o in _messages.GetConsumingEnumerable(_cancellationSource.Token))
{
var json = MessagingHub.ToJson(o);
_remoteListener.Send(json);
}
}

public static void Stop()
{
_cancellationSource.Cancel();
}

public static void SendMessage(string category, string message)
{
SendMessage(new ServiceMessage
{
Category = category,
Message = message
});
}

public static void SendMessage(object message)
{
_messages.Add(message);
}
}

public class ServiceMessage
{
public string Category { get; set; }
public string Message { get; set; }
}
}
4 changes: 2 additions & 2 deletions src/SampleService/Sample.cs
Expand Up @@ -63,7 +63,7 @@ public class RemoteService : IActivator, IDeactivator, IListener<TestSignal>
{
public void Activate(IEnumerable<IPackageInfo> packages, IPackageLog log)
{
ServiceListener.SendMessage(new WasStarted{Name = "RemoteService", AppDomainBase = AppDomain.CurrentDomain.BaseDirectory});
EventAggregator.SendMessage(new WasStarted{Name = "RemoteService", AppDomainBase = AppDomain.CurrentDomain.BaseDirectory});
}


Expand All @@ -75,7 +75,7 @@ public void Deactivate(IPackageLog log)

public void Receive(TestSignal message)
{
ServiceListener.SendMessage(new TestResponse{Number = message.Number});
EventAggregator.SendMessage(new TestResponse{Number = message.Number});
}
}

Expand Down

0 comments on commit 656a664

Please sign in to comment.