public async Task <bool> Initialize(string hostAddress) { List <DeviceBuilder> buildDevices = new List <DeviceBuilder>(); if (_devices != null) { foreach (var device in _devices) { buildDevices.Add(device.BuildDevice()); } } var brain = await NEEOModule.DiscoverOneBrain(); if (brain == null) { _logger.LogWarning("NEEOService : No Brain detected / configured"); return(false); } var conf = new NEEOConf(_name, 0, buildDevices, brain, hostAddress); bool rc = await NEEOModule.StartServer(conf); if (!rc) { _logger.LogWarning("NEEOService : Error starting NEEO server"); } else { _logger.LogInformation("NEEOService : NEEO server started"); } return(rc); }
public static Task <bool> Stop(NEEOConf conf, string adapterName) { var urlPrefix = UrlBuilder.BuildBrainUrl(conf.Brain); _notification = null; _notificationMapping = null; return(Register.UnregisterAdapterOnTheBrain(urlPrefix, adapterName)); }
public static Task <bool> Start(NEEOConf conf, string adapterName) { var urlPrefix = UrlBuilder.BuildBrainUrl(conf.Brain, null, conf.BrainPort); _notification = new Notification(_restClient, urlPrefix, _logger); _notificationMapping = new NotificationMapping(_restClient, urlPrefix, adapterName, _logger); return(Register.RegisterAdapterOnTheBrain(urlPrefix, conf.BaseUrl, adapterName)); }
private static string GenerateAdapterName(NEEOConf conf) { if (conf.Name == "neeo-deviceadapter") { return(conf.Name); } return("src-" + ValidationModule.GetUniqueName(conf.Name)); }
private static string GenerateBaseUrl(NEEOConf conf) { var ipaddress = ValidationModule.GetAnyIpAddress(); var baseUrl = $"http://{ipaddress}:{conf.Port}"; NEEOEnvironment.Logger.LogDebug($"Device | Adapter baseUrl {baseUrl}"); return(baseUrl); }
private static DataBase BuildDevicesDatabase(NEEOConf conf, string adapterName) { List <NEEODevice> devices = new List <NEEODevice>(); foreach (var device in conf.Devices) { var dev = BuildAndRegisterDevice(device, adapterName); devices.Add(dev); } return(DataBase.Build(devices.ToArray())); }
internal static async Task <bool> StopServer(NEEOConf conf) { if (conf == null || conf.Brain == null || conf.Name == null) { throw new NEEOException("INVALID_STOPSERVER_PARAMETER"); } //var adapterName = ValidationModule.GetUniqueName(conf.Name); probably wrong in node.js source var adapterName = GenerateAdapterName(conf); bool rc = await BrainModule.Stop(conf, adapterName); return(rc); }
private static async Task <bool> StartSdkAndRetryIfConnectionFailed(NEEOConf conf, string adapterName, RequestHandler requestHandler) { for (int retryCount = 0; retryCount < conf.MaxConnectionAttempts; retryCount++) { await Task.Delay(retryCount * 1000); bool rc = await BrainModule.Start(conf, adapterName); return(rc); } return(false); }
internal static Task <bool> StartServer(NEEOConf conf) { if (conf == null || conf.Brain == null || conf.Name == null || conf.Devices == null) { throw new NEEOException("INVALID_STARTSERVER_PARAMETER"); } string adapterName = GenerateAdapterName(conf); var devicesDatabase = BuildDevicesDatabase(conf, adapterName); var requestHandler = HandlerModule.Build(devicesDatabase); _requestHandler = new HttpRequestHandler(requestHandler); conf.BaseUrl = conf.BaseUrl ?? GenerateBaseUrl(conf); return(StartSdkAndRetryIfConnectionFailed(conf, adapterName, requestHandler)); }
public static Task <bool> StartServer(NEEOConf configuration) { return(DeviceModule.StartServer(configuration)); }