Skip to content

Commit

Permalink
init first version
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiningRush committed Nov 3, 2017
1 parent b3c8d63 commit b529bf9
Show file tree
Hide file tree
Showing 24 changed files with 1,471 additions and 0 deletions.
39 changes: 39 additions & 0 deletions ServiceAnt.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.8
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
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
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}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {52E5EADF-2B54-4C50-BF32-93550974966D}
EndGlobalSection
EndGlobal
48 changes: 48 additions & 0 deletions src/ServiceAnt/ActionRequestHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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
{
public class ActionRequestHandler<TEvent> : IRequestHandler<TEvent> where TEvent : IntegrationEvent
{
private Func<TEvent, IRequestHandlerContext, Task> _action;

public ActionRequestHandler(Func<TEvent, IRequestHandlerContext, Task> action)
{
}

public Task HandleAsync(TEvent param, IRequestHandlerContext handlerContext)
{
return _action(param, handlerContext);
}

public bool IsSame(Func<TEvent, IRequestHandlerContext, Task> compareAction)
{
return compareAction == _action;
}
}

public class ActionRequestHandler : IDynamicRequestHandler
{
private Func<dynamic, IRequestHandlerContext, Task> _action;

public ActionRequestHandler(Func<dynamic, IRequestHandlerContext, Task> action)
{
_action = action;
}

public Task HandleAsync(dynamic param, IRequestHandlerContext handlerContext)
{
return _action(param, handlerContext);
}

public bool IsSame(Func<dynamic, IRequestHandlerContext, Task> compareAction)
{
return compareAction == _action;
}
}
}
49 changes: 49 additions & 0 deletions src/ServiceAnt/Handler/ActionEventHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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
{
public class ActionEventHandler<TEvent> : IEventHandler<TEvent> where TEvent : IntegrationEvent
{
private Func<TEvent, Task> _action;

public ActionEventHandler(Func<TEvent, Task> action)
{
_action = action;
}

public async Task HandleAsync(TEvent param)
{
await _action(param);
}

public bool IsSame(Func<TEvent, Task> compareAction)
{
return compareAction == _action;
}
}

public class ActionEventHandler : IDynamicEventHandler
{
private Func<dynamic, Task> _action;

public ActionEventHandler(Func<dynamic, Task> action)
{
_action = action;
}

public async Task HandleAsync(dynamic param)
{
await _action(param);
}

public bool IsSame(Func<dynamic, Task> compareAction)
{
return compareAction == _action;
}
}
}
17 changes: 17 additions & 0 deletions src/ServiceAnt/Handler/IEventHandlerFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace YiBan.Common.BaseAbpModule.Events.Abstractions
{
public interface IHandlerFactory
{
IHandler GetHandler();

Type GetLocalEventType();

void ReleaseHandler(object obj);
}
}
22 changes: 22 additions & 0 deletions src/ServiceAnt/Handler/IHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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

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

public interface IDynamicEventHandler : IHandler
{
Task HandleAsync(dynamic param);
}
}
31 changes: 31 additions & 0 deletions src/ServiceAnt/Handler/IntegrationEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace YiBan.Common.BaseAbpModule.Events.Abstractions
{
public class IntegrationEvent
{
public IntegrationEvent()
{
Id = Guid.NewGuid();
CreationDate = DateTime.UtcNow;
}

public Guid Id { get; }
public DateTime CreationDate { get; }
}

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

public IntegrationEvent(TEntity entity) : base()
{
TransportEntity = entity;
}
}

}
39 changes: 39 additions & 0 deletions src/ServiceAnt/Handler/IocHandlerFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Abp.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
{
public class IocHandlerFactory : IHandlerFactory
{
private IIocResolver _iocResolver;
private Type _handlerType;
private Type _localEventType;

public IocHandlerFactory(IIocResolver iocResolver, Type handlerType, Type localEventType)
{
_iocResolver = iocResolver;
_handlerType = handlerType;
_localEventType = localEventType;
}

public IHandler GetHandler()
{
return (IHandler)_iocResolver.Resolve(_handlerType);
}

public void ReleaseHandler(object obj)
{
_iocResolver.Release(obj);
}

public Type GetLocalEventType()
{
return _localEventType;
}
}
}
35 changes: 35 additions & 0 deletions src/ServiceAnt/Handler/SingletonHandlerFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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
{
public class SingletonHandlerFactory : IHandlerFactory
{
private IHandler _instance;
private Type _localEventType;

public SingletonHandlerFactory(IHandler instance, Type localEventType = null)
{
_instance = instance;
_localEventType = localEventType;
}

public IHandler GetHandler()
{
return _instance;
}

public Type GetLocalEventType()
{
return _localEventType;
}

public void ReleaseHandler(object obj)
{
}
}
}
17 changes: 17 additions & 0 deletions src/ServiceAnt/IEventBus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace YiBan.Common.BaseAbpModule.Events.Abstractions
{
public interface IEventBus : IAddSubscription, IAddRequestHandler
{
void Publish(IntegrationEvent @event);

T Send<T>(IntegrationEvent @event);

Task<T> SendAsync<T>(IntegrationEvent @event);
}
}
Loading

0 comments on commit b529bf9

Please sign in to comment.