private void RemoveFromMap(DriverModel model) { modelMap.Remove(model.rowid); modelByIdMap.Remove(model.id); string name = model.driver.name.ToLower(); int count = 0; if (driverCount.TryGetValue(name, out count)) { count--; if (count == 0) { driverCount.Remove(name); driverMap.Remove(name); } else { driverCount[name] = count; } } driverByTypeMap[name].Remove(model); string deviceName = model.device.ToLower(); driverByDeviceMap[deviceName].Remove(model); }
/// <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); }
public void Insert(DriverModel driverModel) { AddToEquivalenceTree(driverModel.driver); lock (_driverdao_lock) { driverDao.Insert(driverModel); } }
public void Insert(DriverModel model) { DriverModel found = Retrieve(model.id, model.device); if (found != null) RemoveFromMap(found); model.rowid = NewId(); InsertOnMap(model); }
public void Insert(DriverModel model) { DriverModel found = Retrieve(model.id, model.device); if (found != null) { RemoveFromMap(found); } model.rowid = NewId(); InsertOnMap(model); }
public UOSDriver GetDriver(string id) { DriverModel model = driverDao.Retrieve(id, currentDevice.name); if (model != null) { return(instances[model.rowid]); } else { return(null); } }
public Response HandleServiceCall(Call serviceCall, CallContext messageContext) { //Handle named InstanceCall DriverModel model = null; if (serviceCall.instanceId != null) { //Find DriversInstance lock (_driverdao_lock) { model = driverDao.Retrieve(serviceCall.instanceId, currentDevice.name); } if (model == null) { logger.LogError("No Instance found with id '" + serviceCall.instanceId + "'"); throw new System.Exception("No Instance found with id '" + serviceCall.instanceId + "'"); } } else { //Handle non-named InstanceCall List <DriverModel> list; lock (_driverdao_lock) { list = driverDao.List(serviceCall.driver, currentDevice.name); } //Tries to find an equivalent driver... if ((list == null) || (list.Count == 0)) { TreeNode driverNode = null; if (!driverHash.TryGetValue(serviceCall.driver, out driverNode)) { logger.Log("No instance found for handling driver '" + serviceCall.driver + "'"); throw new System.Exception("No instance found for handling driver '" + serviceCall.driver + "'"); } list = FindEquivalentDriver(driverNode.children); if ((list == null) || (list.Count == 0)) { logger.Log("No instance found for handling driver '" + serviceCall.driver + "'"); throw new System.Exception("No instance found for handling driver '" + serviceCall.driver + "'"); } } // Select the first driver found (since no specific instance was informed) model = list[0]; } return(gateway.reflectionServiceCaller.CallService(instances[model.rowid], serviceCall, messageContext)); }
private void RegisterRemoteDriverInstances(UpDevice upDevice, IDictionary <string, object> driversListMap, string[] instanceIds) { foreach (string id in instanceIds) { object instance = driversListMap[id]; if (instance is string) { instance = Json.Deserialize(instance as string); } UpDriver upDriver = UpDriver.FromJSON(instance); DriverModel driverModel = new DriverModel(id, upDriver, upDevice.name); try { driverManager.Insert(driverModel); } catch (DriverNotFoundException e) { unknownDrivers.UnionWith(e.driversNames); dependents.Add(driverModel); } catch (System.Exception) { logger.LogError( "Problems occurred in the registering of driver '" + upDriver.name + "' with instanceId '" + id + "' in the device '" + upDevice.name + "' and it will not be registered."); } } if (unknownDrivers.Count > 0) { FindDrivers(unknownDrivers, upDevice); } }
private void InsertOnMap(DriverModel model) { modelMap[model.rowid] = model; modelByIdMap[model.id] = model; string name = model.driver.name.ToLower(); if (!driverMap.ContainsKey(name)) { driverMap[name] = model.driver; driverCount[name] = 0; driverByTypeMap[name] = new List <DriverModel>(); } driverCount[name]++; driverByTypeMap[name].Add(model); string deviceName = model.device.ToLower(); if (!driverByDeviceMap.ContainsKey(deviceName)) { driverByDeviceMap[deviceName] = new List <DriverModel>(); } driverByDeviceMap[deviceName].Add(model); }
private void RemoveFromMap(DriverModel model) { modelMap.Remove(model.rowid); modelByIdMap.Remove(model.id); string name = model.driver.name.ToLower(); int count = 0; if (driverCount.TryGetValue(name, out count)) { count--; if (count == 0) { driverCount.Remove(name); driverMap.Remove(name); } else driverCount[name] = count; } driverByTypeMap[name].Remove(model); string deviceName = model.device.ToLower(); driverByDeviceMap[deviceName].Remove(model); }
private void InsertOnMap(DriverModel model) { modelMap[model.rowid] = model; modelByIdMap[model.id] = model; string name = model.driver.name.ToLower(); if (!driverMap.ContainsKey(name)) { driverMap[name] = model.driver; driverCount[name] = 0; driverByTypeMap[name] = new List<DriverModel>(); } driverCount[name]++; driverByTypeMap[name].Add(model); string deviceName = model.device.ToLower(); if (!driverByDeviceMap.ContainsKey(deviceName)) driverByDeviceMap[deviceName] = new List<DriverModel>(); driverByDeviceMap[deviceName].Add(model); }
public void Delete(string id, string device) { DriverModel driver = Retrieve(id, device); RemoveFromMap(driver); }
/// <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); }
private void RegisterRemoteDriverInstances(UpDevice upDevice, IDictionary<string, object> driversListMap, string[] instanceIds) { foreach (string id in instanceIds) { object instance = driversListMap[id]; if (instance is string) instance = Json.Deserialize(instance as string); UpDriver upDriver = UpDriver.FromJSON(instance); DriverModel driverModel = new DriverModel(id, upDriver, upDevice.name); try { driverManager.Insert(driverModel); } catch (DriverNotFoundException e) { unknownDrivers.UnionWith(e.driversNames); dependents.Add(driverModel); } catch (System.Exception) { logger.LogError( "Problems occurred in the registering of driver '" + upDriver.name + "' with instanceId '" + id + "' in the device '" + upDevice.name + "' and it will not be registered."); } } if (unknownDrivers.Count > 0) FindDrivers(unknownDrivers, upDevice); }