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

ImportCertificateListToStoreBTN_Click() private method

private ImportCertificateListToStoreBTN_Click ( object sender, EventArgs e ) : void
sender object
e System.EventArgs
return void
        private void ImportCertificateListToStoreBTN_Click(object sender, EventArgs e)
        {
            try
            {
                const string caption = "Import Certificate List";
                
                CertificateStoreIdentifier list1 = new CertificateStoreIdentifier();
                list1.StoreType = ManagedStoreCTRL.StoreType;
                list1.StorePath = ManagedStoreCTRL.StorePath;

                if (m_currentStore == null)
                {
                    m_currentStore = new CertificateStoreIdentifier();
                    m_currentStore.StoreType = Utils.DefaultStoreType;
                    m_currentStore.StorePath = Utils.DefaultStorePath;
                }

                CertificateStoreIdentifier list2 = new CertificateStoreDlg().ShowDialog(m_currentStore);

                if (list2 == null)
                {
                    return;
                }

                m_currentStore = list2;

                int count = 0;
                ICertificateStore store1 = list1.OpenStore();
                ICertificateStore store2 = list2.OpenStore();

                try
                {
                    foreach (X509Certificate2 certificate in store2.Enumerate())
                    {
                        if (store1.FindByThumbprint(certificate.Thumbprint) == null)
                        {
                            store1.Add(certificate);
                            count++;
                        }
                    }
                }
                finally
                {
                    store1.Close();
                    store2.Close();
                }

                MessageBox.Show(
                    this,
                    count.ToString() + " certificates added.",
                    caption,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }