using Contracts.BusinessLogicsContracts; using Contracts.SearchModels; using DataModels.Models; using ElectronicSignature.Certification; using Microsoft.Extensions.Logging; using System.Windows.Forms; namespace AppView { public partial class FormKeys : Form { private static readonly string keyPairPath = @"G:\tests\rsaKeyPair.pem"; private static readonly string privateKeyPath = @"G:\tests\rsaPrivateKey.pem"; private static readonly string publicKeyPath = @"G:\tests\rsaPublicKey.pem"; private static readonly string csrPath = @"G:\tests\rsaCSR.pem"; private static readonly string signedCertPath = @"G:\tests\rsaSignedCert.pem"; private static readonly string selfSignedCertPath = @"G:\tests\selfSignedCert.pem"; private static readonly string privateCertPath = @"G:\tests\privateCert.pfx"; private static readonly string privateCertPass = "1234"; private readonly ILogger _logger; private Dictionary _keys; private readonly IKeyLogic _logic; private int? _id; public int Id { set { _id = value; } } public FormKeys(ILogger logger, IKeyLogic logic) { InitializeComponent(); _logger = logger; _logic = logic; _keys = new Dictionary(); } private void buttonKeyCreate_Click(object sender, EventArgs e) { var keyPair = Cryptography.GenerateRSAKeyPair(); keyPair.ToPemFile(keyPairPath); MessageBox.Show("Ключи созданы"); LoadData(); } private void FormFood_Load(object sender, EventArgs e) { if (_id.HasValue) { _logger.LogInformation("Загрузка изделия"); try { var view = _logic.ReadElement(new KeySearchModel { Id = _id.Value }); if (view != null) { LoadData(); } } catch (Exception ex) { _logger.LogError(ex, "Ошибка загрузки изделия"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } private void LoadData() { _logger.LogInformation("Загрузка компонент изделия"); try { if (_keys != null) { dataGridViewKeys.Rows.Clear(); foreach (var pc in _keys) { dataGridViewKeys.Rows.Add(new object[] { pc.Key, pc.Value.Item1.Name, pc.Value.Item2 }); } } } catch (Exception ex) { _logger.LogError(ex, "Ошибка загрузки ключей"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }