Example #1
0
 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);
     }
 }
Example #2
0
 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);
             }
         }
     }
 }
Example #3
0
        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);
        }
Example #4
0
        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);
            }
        }