public RegistryResponse addSensorRecord( string sensorName, string sensorAddr, int sensorPort, int readIndex) { ServiceConfiguration config = ServiceConfiguration.Instance; var newRecord = new SensorRegistryRecord( sensorName, sensorAddr, sensorPort, readIndex); if (Registry.TryAdd(sensorName, newRecord)) { var newEvent = new SensorRegistryEvent( config.serviceId, SensorRegEventType.NewSensor, newRecord); this.broker.publishRegistryEvent( newEvent, config.newSensorFilter); return(this.okResponse(newRecord)); } return(this.badResponse(RegistryStatus.sensorAlreadyExists)); }
public SensorRegistryRecord GetRecord(string sensorName) { SensorRegistryRecord reqRecord = null; Records.TryGetValue(sensorName, out reqRecord); return(reqRecord); }
private RegistryResponse okResponse(SensorRegistryRecord data) { RegistryResponse response = new RegistryResponse(); response.status = RegistryStatus.ok; response.singleData = data; return(response); }
public void RemoveRecord(SensorRegistryRecord oldRecord) { SensorRegistryRecord outRecord = new SensorRegistryRecord(); if (Records.ContainsKey(oldRecord.Name)) { Records.TryRemove(oldRecord.Name, out outRecord); } }
public SensorRegistryEvent( string serviceId, SensorRegEventType eventType, SensorRegistryRecord sensorRecord, string customMessage = "") : base(serviceId, ServiceType.SensorRegistry, customMessage) { this.eventType = eventType; this.sensorRecord = sensorRecord; }
public RegistryResponse getSensorRecord(string sensorName) { SensorRegistryRecord record = null; if (Registry.TryGetValue(sensorName, out record)) { return(this.okResponse(record)); } return(this.badResponse(RegistryStatus.noSuchRecord)); }
public void UpdateRecord(SensorRegistryRecord newRecord) { SensorRegistryRecord outRecord = new SensorRegistryRecord(); if (Records.ContainsKey(newRecord.Name)) { Records.TryRemove(newRecord.Name, out outRecord); } Records.TryAdd(newRecord.Name, newRecord); }
public async Task AddNewRecord(SensorRegistryRecord newRecord) { SensorRegistryRecord outRecord = new SensorRegistryRecord(); if (Records.ContainsKey(newRecord.Name)) { Records.TryRemove(newRecord.Name, out outRecord); } newRecord.AvailableRecords = await database.getRecordsCount(newRecord.Name); Records.TryAdd(newRecord.Name, newRecord); }
public RegistryResponse removeSensorRecord(string sensorName) { ServiceConfiguration config = ServiceConfiguration.Instance; SensorRegistryRecord record = null; if (Registry.TryRemove(sensorName, out record)) { var newEvent = new SensorRegistryEvent( config.serviceId, SensorRegEventType.SensorRemoved, record); this.broker.publishRegistryEvent( newEvent, config.sensorRemovedFilter); return(this.okResponse(record)); } return(this.badResponse(RegistryStatus.noSuchRecord)); }
// ATTENTION this method may not be thread safe public RegistryResponse updateSensorRecord(string name, string address, int port, int readIndex) { ServiceConfiguration config = ServiceConfiguration.Instance; SensorRegistryRecord oldRecord = null; if (Registry.TryRemove(name, out oldRecord)) { var newRecord = new SensorRegistryRecord( name, address, port, readIndex); Registry.TryAdd(name, newRecord); SensorRegistryEvent newEvent = new SensorRegistryEvent( config.serviceId, SensorRegEventType.SensorUpdated, newRecord); // TODO this should be published from mediator request // and not from registry class // this class should be used just as cache record ... nothing else this.broker.publishRegistryEvent(newEvent, config.sensorUpdateFilter); return(this.okResponse(newRecord)); } return(this.badResponse(RegistryStatus.noSuchRecord)); }
public RegistryResponse(RegistryStatus status, SensorRegistryRecord singleData, List <SensorRegistryRecord> listData) { this.status = status; this.singleData = singleData; this.listData = listData; }