diff --git a/aurora-shared/.gitignore b/aurora-shared/.gitignore new file mode 100644 index 0000000..23e17b6 --- /dev/null +++ b/aurora-shared/.gitignore @@ -0,0 +1,351 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +start*.sh diff --git a/aurora-cradle-sharp/AuroraCradle/Src/Cursor/Cursor.cs b/aurora-shared/Cursor/Cursor.cs similarity index 97% rename from aurora-cradle-sharp/AuroraCradle/Src/Cursor/Cursor.cs rename to aurora-shared/Cursor/Cursor.cs index 9a60991..f54c628 100644 --- a/aurora-cradle-sharp/AuroraCradle/Src/Cursor/Cursor.cs +++ b/aurora-shared/Cursor/Cursor.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.Linq; -#nullable enable namespace Aurora.Cursor { public enum SortDirection @@ -15,8 +14,8 @@ namespace Aurora.Cursor { private CursorList _list; - private string? _previousPageToken; - private string? _nextPageToken; + private string _previousPageToken; + private string _nextPageToken; private int _pageSize; private Func, string> _sortDelgate; private SortDirection _direction; diff --git a/aurora-cradle-sharp/AuroraCradle/Src/Cursor/CursorList.cs b/aurora-shared/Cursor/CursorList.cs similarity index 74% rename from aurora-cradle-sharp/AuroraCradle/Src/Cursor/CursorList.cs rename to aurora-shared/Cursor/CursorList.cs index 0dcbf04..b230d44 100644 --- a/aurora-cradle-sharp/AuroraCradle/Src/Cursor/CursorList.cs +++ b/aurora-shared/Cursor/CursorList.cs @@ -4,7 +4,6 @@ using System; using System.Linq; using Aurora.Utils; -#nullable enable namespace Aurora.Cursor { @@ -23,12 +22,8 @@ namespace Aurora.Cursor id = HashUtil.GetHash(new string[] { item.GetHashCode().ToString() }).ToString(); item.Id = id; } - bool res = this.TryAdd(id, item); + this.Add(id, item); - if (res == false) - { - throw new System.Exception("Failed to add item to cursor list"); - } return this; } diff --git a/aurora-cradle-sharp/AuroraCradle/Src/Cursor/CursorObject.cs b/aurora-shared/Cursor/CursorObject.cs similarity index 100% rename from aurora-cradle-sharp/AuroraCradle/Src/Cursor/CursorObject.cs rename to aurora-shared/Cursor/CursorObject.cs diff --git a/aurora-cradle-sharp/AuroraCradle/Src/Cursor/CursorResult.cs b/aurora-shared/Cursor/CursorResult.cs similarity index 100% rename from aurora-cradle-sharp/AuroraCradle/Src/Cursor/CursorResult.cs rename to aurora-shared/Cursor/CursorResult.cs diff --git a/aurora-cradle-sharp/AuroraCradle/Src/Utils/HashUtil.cs b/aurora-shared/Utils/HashUtil.cs similarity index 100% rename from aurora-cradle-sharp/AuroraCradle/Src/Utils/HashUtil.cs rename to aurora-shared/Utils/HashUtil.cs diff --git a/aurora-shared/aurora-shared.csproj b/aurora-shared/aurora-shared.csproj new file mode 100644 index 0000000..dc08ebc --- /dev/null +++ b/aurora-shared/aurora-shared.csproj @@ -0,0 +1,8 @@ + + + + netstandard2.0 + aurora_shared + + + diff --git a/aurora-sharp-desktop/Aurora.gtk/Aurora.gtk.csproj b/aurora-sharp-desktop/Aurora.gtk/Aurora.gtk.csproj index a25420a..6ed3fee 100644 --- a/aurora-sharp-desktop/Aurora.gtk/Aurora.gtk.csproj +++ b/aurora-sharp-desktop/Aurora.gtk/Aurora.gtk.csproj @@ -505,6 +505,7 @@ {17F51282-39BE-4FE3-8EC7-6D108F5DD0FD} Aurora + diff --git a/aurora-sharp-desktop/Aurora.test/Aurora.test.csproj b/aurora-sharp-desktop/Aurora.test/Aurora.test.csproj index 7d9a160..1f6b2f5 100644 --- a/aurora-sharp-desktop/Aurora.test/Aurora.test.csproj +++ b/aurora-sharp-desktop/Aurora.test/Aurora.test.csproj @@ -21,6 +21,7 @@ + diff --git a/aurora-sharp-desktop/Aurora/App.xaml.cs b/aurora-sharp-desktop/Aurora/App.xaml.cs index aa57897..9251647 100644 --- a/aurora-sharp-desktop/Aurora/App.xaml.cs +++ b/aurora-sharp-desktop/Aurora/App.xaml.cs @@ -7,8 +7,7 @@ using Aurora.Design.Views.Profile; using Aurora.Design.Views.Songs; using Aurora.Design.Views.Stations; using Aurora.Services.EventManager; -using Aurora.Services.Server; -using Aurora.Services.Client; +using Aurora.Services; using Autofac; using LibVLCSharp.Shared; using Xamarin.Forms; @@ -28,13 +27,12 @@ namespace Aurora //Register DI ContainerBuilder _builder = new ContainerBuilder(); - // _builder.RegisterInstance(new PlayerService()).SingleInstance(); + _builder.RegisterInstance(new PlayerService()).SingleInstance(); + _builder.RegisterType().As().SingleInstance(); _builder.RegisterType().As().SingleInstance(); _builder.RegisterType().As().SingleInstance(); _builder.RegisterType().As().SingleInstance(); _builder.RegisterType().As().SingleInstance(); - _builder.RegisterType().As().SingleInstance(); - _builder.RegisterType().As().SingleInstance(); _builder.RegisterType().SingleInstance(); _builder.RegisterType(); _builder.RegisterType(); diff --git a/aurora-sharp-desktop/Aurora/Aurora.csproj b/aurora-sharp-desktop/Aurora/Aurora.csproj index 84def05..d8e8ebf 100644 --- a/aurora-sharp-desktop/Aurora/Aurora.csproj +++ b/aurora-sharp-desktop/Aurora/Aurora.csproj @@ -83,4 +83,7 @@ + + + \ No newline at end of file diff --git a/aurora-sharp-desktop/Aurora/Services/Client/ClientService.cs b/aurora-sharp-desktop/Aurora/Services/Client/ClientService.cs deleted file mode 100644 index 3ee1f38..0000000 --- a/aurora-sharp-desktop/Aurora/Services/Client/ClientService.cs +++ /dev/null @@ -1,46 +0,0 @@ -using Grpc.Core; -using Aurora.Proto.Party; -using Aurora.Services.Settings; - -namespace Aurora.Services.Client -{ - - public class ClientService : IClientService - { - private RemotePartyService.RemotePartyServiceClient _remotePartyClient; - - private Channel _channel; - private ISettingsService _settingsService; - - public ClientService(ISettingsService settingsService) - { - this._settingsService = settingsService; - } - - public bool IsStarted - { - get - { - return _remotePartyClient != null; - } - } - - public RemotePartyService.RemotePartyServiceClient RemotePartyServiceClient - { - get { return this._remotePartyClient; } - } - - public void Start(string hostname, string port) - { - _channel = new Channel(string.Format("{0}:{1}", hostname, port), ChannelCredentials.Insecure); - - _remotePartyClient = new RemotePartyService.RemotePartyServiceClient(_channel); - } - - public async void Close() - { - await _channel.ShutdownAsync(); - _remotePartyClient = null; - } - } -} diff --git a/aurora-sharp-desktop/Aurora/Services/Client/IClientService.cs b/aurora-sharp-desktop/Aurora/Services/Client/IClientService.cs deleted file mode 100644 index 5ebe8b5..0000000 --- a/aurora-sharp-desktop/Aurora/Services/Client/IClientService.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Aurora.Proto.Party; - -namespace Aurora.Services.Client -{ - public interface IClientService - { - bool IsStarted { get; } - - RemotePartyService.RemotePartyServiceClient RemotePartyServiceClient { get; } - - void Start(string hostname, string port); - - void Close(); - } -} \ No newline at end of file diff --git a/aurora-sharp-desktop/Aurora/Services/Server/Controllers/Constructor.cs b/aurora-sharp-desktop/Aurora/Services/Controllers/Constructor.cs similarity index 94% rename from aurora-sharp-desktop/Aurora/Services/Server/Controllers/Constructor.cs rename to aurora-sharp-desktop/Aurora/Services/Controllers/Constructor.cs index 2b5e3b2..71d5e63 100644 --- a/aurora-sharp-desktop/Aurora/Services/Server/Controllers/Constructor.cs +++ b/aurora-sharp-desktop/Aurora/Services/Controllers/Constructor.cs @@ -6,9 +6,9 @@ using Aurora.Services.Library; using Aurora.Services.Settings; using Aurora.Models.Media; using Aurora.Services.EventManager; -using Autofac; +using Aurora.Utils; -namespace Aurora.Services.Server.Controllers +namespace Aurora.Services.Controllers { public partial class RemotePartyController : RemotePartyService.RemotePartyServiceBase { @@ -36,9 +36,9 @@ namespace Aurora.Services.Server.Controllers this._hostMember = new Member() { - Name = GetNewMemberResourceName(_partyResourceName, ServerService.GetLocalIPAddress(), userName), + Name = GetNewMemberResourceName(_partyResourceName, IpUtil.GetLocalIPAddress(), userName), UserName = userName, - IpAddress = ServerService.GetLocalIPAddress(), + IpAddress = IpUtil.GetLocalIPAddress(), }; //Add media from library diff --git a/aurora-sharp-desktop/Aurora/Services/Server/Controllers/EventController.cs b/aurora-sharp-desktop/Aurora/Services/Controllers/EventController.cs similarity index 96% rename from aurora-sharp-desktop/Aurora/Services/Server/Controllers/EventController.cs rename to aurora-sharp-desktop/Aurora/Services/Controllers/EventController.cs index abed097..7b4eae4 100644 --- a/aurora-sharp-desktop/Aurora/Services/Server/Controllers/EventController.cs +++ b/aurora-sharp-desktop/Aurora/Services/Controllers/EventController.cs @@ -4,7 +4,7 @@ using System.Threading; using Aurora.Proto.Party; using Aurora.Utils; -namespace Aurora.Services.Server.Controllers +namespace Aurora.Services.Controllers { public partial class RemotePartyController : RemotePartyService.RemotePartyServiceBase { diff --git a/aurora-sharp-desktop/Aurora/Services/Server/Controllers/EventSubscriptionController.cs b/aurora-sharp-desktop/Aurora/Services/Controllers/EventSubscriptionController.cs similarity index 98% rename from aurora-sharp-desktop/Aurora/Services/Server/Controllers/EventSubscriptionController.cs rename to aurora-sharp-desktop/Aurora/Services/Controllers/EventSubscriptionController.cs index 77c7ca7..c49fb5b 100644 --- a/aurora-sharp-desktop/Aurora/Services/Server/Controllers/EventSubscriptionController.cs +++ b/aurora-sharp-desktop/Aurora/Services/Controllers/EventSubscriptionController.cs @@ -5,7 +5,7 @@ using Aurora.Proto.Party; using Aurora.Proto.General; using Aurora.Utils; -namespace Aurora.Services.Server.Controllers +namespace Aurora.Services.Controllers { public partial class RemotePartyController : RemotePartyService.RemotePartyServiceBase { diff --git a/aurora-sharp-desktop/Aurora/Services/Server/Controllers/MediaController.cs b/aurora-sharp-desktop/Aurora/Services/Controllers/MediaController.cs similarity index 99% rename from aurora-sharp-desktop/Aurora/Services/Server/Controllers/MediaController.cs rename to aurora-sharp-desktop/Aurora/Services/Controllers/MediaController.cs index 5b617be..2e6a5f4 100644 --- a/aurora-sharp-desktop/Aurora/Services/Server/Controllers/MediaController.cs +++ b/aurora-sharp-desktop/Aurora/Services/Controllers/MediaController.cs @@ -8,7 +8,7 @@ using Aurora.Services.Library; using Aurora.Services.Player; using Autofac; -namespace Aurora.Services.Server.Controllers +namespace Aurora.Services.Controllers { public partial class RemotePartyController : RemotePartyService.RemotePartyServiceBase { diff --git a/aurora-sharp-desktop/Aurora/Services/Server/Controllers/MemberController.cs b/aurora-sharp-desktop/Aurora/Services/Controllers/MemberController.cs similarity index 98% rename from aurora-sharp-desktop/Aurora/Services/Server/Controllers/MemberController.cs rename to aurora-sharp-desktop/Aurora/Services/Controllers/MemberController.cs index f878101..5e6e932 100644 --- a/aurora-sharp-desktop/Aurora/Services/Server/Controllers/MemberController.cs +++ b/aurora-sharp-desktop/Aurora/Services/Controllers/MemberController.cs @@ -7,7 +7,7 @@ using Aurora.Utils; using Grpc.Core; using Google.Protobuf.WellKnownTypes; -namespace Aurora.Services.Server.Controllers +namespace Aurora.Services.Controllers { public partial class RemotePartyController : RemotePartyService.RemotePartyServiceBase { diff --git a/aurora-sharp-desktop/Aurora/Services/Server/Controllers/PartyController.cs b/aurora-sharp-desktop/Aurora/Services/Controllers/PartyController.cs similarity index 86% rename from aurora-sharp-desktop/Aurora/Services/Server/Controllers/PartyController.cs rename to aurora-sharp-desktop/Aurora/Services/Controllers/PartyController.cs index 1ca6eeb..aa2fbd2 100644 --- a/aurora-sharp-desktop/Aurora/Services/Server/Controllers/PartyController.cs +++ b/aurora-sharp-desktop/Aurora/Services/Controllers/PartyController.cs @@ -1,11 +1,11 @@ using System; using System.Threading.Tasks; -using System.Collections.Generic; +using Aurora.Utils; using Aurora.Proto.Party; using Google.Protobuf.WellKnownTypes; -namespace Aurora.Services.Server.Controllers +namespace Aurora.Services.Controllers { public partial class RemotePartyController : RemotePartyService.RemotePartyServiceBase { @@ -22,7 +22,7 @@ namespace Aurora.Services.Server.Controllers Name = _partyResourceName, DisplayName = this._displayName, Description = this._description, - HostIp = ServerService.GetLocalIPAddress(), + HostIp = IpUtil.GetLocalIPAddress(), HostMember = this._hostMember, CreatedOn = Timestamp.FromDateTime(_startDateTime) }; diff --git a/aurora-sharp-desktop/Aurora/Services/Global.cs b/aurora-sharp-desktop/Aurora/Services/Global.cs new file mode 100644 index 0000000..d5ad33a --- /dev/null +++ b/aurora-sharp-desktop/Aurora/Services/Global.cs @@ -0,0 +1,19 @@ +namespace Aurora.Services +{ + public enum PartyState + { + Idle, + SelectingHost, + InParty, + Hosting, + Connecting, + } + public class Global + { + public Global() + { + this.State = PartyState.Idle; + } + public PartyState State {get; set;} + } +} \ No newline at end of file diff --git a/aurora-sharp-desktop/Aurora/Services/Server/Server/IServerService.cs b/aurora-sharp-desktop/Aurora/Services/Server/Server/IServerService.cs deleted file mode 100644 index daf444f..0000000 --- a/aurora-sharp-desktop/Aurora/Services/Server/Server/IServerService.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Threading.Tasks; - -namespace Aurora.Services.Server -{ - public interface IServerService - { - int Port { get; } - - string Hostname { get; } - - bool Initialized { get; } - - - /// - /// Start Server - /// - void Start(string partyName, string description); - - /// - /// Shutdown server async. - /// - /// Task - Task Stop(); - - Task Reset(); - } -} \ No newline at end of file diff --git a/aurora-sharp-desktop/Aurora/Services/Server/Server/ServerService.cs b/aurora-sharp-desktop/Aurora/Services/Server/Server/ServerService.cs deleted file mode 100644 index 3921bc7..0000000 --- a/aurora-sharp-desktop/Aurora/Services/Server/Server/ServerService.cs +++ /dev/null @@ -1,144 +0,0 @@ -using System; -using System.Threading.Tasks; -using System.Net; -using System.Net.Sockets; -using Grpc.Core; -using Aurora.Services.Server.Controllers; -using Aurora.Services.Settings; -using Aurora.Services.Library; -using Aurora.Services.EventManager; -using Aurora.Proto.Party; - - -namespace Aurora.Services.Server -{ - public class ServerService : IServerService - { - private int _port = 8080; - private string _hostname; - private Grpc.Core.Server _server; - private ILibraryService _libraryService; - private ISettingsService _settingsService; - private IEventManager _eventManager; - - //Implementation class declarations - private RemotePartyController _remotePartyController; - - /// - /// Constructor. Registers GRPC service implementations. - /// - public ServerService(ILibraryService libraryService, ISettingsService settingsService, IEventManager eventManager) - { - string host = GetLocalIPAddress(); - this._libraryService = libraryService; - this._settingsService = settingsService; - this._eventManager = eventManager; - if (string.IsNullOrWhiteSpace(host)) - { - throw new Exception("This device must have a valid IP address"); - } - - _hostname = host; - } - - public int Port - { - get { return _port; } - } - - public string Hostname - { - get { return _hostname; } - } - - public bool Initialized - { - get - { - return (_remotePartyController != null && - _server != null); - } - } - - - /// - /// Start Server - /// - public void Start(string partyName, string description) - { - try - { - - Console.WriteLine(string.Format("Starting gRPC server at hostname: {0}, port: {1}", _hostname, _port)); - - _server = new Grpc.Core.Server - { - Ports = { new ServerPort(_hostname, _port, ServerCredentials.Insecure) } - }; - - //Construct implementations - _remotePartyController = new RemotePartyController( - partyName, - description, - _libraryService, - _settingsService, - _eventManager); - - // Register grpc RemoteService with singleton server service - RegisterService(RemotePartyService.BindService(_remotePartyController)); - - - _server.Start(); - } - catch (Exception ex) - { - Console.WriteLine(string.Format("Error starting gRPC server: {0}", ex.Message)); - } - } - - /// - /// Shutdown server async. - /// - /// Task - public async Task Stop() - { - try - { - await _server.ShutdownAsync(); - await _server.ShutdownTask; - } - catch (Exception ex) - { - Console.WriteLine(string.Format("Error stopping gRPC server: {0}", ex.Message)); - } - } - - public async Task Reset() - { - await Stop(); - _server = new Grpc.Core.Server - { - Ports = { new ServerPort("localhost", _port, ServerCredentials.Insecure) } - }; - } - - private void RegisterService(ServerServiceDefinition definition) - { - _server.Services.Add(definition); - } - - public static string GetLocalIPAddress() - { - string returnIp = ""; - var host = Dns.GetHostEntry(Dns.GetHostName()); - foreach (var ip in host.AddressList) - { - if (ip.AddressFamily == AddressFamily.InterNetwork) - { - returnIp = ip.ToString(); - } - } - return returnIp; - } - } -} \ No newline at end of file diff --git a/aurora-sharp-desktop/Aurora/UserInterface/Views/MainView/MainView.xaml.cs b/aurora-sharp-desktop/Aurora/UserInterface/Views/MainView/MainView.xaml.cs index 68fa748..463f26b 100644 --- a/aurora-sharp-desktop/Aurora/UserInterface/Views/MainView/MainView.xaml.cs +++ b/aurora-sharp-desktop/Aurora/UserInterface/Views/MainView/MainView.xaml.cs @@ -315,6 +315,7 @@ namespace Aurora.Design.Views.Main } var view = (View)Activator.CreateInstance(viewType); + vm.SetView = this.SetView; //Assign viewModel _lastViewModel = vm; diff --git a/aurora-sharp-desktop/Aurora/UserInterface/Views/Party/BasePartyViewModel.cs b/aurora-sharp-desktop/Aurora/UserInterface/Views/Party/BasePartyViewModel.cs index 8424c60..b827770 100644 --- a/aurora-sharp-desktop/Aurora/UserInterface/Views/Party/BasePartyViewModel.cs +++ b/aurora-sharp-desktop/Aurora/UserInterface/Views/Party/BasePartyViewModel.cs @@ -2,36 +2,32 @@ using System.Collections.ObjectModel; using Aurora.Proto.Party; using Aurora.Models.Media; using Aurora.Services.Settings; +using Aurora.Services; namespace Aurora.Design.Views.Party { - public enum PartyStateV2 - { - SelectingHost, - InParty, - Hosting, - Connecting, - } - public class BasePartyViewModel : BasePlayerViewModel { protected string _hostname; - private PartyStateV2 _state; + protected Global _global; + + protected ISettingsService _settingsService; private ObservableCollection _members; private ObservableCollection _queue; private BaseMedia _selectedMedia; - private ISettingsService _settingsService; + private int _selectedTabIndex; public BasePartyViewModel( - ISettingsService settingsService + ISettingsService settingsService, + Global global ) { _members = new ObservableCollection(); _queue = new ObservableCollection(); this._settingsService = settingsService; - + this._global = global; } public int SelectedTabIndex @@ -60,16 +56,10 @@ namespace Aurora.Design.Views.Party /// Public property for the currently selected song. /// /// - public BaseMedia SelectedSong + public BaseMedia SelectedMedia { get { return _selectedMedia; } set { SetProperty(ref _selectedMedia, value); } } - - public PartyStateV2 State - { - get { return _state; } - set { _state = value;} - } } } \ No newline at end of file diff --git a/aurora-sharp-desktop/Aurora/UserInterface/Views/Party/HostPartyViewModel.cs b/aurora-sharp-desktop/Aurora/UserInterface/Views/Party/HostPartyViewModel.cs index b62ec4a..caf51a4 100644 --- a/aurora-sharp-desktop/Aurora/UserInterface/Views/Party/HostPartyViewModel.cs +++ b/aurora-sharp-desktop/Aurora/UserInterface/Views/Party/HostPartyViewModel.cs @@ -1,24 +1,59 @@ +using System; using System.Threading.Tasks; -using Aurora.Design.Views.Party.NewPartyDialog; +using System.Net; +using System.Net.Sockets; +using Grpc.Core; using Xamarin.Forms; -using Aurora.Services.Server; using Aurora.Services.EventManager; +using Aurora.Services.Library; using Aurora.Services.Settings; +using Aurora.Services; +using Aurora.Proto.Party; +using Aurora.Models.Media; +using Aurora.Services.Controllers; +using Aurora.Utils; + namespace Aurora.Design.Views.Party { public class HostPartyViewModel : BasePartyViewModel { - private IServerService _serverService; private IEventManager _eventManager; + private ILibraryService _libraryService; + + private Grpc.Core.Server _server; + private RemotePartyService.RemotePartyServiceClient _remotePartyClient; + private Channel _channel; + private int _port = 8080; + private bool _isServerStarted = false; + public HostPartyViewModel( ISettingsService settingsService, - IServerService serverService, - IEventManager eventManager - ): base(settingsService) + IEventManager eventManager, + ILibraryService libraryService, + Global global + ): base(settingsService, global) { - this._serverService = serverService; this._eventManager = eventManager; + this._global.State = PartyState.Hosting; + this._libraryService = libraryService; + + // Create and start grpc server + string host = IpUtil.GetLocalIPAddress(); + if(string.IsNullOrWhiteSpace(host)) + { + // TODO display error to screen + throw new System.Exception("This device does not have a valid IP address"); + } + this._hostname = IpUtil.GetLocalIPAddress(); + + this.StartServer("test", "test description"); + this.StartClient(); + + // Register commands + PlayCommand = new Command(OnDoubleClickCommandExecute, CanDoubleClickCommandExecute); + LeavePartyCommand = new Command(OnLeavePartyCommandExecute, CanLeavePartyCommandExecute); + } #region Properties @@ -43,7 +78,14 @@ namespace Aurora.Design.Views.Party /// public override Task OnActive() { - + // Start server if not already started + if(!this._isServerStarted) + { + this._hostname = IpUtil.GetLocalIPAddress(); + + this.StartServer("test", "test description"); + this.StartClient(); + } return Task.FromResult(null); } @@ -55,20 +97,13 @@ namespace Aurora.Design.Views.Party { return Task.FromResult(null); } - - private async void OnHostCommandExecute() - { - - } - - private bool CanHostCommandExecute() - { - return true; - } private async void OnLeavePartyCommandExecute() { - + await this._channel.ShutdownAsync(); + await this._server.ShutdownAsync(); + this._global.State = PartyState.Idle; + this.SetView(typeof(PartyView), typeof(PartyViewModel)); } private bool CanLeavePartyCommandExecute() @@ -78,22 +113,43 @@ namespace Aurora.Design.Views.Party public override void OnPlayButtonCommandExecute() { - + if (base.IsPlaying()) + { + //Fire play stopped event + AudioMetadata meta = SelectedMedia.Metadata as AudioMetadata; + MediaPausedEvent mediaPaused = new MediaPausedEvent(); + + _eventManager.FireEvent(new BaseEvent() + { + MediaPausedEvent = mediaPaused + }); + } + else + { + //Fire play resume event + AudioMetadata meta = SelectedMedia.Metadata as AudioMetadata; + MediaResumedEvent mediaResumed = new MediaResumedEvent(); + + _eventManager.FireEvent(new BaseEvent() + { + MediaResumedEvent = mediaResumed + }); + } } public override bool CanPlayButtonCommandExecute() { - return this.State == PartyStateV2.Hosting; + return true; } public override bool CanNextButtonCommandExecute() { - return this.State == PartyStateV2.Hosting; + return true; } public override bool CanPreviousButtonCommandExecute() { - return this.State == PartyStateV2.Hosting; + return true; } /// @@ -101,12 +157,77 @@ namespace Aurora.Design.Views.Party /// public void OnDoubleClickCommandExecute() { + //Fire Playing event + AudioMetadata meta = SelectedMedia.Metadata as AudioMetadata; + NewMediaPlayingEvent mediaPlaying = new NewMediaPlayingEvent() + { + Media = new Media() + { + //TODO need full resource name + Name = SelectedMedia.Id, + Title = meta.Title, + Artist = meta.Artist, + Album = meta.Album, + } + }; + + _eventManager.FireEvent(new BaseEvent() + { + NewMediaPlayingEvent = mediaPlaying + }); } public bool CanDoubleClickCommandExecute() { - return this.State == PartyStateV2.Hosting; + return true; } + #region Private Methods + + private void StartServer(string partyName, string description) + { + try + { + + // TODO bmw replace with display in UI + Console.WriteLine(string.Format("Starting gRPC server at hostname: {0}, port: {1}", _hostname, _port)); + + _server = new Grpc.Core.Server + { + Ports = { new ServerPort(_hostname, _port, ServerCredentials.Insecure) } + }; + + //Construct implementations + RemotePartyController remotePartyController = new RemotePartyController( + partyName, + description, + this._libraryService, + base._settingsService, + _eventManager); + + // Register grpc RemoteService with singleton server service + RemotePartyService.BindService(remotePartyController); + + + _server.Start(); + this._isServerStarted = true; + } + catch (Exception ex) + { + // TODO bmw replace with display in UI + 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 + } } \ No newline at end of file diff --git a/aurora-sharp-desktop/Aurora/UserInterface/Views/Party/PartyViewModel.cs b/aurora-sharp-desktop/Aurora/UserInterface/Views/Party/PartyViewModel.cs index 1373a96..dca6cbb 100644 --- a/aurora-sharp-desktop/Aurora/UserInterface/Views/Party/PartyViewModel.cs +++ b/aurora-sharp-desktop/Aurora/UserInterface/Views/Party/PartyViewModel.cs @@ -1,34 +1,16 @@ -using System; -using System.Collections.ObjectModel; -using System.Collections.Generic; using System.Threading.Tasks; -using System.Threading; -using System.Linq; -using Xamarin.Forms; using Aurora.Proto.Party; -using Aurora.Models.Media; -using Aurora.Services.Client; using Aurora.Design.Views.Party.NewPartyDialog; using Aurora.Services.Settings; -using Aurora.Services.Server; -using Aurora.Services.EventManager; -using Grpc.Core; +using Aurora.Services; namespace Aurora.Design.Views.Party { - //TODO refactor - enum PartyState - { - SelectingHost, - InParty, - Hosting, - Connecting, - } delegate void EventHandler(BaseEvent e); public class PartyViewModel : BasePartyViewModel { - public PartyViewModel(ISettingsService settingsService): base(settingsService) + public PartyViewModel(ISettingsService settingsService, Global global): base(settingsService, global) { } @@ -39,14 +21,14 @@ namespace Aurora.Design.Views.Party public override Task OnActive() { OnPropertyChanged("SelectedTabIndex"); - switch(this.State) + switch(this._global.State) { - case PartyStateV2.Hosting: + case PartyState.Hosting: { this.SetView.Invoke(typeof(PartyView), typeof(HostPartyViewModel)); break; } - case PartyStateV2.InParty: + case PartyState.InParty: { // TODO break; diff --git a/aurora-sharp-desktop/Aurora/Utils/IpUtil.cs b/aurora-sharp-desktop/Aurora/Utils/IpUtil.cs new file mode 100644 index 0000000..d5fd9b9 --- /dev/null +++ b/aurora-sharp-desktop/Aurora/Utils/IpUtil.cs @@ -0,0 +1,22 @@ +using System.Net; +using System.Net.Sockets; + +namespace Aurora.Utils +{ + public static class IpUtil + { + public static string GetLocalIPAddress() + { + string returnIp = ""; + var host = Dns.GetHostEntry(Dns.GetHostName()); + foreach (var ip in host.AddressList) + { + if (ip.AddressFamily == AddressFamily.InterNetwork) + { + returnIp = ip.ToString(); + } + } + return returnIp; + } + } +} \ No newline at end of file diff --git a/aurora.code-workspace b/aurora.code-workspace index c9e437f..ea5c78a 100644 --- a/aurora.code-workspace +++ b/aurora.code-workspace @@ -1,5 +1,8 @@ { - "folders": [ + "folders": [' + { + "path": ".gitea" + }, { "path": "aurora-sharp-desktop" }, @@ -10,7 +13,7 @@ "path": "aurora-proto" }, { - "path": ".gitea" + "path": "aurora-shared" } ], "settings": {