Beispiel #1
0
        public ObservableCollection<Templates> GetCaTemplates(string caserver)
        {
            CCertRequest objCertRequest = new CCertRequestClass();
                ObservableCollection<Templates> Templates = new ObservableCollection<Templates>();

                Regex regex = new Regex(@"([A-Za-z]+)");
                string value = objCertRequest.GetCAProperty(caserver, 29, 0, 4, 0).ToString();
                string[] lines = Regex.Split(value, @"\n");

                foreach (string line in lines)
                {
                    Match match = regex.Match(line);
                    if (match.Success)
                    {
                        Templates.Add(new Templates { Template = line });
                    }
                }

                return Templates;
        }
        private void btn_SelectCA_Click(object sender, RoutedEventArgs e)
        {
            CCertConfig objCertConfig = new CCertConfigClass();
            CCertRequest objCertRequest = new CCertRequestClass();

            try
            {
                // Get CA config from UI
                string strCAConfig = objCertConfig.GetConfig(CC_UIPICKCONFIG);

                if(String.IsNullOrWhiteSpace(strCAConfig))
                {
                    return;
                }

            // Get CA Connection string
            string CACon = objCertConfig.GetField("Config");
            txt_CAServer.Text = CACon;

            // Get CA Type
            string caType = objCertRequest.GetCAProperty(strCAConfig, 10, 0, 1, 0).ToString();
            string caTypeTXT = "";
            switch (caType)
            {
                case "0":
                    caTypeTXT = "ENTERPRISE ROOT CA";
                    break;
                case "1":
                    caTypeTXT = "ENTERPRISE SUB CA";
                    break;
                case "3":
                    caTypeTXT = "STANDALONE ROOT CA";
                    break;
                case "4":
                    caTypeTXT = "STANDALONE SUB CA";
                    break;
            }
            txt_CaType.Text = caTypeTXT;

            if (caType == "3" || caType == "4" || caType == "5")
            {
                cmb_Templates.Visibility = System.Windows.Visibility.Hidden;
                btn_LoadTempls.Visibility = System.Windows.Visibility.Hidden;
                oids.Visibility = System.Windows.Visibility.Visible;
                txt_oid.Visibility = System.Windows.Visibility.Visible;
                oids.ItemsSource = Certificat.ListOids();

                strength.Visibility = System.Windows.Visibility.Visible;
            }
            else if (caType == "0" || caType == "1")
            {
                cmb_Templates.Visibility = System.Windows.Visibility.Visible;
                oids.Visibility = System.Windows.Visibility.Hidden;
                txt_oid.Visibility = System.Windows.Visibility.Hidden;
                btn_LoadTempls.Visibility = System.Windows.Visibility.Visible;
                cmb_Templates.ItemsSource = templates.GetCaTemplates(strCAConfig);
                strength.Visibility = System.Windows.Visibility.Visible;
            }

            }
            catch(Exception ex)
            {

                //Check if the user closed the dialog. Do nothing.
                if (ex.HResult.ToString() == "-2147023673")
                {
                    //MessageBox.Show("Closed By user");
                }
                    //Check if there is no available CA Servers.
                else if (ex.HResult.ToString() == "-2147024637")
                {
                    MessageBox.Show("Can't find available Servers");
                }
                    // If unknown error occurs.
                else
                {
                    MessageBox.Show(ex.Message + " " + ex.HResult.ToString());
                }
            }
        }