Exemple #1
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];
            }
            else
            {
                throw new InvalidOperationException(
                          $"The specific AF database [{Settings.AFDatabase}] does not exist or is not configured.");
            }
        }
Exemple #2
0
        bool attemptLogin(ResolveFieldContext context, string piSystemName)
        {
            PISystems piSystems = new PISystems();

            if (!piSystems.Contains(piSystemName))
            {
                context.Errors.Add(new ExecutionError($"PISystem {piSystemName} not found."));
                return(false);
            }
            else
            {
                aPiSystem = piSystems[piSystemName];
                try
                {
                    aPiSystem.Connect(getCreds(context));
                }
                catch (Exception e)
                {
                    context.Errors.Add(new ExecutionError($"Connection to PiSystem {piSystemName} failed - Connect() failed."));
                }
                if (aPiSystem.ConnectionInfo.IsConnected)
                {
                    return(true);
                }
                else
                {
                    context.Errors.Add(new ExecutionError($"Connection to PiSystem {piSystemName} failed - IsConnected() is false."));
                    return(false);
                }
            }
        }
Exemple #3
0
        private static (bool, string) SMTPServerIsConfigured()
        {
            if (_piSystem == null)
            {
                var systems = new PISystems();
                if (systems.Contains(Settings.AFServer))
                {
                    _piSystem = systems[Settings.AFServer];
                    _piSystem.Connect();
                }
                else
                {
                    return(false, $"The AF Server [{Settings.AFServer}] does not exist or is not configured.");
                }
            }

            var configurationDb = _piSystem.Databases.ConfigurationDatabase;

            if (configurationDb != null)
            {
                if (configurationDb.Elements.Contains(OSIsoft))
                {
                    var pianoElement = configurationDb.Elements[OSIsoft].Elements[PIANO];
                    if (pianoElement != null)
                    {
                        var emailPlugInElement = pianoElement.Elements[DeliveryChannel];
                        if (emailPlugInElement != null)
                        {
                            var subEmailPlugInElement = emailPlugInElement.Elements[PlugInGuid];
                            if (subEmailPlugInElement != null)
                            {
                                if (ElementHasValidAttribute(subEmailPlugInElement, SMTPServer) &&
                                    ElementHasValidAttribute(subEmailPlugInElement, SMTPServerPort))
                                {
                                    return(true, null);
                                }

                                return(false, "The email PlugIn doesn't have a valid SMTP server configuration.");
                            }

                            return(false, $"The [{PlugInGuid}] element is not found in the [{DeliveryChannel}] element in the configuration database.");
                        }

                        return(false, $"The [{DeliveryChannel}] element is not found in the [{PIANO}] element in the configuration database.");
                    }

                    return(false, $"The [{PIANO}] element is not found in the [{OSIsoft}] element in the configuration database.");
                }

                return(false, $"The [{OSIsoft}] element is not found in the configuration database.");
            }

            return(false, "The configuration database is not found.");
        }
        /// <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;
        }
Exemple #5
0
        internal static PISystem GetPISystemFromConfig()
        {
            PISystem pisys;

            var systems = new PISystems();

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

            return(pisys);
        }
Exemple #6
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;
        }
Exemple #7
0
        /// <summary>
        /// Gets an instanced PISystem.
        /// </summary>
        /// <returns>Returns a new PISystem from a new PISystems instance.</returns>
        /// <remarks>
        /// This operation gets an instanced PISystem object. It is used to prevent the main PISystem
        /// from using any cached data from a system check.
        /// </remarks>
        public PISystem GetInstancedSystem()
        {
            var systems = new PISystems(true);

            if (systems.Contains(Settings.AFServer))
            {
                var system = systems[Settings.AFServer];

                if (system is null)
                {
                    throw new InvalidOperationException(
                              $"The specific AF Server [{Settings.AFServer}] does not exist or is not configured.");
                }

                return(system);
            }
            else
            {
                throw new InvalidOperationException(
                          $"The specific AF Server [{Settings.AFServer}] does not exist or is not configured.");
            }
        }