From 46173f4f9984e23c3fc4d47bb67e2e6ad9c615c2 Mon Sep 17 00:00:00 2001 From: Brandon Watson Date: Mon, 12 Apr 2021 21:54:21 -0400 Subject: [PATCH] Refactoring controllers to use publicly accessible CursorLists --- .../Src/Services/Signal/Events.cs | 7 --- aurora-proto/Proto/party.proto | 7 ++- .../Models/{PartyMember.cs => Member.cs} | 3 +- .../Services/Controllers/Constructor.cs | 3 +- .../Services/Controllers/MemberController.cs | 56 +++++++++++-------- .../Views/Party/HostPartyViewModel.cs | 20 ++----- 6 files changed, 47 insertions(+), 49 deletions(-) delete mode 100644 aurora-cradle-sharp/AuroraCradle/Src/Services/Signal/Events.cs rename aurora-sharp-desktop/Aurora/Models/{PartyMember.cs => Member.cs} (86%) diff --git a/aurora-cradle-sharp/AuroraCradle/Src/Services/Signal/Events.cs b/aurora-cradle-sharp/AuroraCradle/Src/Services/Signal/Events.cs deleted file mode 100644 index 41e7034..0000000 --- a/aurora-cradle-sharp/AuroraCradle/Src/Services/Signal/Events.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Aurora.Services.Signal -{ - public partial class SignalService : Signal.SignalBase - { - - } -} \ No newline at end of file diff --git a/aurora-proto/Proto/party.proto b/aurora-proto/Proto/party.proto index d26950a..bf688c6 100644 --- a/aurora-proto/Proto/party.proto +++ b/aurora-proto/Proto/party.proto @@ -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 { diff --git a/aurora-sharp-desktop/Aurora/Models/PartyMember.cs b/aurora-sharp-desktop/Aurora/Models/Member.cs similarity index 86% rename from aurora-sharp-desktop/Aurora/Models/PartyMember.cs rename to aurora-sharp-desktop/Aurora/Models/Member.cs index b3eec9b..2073813 100644 --- a/aurora-sharp-desktop/Aurora/Models/PartyMember.cs +++ b/aurora-sharp-desktop/Aurora/Models/Member.cs @@ -1,11 +1,12 @@ using System; +using Aurora.Cursor; namespace Aurora.Proto.Party { /// /// Partial PartyMember class with a constructor that generates a new id /// - public partial class Member + public partial class Member : ICursorObject { public Member(string id) { diff --git a/aurora-sharp-desktop/Aurora/Services/Controllers/Constructor.cs b/aurora-sharp-desktop/Aurora/Services/Controllers/Constructor.cs index 71d5e63..9d536d9 100644 --- a/aurora-sharp-desktop/Aurora/Services/Controllers/Constructor.cs +++ b/aurora-sharp-desktop/Aurora/Services/Controllers/Constructor.cs @@ -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(); + this._memberList = new CursorList(); this._mediaList = new SortedList(); _libraryService = libraryService; diff --git a/aurora-sharp-desktop/Aurora/Services/Controllers/MemberController.cs b/aurora-sharp-desktop/Aurora/Services/Controllers/MemberController.cs index 5e6e932..83698ae 100644 --- a/aurora-sharp-desktop/Aurora/Services/Controllers/MemberController.cs +++ b/aurora-sharp-desktop/Aurora/Services/Controllers/MemberController.cs @@ -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 _memberList; + private CursorList _memberList; + + public CursorList MemberList + { + get + { + return this._memberList; + } + set + { + if(this._memberList != value) + { + _memberList = value; + } + } + } public override Task ListMembers(ListMembersRequest request, Grpc.Core.ServerCallContext context) { + Cursor cursor = new Cursor(ref this._memberList); + + Aurora.Cursor.SortDirection direction = Aurora.Cursor.SortDirection.Asc; + + CursorResult 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 members = new List(_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 { diff --git a/aurora-sharp-desktop/Aurora/UserInterface/Views/Party/HostPartyViewModel.cs b/aurora-sharp-desktop/Aurora/UserInterface/Views/Party/HostPartyViewModel.cs index caf51a4..bccf39c 100644 --- a/aurora-sharp-desktop/Aurora/UserInterface/Views/Party/HostPartyViewModel.cs +++ b/aurora-sharp-desktop/Aurora/UserInterface/Views/Party/HostPartyViewModel.cs @@ -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(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 }