Opc.Ua.Configuration.MainForm.ImportCertificateToTrustListBTN_Click C# (CSharp) Method

ImportCertificateToTrustListBTN_Click() private method

private ImportCertificateToTrustListBTN_Click ( object sender, EventArgs e ) : void
sender object
e System.EventArgs
return void
        private void ImportCertificateToTrustListBTN_Click(object sender, EventArgs e)
        {
            try
            {
                // get application.
                ManagedApplication application = ApplicationToManageCTRL.GetSelectedApplication();;

                if (application == null)
                {
                    return;
                }

                // load the configuration.
                application.Reload();

                // set current directory.
                if (m_currentDirectory == null)
                {
                    m_currentDirectory = Utils.GetAbsoluteDirectoryPath("%CommonApplicationData%\\OPC Foundation\\CertificateStores\\UA Applications", false, false);
                }

                if (m_currentDirectory == null)
                {
                    m_currentDirectory = new FileInfo(Application.ExecutablePath).DirectoryName;
                }

                // open file dialog.
                OpenFileDialog dialog = new OpenFileDialog();

                dialog.CheckFileExists = true;
                dialog.CheckPathExists = true;
                dialog.DefaultExt = ".der";
                dialog.Filter = "DER Files (*.der)|*.der|PKCS #12 Files (*.pfx)|*.pfx|All Files (*.*)|*.*";
                dialog.Multiselect = false;
                dialog.ValidateNames = true;
                dialog.Title = "Open Certificate File";
                dialog.FileName = null;
                dialog.InitialDirectory = m_currentDirectory;
                dialog.RestoreDirectory = true;

                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                FileInfo fileInfo = new FileInfo(dialog.FileName);
                m_currentDirectory = fileInfo.Directory.FullName;

                if (!fileInfo.Exists)
                {
                    return;
                }

                X509Certificate2 certificate = new X509Certificate2(fileInfo.FullName, (string)null, X509KeyStorageFlags.Exportable);
                ValidateAndImport(application.TrustList, certificate);
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }