Exemplo n.º 1
0
        public void TestAddDataPointHistoryData()
        {
            IUnitOfWork unitOfWork = new AdoUnitOfWork();
            IDataPointHistoryDataRepository dataPointHistoryDataRepository = new DataPointHistoryDataRepository(unitOfWork);

            DataPointHistoryDataService dataPointHistoryDataService
                = new DataPointHistoryDataService(dataPointHistoryDataRepository,
                                                  unitOfWork);

            List <DataPointHistoryData> dataPointHistoryDatas = new List <DataPointHistoryData>();

            for (int i = 0; i < 5000; i++)
            {
                DataPointHistoryData dataPointHistoryData = new DataPointHistoryData()
                {
                    Id        = Guid.NewGuid().ToString("D"),
                    DataPoint = new DataPoint()
                    {
                        Id = 1726
                    },
                    DateTime = DateTime.Now,
                    Value    = 123456789.12345
                };

                dataPointHistoryDatas.Add(dataPointHistoryData);
            }

            AddDataPointHistoryDataRequst requst = new AddDataPointHistoryDataRequst();

            requst.DataPointHistoryDatasToAdd = dataPointHistoryDatas;

            AddDataPointHistoryDataResponse response =
                dataPointHistoryDataService.AddDataPointHistoryData(requst);
        }
Exemplo n.º 2
0
        private void SaveDataPointHistoryValue()
        {
            if (null != this.allDataPoints && null != this.dataPointHistoryDataRepository)
            {
                foreach (var dataPoint in this.allDataPoints)
                {
                    DataPointHistoryData dataPointHistoryData = new DataPointHistoryData();

                    //蛋疼的UintOfWork机制要求:插入前要Id!!解决办法:
                    //每添加一个,就commit一次 uwRepository.UnitOfWork.Commit();
                    dataPointHistoryData.Id        = "123";//Guid.NewGuid().ToString("D");
                    dataPointHistoryData.DataPoint = dataPoint;
                    dataPointHistoryData.DateTime  = DateTime.Now;
                    dataPointHistoryData.Value     = dataPoint.RealTimeValue;

                    try
                    {
                        this.dataPointHistoryDataRepository.Add(dataPointHistoryData);
                        var uwRepository = this.dataPointHistoryDataRepository as IUnitOfWorkRepository;
                        if (uwRepository != null)
                        {
                            uwRepository.UnitOfWork.Commit();
                        }
                    }
                    catch (Exception)
                    {
                        //保证一个小时内在异常不出现后能将这小时内的数据保存到数据库
                        this.saveDataPointHistoryValueTimer.Interval = 1000 * 5;
                        return;
                    }
                }
            }
        }
Exemplo n.º 3
0
        public static DataPointHistoryValue ConvetToDataPointHistoryValue(
            this DataPointHistoryData dataPointHistoryData)
        {
            DataPointHistoryValue dataPointHistoryValue = new DataPointHistoryValue();

            dataPointHistoryValue.DataPointHistoryDataId = dataPointHistoryData.Id;
            dataPointHistoryValue.DataPointId            = dataPointHistoryData.DataPoint.Id;
            dataPointHistoryValue.DateTime     = dataPointHistoryData.DateTime;
            dataPointHistoryValue.HistoryValue = dataPointHistoryData.Value;

            return(dataPointHistoryValue);
        }
        public void CanAddDataPointHistoryData()
        {
            AdoUnitOfWork unitOfWork = new AdoUnitOfWork();
            DataPointHistoryDataRepository dataPointHistoryDataRepository = new DataPointHistoryDataRepository(unitOfWork);

            DataPointHistoryData dataPointHistoryData = new DataPointHistoryData()
            {
                Id        = Guid.NewGuid().ToString("D"),
                DataPoint = new DataPoint()
                {
                    Id = 1726
                },
                DateTime = DateTime.Now.AddDays(8),
                Value    = 123456789.12345
            };

            dataPointHistoryDataRepository.Add(dataPointHistoryData);
            unitOfWork.Commit();
        }