Refactored to only having one executor per platform

This commit is contained in:
watsonb8
2019-07-05 11:37:44 -04:00
parent 0cb0546741
commit a01d399a1f
18 changed files with 226 additions and 170 deletions

View File

@ -7,7 +7,8 @@ namespace Aurora.Backend.Services
{
public class ServerService : BaseService<ServerService>
{
private const int Port = 50051;
private string _hostname = "127.0.0.1";
private int _port = 50001;
private Grpc.Core.Server _server;
/// <summary>
@ -15,12 +16,16 @@ namespace Aurora.Backend.Services
/// </summary>
public ServerService()
{
}
public void Initialize(string hostname, int port)
{
this._port = port;
this._hostname = hostname;
_server = new Grpc.Core.Server
{
Ports = { new ServerPort("localhost", Port, ServerCredentials.Insecure) }
Ports = { new ServerPort(_hostname, _port, ServerCredentials.Insecure) }
};
Start();
}
/// <summary>
@ -28,7 +33,15 @@ namespace Aurora.Backend.Services
/// </summary>
public void Start()
{
_server.Start();
try
{
Console.WriteLine(string.Format("Starting gRPC server at hostname: {0}, port: {1}", _hostname, _port));
_server.Start();
}
catch (Exception ex)
{
Console.WriteLine(string.Format("Error starting gRPC server: {0}", ex.Message));
}
}
/// <summary>
@ -45,7 +58,7 @@ namespace Aurora.Backend.Services
await Stop();
_server = new Grpc.Core.Server
{
Ports = { new ServerPort("localhost", Port, ServerCredentials.Insecure) }
Ports = { new ServerPort("localhost", _port, ServerCredentials.Insecure) }
};
}

View File

@ -0,0 +1,36 @@
using System;
using Xamarin.Forms;
namespace Aurora.Backend.Services
{
public class SettingsService : BaseService<SettingsService>
{
private string _usernameKey = "Username";
public SettingsService()
{
}
public string Username
{
get
{
if (!Application.Current.Properties.ContainsKey(_usernameKey))
{
return "";
}
Application.Current.Properties.TryGetValue(_usernameKey, out object val);
return val as string;
}
set
{
if (Application.Current.Properties.ContainsKey(_usernameKey))
{
Application.Current.Properties.Remove(_usernameKey);
}
Application.Current.Properties.Add(_usernameKey, value);
}
}
}
}