Compare commits

...

4 Commits

Author SHA1 Message Date
dc6776f70c Adding .vscode 2021-03-05 20:49:49 -05:00
0945ccfd12 Wip 2021-03-05 20:45:26 -05:00
e9065db23c First pass at party service 2021-03-05 19:09:42 -05:00
6f73df0fb7 Updated folder paths 2021-03-05 16:50:54 -05:00
22 changed files with 185 additions and 56 deletions

1
.gitignore vendored
View File

@ -6,7 +6,6 @@ project.lock.json
nupkg/ nupkg/
# Visual Studio Code # Visual Studio Code
.vscode
# Rider # Rider
.idea .idea

27
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,27 @@
{
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/AuroraCradle/bin/Debug/netcoreapp3.1/aurora-cradle-sharp.dll",
"args": [],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}

42
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,42 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/AuroraCradle/aurora-cradle-sharp.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/aurora-cradle-sharp.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/aurora-cradle-sharp.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}

View File

@ -21,7 +21,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\AuroraSignal\aurora-cradle-sharp.csproj" /> <ProjectReference Include="..\AuroraCradle\aurora-cradle-sharp.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -1,21 +1,17 @@
using Xunit; using Xunit;
using Aurora.Services.Signal; using Aurora.Services.Signal;
using Aurora.Cursor; using Aurora.Cursor;
using Faker;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace AuroraCradle.test
namespace AuroraSignal.test
{ {
public class CursorListTest public class CursorListTest
{ {
[Theory()] [Theory()]
[InlineData(SortDirection.Asc)] [InlineData(Aurora.Cursor.SortDirection.Asc)]
[InlineData(SortDirection.Desc)] [InlineData(Aurora.Cursor.SortDirection.Desc)]
public void CursorListSortOnStringValue(SortDirection direction) public void CursorListSortOnStringValue(Aurora.Cursor.SortDirection direction)
{ {
CursorList<Party> list = new CursorList<Party>(); CursorList<Party> list = new CursorList<Party>();
list.Add(new Party() { Name = "asdf", Id = Faker.RandomNumber.Next().ToString() }); list.Add(new Party() { Name = "asdf", Id = Faker.RandomNumber.Next().ToString() });
@ -26,7 +22,7 @@ namespace AuroraSignal.test
.WithSort(item => item.Value.Name, direction) .WithSort(item => item.Value.Name, direction)
.GetNextPage(); .GetNextPage();
if (direction == SortDirection.Desc) if (direction == Aurora.Cursor.SortDirection.Desc)
{ {
Assert.Collection<Party>(result.Result, Assert.Collection<Party>(result.Result,
item => item.Name.Equals("asdf"), item => item.Name.Equals("asdf"),
@ -149,7 +145,7 @@ namespace AuroraSignal.test
{ {
CursorResult<Party> res = cursor CursorResult<Party> res = cursor
.WithSize(10) .WithSize(10)
.WithSort(item => item.Value.Name, SortDirection.Asc) .WithSort(item => item.Value.Name, Aurora.Cursor.SortDirection.Asc)
.WithNextPageToken(pageToken) .WithNextPageToken(pageToken)
.GetNextPage(); .GetNextPage();

View File

@ -109,6 +109,13 @@ namespace Aurora.Cursor
return this; return this;
} }
public Cursor<T> WithSort(string key, SortDirection direction)
{
this._sortDelgate = (item) => key;
this._direction = direction;
return this;
}
public Cursor<T> WithSize(int size) public Cursor<T> WithSize(int size)
{ {
this._pageSize = size; this._pageSize = size;

View File

@ -17,8 +17,13 @@ namespace Aurora.Cursor
public CursorList<T> Add(T item) public CursorList<T> Add(T item)
{ {
string itemHashId = HashUtil.GetHash(new string[] { item.Id, item.GetHashCode().ToString() }).ToString(); string id = item.Id;
bool res = this.TryAdd(itemHashId, item); if (item.Id == null)
{
id = HashUtil.GetHash(new string[] { item.GetHashCode().ToString() }).ToString();
item.Id = id;
}
bool res = this.TryAdd(id, item);
if (res == false) if (res == false)
{ {

View File

@ -69,6 +69,13 @@ message PartyListItem {
message ListPartiesRequest { message ListPartiesRequest {
int32 page_size = 1; int32 page_size = 1;
string page_token = 2; string page_token = 2;
string order_by = 3;
SortDirection order_direction = 4;
}
enum SortDirection {
Asc = 0;
Desc = 1;
} }
message ListPartiesResponse { message ListPartiesResponse {

View File

@ -0,0 +1,79 @@
using System.Threading.Tasks;
using Google.Protobuf.WellKnownTypes;
using Grpc.Core;
using Aurora.Cursor;
using Microsoft.Extensions.Logging;
namespace Aurora.Services.Signal
{
public partial class SignalService : Signal.SignalBase
{
private CursorList<Party> _partyList;
public override Task<Party> CreateParty(CreatePartyRequest request, ServerCallContext context)
{
Party party = new Party(request.Party);
_partyList.Add(party);
this._logger.LogInformation(string.Format("Added party with name: ${0} to parties", party.Name));
return Task.FromResult(party);
}
public override Task<Empty> DeleteParty(DeletePartyRequest request, ServerCallContext context)
{
if (this._partyList.ContainsKey(request.PartyId))
{
this._partyList.Remove(request.PartyId);
}
this._logger.LogInformation(string.Format("Deleted party with id: ${0} to parties", request.PartyId));
return Task.FromResult(new Empty());
}
public override Task<ListPartiesResponse> ListParties(ListPartiesRequest request, ServerCallContext context)
{
Cursor<Party> cursor = new Cursor<Party>(ref this._partyList);
Aurora.Cursor.SortDirection direction = Aurora.Cursor.SortDirection.Asc;
if (request.OrderDirection == SortDirection.Desc)
{
direction = Aurora.Cursor.SortDirection.Desc;
}
CursorResult<Party> res = cursor
.WithSort(request.OrderBy, direction)
.WithNextPageToken(request.PageToken)
.WithSize(request.PageSize)
.GetNextPage();
ListPartiesResponse response = new ListPartiesResponse()
{
NextPageToken = res.NextPageToken
};
response.Parties.AddRange(res.Result.ConvertAll(party => new PartyListItem()
{
Name = party.Name,
Id = party.Id
}));
return Task.FromResult(response);
}
public override Task<Party> GetParty(GetPartyRequest request, ServerCallContext context)
{
Party party = new Party();
if (this._partyList.ContainsKey(request.PartyId))
{
this._partyList.TryGetValue(request.PartyId, out party);
}
return Task.FromResult(party);
}
public override Task<Party> UpdateParty(UpdatePartyRequest request, ServerCallContext context)
{
throw new System.NotImplementedException();
}
}
}

View File

@ -1,8 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Grpc.Core;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Aurora.Cursor; using Aurora.Cursor;
@ -12,7 +7,6 @@ namespace Aurora.Services.Signal
{ {
private readonly ILogger<SignalService> _logger; private readonly ILogger<SignalService> _logger;
private CursorList<Party> _partyList;
public SignalService(ILogger<SignalService> logger) public SignalService(ILogger<SignalService> logger)
{ {
_logger = logger; _logger = logger;

View File

@ -18,6 +18,7 @@ namespace Aurora
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddGrpc(); services.AddGrpc();
services.AddGrpcReflection();
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@ -26,6 +27,7 @@ namespace Aurora
if (env.IsDevelopment()) if (env.IsDevelopment())
{ {
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
} }
app.UseRouting(); app.UseRouting();
@ -34,6 +36,10 @@ namespace Aurora
{ {
endpoints.MapGrpcService<SignalService>(); endpoints.MapGrpcService<SignalService>();
if (env.IsDevelopment())
{
endpoints.MapGrpcReflectionService();
}
endpoints.MapGet("/", async context => endpoints.MapGet("/", async context =>
{ {
await context.Response.WriteAsync("Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909"); await context.Response.WriteAsync("Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");

View File

@ -10,6 +10,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Grpc.AspNetCore" Version="2.27.0" /> <PackageReference Include="Grpc.AspNetCore" Version="2.27.0" />
<PackageReference Include="Grpc.AspNetCore.Server.Reflection" Version="2.35.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -1,34 +0,0 @@
using System.Threading.Tasks;
using Google.Protobuf.WellKnownTypes;
using Grpc.Core;
namespace Aurora.Services.Signal
{
public partial class SignalService : Signal.SignalBase
{
public override Task<Party> CreateParty(CreatePartyRequest request, ServerCallContext context)
{
return base.CreateParty(request, context);
}
public override Task<Empty> DeleteParty(DeletePartyRequest request, ServerCallContext context)
{
return base.DeleteParty(request, context);
}
public override Task<ListPartiesResponse> ListParties(ListPartiesRequest request, ServerCallContext context)
{
return base.ListParties(request, context);
}
public override Task<Party> GetParty(GetPartyRequest request, ServerCallContext context)
{
return base.GetParty(request, context);
}
public override Task<Party> UpdateParty(UpdatePartyRequest request, ServerCallContext context)
{
return base.UpdateParty(request, context);
}
}
}

View File

@ -8,7 +8,7 @@
"files.exclude": { "files.exclude": {
"**/obj": true "**/obj": true
}, },
"dotnet-test-explorer.testProjectPath": "./AuroraSignal.test", "dotnet-test-explorer.testProjectPath": "./AuroraCradle.test",
"editor.formatOnSave": true, "editor.formatOnSave": true,
"editor.defaultFormatter": "ms-dotnettools.csharp" "editor.defaultFormatter": "ms-dotnettools.csharp"
} }