Compare commits
4 Commits
4a4cef8dd7
...
develop
Author | SHA1 | Date | |
---|---|---|---|
dc6776f70c | |||
0945ccfd12 | |||
e9065db23c | |||
6f73df0fb7 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,7 +6,6 @@ project.lock.json
|
||||
nupkg/
|
||||
|
||||
# Visual Studio Code
|
||||
.vscode
|
||||
|
||||
# Rider
|
||||
.idea
|
||||
|
27
.vscode/launch.json
vendored
Normal file
27
.vscode/launch.json
vendored
Normal 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
42
.vscode/tasks.json
vendored
Normal 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"
|
||||
}
|
||||
]
|
||||
}
|
@ -20,8 +20,8 @@
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AuroraSignal\aurora-cradle-sharp.csproj" />
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AuroraCradle\aurora-cradle-sharp.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -1,21 +1,17 @@
|
||||
using Xunit;
|
||||
using Aurora.Services.Signal;
|
||||
using Aurora.Cursor;
|
||||
using Faker;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
|
||||
|
||||
namespace AuroraSignal.test
|
||||
namespace AuroraCradle.test
|
||||
{
|
||||
public class CursorListTest
|
||||
{
|
||||
[Theory()]
|
||||
[InlineData(SortDirection.Asc)]
|
||||
[InlineData(SortDirection.Desc)]
|
||||
public void CursorListSortOnStringValue(SortDirection direction)
|
||||
[InlineData(Aurora.Cursor.SortDirection.Asc)]
|
||||
[InlineData(Aurora.Cursor.SortDirection.Desc)]
|
||||
public void CursorListSortOnStringValue(Aurora.Cursor.SortDirection direction)
|
||||
{
|
||||
CursorList<Party> list = new CursorList<Party>();
|
||||
list.Add(new Party() { Name = "asdf", Id = Faker.RandomNumber.Next().ToString() });
|
||||
@ -26,7 +22,7 @@ namespace AuroraSignal.test
|
||||
.WithSort(item => item.Value.Name, direction)
|
||||
.GetNextPage();
|
||||
|
||||
if (direction == SortDirection.Desc)
|
||||
if (direction == Aurora.Cursor.SortDirection.Desc)
|
||||
{
|
||||
Assert.Collection<Party>(result.Result,
|
||||
item => item.Name.Equals("asdf"),
|
||||
@ -149,7 +145,7 @@ namespace AuroraSignal.test
|
||||
{
|
||||
CursorResult<Party> res = cursor
|
||||
.WithSize(10)
|
||||
.WithSort(item => item.Value.Name, SortDirection.Asc)
|
||||
.WithSort(item => item.Value.Name, Aurora.Cursor.SortDirection.Asc)
|
||||
.WithNextPageToken(pageToken)
|
||||
.GetNextPage();
|
||||
|
@ -109,6 +109,13 @@ namespace Aurora.Cursor
|
||||
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)
|
||||
{
|
||||
this._pageSize = size;
|
@ -17,8 +17,13 @@ namespace Aurora.Cursor
|
||||
|
||||
public CursorList<T> Add(T item)
|
||||
{
|
||||
string itemHashId = HashUtil.GetHash(new string[] { item.Id, item.GetHashCode().ToString() }).ToString();
|
||||
bool res = this.TryAdd(itemHashId, item);
|
||||
string id = item.Id;
|
||||
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)
|
||||
{
|
@ -69,6 +69,13 @@ message PartyListItem {
|
||||
message ListPartiesRequest {
|
||||
int32 page_size = 1;
|
||||
string page_token = 2;
|
||||
string order_by = 3;
|
||||
SortDirection order_direction = 4;
|
||||
}
|
||||
|
||||
enum SortDirection {
|
||||
Asc = 0;
|
||||
Desc = 1;
|
||||
}
|
||||
|
||||
message ListPartiesResponse {
|
79
AuroraCradle/Src/Services/Signal/Party.cs
Normal file
79
AuroraCradle/Src/Services/Signal/Party.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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 Aurora.Cursor;
|
||||
|
||||
@ -12,7 +7,6 @@ namespace Aurora.Services.Signal
|
||||
{
|
||||
private readonly ILogger<SignalService> _logger;
|
||||
|
||||
private CursorList<Party> _partyList;
|
||||
public SignalService(ILogger<SignalService> logger)
|
||||
{
|
||||
_logger = logger;
|
@ -18,6 +18,7 @@ namespace Aurora
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddGrpc();
|
||||
services.AddGrpcReflection();
|
||||
}
|
||||
|
||||
// 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())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
|
||||
}
|
||||
|
||||
app.UseRouting();
|
||||
@ -34,6 +36,10 @@ namespace Aurora
|
||||
{
|
||||
endpoints.MapGrpcService<SignalService>();
|
||||
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
endpoints.MapGrpcReflectionService();
|
||||
}
|
||||
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");
|
@ -10,6 +10,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Grpc.AspNetCore" Version="2.27.0" />
|
||||
<PackageReference Include="Grpc.AspNetCore.Server.Reflection" Version="2.35.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@
|
||||
"files.exclude": {
|
||||
"**/obj": true
|
||||
},
|
||||
"dotnet-test-explorer.testProjectPath": "./AuroraSignal.test",
|
||||
"dotnet-test-explorer.testProjectPath": "./AuroraCradle.test",
|
||||
"editor.formatOnSave": true,
|
||||
"editor.defaultFormatter": "ms-dotnettools.csharp"
|
||||
}
|
||||
|
Reference in New Issue
Block a user