コード例 #1
0
ファイル: InMemoryRegistry.cs プロジェクト: pereca303/soa
        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));
        }
コード例 #2
0
        public SensorRegistryRecord GetRecord(string sensorName)
        {
            SensorRegistryRecord reqRecord = null;

            Records.TryGetValue(sensorName, out reqRecord);

            return(reqRecord);
        }
コード例 #3
0
ファイル: InMemoryRegistry.cs プロジェクト: pereca303/soa
        private RegistryResponse okResponse(SensorRegistryRecord data)
        {
            RegistryResponse response = new RegistryResponse();

            response.status     = RegistryStatus.ok;
            response.singleData = data;

            return(response);
        }
コード例 #4
0
        public void RemoveRecord(SensorRegistryRecord oldRecord)
        {
            SensorRegistryRecord outRecord = new SensorRegistryRecord();

            if (Records.ContainsKey(oldRecord.Name))
            {
                Records.TryRemove(oldRecord.Name, out outRecord);
            }
        }
コード例 #5
0
ファイル: SensorRegistryEvent.cs プロジェクト: pereca303/soa
        public SensorRegistryEvent(
            string serviceId,
            SensorRegEventType eventType,
            SensorRegistryRecord sensorRecord,
            string customMessage = "")

            : base(serviceId, ServiceType.SensorRegistry, customMessage)
        {
            this.eventType    = eventType;
            this.sensorRecord = sensorRecord;
        }
コード例 #6
0
ファイル: InMemoryRegistry.cs プロジェクト: pereca303/soa
        public RegistryResponse getSensorRecord(string sensorName)
        {
            SensorRegistryRecord record = null;

            if (Registry.TryGetValue(sensorName, out record))
            {
                return(this.okResponse(record));
            }

            return(this.badResponse(RegistryStatus.noSuchRecord));
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
ファイル: InMemoryRegistry.cs プロジェクト: pereca303/soa
        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));
        }
コード例 #10
0
ファイル: InMemoryRegistry.cs プロジェクト: pereca303/soa
        // 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));
        }
コード例 #11
0
ファイル: ISensorRegistry.cs プロジェクト: pereca303/soa
 public RegistryResponse(RegistryStatus status, SensorRegistryRecord singleData, List <SensorRegistryRecord> listData)
 {
     this.status     = status;
     this.singleData = singleData;
     this.listData   = listData;
 }