Refactoring controllers to use publicly accessible CursorLists
This commit is contained in:
parent
4acf091511
commit
46173f4f99
@ -1,7 +0,0 @@
|
||||
namespace Aurora.Services.Signal
|
||||
{
|
||||
public partial class SignalService : Signal.SignalBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -105,13 +105,14 @@ message LeavePartyResponse {
|
||||
message Member {
|
||||
//Resource name of the party member to be returned (Added by server)
|
||||
string name = 1;
|
||||
string userName = 2;
|
||||
string id = 2;
|
||||
string userName = 3;
|
||||
|
||||
//Added by server
|
||||
string ipAddress = 3;
|
||||
string ipAddress = 4;
|
||||
|
||||
//Added by server
|
||||
google.protobuf.Timestamp addedOn = 4;
|
||||
google.protobuf.Timestamp addedOn = 5;
|
||||
}
|
||||
|
||||
message ListMembersRequest {
|
||||
|
@ -1,11 +1,12 @@
|
||||
using System;
|
||||
using Aurora.Cursor;
|
||||
|
||||
namespace Aurora.Proto.Party
|
||||
{
|
||||
/// <summary>
|
||||
/// Partial PartyMember class with a constructor that generates a new id
|
||||
/// </summary>
|
||||
public partial class Member
|
||||
public partial class Member : ICursorObject
|
||||
{
|
||||
public Member(string id)
|
||||
{
|
@ -7,6 +7,7 @@ using Aurora.Services.Settings;
|
||||
using Aurora.Models.Media;
|
||||
using Aurora.Services.EventManager;
|
||||
using Aurora.Utils;
|
||||
using Aurora.Cursor;
|
||||
|
||||
namespace Aurora.Services.Controllers
|
||||
{
|
||||
@ -24,7 +25,7 @@ namespace Aurora.Services.Controllers
|
||||
this._startDateTime = DateTime.UtcNow;
|
||||
this._displayName = partyName;
|
||||
this._description = description;
|
||||
this._memberList = new SortedList<string, Member>();
|
||||
this._memberList = new CursorList<Member>();
|
||||
this._mediaList = new SortedList<string, Media>();
|
||||
|
||||
_libraryService = libraryService;
|
||||
|
@ -6,40 +6,50 @@ using Aurora.Proto.General;
|
||||
using Aurora.Utils;
|
||||
using Grpc.Core;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using Aurora.Cursor;
|
||||
|
||||
namespace Aurora.Services.Controllers
|
||||
{
|
||||
public partial class RemotePartyController : RemotePartyService.RemotePartyServiceBase
|
||||
{
|
||||
private SortedList<string, Member> _memberList;
|
||||
private CursorList<Member> _memberList;
|
||||
|
||||
public CursorList<Member> MemberList
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._memberList;
|
||||
}
|
||||
set
|
||||
{
|
||||
if(this._memberList != value)
|
||||
{
|
||||
_memberList = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override Task<ListMembersResponse> ListMembers(ListMembersRequest request, Grpc.Core.ServerCallContext context)
|
||||
{
|
||||
Cursor<Member> cursor = new Cursor<Member>(ref this._memberList);
|
||||
|
||||
Aurora.Cursor.SortDirection direction = Aurora.Cursor.SortDirection.Asc;
|
||||
|
||||
CursorResult<Member> res = cursor
|
||||
.WithNextPageToken(request.PageToken)
|
||||
.WithSize(request.PageSize)
|
||||
.GetNextPage();
|
||||
|
||||
//Ignoring parent field because there is only one instance of the party
|
||||
ListMembersResponse resp = new ListMembersResponse();
|
||||
|
||||
//Determine start idx
|
||||
int startIdx = 0;
|
||||
if (!string.IsNullOrEmpty(request.PageToken))
|
||||
resp.Members.AddRange(res.Result.ConvertAll(member => new Member()
|
||||
{
|
||||
startIdx = _memberList.IndexOfKey(request.PageToken) + 1;
|
||||
}
|
||||
|
||||
int pageSize = request.PageSize;
|
||||
|
||||
//Assign pageSize
|
||||
if (pageSize > _memberList.Count)
|
||||
{
|
||||
pageSize = _memberList.Count;
|
||||
}
|
||||
|
||||
|
||||
//Gather page
|
||||
List<Member> members = new List<Member>(_memberList.Values);
|
||||
resp.Members.AddRange(members.GetRange(startIdx, pageSize));
|
||||
|
||||
//Set next page token
|
||||
resp.NextPageToken = resp.Members[resp.Members.Count - 1].Name;
|
||||
Name = member.Name,
|
||||
UserName = member.UserName,
|
||||
IpAddress = member.IpAddress,
|
||||
AddedOn = member.AddedOn
|
||||
}));
|
||||
|
||||
return Task.FromResult(resp);
|
||||
}
|
||||
@ -76,7 +86,7 @@ namespace Aurora.Services.Controllers
|
||||
request.Member.AddedOn = Timestamp.FromDateTime(DateTime.UtcNow);
|
||||
request.Member.IpAddress = context.Host;
|
||||
|
||||
_memberList.Add(resourceName, request.Member);
|
||||
_memberList.Add(request.Member);
|
||||
|
||||
BaseEvent @event = new BaseEvent
|
||||
{
|
||||
|
@ -22,7 +22,7 @@ namespace Aurora.Design.Views.Party
|
||||
private ILibraryService _libraryService;
|
||||
|
||||
private Grpc.Core.Server _server;
|
||||
private RemotePartyService.RemotePartyServiceClient _remotePartyClient;
|
||||
private RemotePartyController _remotePartyController;
|
||||
private Channel _channel;
|
||||
private int _port = 8080;
|
||||
private bool _isServerStarted = false;
|
||||
@ -48,7 +48,9 @@ namespace Aurora.Design.Views.Party
|
||||
this._hostname = IpUtil.GetLocalIPAddress();
|
||||
|
||||
this.StartServer("test", "test description");
|
||||
this.StartClient();
|
||||
|
||||
// TODO assign members
|
||||
// TODO assign songList
|
||||
|
||||
// Register commands
|
||||
PlayCommand = new Command(OnDoubleClickCommandExecute, CanDoubleClickCommandExecute);
|
||||
@ -84,7 +86,6 @@ namespace Aurora.Design.Views.Party
|
||||
this._hostname = IpUtil.GetLocalIPAddress();
|
||||
|
||||
this.StartServer("test", "test description");
|
||||
this.StartClient();
|
||||
}
|
||||
return Task.FromResult<object>(null);
|
||||
}
|
||||
@ -198,7 +199,7 @@ namespace Aurora.Design.Views.Party
|
||||
};
|
||||
|
||||
//Construct implementations
|
||||
RemotePartyController remotePartyController = new RemotePartyController(
|
||||
this._remotePartyController = new RemotePartyController(
|
||||
partyName,
|
||||
description,
|
||||
this._libraryService,
|
||||
@ -206,7 +207,7 @@ namespace Aurora.Design.Views.Party
|
||||
_eventManager);
|
||||
|
||||
// Register grpc RemoteService with singleton server service
|
||||
RemotePartyService.BindService(remotePartyController);
|
||||
RemotePartyService.BindService(this._remotePartyController);
|
||||
|
||||
|
||||
_server.Start();
|
||||
@ -218,15 +219,6 @@ namespace Aurora.Design.Views.Party
|
||||
Console.WriteLine(string.Format("Error starting gRPC server: {0}", ex.Message));
|
||||
}
|
||||
}
|
||||
|
||||
private void StartClient()
|
||||
{
|
||||
_channel = new Channel(string.Format("{0}:{1}", this._hostname, this._port), ChannelCredentials.Insecure);
|
||||
|
||||
_remotePartyClient = new RemotePartyService.RemotePartyServiceClient(_channel);
|
||||
}
|
||||
|
||||
|
||||
#endregion Private Methods
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user