Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiningRush committed Nov 18, 2017
1 parent b529bf9 commit d4a27f0
Show file tree
Hide file tree
Showing 28 changed files with 403 additions and 176 deletions.
16 changes: 8 additions & 8 deletions ServiceAnt.sln
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.8
VisualStudioVersion = 15.0.26730.16
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{0E041832-D5A5-4220-BD7D-95B03E66FF98}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{BDFDFA2C-DA6F-4405-B7B0-31D1B0997150}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServiceAnt", "src\ServiceAnt\ServiceAnt.csproj", "{DAB39FAA-15AB-4234-89BB-5C95892C23B1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceAnt.test", "test\ServiceAnt.test\ServiceAnt.test.csproj", "{C1990ED7-2C77-453E-BFE3-5F43E1654CF0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceAnt", "src\ServiceAnt\ServiceAnt.csproj", "{FB6688E2-094A-4D25-9EEA-85C3B7CCC4A2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DAB39FAA-15AB-4234-89BB-5C95892C23B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DAB39FAA-15AB-4234-89BB-5C95892C23B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DAB39FAA-15AB-4234-89BB-5C95892C23B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DAB39FAA-15AB-4234-89BB-5C95892C23B1}.Release|Any CPU.Build.0 = Release|Any CPU
{C1990ED7-2C77-453E-BFE3-5F43E1654CF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C1990ED7-2C77-453E-BFE3-5F43E1654CF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C1990ED7-2C77-453E-BFE3-5F43E1654CF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C1990ED7-2C77-453E-BFE3-5F43E1654CF0}.Release|Any CPU.Build.0 = Release|Any CPU
{FB6688E2-094A-4D25-9EEA-85C3B7CCC4A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FB6688E2-094A-4D25-9EEA-85C3B7CCC4A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB6688E2-094A-4D25-9EEA-85C3B7CCC4A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB6688E2-094A-4D25-9EEA-85C3B7CCC4A2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{DAB39FAA-15AB-4234-89BB-5C95892C23B1} = {0E041832-D5A5-4220-BD7D-95B03E66FF98}
{C1990ED7-2C77-453E-BFE3-5F43E1654CF0} = {BDFDFA2C-DA6F-4405-B7B0-31D1B0997150}
{FB6688E2-094A-4D25-9EEA-85C3B7CCC4A2} = {0E041832-D5A5-4220-BD7D-95B03E66FF98}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {52E5EADF-2B54-4C50-BF32-93550974966D}
Expand Down
11 changes: 11 additions & 0 deletions src/ServiceAnt/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ServiceAnt
{
public class Class1
{
}
}
17 changes: 17 additions & 0 deletions src/ServiceAnt/Common/Extension/ObjectExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace ServiceAnt.Common.Extension
{
public static class ObjectExtension
{
public static void Locking<T>(this T @this, Action<T> action)
{
lock (@this)
{
action(@this);
}
}
}
}
18 changes: 1 addition & 17 deletions src/ServiceAnt/Handler/IHandler.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace YiBan.Common.BaseAbpModule.Events.Abstractions
namespace ServiceAnt.Handler
{
public interface IHandler
{
}

public interface IEventHandler<TEvent> : IHandler where TEvent : IntegrationEvent
{
Task HandleAsync(TEvent param);
}

public interface IDynamicEventHandler : IHandler
{
Task HandleAsync(dynamic param);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Text;
using System.Threading.Tasks;

namespace YiBan.Common.BaseAbpModule.Events.Abstractions
namespace ServiceAnt.Handler
{
public interface IHandlerFactory
{
Expand Down
8 changes: 2 additions & 6 deletions src/ServiceAnt/Handler/IocHandlerFactory.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using Abp.Dependency;
using ServiceAnt.Handler;
using ServiceAnt.Infrastructure.Dependency;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YiBan.Common.BaseAbpModule.Events.Abstractions;

namespace YiBan.Common.BaseAbpModule.Events
{
Expand Down
7 changes: 1 addition & 6 deletions src/ServiceAnt/Handler/SingletonHandlerFactory.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YiBan.Common.BaseAbpModule.Events.Abstractions;

namespace YiBan.Common.BaseAbpModule.Events
namespace ServiceAnt.Handler
{
public class SingletonHandlerFactory : IHandlerFactory
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
using System.Text;
using System.Threading.Tasks;

namespace YiBan.Common.BaseAbpModule.Events.Abstractions
namespace ServiceAnt.Handler
{
public class IntegrationEvent
public class TransportTray
{
public IntegrationEvent()
public TransportTray()
{
Id = Guid.NewGuid();
CreationDate = DateTime.UtcNow;
Expand All @@ -18,11 +18,11 @@ public IntegrationEvent()
public DateTime CreationDate { get; }
}

public class IntegrationEvent<TEntity> : IntegrationEvent
public class TransportTray<TEntity> : TransportTray
{
public TEntity TransportEntity { get; set; }

public IntegrationEvent(TEntity entity) : base()
public TransportTray(TEntity entity) : base()
{
TransportEntity = entity;
}
Expand Down
17 changes: 0 additions & 17 deletions src/ServiceAnt/IEventBus.cs

This file was deleted.

16 changes: 16 additions & 0 deletions src/ServiceAnt/IServiceBus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using ServiceAnt.Handler;
using ServiceAnt.Handler.Request;
using ServiceAnt.Subscription;
using System.Threading.Tasks;

namespace ServiceAnt
{
public interface IServiceBus : IAddSubscription, IAddRequestHandler
{
void Publish(TransportTray @event);

T Send<T>(TransportTray @event);

Task<T> SendAsync<T>(TransportTray @event);
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
using Abp.Dependency;
using Castle.Core.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using ServiceAnt.Handler;
using ServiceAnt.Handler.Request;
using ServiceAnt.Handler.Request.Handler;
using ServiceAnt.Handler.Subscription.Handler;
using ServiceAnt.Infrastructure.Log;
using ServiceAnt.Subscription;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using YiBan.Common.BaseAbpModule.Events.Abstractions;

namespace YiBan.Common.BaseAbpModule.Events
namespace ServiceAnt
{
public class InProcessEventBus : IEventBus
public class InProcessServiceBus : IServiceBus
{
private ISubscriptionManager _subcriptionManager;
private IRequestHandlerManager _requestHandlerManager;

public ILogger Logger { get; set; }

public InProcessEventBus()
public InProcessServiceBus()
{
_subcriptionManager = new InMemorySubscriptionsManager();
_requestHandlerManager = new InMemoryRequestHandlerManager();
Logger = NullLogger.Instance;
//Logger = NullLogger.Instance;
}

public InProcessEventBus(ISubscriptionManager subcriptionManager)
public InProcessServiceBus(ISubscriptionManager subcriptionManager)
{
_subcriptionManager = subcriptionManager;
}
Expand All @@ -44,12 +43,12 @@ public void AddSubScription(Type eventType, IHandlerFactory factory)
_subcriptionManager.AddSubScription(eventType, factory);
}

public void AddSubScription<TEvent>(Func<TEvent, Task> action) where TEvent : IntegrationEvent
public void AddSubScription<TEvent>(Func<TEvent, Task> action) where TEvent : TransportTray
{
_subcriptionManager.AddSubScription<TEvent>(action);
}

public void AddSubScription<TEvent>(IHandlerFactory factory) where TEvent : IntegrationEvent
public void AddSubScription<TEvent>(IHandlerFactory factory) where TEvent : TransportTray
{
_subcriptionManager.AddSubScription<TEvent>(factory);
}
Expand All @@ -59,12 +58,12 @@ public void RemoveDynamicSubscription(string eventName, Func<dynamic, Task> acti
_subcriptionManager.RemoveDynamicSubscription(eventName, action);
}

public void RemoveSubscription<TEvent>(Func<TEvent, Task> action) where TEvent : IntegrationEvent
public void RemoveSubscription<TEvent>(Func<TEvent, Task> action) where TEvent : TransportTray
{
_subcriptionManager.RemoveSubscription<TEvent>(action);
}

public void Publish(IntegrationEvent @event)
public void Publish(TransportTray @event)
{
var asyncTask = ProcessEvent(_subcriptionManager.GetEventName(@event.GetType()), JsonConvert.SerializeObject(@event));
}
Expand All @@ -73,7 +72,7 @@ public void Publish(IntegrationEvent @event)
/// It's for Unit test
/// </summary>
/// <param name="event"></param>
public void PublishSync(IntegrationEvent @event)
public void PublishSync(TransportTray @event)
{
var asyncTask = ProcessEvent(_subcriptionManager.GetEventName(@event.GetType()), JsonConvert.SerializeObject(@event));
asyncTask.Wait();
Expand Down Expand Up @@ -122,13 +121,13 @@ public void AddRequestHandler(Type eventType, IHandlerFactory factory)
}

public void AddRequestHandler<TEvent>(IHandlerFactory factory)
where TEvent : IntegrationEvent
where TEvent : TransportTray
{
_requestHandlerManager.AddRequestHandler<TEvent>(factory);
}

public void AddRequestHandler<TEvent>(Func<TEvent, IRequestHandlerContext, Task> action)
where TEvent : IntegrationEvent
where TEvent : TransportTray
{
_requestHandlerManager.AddRequestHandler<TEvent>(action);
}
Expand All @@ -140,7 +139,7 @@ public void AddDynamicRequestHandler(string eventName, Func<dynamic, IRequestHan


public void RemoveRequestHandler<TEvent>(Func<TEvent, IRequestHandlerContext, Task> action)
where TEvent : IntegrationEvent
where TEvent : TransportTray
{
_requestHandlerManager.RemoveRequestHandler(action);
}
Expand All @@ -149,14 +148,14 @@ public void RemoveDynamicRequestHandler(string eventName, Func<dynamic, IRequest
_requestHandlerManager.RemoveDynamicRequestHandler(eventName, action);
}

public T Send<T>(IntegrationEvent @event)
public T Send<T>(TransportTray @event)
{
var asyncTask = ProcessRequest<T>(_requestHandlerManager.GetRequestName(@event.GetType()), JsonConvert.SerializeObject(@event));
asyncTask.ConfigureAwait(false);
return asyncTask.Result;
}

public async Task<T> SendAsync<T>(IntegrationEvent @event)
public async Task<T> SendAsync<T>(TransportTray @event)
{
return await ProcessRequest<T>(_requestHandlerManager.GetRequestName(@event.GetType()), JsonConvert.SerializeObject(@event));
}
Expand Down
Loading

0 comments on commit d4a27f0

Please sign in to comment.