public ITrendsRunTarget Create(string connectionString, IProject project, TrendCategory trendCategory, ITimeService timeService) { var npgsqlConnectionFactory = new NpgsqlConnectionFactory(connectionString); var repositoryFactory = new TrendsRepositoryFactory( npgsqlConnectionFactory, trendCategory.Id, trendCategory.TrendTags.Select(t => t.Id).ToArray()); using (var repository = repositoryFactory.Create()) { repository.EnsureTables(); } return new TrendsRunTarget( trendCategory, new NotificationReporter(timeService) { LifeTime = TimeSpan.FromTicks(0) }, repositoryFactory, project, timeService, new TrendTableSelector()); }
public TrendsRunTarget( TrendCategory trendCategory, INotificationReporter reporter, ITrendsRepositoryFactory repositoryFactory, IProject project, ITimeService timeService, ITrendTableSelector tableSelector) { Name = string.Format("{0} \"{1}\"", Res.Trends, trendCategory.Name); _timeToStore = trendCategory.TimeToStoreDb.HasValue ? new TimeSpan(trendCategory.TimeToStoreDb.Value) as TimeSpan? : null; foreach (TrendTag t in trendCategory.TrendTags.ToArray()) { Func <bool> triggerValueGetter; if (t.Trigger == null) { triggerValueGetter = () => true; } else { int trIoDevId = t.Trigger.IoDevice.Id; int trId = t.Trigger.Id; triggerValueGetter = () => project.IoDeviceRunTargets[trIoDevId].GetDigitalValue(trId) == true; } int ioDeviceId = t.NumTag.IoDevice.Id; int tagId = t.NumTag.Id; var trendInfo = new TrendTagInfo( t.Id, triggerValueGetter, () => project.IoDeviceRunTargets[ioDeviceId].GetNumericValue(tagId)); _trendsInfo.Add(t.Id, trendInfo); } Reporter = reporter; _repositoryFactory = repositoryFactory; _timeService = timeService; _tableSelector = tableSelector; }
public TrendsRunTarget( TrendCategory trendCategory, INotificationReporter reporter, ITrendsRepositoryFactory repositoryFactory, IProject project, ITimeService timeService, ITrendTableSelector tableSelector) { _name = string.Format("{0} \"{1}\"", Res.Trends, trendCategory.Name); _timeToStore = trendCategory.TimeToStoreDb.HasValue ? new TimeSpan(trendCategory.TimeToStoreDb.Value) as TimeSpan? : null; foreach (var t in trendCategory.TrendTags.ToArray()) { Func<bool> triggerValueGetter; if (t.Trigger == null) { triggerValueGetter = () => true; } else { var trIoDevId = t.Trigger.IoDevice.Id; var trId = t.Trigger.Id; triggerValueGetter = () => project.IoDeviceRunTargets[trIoDevId].GetDigitalValue(trId) == true; } var ioDeviceId = t.NumTag.IoDevice.Id; var tagId = t.NumTag.Id; var trendInfo = new TrendTagInfo( t.Id, triggerValueGetter, () => project.IoDeviceRunTargets[ioDeviceId].GetNumericValue(tagId)); _trendsInfo.Add(t.Id, trendInfo); } _reporter = reporter; _repositoryFactory = repositoryFactory; _timeService = timeService; _tableSelector = tableSelector; }
public ITrendsRunTarget Create(string connectionString, IProject project, TrendCategory trendCategory, ITimeService timeService) { var npgsqlConnectionFactory = new NpgsqlConnectionFactory(connectionString); var repositoryFactory = new TrendsRepositoryFactory( npgsqlConnectionFactory, trendCategory.Id, trendCategory.TrendTags.Select(t => t.Id).ToArray()); using (var repository = repositoryFactory.Create()) { repository.EnsureTables(); } return(new TrendsRunTarget( trendCategory, new NotificationReporter(timeService) { LifeTime = TimeSpan.FromTicks(0) }, repositoryFactory, project, timeService, new TrendTableSelector())); }