private void ButtonGetInfo_Click(object sender, RoutedEventArgs e) { object userCertSubjectName = ListBoxUserCerts.SelectedItem; object fssCertSubjectName = ListBoxFssCerts.SelectedItem; if (userCertSubjectName == null || fssCertSubjectName == null) { MessageBox.Show(this, "Необходимо выбрать сертификаты для продолжения", "", MessageBoxButton.OK, MessageBoxImage.Information); return; } DateTime dateBegin = DatePickerBegin.SelectedDate.Value.Date; DateTime dateEnd = DatePickerEnd.SelectedDate.Value.Date; if (dateBegin > dateEnd) { MessageBox.Show(this, "Дата начала выбранного периода не может быть больше даты окончания", "", MessageBoxButton.OK, MessageBoxImage.Information); return; } X509Certificate2 userCert = CryptoTools.GetCertificate( (StoreLocation)ComboBoxUserCertStoreLocation.SelectedItem, (StoreName)ComboBoxUserCertStoreName.SelectedItem, (string)userCertSubjectName); X509Certificate2 fssCert = CryptoTools.GetCertificate( (StoreLocation)ComboBoxFssCertStoreLocation.SelectedItem, (StoreName)ComboBoxFssCertStoreName.SelectedItem, (string)fssCertSubjectName); WsdlServiceHandle.Instance.Initialize( dateBegin, dateEnd, userCert, fssCert); WindowFssList windowFssList = new WindowFssList(); windowFssList.Owner = this; windowFssList.ShowDialog(); }
static private X509Certificate2 GetCertificate(bool isUserCertificate) { string storeLocation; string storeName; string subjectDN; if (isUserCertificate) { storeLocation = Properties.Settings.Default.CertificateUserStoreLocation; storeName = Properties.Settings.Default.CertificateUserStoreName; subjectDN = Properties.Settings.Default.CertificateUserSubjectDN; } else { storeLocation = Properties.Settings.Default.CertificateFssStoreLocation; storeName = Properties.Settings.Default.CertificateFssStoreName; subjectDN = Properties.Settings.Default.CertificateFssSubjectDN; } bool isStoreLocationOK = Enum.TryParse(storeLocation, out StoreLocation storeLocationEnum); if (!isStoreLocationOK) { Logging.ToLog("!!! Не удалось определить расположение хранилища для параметра: " + storeLocation); return(null); } bool isStoreNameOK = Enum.TryParse(storeName, out StoreName storeNameEnum); if (!isStoreNameOK) { Logging.ToLog("!!! Не удалось определить имя хранилища для параметра: " + storeName); return(null); } try { return(CryptoTools.GetCertificate(storeLocationEnum, storeNameEnum, subjectDN)); } catch (Exception e) { Logging.ToLog("!!! Не удалось найти сертификат: " + Environment.NewLine + e.Message + Environment.NewLine + e.StackTrace); return(null); } }