Exemplo n.º 1
0
        /// <summary>
        /// Prepares OPC UA server for operating.
        /// </summary>
        private async Task PrepareOpcServer()
        {
            // create OPC application instance
            opcApp = new ApplicationInstance
            {
                ApplicationName   = DataSourceConfig.Name,
                ApplicationType   = ApplicationType.Server,
                ConfigSectionName = "Scada.Comm.Drivers.DrvDsOpcUaServer"
            };

            // load the application configuration
            WriteConfigFile(out string configFileName);
            ApplicationConfiguration opcConfig = await opcApp.LoadApplicationConfiguration(configFileName, false);

            // check the application certificate
            bool haveAppCertificate = await opcApp.CheckApplicationInstanceCertificate(false,
                                                                                       CertificateFactory.DefaultKeySize, CertificateFactory.DefaultLifeTime);

            if (!haveAppCertificate)
            {
                throw new ScadaException(Locale.IsRussian ?
                                         "Сертификат экземпляра приложения недействителен!" :
                                         "Application instance certificate invalid!");
            }

            if (!opcConfig.SecurityConfiguration.AutoAcceptUntrustedCertificates)
            {
                opcConfig.CertificateValidator.CertificateValidation += CertificateValidator_CertificateValidation;
            }

            // create OPC server
            opcServer = new CustomServer(CommContext, options, dsLog);
        }