Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
丁松杰
/
Pole
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
88875948
authored
Feb 24, 2020
by
dingsongjie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复 bug
parent
4ffee379
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
42 additions
and
16 deletions
samples/apis/Backet.Api/Domain/AggregatesModel/BacketAggregate/Backet.cs → samples/apis/Backet.Api/Domain/AggregatesModels/BacketAggregate/Backet.cs
samples/apis/Backet.Api/Domain/AggregatesModel/BacketAggregate/BacketItem.cs → samples/apis/Backet.Api/Domain/AggregatesModels/BacketAggregate/BacketItem.cs
samples/apis/Backet.Api/Domain/Event/BacketCreatedEvent.cs → samples/apis/Backet.Api/Domain/Events/BacketCreatedEvent.cs
src/Pole.Core/EventBus/Event/EventAttribute.cs → src/Pole.Core/EventBus/Event/EventInfoAttribute.cs
src/Pole.Core/EventBus/ObserverUnitContainer.cs
src/Pole.Core/Serialization/EventTypeFinder.cs
src/Pole.EventBus.Rabbitmq/Core/EventBusContainer.cs
samples/apis/Backet.Api/Domain/AggregatesModel/BacketAggregate/Backet.cs
→
samples/apis/Backet.Api/Domain/AggregatesModel
s
/BacketAggregate/Backet.cs
View file @
88875948
File moved
samples/apis/Backet.Api/Domain/AggregatesModel/BacketAggregate/BacketItem.cs
→
samples/apis/Backet.Api/Domain/AggregatesModel
s
/BacketAggregate/BacketItem.cs
View file @
88875948
File moved
samples/apis/Backet.Api/Domain/Event/BacketCreatedEvent.cs
→
samples/apis/Backet.Api/Domain/Event
s
/BacketCreatedEvent.cs
View file @
88875948
...
...
@@ -2,11 +2,13 @@
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Reflection
;
using
System.Threading.Tasks
;
namespace
Backet.Api.Domain.Event
{
public
class
BacketCreatedEvent
:
IEvent
[
EventInfo
(
EventName
=
"Backet"
)]
public
class
BacketCreatedEvent
:
IEvent
{
public
string
BacketId
{
get
;
set
;
}
}
...
...
src/Pole.Core/EventBus/Event/EventAttribute.cs
→
src/Pole.Core/EventBus/Event/Event
Info
Attribute.cs
View file @
88875948
...
...
@@ -5,7 +5,7 @@ using System.Text;
namespace
Pole.Core.EventBus.Event
{
[
AttributeUsage
(
AttributeTargets
.
Class
)]
public
class
EventAttribute
:
Attribute
public
class
Event
Info
Attribute
:
Attribute
{
public
string
EventName
{
get
;
set
;
}
}
...
...
src/Pole.Core/EventBus/ObserverUnitContainer.cs
View file @
88875948
...
...
@@ -8,6 +8,7 @@ using Microsoft.Extensions.DependencyInjection;
using
Pole.Core.EventBus.EventHandler
;
using
System.Linq
;
using
Pole.Core.Exceptions
;
using
Pole.Core.EventBus.Event
;
namespace
Pole.Core.EventBus
{
...
...
@@ -16,17 +17,28 @@ namespace Pole.Core.EventBus
readonly
ConcurrentDictionary
<
string
,
List
<
object
>>
unitDict
=
new
ConcurrentDictionary
<
string
,
List
<
object
>>();
public
ObserverUnitContainer
(
IServiceProvider
serviceProvider
)
{
var
eventHandlerList
=
new
List
<(
Type
,
Event
Handler
Attribute
)>();
var
eventHandlerList
=
new
List
<(
Type
,
Event
Info
Attribute
)>();
foreach
(
var
assembly
in
AssemblyHelper
.
GetAssemblies
(
serviceProvider
.
GetService
<
ILogger
<
ObserverUnitContainer
>>()))
{
foreach
(
var
type
in
assembly
.
GetTypes
().
Where
(
m
=>
typeof
(
IPoleEventHandler
).
IsAssignableFrom
(
m
)
&&
m
.
IsClass
&&
!
m
.
IsAbstract
&&
!
typeof
(
Orleans
.
Runtime
.
GrainReference
).
IsAssignableFrom
(
m
)))
{
var
attribute
=
type
.
GetCustomAttributes
(
typeof
(
EventHandlerAttribute
),
false
).
FirstOrDefault
();
var
eventHandlerInterface
=
type
.
GetInterfaces
().
FirstOrDefault
(
type
=>
typeof
(
IPoleEventHandler
).
IsAssignableFrom
(
type
)
&&
!
type
.
IsGenericType
);
var
basePoleEventHandlerInterface
=
eventHandlerInterface
.
GetInterfaces
().
FirstOrDefault
(
m
=>
m
.
IsGenericType
);
if
(
basePoleEventHandlerInterface
==
null
)
{
throw
new
PoleEventHandlerImplementException
(
"PoleEventHandler interface must Inherited from IPoleEventHandler<TEvent>"
);
}
var
eventType
=
basePoleEventHandlerInterface
.
GetGenericArguments
().
FirstOrDefault
();
if
(
eventType
==
null
)
{
throw
new
PoleEventHandlerImplementException
(
"PoleEventHandler interface must Inherited from IPoleEventHandler<TEvent>"
);
}
var
attribute
=
eventType
.
GetCustomAttributes
(
typeof
(
EventInfoAttribute
),
false
).
FirstOrDefault
();
if
(
attribute
!=
null
)
{
eventHandlerList
.
Add
((
eventHandlerInterface
,
(
Event
Handler
Attribute
)
attribute
));
eventHandlerList
.
Add
((
eventHandlerInterface
,
(
Event
Info
Attribute
)
attribute
));
}
else
{
...
...
src/Pole.Core/Serialization/EventTypeFinder.cs
View file @
88875948
...
...
@@ -25,8 +25,8 @@ namespace Pole.Core.Serialization
foreach
(
var
type
in
assembly
.
GetTypes
().
Where
(
m
=>
baseEventType
.
IsAssignableFrom
(
m
)&&!
m
.
IsAbstract
))
{
var
eventCode
=
type
.
FullName
;
var
eventAttribute
=
type
.
GetCustomAttributes
(
typeof
(
EventAttribute
),
false
).
FirstOrDefault
();
if
(
eventAttribute
is
EventAttribute
attribute
)
var
eventAttribute
=
type
.
GetCustomAttributes
(
typeof
(
Event
Info
Attribute
),
false
).
FirstOrDefault
();
if
(
eventAttribute
is
Event
Info
Attribute
attribute
)
{
eventCode
=
attribute
.
EventName
;
}
...
...
src/Pole.EventBus.Rabbitmq/Core/EventBusContainer.cs
View file @
88875948
...
...
@@ -38,8 +38,8 @@ namespace Pole.EventBus.RabbitMQ
}
public
async
Task
AutoRegister
()
{
var
eventList
=
new
List
<(
Type
type
,
EventAttribute
config
)>();
var
evenHandlertList
=
new
List
<(
Type
type
,
Event
Handler
Attribute
config
)>();
var
eventList
=
new
List
<(
Type
type
,
Event
Info
Attribute
config
)>();
var
evenHandlertList
=
new
List
<(
Type
type
,
Event
Info
Attribute
config
)>();
AddEventAndEventHandlerInfoList
(
eventList
,
evenHandlertList
);
foreach
(
var
(
type
,
config
)
in
eventList
)
{
...
...
@@ -110,21 +110,21 @@ namespace Pole.EventBus.RabbitMQ
#
region
helpers
private
void
AddEventAndEventHandlerInfoList
(
List
<(
Type
type
,
Event
Attribute
config
)>
eventList
,
List
<(
Type
type
,
EventHandler
Attribute
config
)>
eventHandlertList
)
private
void
AddEventAndEventHandlerInfoList
(
List
<(
Type
type
,
Event
InfoAttribute
config
)>
eventList
,
List
<(
Type
type
,
EventInfo
Attribute
config
)>
eventHandlertList
)
{
foreach
(
var
assembly
in
AssemblyHelper
.
GetAssemblies
(
serviceProvider
.
GetService
<
ILogger
<
EventBusContainer
>>()))
{
foreach
(
var
type
in
assembly
.
GetTypes
().
Where
(
m
=>
typeof
(
IEvent
).
IsAssignableFrom
(
m
)
&&
m
.
IsClass
))
{
var
attribute
=
type
.
GetCustomAttributes
(
typeof
(
EventAttribute
),
false
).
FirstOrDefault
();
var
attribute
=
type
.
GetCustomAttributes
(
typeof
(
Event
Info
Attribute
),
false
).
FirstOrDefault
();
if
(
attribute
!=
null
)
{
eventList
.
Add
((
type
,
(
EventAttribute
)
attribute
));
eventList
.
Add
((
type
,
(
Event
Info
Attribute
)
attribute
));
}
else
{
eventList
.
Add
((
type
,
new
EventAttribute
()
{
EventName
=
type
.
FullName
}));
eventList
.
Add
((
type
,
new
Event
Info
Attribute
()
{
EventName
=
type
.
FullName
}));
}
}
}
...
...
@@ -132,13 +132,25 @@ namespace Pole.EventBus.RabbitMQ
foreach
(
var
assembly
in
AssemblyHelper
.
GetAssemblies
(
serviceProvider
.
GetService
<
ILogger
<
EventBusContainer
>>()))
{
foreach
(
var
type
in
assembly
.
GetTypes
().
Where
(
m
=>
typeof
(
IPoleEventHandler
).
IsAssignableFrom
(
m
)
&&
m
.
IsClass
&&
!
m
.
IsAbstract
&&
!
typeof
(
Orleans
.
Runtime
.
GrainReference
).
IsAssignableFrom
(
m
)))
foreach
(
var
type
in
assembly
.
GetTypes
().
Where
(
m
=>
typeof
(
IPoleEventHandler
).
IsAssignableFrom
(
m
)
&&
m
.
IsClass
&&
!
m
.
IsAbstract
&&
!
typeof
(
Orleans
.
Runtime
.
GrainReference
).
IsAssignableFrom
(
m
)))
{
var
attribute
=
type
.
GetCustomAttributes
(
typeof
(
EventHandlerAttribute
),
false
).
FirstOrDefault
();
var
eventHandlerInterface
=
type
.
GetInterfaces
().
FirstOrDefault
(
type
=>
typeof
(
IPoleEventHandler
).
IsAssignableFrom
(
type
)
&&
!
type
.
IsGenericType
);
var
basePoleEventHandlerInterface
=
eventHandlerInterface
.
GetInterfaces
().
FirstOrDefault
(
m
=>
m
.
IsGenericType
);
if
(
basePoleEventHandlerInterface
==
null
)
{
throw
new
PoleEventHandlerImplementException
(
"PoleEventHandler interface must Inherited from IPoleEventHandler<TEvent>"
);
}
var
eventType
=
basePoleEventHandlerInterface
.
GetGenericArguments
().
FirstOrDefault
();
if
(
eventType
==
null
)
{
throw
new
PoleEventHandlerImplementException
(
"PoleEventHandler interface must Inherited from IPoleEventHandler<TEvent>"
);
}
var
attribute
=
eventType
.
GetCustomAttributes
(
typeof
(
EventInfoAttribute
),
false
).
FirstOrDefault
();
if
(
attribute
!=
null
)
{
eventHandlertList
.
Add
((
type
,
(
EventHandler
Attribute
)
attribute
));
eventHandlertList
.
Add
((
eventHandlerInterface
,
(
EventInfo
Attribute
)
attribute
));
}
else
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment