public void TestDatapiontRepositoryFindByTEntityKeyMethod()
        {
            NHUnitOfWork        nhUnitOfWork        = new NHUnitOfWork();
            DataPointRepository dataPointRepository = new DataPointRepository(nhUnitOfWork);

            DataPoint dataPoint = dataPointRepository.FindBy(14);
        }
Beispiel #2
0
        static Functions()
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                CloudConfigurationManager.GetSetting("IoTStorageConnectionString"));
            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

            //DataPointTable = tableClient.GetTableReference("SumpPumpMonitorData");
            string tableStorageConnectionString = storageAccount.ToString(true);

            DataPointRepository = new DataPointRepository(tableStorageConnectionString);
            DutyCycleRepository = new DutyCycleRepository(tableStorageConnectionString);
            AlertRepository     = new AlertRepository(tableStorageConnectionString);
        }
Beispiel #3
0
        public void TestFindByQueryAndCount()
        {
            AdoUnitOfWork       unitOfWork          = new AdoUnitOfWork();
            DataPointRepository dataPointRepository = new DataPointRepository(unitOfWork);

            Query query = new Query();

            query.AddCriterion(Criterion.Create <DataPoint>(p => p.Number, 10, CriteriaOperator.LesserThanOrEqual));
            query.AddCriterion(Criterion.Create <DataPoint>(p => p.ModuleBelongTo.Id, 2, CriteriaOperator.Equal));
            query.OrderByProperty = OrderByClause.Create <DataPoint>(p => p.Name, true);

            IEnumerable <DataPoint> result = dataPointRepository.FindBy(query, 1, 1);
        }
        public ActionResult Get(string symbol)
        {
            var repository = new DataPointRepository();
            var datapoints = repository.FindAll(symbol);
            var list = datapoints.Select(d => new []
                {
                    d.Date.ToEpoch(), d.Open, d.High, d.Low, d.Close, d.Volume,
                    d.ForceIndexThirteenPeriod,
                    d.UpperBollingerBandTwoDeviation, d.LowerBollingerBandTwoDeviation,
                    d.MacdTwentyTwoOverTwelveDay, d.MacdTwentyTwoOverTwelveDaySignalLine, d.MacdTwentyTwoOverTwelveDayHistogram, d.MovingAverageTwentyDay
                }).ToList();

            return JsonNetResult.Create(list);
        }
        public void TestReadConfigFormModbusConfigFile()
        {
            ApplicationSettingsFactory.InitializeApplicationSettingsFactory(new AppConfigApplicationSettings());
            IApplicationSettings applicationSettings =
                ApplicationSettingsFactory.GetApplicationSettings();

            IUnitOfWork          unitOfWork          = new AdoUnitOfWork();
            IDataPointRepository dataPointRepository = new DataPointRepository(unitOfWork);
            IModuleRepository    moduleRepository    = new ModuleRepository(unitOfWork);

            ModbusConfigService modbusConfigService = new ModbusConfigService(dataPointRepository,
                                                                              moduleRepository);

            modbusConfigService.ReadConfigFormModbusConfigFile();
        }
        public void TestDatapiontRepositoryRemoveMethod_RemovingEntityFromISessionButNotFormDataBase()
        {
            NHUnitOfWork        nhUnitOfWork        = new NHUnitOfWork();
            DataPointRepository dataPointRepository = new DataPointRepository(nhUnitOfWork);

            DataPoint dataPointPre = dataPointRepository.FindBy(15);

            if (dataPointPre != null)
            {
                dataPointRepository.Remove(dataPointPre);
            }

            DataPoint dataPointAfter = dataPointRepository.FindBy(15);

            Assert.IsNull(dataPointAfter);
        }
        public ActionResult GetInidcator(string symbol, string indicatorName)
        {
            var indicatorMap = new Dictionary<string, Func<DataPoints, decimal?>>{
                                                                                    { "MovingAverageTwoHundredDay", points => points.MovingAverageTwoHundredDay},
                                                                                    { "MovingAverageFiftyDay", points => points.MovingAverageFiftyDay},
                                                                                    { "UpperBollingerBandTwoDeviation", points => points.UpperBollingerBandTwoDeviation},
                                                                                    { "LowerBollingerBandTwoDeviation", points => points.LowerBollingerBandTwoDeviation},
                                                                                    { "Volume", points => points.Volume}
                                                                                };

            var repository = new DataPointRepository();
            var dataPointToUse = indicatorMap[indicatorName];
            var datapoints = repository.FindAll(symbol);
            var list = datapoints.Select(d => new object[] { d.Date.ToEpoch(), dataPointToUse(d) }).ToList();
            return JsonNetResult.Create(list);
        }
Beispiel #8
0
        public void TestFindById()
        {
            IApplicationSettings applicationSettings = new AppConfigApplicationSettings();

            ApplicationSettingsFactory.InitializeApplicationSettingsFactory(applicationSettings);

            log4net.Config.XmlConfigurator.Configure();

            ILogger logger = new Log4NetAdapter();

            LoggingFactory.InitializeLogFactory(logger);

            AdoUnitOfWork       unitOfWork          = new AdoUnitOfWork();
            DataPointRepository dataPointRepository = new DataPointRepository(unitOfWork);

            dataPointRepository.FindBy(1);
        }
        public void TestDatapiontRepositorySavaMethod()
        {
            NHUnitOfWork        nhUnitOfWork        = new NHUnitOfWork();
            DataPointRepository dataPointRepository = new DataPointRepository(nhUnitOfWork);

            DataPoint dataPointPre = dataPointRepository.FindBy(1);

            dataPointPre.Description = "MyID is" + Convert.ToString((dataPointPre.Id));

            dataPointRepository.Save(dataPointPre);

            DataPoint dataPointAfter = dataPointRepository.FindBy(1);

            nhUnitOfWork.Commit();

            Assert.AreEqual(dataPointPre.Description, dataPointAfter.Description);
        }
        public void TestDatapiontRepositoryFindByQueryMethod()
        {
            NHUnitOfWork        nhUnitOfWork        = new NHUnitOfWork();
            DataPointRepository dataPointRepository = new DataPointRepository(nhUnitOfWork);

            Query query = new Query();

            query.AddCriterion(Criterion.Create <DataPoint>(p => p.DataType, DataType.S32, CriteriaOperator.Equal));
            query.QueryOperator = QueryOperator.And;

            //query.OrderByProperty = new OrderByClause() { PropertyName = "Number" ,Desc = true};
            query.OrderByProperty = OrderByClause.Create <DataPoint>(p => p.Number, false);

            List <DataPoint> dataPoints = (List <DataPoint>)dataPointRepository.FindBy(query);

            Assert.NotNull(dataPoints);
        }
Beispiel #11
0
        public void TestGroupingDataPointsForWriteRegister()
        {
            IUnitOfWork          unitOfWork          = new AdoUnitOfWork();
            IDataPointRepository dataPointRepository = new DataPointRepository(unitOfWork);

            List <DataPoint> allDataPoints = dataPointRepository.FindAll().ToList();

            int dataPointCount = 0;
            List <List <DataPoint> > dataPointsGroupedForWrite =
                DataPointGrouper.GroupingDataPointsForWriteRegister(allDataPoints);

            foreach (var groud in dataPointsGroupedForWrite)
            {
                dataPointCount += groud.Count;
            }
            Assert.IsTrue(allDataPoints.Count == dataPointCount);
        }
Beispiel #12
0
        public void TestGetAllDataPointsHistoryData()
        {
            IUnitOfWork                     unitOfWork                     = new AdoUnitOfWork();
            IDataPointRepository            dataPointRepository            = new DataPointRepository(unitOfWork);
            IDataPointHistoryDataRepository dataPointHistoryDataRepository = new DataPointHistoryDataRepository(unitOfWork);
            IModuleRepository               moduleRepository               = new ModuleRepository(unitOfWork);

            DataPointHistoryDataService dataPointHistoryDataService
                = new DataPointHistoryDataService(dataPointHistoryDataRepository,
                                                  unitOfWork);

            GetAllDataPointsHistoryDataResponse response = new GetAllDataPointsHistoryDataResponse();

            response = dataPointHistoryDataService.GetAllDataPointsHistoryData();

            Assert.True(response.ResponseSucceed);
        }
        public static void Main(string[] args)
        {
            LogManager.SetLogger(new ConsoleLogger());

            var configurationProvider = GetConfigurationProvider();
            var consumerFactory       = new KafkaMessageConsumerFactory(configurationProvider);

            var kafkaPublisher      = new KafkaMessagePublisher(configurationProvider.KafkaBroker);
            var dataPointsPublisher = new DataPointPublisher(kafkaPublisher, configurationProvider.DataPointTopicName);

            var database   = new MongoDbDatabase(configurationProvider.MongoDbHost, configurationProvider.MongoDbPort, configurationProvider.MongoDbDatabaseName);
            var repository = new DataPointRepository(database);

            RunLongRunning(new TimeSeriesAggregatorService(repository, dataPointsPublisher, consumerFactory, configurationProvider));

            kafkaPublisher.Dispose();
        }
Beispiel #14
0
        public void TestDatapiontRepositoryAddMethod()
        {
            NHUnitOfWork        nhUnitOfWork        = new NHUnitOfWork();
            DataPointRepository dataPointRepository = new DataPointRepository(nhUnitOfWork);

            Random seed      = new Random();
            Random randomNum = new Random(seed.Next());

            DataPoint dataPoint = new DataPoint()
            {
                Number = randomNum.Next(1000),
                Name   = "35#",
                StartRegisterAddress = 12,
                DataType             = DataType.Bit,
                Description          = "20130725测试!"
            };

            dataPointRepository.Add(dataPoint);
        }
Beispiel #15
0
        public void CanAddDataPoint()
        {
            AdoUnitOfWork       unitOfWork          = new AdoUnitOfWork();
            DataPointRepository dataPointRepository = new DataPointRepository(unitOfWork);

            Random seed      = new Random();
            Random randomNum = new Random(seed.Next());

            DataPoint dataPoint = new DataPoint()
            {
                Number = randomNum.Next(1000),
                Name   = "35#",
                StartRegisterAddress = 12,
                DataType             = DataType.Bit,
                Description          = "20130801测试!"
            };

            dataPointRepository.Add(dataPoint);
            unitOfWork.Commit();
        }
        public void TestDatapiontRepositoryUpdatAndCommitModthInUnitOfWork()
        {
            NHUnitOfWork        nhUnitOfWork        = new NHUnitOfWork();
            DataPointRepository dataPointRepository = new DataPointRepository(nhUnitOfWork);

            DataPoint dataPointPre = dataPointRepository.FindBy(1);

            dataPointPre.Description = "MyID is" + Convert.ToString((dataPointPre.Id));

            dataPointRepository.Save(dataPointPre);

            DataPoint dataPointAfter = dataPointRepository.FindBy(1);

            //如果不调用nhUnitOfWork.Commit(),
            //修改的数据还保存在ISession中,但是不会被保存到数据库
            //测试方法:
            //在Commit前后分别查看数据库的变化
            nhUnitOfWork.Commit();

            Assert.AreEqual(dataPointPre.Description, dataPointAfter.Description);
        }
        public void TestDatapiontRepositoryRemoveMethod_BothRemovingEntityForISessionAndemoveFormDataBase()
        {
            NHUnitOfWork        nhUnitOfWork        = new NHUnitOfWork();
            DataPointRepository dataPointRepository = new DataPointRepository(nhUnitOfWork);

            DataPoint dataPointPre = dataPointRepository.FindBy(15);

            if (dataPointPre != null)
            {
                dataPointRepository.Remove(dataPointPre);
            }

            //如果不调用nhUnitOfWork.Commit(),就会:
            //只是在ISession中删除,但是没有在数据库中删除
            //测试方法:
            //在Commit前后分别查看数据库的变化
            nhUnitOfWork.Commit();

            DataPoint dataPointAfter = dataPointRepository.FindBy(15);

            Assert.IsNull(dataPointAfter);
        }
Beispiel #18
0
        public void TestGetDataPiontHistoryData()
        {
            IUnitOfWork                     unitOfWork                     = new AdoUnitOfWork();
            IDataPointRepository            dataPointRepository            = new DataPointRepository(unitOfWork);
            IDataPointHistoryDataRepository dataPointHistoryDataRepository = new DataPointHistoryDataRepository(unitOfWork);
            IModuleRepository               moduleRepository               = new ModuleRepository(unitOfWork);

            DataPointHistoryDataService dataPointHistoryDataService =
                new DataPointHistoryDataService(dataPointHistoryDataRepository,
                                                unitOfWork);

            GetDataPointHistoryDataRequest  request  = new GetDataPointHistoryDataRequest();
            GetDataPiontHistoryDataResponse response = new GetDataPiontHistoryDataResponse();

            request.DataPointId = 1;
            request.BeginTime   = new DateTime();
            request.EndTime     = DateTime.Now;

            response = dataPointHistoryDataService.GetDataPiontHistoryData(request);

            Assert.True(response.ResponseSucceed);
        }
 public ActionResult GetCandleSticks(string ticker)
 {
     var repository = new DataPointRepository();
     var datapoints = repository.FindAll(ticker);
     return JsonNetResult.Create(datapoints.Select(d => new object[] { d.Date.ToEpoch(), d.Open, d.High, d.Low, d.Close }));
 }