public AddDataPointResponse AddDataPoint(AddDataPointRequst requst)
        {
            AddDataPointResponse response = new AddDataPointResponse();

            try
            {
                foreach (DataPoint dataPoint in requst.DataPointsToAdd)
                {
                    _dataPointRepository.Add(dataPoint);
                }

                _unitOfWork.Commit();
            }
            catch (Exception ex)
            {
                string message = "添加失败!错误信息:/n" + ex.Message;
                response = new AddDataPointResponse()
                {
                    ResponseSucceed = false,
                    Message         = "添加失败"
                };
                LoggingFactory.GetLogger().WriteDebugLogger(message);

                return(response);
            }

            return(response);
        }
        public void WriteConfigToDataBase()
        {
            ClearConfigWhichInDataBse();

            //Module是DataPoint的外键,先添加Module
            foreach (KeyValuePair <int, Module> keyValuePair in _modulesFromConfigFile)
            {
                _moduleRepository.Add(keyValuePair.Value);
            }

            //UnitOfWork机制,调用Commit()才提交到数据库,
            var uwModuleRepository = _moduleRepository as IUnitOfWorkRepository;

            if (uwModuleRepository != null)
            {
                uwModuleRepository.UnitOfWork.Commit();
            }

            //Module是DataPoint的外键,故先设置DataPoint的数据库表中的外键值,否则添加失败
            SetForeignKeyForDataPiont();

            foreach (KeyValuePair <int, DataPoint> keyValuePair in _dataPointsFromConfigFile)
            {
                _dataPointRepository.Add(keyValuePair.Value);
            }

            var uwDataPointReposity = _dataPointRepository as IUnitOfWorkRepository;

            if (uwDataPointReposity != null)
            {
                uwDataPointReposity.UnitOfWork.Commit();
            }
        }
        protected override void OnReceive(object message)
        {
            if (message is DataPoint dataPoint)
            {
                _dataPointRepository.Add(dataPoint).Wait();

                LogManager.Instance.Info($"Saved datapoint {dataPoint}");
            }
            else
            {
                LogManager.Instance.Error($"Invalid message received {message.GetType()} {message}");
                Unhandled(message);
            }
        }