Пример #1
0
        /// <summary>
        /// Deploys a driver into the context.
        /// </summary>
        /// <param name="instance">Instance of the object implementing the informed Driver.</param>
        /// <param name="instanceId">Optional instanceId which to call this instance of the driver.</param>
        public void DeployDriver(UOSDriver instance, string instanceId = null)
        {
            UpDriver driver = instance.GetDriver();

            if (instanceId == null)
            {
                instanceId = driver.name + IncDeployedDriversCount();
            }

            DriverModel model = new DriverModel(instanceId, instance.GetDriver(), this.currentDevice.name);

            if (!driverHash.ContainsKey(driver.name))
            {
                if (instance.GetParent() != null)
                {
                    AddToEquivalenceTree(instance.GetParent());
                }
                AddToEquivalenceTree(driver);
            }

            lock (_driverdao_lock) { driverDao.Insert(model); }
            instances[model.rowid] = instance;
            toInitialize.Add(instanceId);
            logger.Log("Deployed Driver : " + model.driver.name + " with id " + instanceId);
        }
Пример #2
0
        /// <summary>
        /// Undeploys the referenced driver instance from the Driver.
        /// </summary>
        /// <param name="instanceId">The instance id of the Driver to be removed.</param>
        public void UndeployDriver(string instanceId)
        {
            logger.Log("Undeploying driver with InstanceId : '" + instanceId + "'");

            DriverModel model;

            lock (_driverdao_lock) { model = driverDao.Retrieve(instanceId, currentDevice.name); }

            if (model != null)
            {
                UOSDriver uDriver = instances[model.rowid];
                if (!toInitialize.Contains(model.id))
                {
                    uDriver.Destroy();
                }

                lock (_driverdao_lock) { driverDao.Delete(model.id, currentDevice.name); }
                toInitialize.Remove(model.id);
            }
            else
            {
                logger.LogError(
                    "Undeploying driver with InstanceId : '" + instanceId +
                    "' was not possible, since it's not present in the current database.");
            }
        }
Пример #3
0
        /// <summary>
        /// Initializes the driver that are not initialized yet.
        /// </summary>
        public void InitDrivers()
        {
            List <DriverModel> list;

            lock (_driverdao_lock) { list = driverDao.List("uos.DeviceDriver"); }
            if (list.Count == 0)
            {
                DeviceDriver deviceDriver = new DeviceDriver();
                DeployDriver(deviceDriver);
            }

            logger.Log("Initializing " + toInitialize.Count + " drivers.");
            foreach (string id in toInitialize)
            {
                DriverModel model;
                lock (_driverdao_lock) { model = driverDao.Retrieve(id, currentDevice.name); }
                UOSDriver driver = instances[model.rowid];
                driver.Init(gateway, settings, id);
                logger.Log("Initialized Driver " + model.driver.name + " with id '" + id + "'");
            }
            toInitialize.Clear();
        }
Пример #4
0
        /// <summary>
        /// Deploys a driver into the context.
        /// </summary>
        /// <param name="instance">Instance of the object implementing the informed Driver.</param>
        /// <param name="instanceId">Optional instanceId which to call this instance of the driver.</param>
        public void DeployDriver(UOSDriver instance, string instanceId = null)
        {
            UpDriver driver = instance.GetDriver();

            if (instanceId == null)
                instanceId = driver.name + IncDeployedDriversCount();

            DriverModel model = new DriverModel(instanceId, instance.GetDriver(), this.currentDevice.name);

            if (!driverHash.ContainsKey(driver.name))
            {
                if (instance.GetParent() != null)
                    AddToEquivalenceTree(instance.GetParent());
                AddToEquivalenceTree(driver);
            }

            lock (_driverdao_lock) { driverDao.Insert(model); }
            instances[model.rowid] = instance;
            toInitialize.Add(instanceId);
            logger.Log("Deployed Driver : " + model.driver.name + " with id " + instanceId);
        }