Ejemplo n.º 1
0
        public async Task<Sensor> Register(string typeName)
        {
            bool isRegistered = await IsRegisteredType(typeName);
            if (!isRegistered)
            {
                using (var uow = new UnitOfWork<SensorPoco>(new RomiDbContext()))
                {
                    SensorPoco poco = new SensorPoco() { TypeName = typeName };
                    uow.Repository().Add(poco);
                }
            }

            Sensor result = await this.GetSensor(typeName);
            return result;
        }
Ejemplo n.º 2
0
        public async Task<TSensor> Register<TSensor>()
            where TSensor : Sensor, new()
        {
            Type sensorType = typeof(TSensor);
            string typeName = sensorType.FullName;
            TSensor result;
            this._logger.LogDebug($"Registering Sensor: {typeName}");
            bool isRegistered = await IsRegisteredType(typeName);
            if (!isRegistered)
            {
                using (var uow = new UnitOfWork<SensorPoco>((DbContext)new RomiDbContext()))
                {
                    SensorPoco poco = new SensorPoco() { TypeName = typeName };
                    uow.Repository().Add(poco);
                }
            }
            else
            {
                this._logger.LogWarning($"Sensor is already registered: {typeName}");
            }

            result = await this.GetSensor<TSensor>();
            return result;
        }