Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public static Task <bool> Stop(NEEOConf conf, string adapterName)
        {
            var urlPrefix = UrlBuilder.BuildBrainUrl(conf.Brain);

            _notification        = null;
            _notificationMapping = null;
            return(Register.UnregisterAdapterOnTheBrain(urlPrefix, adapterName));
        }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
 private static string GenerateAdapterName(NEEOConf conf)
 {
     if (conf.Name == "neeo-deviceadapter")
     {
         return(conf.Name);
     }
     return("src-" + ValidationModule.GetUniqueName(conf.Name));
 }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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()));
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        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));
        }
Esempio n. 10
0
 public static Task <bool> StartServer(NEEOConf configuration)
 {
     return(DeviceModule.StartServer(configuration));
 }