public PITSDB(int[] sourceIDs, Resolution[] targetResolutions) { Resolutions = targetResolutions; db = new Dictionary <int, Dictionary <Resolution, Dictionary <ValueType, AFAttribute> > >(sourceIDs.Length); using (var connection = new PIConnection()) { var template = PrepareTemplate(connection, targetResolutions); LoadTimeSeries(connection, template, sourceIDs, targetResolutions); } }
private void LoadTimeSeries(PIConnection connection, AFElementTemplate template, int[] sourceIDs, Resolution[] resolutions) { foreach (int id in sourceIDs) { template.AddElement(id); foreach (var resolution in resolutions) { foreach (var valueType in ValueTypes.All) { var name = template.GetTimeSeriesName(id, resolution, valueType); var timeseries = connection.AddOrGetTimeSeries(name, PIPointType.Float32); AddTimeSeries(id, resolution, valueType, timeseries); } } } }
private AFElementTemplate PrepareTemplate(PIConnection connection, Resolution[] resolutions) { connection.ClearTemplates(); var template = connection.AddTemplate(nameof(PITSDB)); foreach (var resolution in resolutions) { foreach (var valueType in ValueTypes.All) { template.AddTimeSeries(resolution, valueType); } } template.CheckIn(); return(template); }
private bool Clean() { Console.Write("Press enter to remove existing points from PI server or any other key to continue..."); bool remove = Console.ReadKey().Key == ConsoleKey.Enter; Console.WriteLine(); if (!remove) { return(false); } using (var db = new PIConnection()) { int deleted = db.ClearTimeSeries(); if (deleted == 0) { return(false); } Console.WriteLine($"Successfully deleted {deleted} time series from PI server but for the action to take effect on licence limits you must restart the system."); Console.Write("Press esc to exit or any other key to continue..."); return(Console.ReadKey().Key == ConsoleKey.Escape); } }