Opc.Ua.Configuration.ManagedApplication.LoadSdkConfigFile C# (CSharp) Method

LoadSdkConfigFile() private method

Tries to loads the SDK config file.
private LoadSdkConfigFile ( ) : void
return void
        private void LoadSdkConfigFile()
        {
            m_isSdkCompatible = false;
            m_application = null;

            if (String.IsNullOrEmpty(m_configurationPath))
            {
                return;
            }

            FileInfo executablePath = new FileInfo(m_executablePath);
            string currentDirectory = Environment.CurrentDirectory;
            Environment.CurrentDirectory = executablePath.DirectoryName;

            try
            {
                try
                {
                    m_application = GetApplicationSettings(m_configurationPath);

                    if (m_application != null)
                    {
                        m_isSdkCompatible = true;
                        m_certificate = Opc.Ua.Security.SecuredApplication.FromCertificateIdentifier(m_application.ApplicationCertificate);
                        m_trustList = Opc.Ua.Security.SecuredApplication.FromCertificateStoreIdentifier(m_application.TrustedCertificateStore);
                        m_application.ExecutableFile = m_executablePath;
                        m_configurationPath = m_application.ConfigurationFile;
                    }
                }

                // ignore errors.
                catch (Exception)
                {
                    m_application = null;
                }
            }
            finally
            {
                Environment.CurrentDirectory = currentDirectory;
            }
        }

Usage Example

Esempio n. 1
0
        /// <summary>
        /// Loads the specified file path.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <returns></returns>
        public static ManagedApplication Load(string filePath)
        {
            using (Stream istrm = File.Open(filePath, FileMode.Open, FileAccess.ReadWrite))
            {
                DataContractSerializer serializer  = new DataContractSerializer(typeof(ManagedApplication));
                ManagedApplication     application = (ManagedApplication)serializer.ReadObject(istrm);
                application.m_sourceFile = new FileInfo(filePath);

                if (String.IsNullOrEmpty(application.DisplayName))
                {
                    string name  = application.m_sourceFile.Name;
                    int    index = name.LastIndexOf('.');

                    if (index > 0)
                    {
                        name = name.Substring(0, index);
                    }

                    application.DisplayName = name;
                }

                application.LoadSdkConfigFile();
                return(application);
            }
        }