Re-arranging files to add test project. Adding WIP cursor list
This commit is contained in:
94
AuroraSignal/Src/CursorList.cs
Normal file
94
AuroraSignal/Src/CursorList.cs
Normal file
@ -0,0 +1,94 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Aurora
|
||||
{
|
||||
public enum SortDirection {
|
||||
Asc,
|
||||
Desc,
|
||||
}
|
||||
|
||||
public class CursorList<T> : List<T>
|
||||
{
|
||||
private string _orderBy;
|
||||
private SortDirection _direction;
|
||||
private string _previousPageToken;
|
||||
private string _nextPageToken;
|
||||
private int _pageSize;
|
||||
|
||||
public CursorList(){
|
||||
this._direction = SortDirection.Desc;
|
||||
this._orderBy = string.Empty;
|
||||
this._previousPageToken = string.Empty;
|
||||
this._nextPageToken = string.Empty;
|
||||
this._pageSize = 10;
|
||||
}
|
||||
|
||||
public CursorList<T> WithNextPage(string nextPageToken){
|
||||
this._nextPageToken = nextPageToken;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CursorList<T> WithPreviousPage(string prevPageToken){
|
||||
this._previousPageToken = prevPageToken;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CursorList<T> WithSort(string orderBy, SortDirection direction ) {
|
||||
this._orderBy = orderBy;
|
||||
this._direction = direction;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CursorList<T> WithSize(int size){
|
||||
this._pageSize = size;
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<T> Get(){
|
||||
if(this._nextPageToken != string.Empty && this._previousPageToken != string.Empty){
|
||||
throw new System.InvalidOperationException("Cannot specify both next and previous page tokens");
|
||||
}
|
||||
|
||||
List<T> tmpList = new List<T>(this);
|
||||
|
||||
|
||||
tmpList.Sort(delegate(T first, T second){
|
||||
object firstVal = first.GetType().GetProperty(this._orderBy).GetValue(first, null);
|
||||
object secondVal = first.GetType().GetProperty(this._orderBy).GetValue(second, null);
|
||||
int compare = 0;
|
||||
|
||||
if(firstVal == null && secondVal == null)
|
||||
{
|
||||
compare = 0;
|
||||
}
|
||||
else if(firstVal == null)
|
||||
{
|
||||
compare = 1;
|
||||
}
|
||||
else if(secondVal == null)
|
||||
{
|
||||
compare = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
// Determine number or string types
|
||||
if(firstVal is string)
|
||||
{
|
||||
string firstStr = firstVal as string;
|
||||
string secondStr = secondVal as string;
|
||||
compare = firstStr.CompareTo(secondStr);
|
||||
} else if(firstVal is int)
|
||||
{
|
||||
int? firstInt = firstVal as int?;
|
||||
int? secondInt = secondVal as int?;
|
||||
compare = firstInt > secondInt ? 1 : -1;
|
||||
}
|
||||
}
|
||||
return this._direction == SortDirection.Asc ? compare : compare * -1;
|
||||
});
|
||||
|
||||
return tmpList.GetRange(0, this._pageSize > tmpList.Count ? tmpList.Count : this._pageSize);
|
||||
}
|
||||
}
|
||||
}
|
27
AuroraSignal/Src/Program.cs
Normal file
27
AuroraSignal/Src/Program.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Aurora
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
}
|
||||
|
||||
// Additional configuration is required to successfully run gRPC on macOS.
|
||||
// For instructions on how to configure Kestrel and gRPC clients on macOS, visit https://go.microsoft.com/fwlink/?linkid=2099682
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
webBuilder.UseStartup<Startup>();
|
||||
});
|
||||
}
|
||||
}
|
160
AuroraSignal/Src/Protos/signal.proto
Normal file
160
AuroraSignal/Src/Protos/signal.proto
Normal file
@ -0,0 +1,160 @@
|
||||
syntax = "proto3";
|
||||
|
||||
option csharp_namespace = "Aurora.Services.Signal";
|
||||
|
||||
package signal;
|
||||
|
||||
|
||||
import "google/protobuf/timestamp.proto";
|
||||
import "google/protobuf/field_mask.proto";
|
||||
import "google/protobuf/empty.proto";
|
||||
|
||||
|
||||
service Signal {
|
||||
//**************
|
||||
//Party Resource
|
||||
//**************
|
||||
//Get Party
|
||||
rpc ListParties(ListPartiesRequest) returns (ListPartiesResponse);
|
||||
|
||||
rpc GetParty(GetPartyRequest) returns (Party);
|
||||
|
||||
rpc UpdateParty(UpdatePartyRequest) returns (Party);
|
||||
|
||||
rpc CreateParty(CreatePartyRequest) returns (Party);
|
||||
|
||||
rpc DeleteParty(DeletePartyRequest) returns (google.protobuf.Empty);
|
||||
|
||||
|
||||
//***************************
|
||||
//EventSubscriptions Resource
|
||||
//***************************
|
||||
//List
|
||||
rpc ListEventSubscriptions(ListEventSubscriptionsRequest) returns (ListEventSubscriptionsResponse);
|
||||
|
||||
//Create
|
||||
rpc SubscribeToEvent(EventSubscriptionRequest) returns (EventSubscription);
|
||||
|
||||
//Delete
|
||||
rpc DeleteEventSubscription(DeleteEventSubscriptionRequest) returns (google.protobuf.Empty);
|
||||
|
||||
//CUSTOM: Create EventSubscription List
|
||||
rpc SubscribeToEvents(EventSubscriptionListRequest) returns (EventSubscriptionListResponse);
|
||||
|
||||
//CUSTOM: Delete all
|
||||
rpc DeleteAllEventSubscriptions(DeleteAllEventSubscriptionsRequest) returns (google.protobuf.Empty);
|
||||
|
||||
//*****
|
||||
//Event
|
||||
//*****
|
||||
//Get
|
||||
rpc GetEventStream(GetEventsRequest) returns (stream BaseEvent) {};
|
||||
}
|
||||
|
||||
message Party {
|
||||
//The resource name of the party
|
||||
string name = 1;
|
||||
string party_id = 2;
|
||||
string display_name = 3;
|
||||
string description = 4;
|
||||
string host_ip = 5;
|
||||
google.protobuf.Timestamp created_on = 6;
|
||||
}
|
||||
|
||||
message PartyListItem {
|
||||
string name = 1;
|
||||
string party_id = 2;
|
||||
}
|
||||
|
||||
message ListPartiesRequest {
|
||||
int32 page_size = 1;
|
||||
string page_token = 2;
|
||||
}
|
||||
|
||||
message ListPartiesResponse {
|
||||
repeated PartyListItem parties = 1;
|
||||
string next_page_token = 2;
|
||||
}
|
||||
|
||||
message GetPartyRequest {
|
||||
string party_id = 1;
|
||||
}
|
||||
|
||||
message CreatePartyRequest {
|
||||
string party_id = 1;
|
||||
Party party = 2;
|
||||
}
|
||||
|
||||
message DeletePartyRequest {
|
||||
string party_id = 1;
|
||||
}
|
||||
|
||||
message UpdatePartyRequest {
|
||||
Party party = 1;
|
||||
google.protobuf.FieldMask update_mask = 2;
|
||||
}
|
||||
|
||||
/* Event Types */
|
||||
enum EventType {
|
||||
NewPartiesAvailable = 0;
|
||||
}
|
||||
|
||||
message NewPartiesAvailableEvent {
|
||||
}
|
||||
|
||||
message BaseEvent {
|
||||
//Resource name of the event ?
|
||||
string name = 1;
|
||||
EventType event_type = 2;
|
||||
oneof derivedEvent {
|
||||
NewPartiesAvailableEvent new_parties_available_event = 3;
|
||||
}
|
||||
}
|
||||
|
||||
message EventSubscription {
|
||||
EventType type = 2;
|
||||
}
|
||||
|
||||
message ListEventSubscriptionsRequest {
|
||||
//Resource name of parent to the subscription list (The member)
|
||||
string parent = 1;
|
||||
int32 page_size = 2;
|
||||
string page_token = 3;
|
||||
}
|
||||
|
||||
message ListEventSubscriptionsResponse {
|
||||
repeated EventSubscription subscriptions = 1;
|
||||
string next_page_token = 2;
|
||||
}
|
||||
|
||||
message EventSubscriptionRequest {
|
||||
//Resource name of the parent to the subscription list (The member)
|
||||
string parent = 1;
|
||||
EventSubscription event_subscription = 2;
|
||||
}
|
||||
|
||||
message DeleteEventSubscriptionRequest {
|
||||
//Resource name of the subscription to delete
|
||||
string parent = 1;
|
||||
EventType type = 2;
|
||||
}
|
||||
|
||||
message EventSubscriptionListRequest {
|
||||
//Resource name of the parent to the subscription list (The member)
|
||||
string parent = 1;
|
||||
repeated EventSubscription event_subscriptions = 2;
|
||||
}
|
||||
|
||||
message EventSubscriptionListResponse {
|
||||
repeated EventSubscription event_subscriptions = 1;
|
||||
}
|
||||
|
||||
message DeleteAllEventSubscriptionsRequest {
|
||||
//Resource name of the parent to the subscription list (the member)
|
||||
string parent = 1;
|
||||
}
|
||||
|
||||
message GetEventsRequest {
|
||||
//Resource name of the parent to the event stream (the member)
|
||||
string parent = 1;
|
||||
}
|
7
AuroraSignal/Src/Services/Signal/Events.cs
Normal file
7
AuroraSignal/Src/Services/Signal/Events.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace Aurora.Services.Signal
|
||||
{
|
||||
public partial class SignalService : Signal.SignalBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
34
AuroraSignal/Src/Services/Signal/Party.cs
Normal file
34
AuroraSignal/Src/Services/Signal/Party.cs
Normal file
@ -0,0 +1,34 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
22
AuroraSignal/Src/Services/Signal/SignalService.cs
Normal file
22
AuroraSignal/Src/Services/Signal/SignalService.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Grpc.Core;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Aurora.Services.Signal
|
||||
{
|
||||
public partial class SignalService : Signal.SignalBase
|
||||
{
|
||||
private readonly ILogger<SignalService> _logger;
|
||||
|
||||
private CursorList<Party> _partyList;
|
||||
public SignalService(ILogger<SignalService> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
this._partyList = new CursorList<Party>();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
44
AuroraSignal/Src/Startup.cs
Normal file
44
AuroraSignal/Src/Startup.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Aurora.Services.Signal;
|
||||
|
||||
namespace Aurora
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddGrpc();
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapGrpcService<SignalService>();
|
||||
|
||||
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
AuroraSignal/appsettings.Development.json
Normal file
10
AuroraSignal/appsettings.Development.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Debug",
|
||||
"System": "Information",
|
||||
"Grpc": "Information",
|
||||
"Microsoft": "Information"
|
||||
}
|
||||
}
|
||||
}
|
15
AuroraSignal/appsettings.json
Normal file
15
AuroraSignal/appsettings.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"Kestrel": {
|
||||
"EndpointDefaults": {
|
||||
"Protocols": "Http1"
|
||||
}
|
||||
}
|
||||
}
|
15
AuroraSignal/aurora-cradle-sharp.csproj
Normal file
15
AuroraSignal/aurora-cradle-sharp.csproj
Normal file
@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Protobuf Include="Src\Protos\signal.proto" GrpcServices="Server" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Grpc.AspNetCore" Version="2.27.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Reference in New Issue
Block a user