Skip to content

Commit 0786bc1

Browse files
committed
finished the prototype (webapi, signalr and blazor) #15
1 parent 27e4041 commit 0786bc1

File tree

21 files changed

+569
-81
lines changed

21 files changed

+569
-81
lines changed

samples/Contracts/Project.cs

Lines changed: 316 additions & 8 deletions
Large diffs are not rendered by default.

samples/Contracts/protos/project.proto

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ package project.proto;
55
import "google/protobuf/timestamp.proto";
66

77
message ProjectCreatedMsg {
8-
string Name = 1;
9-
google.protobuf.Timestamp OccurredOn = 2;
8+
string Key = 1;
9+
string Id = 2;
10+
string Name = 3;
11+
google.protobuf.Timestamp OccurredOn = 4;
12+
}
13+
14+
message TaskCreatedMsg {
15+
string Key = 1;
16+
string Id = 2;
17+
string Title = 3;
18+
string ProjectId = 4;
19+
google.protobuf.Timestamp OccurredOn = 5;
1020
}

samples/SignalRNotifier/NetCoreKit.Samples.SignalRNotifier.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<PackageReference Include="Microsoft.AspNetCore.App" />
1111
<PackageReference Include="MediatR" Version="5.1.0" />
1212
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="5.1.0" />
13+
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Core" Version="2.1.3" />
1314
</ItemGroup>
1415

1516
<ItemGroup>

samples/SignalRNotifier/Services/Hubs/ProjectHub.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public async Task Handle(Notifications.TaskCreated notification, CancellationTok
3737

3838
protected override Task ExecuteAsync(CancellationToken cancellationToken)
3939
{
40-
_eventBus.Subscribe<ProjectCreatedMsg>("project").Wait(cancellationToken);
40+
Task.Run(() => _eventBus.Subscribe<ProjectCreatedMsg>("project-created"), cancellationToken);
41+
Task.Run(() => _eventBus.Subscribe<TaskCreatedMsg>("task-created"), cancellationToken);
4142
return Task.CompletedTask;
4243
}
4344
}

samples/SignalRNotifier/Services/Notifications/ProjectCreated.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace NetCoreKit.Samples.SignalRNotifier.Services.Notifications
55
{
66
public class ProjectCreated : INotification
77
{
8+
public Guid Id { get; set; }
89
public string Name { get; set; }
910
public DateTime OccurredOn { get; set; }
1011
}

samples/SignalRNotifier/Services/Notifications/TaskCreated.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ namespace NetCoreKit.Samples.SignalRNotifier.Services.Notifications
55
{
66
public class TaskCreated : INotification
77
{
8+
public Guid Id { get; set; }
89
public string Title { get; set; }
10+
public Guid ProjectId { get; set; }
911
public DateTime OccurredOn { get; set; }
1012
}
1113
}
Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
using System;
12
using AutoMapper;
2-
using NetCoreKit.Infrastructure.Mappers;
3+
using MediatR;
34
using Project.Proto;
45

56
namespace NetCoreKit.Samples.SignalRNotifier.Services.Profiles
@@ -8,8 +9,18 @@ public class ProjectProfile : Profile
89
{
910
public ProjectProfile()
1011
{
11-
this.MapToNotification<ProjectCreatedMsg, Notifications.ProjectCreated>();
12-
//this.MapToNotification<TaskCreated, Notifications.TaskCreated>();
12+
// this.MapToNotification<ProjectCreatedMsg, Notifications.ProjectCreated>();
13+
CreateMap<TaskCreatedMsg, Notifications.TaskCreated>()
14+
.ForMember(x => x.Id, conf => conf.MapFrom(cg => new Guid(cg.Id)))
15+
.ForMember(x => x.ProjectId, conf => conf.MapFrom(cg => new Guid(cg.ProjectId)))
16+
.ForMember(x => x.OccurredOn, conf => conf.MapFrom(cg => cg.OccurredOn.ToDateTime()));
17+
18+
CreateMap<ProjectCreatedMsg, Notifications.ProjectCreated>()
19+
.ForMember(x => x.Id, conf => conf.MapFrom(cg => new Guid(cg.Id)))
20+
.ForMember(x => x.OccurredOn, conf => conf.MapFrom(cg => cg.OccurredOn.ToDateTime()));
21+
22+
// CreateMap<ProjectCreatedMsg, INotification>()
23+
// .As<Notifications.ProjectCreated>();
1324
}
1425
}
1526
}

samples/TodoApi/Domain/Project.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ private Project()
1515
private Project(string name)
1616
{
1717
Name = name;
18-
AddEvent(new ProjectCreated(name));
18+
AddEvent(new ProjectCreated(Id, name));
1919
}
2020

2121
public string Name { get; private set; }
@@ -35,7 +35,7 @@ public Project ChangeName(string name)
3535
public Project AddTask(Task task)
3636
{
3737
Tasks.Add(task.SetProject(this));
38-
AddEvent(new TaskCreated(task.Title));
38+
AddEvent(new TaskCreated(task.Id, task.Title, Id));
3939
return this;
4040
}
4141

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1+
using System;
12
using MediatR;
23
using NetCoreKit.Domain;
34

45
namespace NetCoreKit.Samples.TodoAPI.Domain
56
{
67
public class ProjectCreated : EventBase, INotification
78
{
8-
public ProjectCreated(string name)
9+
public ProjectCreated(Guid id, string name)
910
{
11+
Id = id;
1012
Name = name;
1113
}
1214

15+
public Guid Id { get; }
1316
public string Name { get; }
1417
}
1518
}
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1+
using System;
12
using NetCoreKit.Domain;
23

34
namespace NetCoreKit.Samples.TodoAPI.Domain
45
{
56
public class TaskCreated : EventBase
67
{
7-
public TaskCreated(string title)
8+
public TaskCreated(Guid id, string title, Guid projectId)
89
{
10+
Id = id;
911
Title = title;
12+
ProjectId = projectId;
1013
}
14+
15+
public Guid Id { get; }
1116
public string Title { get; }
17+
public Guid ProjectId { get; }
1218
}
1319
}

0 commit comments

Comments
 (0)