Example #1
0
        public void piSystemPicker1_ConnectionChange(object sender, OSIsoft.AF.UI.SelectionChangeEventArgs e)
        {

            //Set the AF Server to the current selected object
            myAFServer = (PISystem)e.SelectedObject;
            AFDatabases databaseList = myAFServer.Databases;
        }
        public AFProbe(string name, PISystem piSystem)
        {
            _name = name;
            _piSystem = piSystem;

            _startServer = piSystem.GetRpcMetrics();
            _startClient = piSystem.GetClientRpcMetrics();

            _sw = Stopwatch.StartNew();
        }
        static void PrintEnergyUOMs(PISystem system)
        {
            Console.WriteLine("Print Energy UOMs");
            UOMClass uomClass = system.UOMDatabase.UOMClasses["Energy"];
            foreach (UOM uom in uomClass.UOMs)
            {
                Console.WriteLine("UOM: {0}, Abbreviation: {1}", uom.Name, uom.Abbreviation);
            }

            Console.WriteLine();
        }
        static AFDatabase GetDatabase(string serverName, string databaseName)
        {
            PISystem assetServer = GetPISystem(null, serverName);

            if (!string.IsNullOrEmpty(databaseName))
            {
                return(assetServer.Databases[databaseName]);
            }
            else
            {
                return(assetServer.Databases.DefaultDatabase);
            }
        }
        static AFDatabase GetDatabase(string servername, string databasename)
        {
            PISystem system = GetPISystem(null, servername);

            if (!string.IsNullOrEmpty(databasename))
            {
                return(system.Databases[databasename]);
            }
            else
            {
                return(system.Databases.DefaultDatabase);
            }
        }
        public MainWindow()
        {
            PISystems piSystems = new PISystems();

            aPiSystem = piSystems.DefaultPISystem;

            InitializeComponent();

            Closed += MainWindow_Closed;

            InitializeComponent();
            msalAuthHelper = new MsalAuthHelper();
            RefreshSignInStatus();
        }
Example #7
0
        static void Main(string[] args)
        {

            Options arguments = Parser.Default.ParseArguments<Options>(args).MapResult(options => options, _ => null);
            Logger logger = new Logger(true, arguments.LogFile != null ? arguments.LogFile : null);

            logger.Log("Started");

            // Server

            logger.Log($"Connecting to server {arguments.ServerName}");
            PIServer piServer = PIUtil.GetPIServer(arguments.ServerName);

            logger.Log($"Connecting to system {arguments.SystemName}");
            PISystem piSystem = AFUtil.GetPISystem(arguments.SystemName);

            logger.Log("Connected");

            logger.Log($"Listing databases: system {arguments.SystemName}");
            AFUtil.WriteDatabases(piSystem, arguments.DatabaseOutputFile);

            // Database

            if (arguments.DatabaseName != null)
            {
                AFDatabase database = AFUtil.GetDatabase(piSystem, arguments.DatabaseName);

                logger.Log($"Listing attributes for database {database.Name}");
                AFUtil.WriteAttributes(database, arguments.AttributeOutputFile);
            }
            else
            {
                var outputFileExtension = Path.GetExtension(arguments.AttributeOutputFile);
                var outputFileName = Path.ChangeExtension(arguments.AttributeOutputFile, null);

                AFDatabases databases = piSystem.Databases;
                Parallel.ForEach(
                    databases,
                    new ParallelOptions { MaxDegreeOfParallelism = arguments.NumParallelTasks },
                    (AFDatabase database) =>
                    {
                        logger.Log($"Listing attributes: database {database.Name}");
                        AFUtil.WriteAttributes(database, $"{outputFileName} {database.Name}{outputFileExtension}");
                    });
            }
            
            logger.Log("Finished - press Enter to close terminal");
            logger.Close();
            Console.ReadLine();
        }
        static AFDatabase GetDatabase(string serverName, string databaseName)
        {
            Console.WriteLine("Retrieving the AF database");
            PISystem assetServer = GetPISystem(null, serverName);

            if (!string.IsNullOrEmpty(databaseName))
            {
                return(assetServer.Databases[databaseName]);
            }
            else
            {
                return(assetServer.Databases.DefaultDatabase);
            }
        }
        /// <summary>
        /// Initialize an AF Connnection object.
        /// it is required to call the Connect method before getting Database or the connected PISystem object
        /// </summary>
        /// <param name="server">Name of the PI System (AF Server) to connect to</param>
        /// <param name="databaseName">Name of the AF DatabaseName to connect to</param>
        public AFConnectionHelper(string server, string databaseName=null)
        {
            PISystems.DirectoryOptions = PISystems.AFDirectoryOptions.AutoAdd;

            if (_piSystems.Contains(server))
                _piSystem = _piSystems[server];
            else
            {
             _logger.Warn("PI System does not exist in the KST, it will be added");
             _piSystem = _piSystems[server];
             }

            _databaseName = databaseName;
        }
Example #10
0
        static AFDatabase GetDatabase(string servername, string databasename)
        {
            PISystems piafsystems = new PISystems();
            PISystem  system      = piafsystems[servername];

            if (system != null && system.Databases.Contains(databasename))
            {
                Console.WriteLine("Found '{0}' with '{1}' databases", system.Name, system.Databases.Count);
                return(system.Databases[databasename]);
            }
            else
            {
                return(null);
            }
        }
Example #11
0
        public void ConnectToAfDatabase(string afServer, string afDatabase)
        {
            XmlConfigurator.Configure();

            PISystems myPISystems = new PISystems();

            PISystem myPISystem = string.IsNullOrEmpty(afServer) ? myPISystems.DefaultPISystem : myPISystems[afServer];

            myPISystem.Connect();
            Log.InfoFormat("SDK: {0}, Server: {1}", myPISystems.Version, myPISystem.ServerVersion);

            _afDatabase = string.IsNullOrEmpty(afDatabase) ? myPISystem.Databases.DefaultDatabase : myPISystem.Databases[afDatabase];

            Log.InfoFormat("PI System {0} ; Database {1}", myPISystem.Name, _afDatabase.Name);
        }
Example #12
0
        private void piSystemPicker_SelectionChange(object sender, SelectionChangeEventArgs e)
        {
            PISystem pisystem = piSystemPicker.PISystem;

            if (pisystem != null)
            {
                AFElement limitcalculator = piSystemPicker.PISystem.Databases["Configuration"].Elements["LimitCalculator"];
                if (limitcalculator == null)
                {
                    piSystemPicker.PISystem.Databases["Configuration"].Elements.Add(new AFElement("LimitCalculator"));
                    piSystemPicker.PISystem.Databases["Configuration"].CheckIn();
                }
                configurationTreeView.AFRoot = piSystemPicker.PISystem.Databases["Configuration"].Elements["LimitCalculator"];
            }
        }
        public void Connect(string piSystemName, string afDatabaseName, string piDataArchiveName)
        {
            piPointNamesToBeCreated = new List <string>();

            try
            {
                piSystem = new PISystems()[piSystemName];
                piSystem.Connect();
                log.Info("Connected to the AF Server.");
            }
            catch (Exception ex)
            {
                log.Fatal("Could not connect to AF Server: " + ex.Message);
                throw ex;
            }

            try
            {
                afDb = piSystem.Databases[afDatabaseName];
                if (afDb == null)
                {
                    log.Info("AF Database not found. Creating new AF Database.");
                    afDb = piSystem.Databases.Add(afDatabaseName);
                }
                else
                {
                    log.Info("AF Database found.");
                }
            }
            catch (Exception ex)
            {
                log.Fatal("Could not connect to AF Database: " + ex.Message);
                throw ex;
            }


            try
            {
                piServer = new PIServers()[piDataArchiveName];
                piServer.Connect();
                log.Info("Connected to the PI Data Archive.");
            }
            catch (Exception ex)
            {
                log.Fatal("Could not connect to PI Data Archive: " + ex.Message);
                throw ex;
            }
        }
Example #14
0
        public void Run()
        {
            PISystems piSystems = new PISystems();
            PISystem  piSystem  = piSystems["<AFSERVER>"];

            AFDatabase afDatabase = piSystem.Databases["NuGreen"];

            const int pageSize   = 1000;
            int       startIndex = 0;
            int       totalCount;

            do
            {
                // Find a collection of elements instantiated from the Boiler tempplate.
                // Only the Elements' header information (Name, Description, Template, Type, etc.)
                // are loaded from the AF Server by this call.
                AFNamedCollection <AFElement> elements = AFElement.FindElements(
                    database: afDatabase,
                    searchRoot: null,
                    query: "Boiler",
                    field: AFSearchField.Template,
                    searchFullHierarchy: true,
                    sortField: AFSortField.Name,
                    sortOrder: AFSortOrder.Ascending,
                    startIndex: startIndex,
                    maxCount: pageSize,
                    totalCount: out totalCount);
                if (elements == null)
                {
                    break;
                }

                // This call goes to the AF Server to fully load the found elements in one call,
                // so further AF Server calls can be avoided.
                AFElement.LoadElements(elements);

                // Now we can use the elements without having to make any additional server calls.
                // In the example below, accessing the Attributes collection would have
                // caused an additional call per element if we had not called LoadElements previously.
                Console.WriteLine("Found {0} Elements.", elements.Count);
                foreach (AFElement item in elements)
                {
                    Console.WriteLine("  Element {0} has {1} Attributes", item.Name, item.Attributes.Count);
                }

                startIndex += pageSize;
            } while (startIndex < totalCount);
        }
Example #15
0
        public PBToolkitBar()
        {
            InitializeComponent();

            PISystems systems = new PISystems();

            m_System = systems.DefaultPISystem;
            if (m_Database == null)
            {
                DialogResult dialogResult;
                m_Database = AFOperations.ConnectToDatabase(this, m_System.Name, "", true, out dialogResult);
            }
            m_FoundElement = null;

            btnConnect_Click(null, null);
        }
        static UOMClass createUOM(PISystem system, string UOMClassName, string UOMCanonicalName, string UOMCanonicalAbbreviation)
        {
            UOMDatabase uomdb    = system.UOMDatabase;
            UOMClass    UOMClass = uomdb.UOMClasses[UOMClassName];

            if (UOMClass == null)
            {
                UOMClass = uomdb.UOMClasses.Add(UOMClassName, UOMCanonicalName, UOMCanonicalAbbreviation);
                system.CheckIn();
            }
            if (UOMClass.CanonicalUOM.Name != UOMCanonicalName)
            {
                throw new System.ArgumentException("The current existing UOM Classes has a different canonical UOM");
            }
            return(UOMClass);
        }
        /// <summary>
        /// Initialize an AF Connnection object.
        /// it is required to call the Connect method before getting Database or the connected PISystem object
        /// </summary>
        /// <param name="server">Name of the PI System (AF Server) to connect to</param>
        /// <param name="databaseName">Name of the AF DatabaseName to connect to</param>
        public AFConnectionHelper(string server, string databaseName = null)
        {
            PISystems.DirectoryOptions = PISystems.AFDirectoryOptions.AutoAdd;

            if (_piSystems.Contains(server))
            {
                _piSystem = _piSystems[server];
            }
            else
            {
                _logger.Warn("PI System does not exist in the KST, it will be added");
                _piSystem = _piSystems[server];
            }

            _databaseName = databaseName;
        }
Example #18
0
        public static void PrintEnergyUOMs(PISystem system)
        {
            if (system == null)
            {
                throw new ArgumentNullException(nameof(system));
            }
            Console.WriteLine("Print Energy UOMs");
            UOMClass uomClass = system.UOMDatabase.UOMClasses["Energy"];

            foreach (UOM uom in uomClass.UOMs)
            {
                Console.WriteLine("UOM: {0}, Abbreviation: {1}", uom.Name, uom.Abbreviation);
            }

            Console.WriteLine();
        }
        static void Main(string[] args)
        {
            var options = new Options();

            if (CommandLine.Parser.Default.ParseArguments(args, options))
            {
                // Command values are available here
                uomgrouping = options.uomgrouping;
            }

            system = new PISystems().DefaultPISystem;
            var db = system.Databases.DefaultDatabase;

            UOMdb = system.UOMDatabase;
            dt    = db.Tables["UOM Groupings"].Table;
            convertAttributesAndAnalysis(db);
        }
        /// <summary>
        /// Initialize an AF Connnection object.
        /// it is required to call the Connect method before getting Database or the connected PISystem object
        /// </summary>
        /// <param name="server">Name of the PI System (AF Server) to connect to</param>
        /// <param name="databaseName">Name of the AF DatabaseName to connect to</param>
        public AfConnectionMgr(string server, string databaseName=null)
        {
            if (_piSystems.Contains(server))
                _piSystem = _piSystems[server];
            else
            {
                // in case you would like to force the auto-creation of the PI System in KST if it does not exist, uncomment the following two lines
                // and remove the exception throwing
                //
                // PISystems.DirectoryOptions = PISystems.AFDirectoryOptions.AutoAdd;
                // _piSystem = _piSystems[server];

                throw new KeyNotFoundException("Specified PI System does not exist");
            }

            _databaseName = databaseName;
        }
Example #21
0
        /// <summary>
        /// Removes the named notification contact template if it exists.
        /// </summary>
        /// <param name="name">The name of the notification contact template to remove.</param>
        /// <param name="output">The output logger used for writing messages.</param>
        public void RemoveNotificationContactTemplateIfExists(string name, ITestOutputHelper output)
        {
            Contract.Requires(output != null);

            var preCheckNCT = PISystem.NotificationContactTemplates[name];

            if (preCheckNCT != null)
            {
                output.WriteLine($"Notification Contact Template [{preCheckNCT}] exists, delete it.");
                PISystem.NotificationContactTemplates.Remove(preCheckNCT);
                PISystem.CheckIn();
            }
            else
            {
                output.WriteLine($"Notification Contact Template [{name}] does not exist, can not be deleted.");
            }
        }
Example #22
0
        /// <summary>
        /// Removes the UOM Class from the AF Database if it exists.
        /// </summary>
        /// <param name="name">The name of UOM Class to remove.</param>
        /// <param name="output">The output logger used for writing messages.</param>
        public void RemoveUOMClassIfExists(string name, ITestOutputHelper output)
        {
            Contract.Requires(output != null);

            var preCheckUOMClass = PISystem.UOMDatabase.UOMClasses[name];

            if (preCheckUOMClass != null)
            {
                output.WriteLine($"UOM Class [{preCheckUOMClass}] exists, delete it.");
                PISystem.UOMDatabase.UOMClasses.Remove(preCheckUOMClass);
                PISystem.CheckIn();
            }
            else
            {
                output.WriteLine($"UOM Class [{name}] does not exist, can not be deleted.");
            }
        }
        static void Main(string[] args)
        {
            var options = new Options();

            if (CommandLine.Parser.Default.ParseArguments(args, options))
            {
                // Command values are available here
                currency = options.currency;
                rate     = options.rate;
            }
            system = new PISystems().DefaultPISystem;
            var db = system.Databases.DefaultDatabase;

            UOMdb = system.UOMDatabase;
            dt    = db.Tables["Currency Conversion"].Table;
            convertAttributesAndAnalysis(db);
        }
Example #24
0
        /// <summary>
        /// Example that shows how to connect to PI System
        /// in your application, you should keep a reference to piSystems so its not garbage collected.
        /// The class  <see cref="AfConnectionHelper"/> illustrates this. (ctrl+click to navigate to the class.)
        /// </summary>
        /// <param name="server"></param>
        /// <returns></returns>
        public PISystem Connect(string server)
        {
            string    serverName = server;
            PISystems piSystems  = new PISystems();

            // in case you would like to force the auto-creation of the PI System in KST if it does not exist, uncomment the following line
            // see: https://techsupport.osisoft.com/Documentation/PI-AF-SDK/html/T_OSIsoft_AF_PISystems_AFDirectoryOptions.htm
            // PISystems.DirectoryOptions = PISystems.AFDirectoryOptions.AutoAdd;

            PISystem piSystem = piSystems[serverName];

            // true, null option will force a password dialog to appear.
            // you should not use this option for a service or an executable that runs outside a windows session.
            // instead use the empty constructor and make sure that the user that runs the application have an account that allows it to connect.
            piSystem.Connect(true, null);

            return(piSystem);
        }
        public void Run()
        {
            PISystems piSystems = new PISystems();
            PISystem  piSystem  = piSystems["<AFSERVER>"];

            AFDatabase afDatabase = piSystem.Databases["NuGreen"];

            AFCategory elementCategory   = afDatabase.ElementCategories["Equipment Assets"];
            AFCategory attributeCategory = afDatabase.AttributeCategories["Real-Time Data"];

            AFElementTemplate elementTemplate = afDatabase.ElementTemplates["Boiler"];

            const int pageSize   = 1000;
            int       startIndex = 0;
            int       totalCount;

            do
            {
                // Find all "Water Flow" attributes in the NuGreen database.
                AFAttributeList attrList = AFAttribute.FindElementAttributes(
                    database: afDatabase,
                    searchRoot: null,
                    nameFilter: "*",
                    elemCategory: elementCategory,
                    elemTemplate: elementTemplate,
                    elemType: AFElementType.Any,
                    attrNameFilter: "*",
                    attrCategory: attributeCategory,
                    attrType: TypeCode.Double,
                    searchFullHierarchy: true,
                    sortField: AFSortField.Name,
                    sortOrder: AFSortOrder.Ascending,
                    startIndex: startIndex,
                    maxCount: pageSize,
                    totalCount: out totalCount);

                foreach (AFAttribute attr in attrList)
                {
                    Console.WriteLine("Parent element name: {0}", attr.Element);
                }

                startIndex += pageSize;
            } while (startIndex < totalCount);
        }
        public void Run()
        {
            PISystems piSystems = new PISystems();
            PISystem  piSystem  = piSystems["<AFSERVER>"];

            AFDatabase afDatabase = piSystem.Databases["NuGreen"];

            AFElement nuGreen         = afDatabase.Elements["NuGreen"];
            AFElement houston         = nuGreen.Elements["Houston"];
            AFElement crackingProcess = houston.Elements["Cracking Process"];
            AFElement equipment       = crackingProcess.Elements["Equipment"];
            AFElement b210            = equipment.Elements["B-210"];

            AFAttribute processFeedRate = b210.Attributes["Process Feedrate"];

            AFValue val = processFeedRate.GetValue();

            Console.WriteLine("Timestamp: {0}, Value: {1}", val.Timestamp, val.Value.ToString());
        }
Example #27
0
        /// <summary>
        /// Initialize an AF Connnection object.
        /// it is required to call the Connect method before getting Database or the connected PISystem object
        /// </summary>
        /// <param name="server">Name of the PI System (AF Server) to connect to</param>
        /// <param name="databaseName">Name of the AF DatabaseName to connect to</param>
        public AfConnectionMgr(string server, string databaseName = null)
        {
            if (_piSystems.Contains(server))
            {
                _piSystem = _piSystems[server];
            }
            else
            {
                // in case you would like to force the auto-creation of the PI System in KST if it does not exist, uncomment the following two lines
                // and remove the exception throwing
                //
                // PISystems.DirectoryOptions = PISystems.AFDirectoryOptions.AutoAdd;
                // _piSystem = _piSystems[server];

                throw new KeyNotFoundException("Specified PI System does not exist");
            }

            _databaseName = databaseName;
        }
Example #28
0
        public void Run()
        {
            PISystems piSystems = new PISystems();
            PISystem  piSystem  = piSystems["<AFSERVER>"];

            AFDatabase afDatabase = piSystem.Databases["NuGreen"];

            const int pageSize   = 1000;
            int       startIndex = 0;
            int       totalCount;

            do
            {
                // Find a collection of elements instantiated from the Boiler tempplate.
                // Only the Elements' header information (Name, Description, Template, Type, etc.)
                // are loaded from the AF Server by this call.
                AFNamedCollection <AFElement> elements = AFElement.FindElements(
                    database: afDatabase,
                    searchRoot: null,
                    query: "Boiler",
                    field: AFSearchField.Template,
                    searchFullHierarchy: true,
                    sortField: AFSortField.Name,
                    sortOrder: AFSortOrder.Ascending,
                    startIndex: startIndex,
                    maxCount: pageSize,
                    totalCount: out totalCount);
                if (elements == null)
                {
                    break;
                }

                // Because we are just retrieving the element's name, no additional calls
                // to the AF Server are made.
                Console.WriteLine("Found {0} Elements.", elements.Count);
                foreach (AFElement item in elements)
                {
                    Console.WriteLine("  Element name is {0}.", item.Name);
                }

                startIndex += pageSize;
            } while (startIndex < totalCount);
        }
Example #29
0
        static void Main(string[] args)
        {
            myPISystem   = new PISystems()["MARC-PI2014"];
            PIServerName = "MARC-PI2014";
            AFDatabase myDb = myPISystem.Databases["PIWebAPIWhitePaperSampleDb"];

            if (myDb == null)
            {
                myDb = myPISystem.Databases.Add("PIWebAPIWhitePaperSampleDb");
            }

            AFElementTemplate myCityTemplate = myDb.ElementTemplates["CityTemplate"];

            if (myCityTemplate == null)
            {
                myCityTemplate = myDb.ElementTemplates.Add("Cities");
            }


            UOM degreeC    = myPISystem.UOMDatabase.UOMClasses["Temperature"].UOMs["degree Celsius"];
            UOM speedKmph  = myPISystem.UOMDatabase.UOMClasses["Speed"].UOMs["kilometer per hour"];
            UOM millibar   = myPISystem.UOMDatabase.UOMClasses["Pressure"].UOMs["milibar"];
            UOM percent    = myPISystem.UOMDatabase.UOMClasses["Ratio"].UOMs["percent"];
            UOM kilometres = myPISystem.UOMDatabase.UOMClasses["Length"].UOMs["kilometer"];


            CreateAttributeTemplate("Cloud Cover", myCityTemplate, typeof(int), percent);
            CreateAttributeTemplate("Humidity", myCityTemplate, typeof(double), percent);
            CreateAttributeTemplate("Pressure", myCityTemplate, typeof(int), millibar);
            CreateAttributeTemplate("Temperature", myCityTemplate, typeof(int), degreeC);
            CreateAttributeTemplate("Visibility", myCityTemplate, typeof(int), kilometres);
            CreateAttributeTemplate("Wind Speed", myCityTemplate, typeof(int), speedKmph);

            AFElement cities = myDb.Elements.Add("Cities");

            cities.Elements.Add("Chicago", myCityTemplate);
            cities.Elements.Add("Los Angeles", myCityTemplate);
            cities.Elements.Add("New York", myCityTemplate);
            cities.Elements.Add("San Francisco", myCityTemplate);
            cities.Elements.Add("Washington", myCityTemplate);
            myDb.CheckIn();
        }
        public QLPiSystemResolve(PISystem aPiSystem, Field afDbsField)
        {
            name = aPiSystem.Name;
            if (afDbsField != null)
            {
                var nameFilterStrings = GraphQlHelpers.GetArgumentStrings(afDbsField, "nameFilter");
                var afElementsField   = GraphQlHelpers.GetFieldFromFieldOrContext(afDbsField, "afElements");

                var returnElementsObject = new ConcurrentBag <QLAfDatabase>();
                var afDbsList            = aPiSystem.Databases;
                Parallel.ForEach(afDbsList, aAfDb =>
                {
                    if (nameFilterStrings.Count == 0 || nameFilterStrings.Contains(aAfDb.Name))
                    {
                        returnElementsObject.Add(new QLAfDatabaseResolve(aAfDb, afElementsField));
                    }
                });
                afDbs = returnElementsObject.OrderBy(x => x.name).ToList();
            }
        }
Example #31
0
        private static AFDatabase CreateDatabase(string servername, string databasename)
        {
            AFDatabase database    = null;
            PISystems  piafsystems = new PISystems();
            PISystem   system      = piafsystems[servername];

            if (system != null)
            {
                if (system.Databases.Contains(databasename))
                {
                    database = system.Databases[databasename];
                }
                else
                {
                    database = system.Databases.Add(databasename);
                }
            }

            return(database);
        }
Example #32
0
        /// <summary>
        /// Creates an instance of the AFFixture class.
        /// </summary>
        public AFFixture()
        {
            var systems = new PISystems();

            if (systems.Contains(Settings.AFServer))
            {
                PISystem = systems[Settings.AFServer];
                PISystem.Connect();
            }
            else
            {
                throw new InvalidOperationException(
                          $"The specific AF Server [{Settings.AFServer}] does not exist or is not configured.");
            }

            if (PISystem.Databases.Contains(Settings.AFDatabase))
            {
                AFDatabase = PISystem.Databases[Settings.AFDatabase];
            }
        }
        public void Run()
        {
            PISystems piSystems = new PISystems();
            PISystem  piSystem  = piSystems["<AFSERVER>"];

            AFDatabase afDatabase = piSystem.Databases["Basic-AFSDK-Sample"];

            AFElement boilerA = afDatabase.Elements["Region_0"].Elements["BoilerA"];

            AFElementTemplate   elementTemplate         = afDatabase.ElementTemplates["BasicBoilerTemplate"];
            AFAttributeTemplate temperatureAttrTemplate = elementTemplate.AttributeTemplates["Temperature"];
            AFAttributeTemplate modeAttrTemplate        = elementTemplate.AttributeTemplates["Mode"];

            AFElement.LoadAttributes(new[] { boilerA }, new[] { temperatureAttrTemplate, modeAttrTemplate });

            AFEnumerationSet digSet = afDatabase.EnumerationSets["Modes"];

            IList <AFValue> valuesToWrite = new List <AFValue>();

            for (int i = 0; i < 10; i++)
            {
                AFTime time = new AFTime(new DateTime(2015, 1, 1, i, 0, 0, DateTimeKind.Local));

                AFValue afValueFloat = new AFValue(i, time);
                // Associate the AFValue to an attribute so we know where to write to.
                afValueFloat.Attribute = boilerA.Attributes["Temperature"];

                AFEnumerationValue digSetValue    = i % 2 == 0 ? digSet["Auto"] : digSet["Manual"];
                AFValue            afValueDigital = new AFValue(digSetValue, time);
                afValueDigital.Attribute = boilerA.Attributes["Mode"];

                valuesToWrite.Add(afValueFloat);
                valuesToWrite.Add(afValueDigital);
            }

            // Perform a bulk write. Use a single local call to PI Buffer Subsystem if possible.
            // Otherwise, make a single call to the PI Data Archive.
            // We use no compression just so we can check all the values are written.
            // AFListData is the class that provides the bulk write method.
            AFListData.UpdateValues(valuesToWrite, AFUpdateOption.InsertNoCompression, AFBufferOption.BufferIfPossible);
        }
Example #34
0
        //PIPoints
        /// <summary>
        /// Accesses the PIServer to get the PIPoints that are available.
        /// </summary>
        /// <param name="sys"> The current PISystem</param>
        /// <param name="serv"> The current PIServer</param>
        /// <returns></returns>
        public List <PIPoint> getPIPoints(PISystem sys, PIServer serv)
        {
            mainForm.Status("Getting PIPoints...");
            currentSystem   = sys;
            currentPIServer = serv;
            List <PIPoint> list;

            try
            {
                List <string> query = new List <string>()
                {
                    "*"
                };
                list = (List <PIPoint>)PIPoint.FindPIPoints(serv, query, null);
                return(list);
            }
            catch
            {
                mainForm.Status("ERROR: Unable to attach to " + serv.Name);
                return(null);
            }
        }
Example #35
0
        static void PrintEnergyUOMs(PISystem system)
        {
            try
            {
                Console.WriteLine("Print Energy UOMS");
                UOMClass uomClass = system.UOMDatabase.UOMClasses["Specific Entropy, Specific Heat Capacity"];


                foreach (UOM uom in uomClass.UOMs)
                {
                    Console.WriteLine("UOM: {0}, Abbrevation: {1}", uom.Name, uom.Abbreviation);
                }
                Console.WriteLine();
            }
            catch (Exception ex)
            {
                Logs Err = new Logs();
                Err.MyLogFile(ex);
                Console.WriteLine("An Error has occured for details please check the Log File: '" + ex.Message + "'");
                Console.ReadLine();
            }
        }
        static void Main(string[] args)
        {
            myPISystem = new PISystems()["MARC-PI2014"];
            PIServerName = "MARC-PI2014";
            AFDatabase myDb = myPISystem.Databases["PIWebAPIWhitePaperSampleDb"];
            if (myDb == null)
            {
                myDb = myPISystem.Databases.Add("PIWebAPIWhitePaperSampleDb");
            }

            AFElementTemplate myCityTemplate = myDb.ElementTemplates["CityTemplate"];
            if (myCityTemplate == null)
            {
                myCityTemplate = myDb.ElementTemplates.Add("Cities");
            }

            UOM degreeC = myPISystem.UOMDatabase.UOMClasses["Temperature"].UOMs["degree Celsius"];
            UOM speedKmph = myPISystem.UOMDatabase.UOMClasses["Speed"].UOMs["kilometer per hour"];
            UOM millibar = myPISystem.UOMDatabase.UOMClasses["Pressure"].UOMs["milibar"];
            UOM percent = myPISystem.UOMDatabase.UOMClasses["Ratio"].UOMs["percent"];
            UOM kilometres = myPISystem.UOMDatabase.UOMClasses["Length"].UOMs["kilometer"];

            CreateAttributeTemplate("Cloud Cover", myCityTemplate, typeof(int), percent);
            CreateAttributeTemplate("Humidity", myCityTemplate, typeof(double), percent);
            CreateAttributeTemplate("Pressure", myCityTemplate, typeof(int), millibar);
            CreateAttributeTemplate("Temperature", myCityTemplate, typeof(int), degreeC);
            CreateAttributeTemplate("Visibility", myCityTemplate, typeof(int), kilometres);
            CreateAttributeTemplate("Wind Speed", myCityTemplate, typeof(int), speedKmph);

            AFElement cities = myDb.Elements.Add("Cities");
            cities.Elements.Add("Chicago", myCityTemplate);
            cities.Elements.Add("Los Angeles", myCityTemplate);
            cities.Elements.Add("New York", myCityTemplate);
            cities.Elements.Add("San Francisco", myCityTemplate);
            cities.Elements.Add("Washington", myCityTemplate);
            myDb.CheckIn();
        }
Example #37
0
		public WAFElement()
		{
			PISystems syss = new PISystems();
			m_piSys = syss.DefaultPISystem;
			m_afDb = m_piSys.Databases.DefaultDatabase;
		}
Example #38
0
 public UOMManager(PISystem piSystem)
 {
     this.piSystem = piSystem;
 }
 static void PrintEnergyUOMs(PISystem system)
 {
     // Your code here
 }
        // Define other instance members here

        public AFHierarchyBuilder(string server)
        {
            _piSystem = new PISystems()[server];
        }
 //PIPoints
 /// <summary>
 /// Accesses the PIServer to get the PIPoints that are available.
 /// </summary>
 /// <param name="sys"> The current PISystem</param>
 /// <param name="serv"> The current PIServer</param>
 /// <returns></returns>
 public List<PIPoint> getPIPoints(PISystem sys, PIServer serv)
 {
     mainForm.Status("Getting PIPoints...");
     currentSystem = sys;
     currentPIServer = serv;
     List<PIPoint> list;
     try
     {
         List<string> query = new List<string>() { "*" };
         list = (List<PIPoint>)PIPoint.FindPIPoints(serv, query, null);
         return list;
     }
     catch
     {
             mainForm.Status("ERROR: Unable to attach to " + serv.Name);
             return null;
     }
 }