コード例 #1
0
 void OnGetValue(GXActionArgs arg)
 {
     if (arg.Index == 1)
     {
         arg.Value = new GXEnum(Convert.ToByte(SecurityPolicyTB.Value));
     }
     else if (arg.Index == 2)
     {
         GXSecuritySetupKeyDlg dlg = new GXSecuritySetupKeyDlg(0);
         if (dlg.ShowDialog(this) == DialogResult.OK)
         {
             List <KeyValuePair <GlobalKeyType, byte[]> > list = new List <KeyValuePair <GlobalKeyType, byte[]> >();
             list.Add(new KeyValuePair <GlobalKeyType, byte[]>(dlg.Type, dlg.Key));
             arg.Value = (Target as GXDLMSSecuritySetup).GlobalKeyTransfer(arg.Client, dlg.Kek, list);
         }
         else
         {
             arg.Handled = true;
         }
     }
 }
コード例 #2
0
 void OnGetValue(GXActionArgs arg)
 {
     try
     {
         if (arg.Index == 1)
         {
             if (Target.Version == 1)
             {
                 byte value = 0;
                 foreach (SecurityPolicy it in SecurityPolicyTB.CheckedItems)
                 {
                     value |= Convert.ToByte(it);
                 }
                 arg.Value = new GXEnum(value);
             }
             else
             {
                 //Version 0.
                 arg.Value = new GXEnum((byte)SecurityCb.SelectedItem);
             }
         }
         else if (arg.Index == 2)
         {
             GXSecuritySetupKeyDlg dlg = new GXSecuritySetupKeyDlg(0);
             if (dlg.ShowDialog(this) == DialogResult.OK)
             {
                 List <KeyValuePair <GlobalKeyType, byte[]> > list = new List <KeyValuePair <GlobalKeyType, byte[]> >();
                 list.Add(new KeyValuePair <GlobalKeyType, byte[]>(dlg.Type, dlg.Key));
                 arg.Value = (Target as GXDLMSSecuritySetup).GlobalKeyTransfer(arg.Client, dlg.Kek, list);
             }
             else
             {
                 arg.Handled = true;
             }
         }
         else if (arg.Index == 4)
         {
             GXCertificateType dlg = new GXCertificateType("Generate key pair");
             if (dlg.ShowDialog(this) == DialogResult.OK)
             {
                 arg.Value = (Target as GXDLMSSecuritySetup).GenerateKeyPair(arg.Client, dlg.GetValue());
             }
             else
             {
                 arg.Handled = true;
             }
         }
         else if (arg.Index == 5)
         {
             GXCertificateType dlg = new GXCertificateType("Generate certificate request");
             if (dlg.ShowDialog(this) == DialogResult.OK)
             {
                 _certificateType = dlg.GetValue();
                 arg.Value        = (Target as GXDLMSSecuritySetup).GenerateCertificate(arg.Client, _certificateType);
             }
             else
             {
                 arg.Handled = true;
             }
         }
         else if (arg.Index == 7)
         {
             if (CertificatesLv.SelectedItems.Count == 0)
             {
                 throw new Exception("Failed to export certificate. Select certificate to export.");
             }
             GXDLMSCertificateInfo cert = (GXDLMSCertificateInfo)CertificatesLv.SelectedItems[0].Tag;
             arg.Value = (Target as GXDLMSSecuritySetup).ExportCertificateBySerial(arg.Client, cert.SerialNumber,
                                                                                   ASCIIEncoding.ASCII.GetBytes(cert.Issuer));
         }
         else if (arg.Index == 8)
         {
             if (CertificatesLv.SelectedItems.Count == 0)
             {
                 throw new Exception("Failed to remove certificate. Select certificate to remove.");
             }
             GXDLMSCertificateInfo cert = (GXDLMSCertificateInfo)CertificatesLv.SelectedItems[0].Tag;
             CertificatesLv.SelectedItems[0].Remove();
             arg.Value = (Target as GXDLMSSecuritySetup).RemoveCertificateBySerial(arg.Client, cert.SerialNumber,
                                                                                   ASCIIEncoding.ASCII.GetBytes(cert.Issuer));
         }
     }
     catch (Exception ex)
     {
         arg.Handled = true;
         MessageBox.Show(Parent, ex.Message);
     }
 }