public DLMSTranslatorForm()
 {
     InitializeComponent();
     translator.Comments = true;
     DataPdu.Text        = Properties.Settings.Default.Data;
     tabControl1_SelectedIndexChanged(null, null);
     if (!string.IsNullOrEmpty(Properties.Settings.Default.Pdu))
     {
         PduTB.Text = Properties.Settings.Default.Pdu;
     }
     if (!string.IsNullOrEmpty(Properties.Settings.Default.Message))
     {
         MessagePduTB.Text = Properties.Settings.Default.Message;
     }
     try
     {
         string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "GXDLMSDirector");
         if (!Directory.Exists(path))
         {
             Directory.CreateDirectory(path);
         }
         string certificates = Path.Combine(path, "Certificates");
         if (!Directory.Exists(certificates))
         {
             Directory.CreateDirectory(certificates);
         }
         string keys = Path.Combine(path, "Keys");
         if (!Directory.Exists(keys))
         {
             Directory.CreateDirectory(keys);
         }
         try
         {
             translator.SecuritySuite     = (SecuritySuite)Properties.Settings.Default.SecuritySuite;
             translator.Security          = (Security)Enum.Parse(typeof(Security), Properties.Settings.Default.Security);
             translator.SystemTitle       = GXDLMSTranslator.HexToBytes(Properties.Settings.Default.NotifySystemTitle);
             translator.ServerSystemTitle = GXDLMSTranslator.HexToBytes(Properties.Settings.Default.ServerSystemTitle);
             translator.BlockCipherKey    = GXDLMSTranslator.HexToBytes(Properties.Settings.Default.NotifyBlockCipherKey);
             translator.AuthenticationKey = GXDLMSTranslator.HexToBytes(Properties.Settings.Default.AuthenticationKey);
             translator.InvocationCounter = (UInt32)Properties.Settings.Default.InvocationCounter;
             translator.DedicatedKey      = GXDLMSTranslator.HexToBytes(Properties.Settings.Default.DedicatedKey);
         }
         catch (Exception)
         {
             //Set default settings if settings are corrupted.
             translator.Security          = Security.None;
             translator.SystemTitle       = GXDLMSTranslator.HexToBytes(Properties.Settings.Default.NotifySystemTitle);
             translator.ServerSystemTitle = GXDLMSTranslator.HexToBytes(Properties.Settings.Default.ServerSystemTitle);
             translator.BlockCipherKey    = GXDLMSTranslator.HexToBytes(Properties.Settings.Default.NotifyBlockCipherKey);
             translator.AuthenticationKey = GXDLMSTranslator.HexToBytes(Properties.Settings.Default.AuthenticationKey);
             translator.InvocationCounter = 0;
             translator.DedicatedKey      = GXDLMSTranslator.HexToBytes(Properties.Settings.Default.DedicatedKey);
         }
         Ciphering = new GXCipheringSettings(translator, keys, certificates,
                                             Properties.Settings.Default.ClientAgreementKey,
                                             Properties.Settings.Default.ClientSigningKey,
                                             Properties.Settings.Default.ServerAgreementKey,
                                             Properties.Settings.Default.ServerSigningKey);
         Ciphering.Challenge = GXDLMSTranslator.HexToBytes(Properties.Settings.Default.Challenge);
         tabControl1.TabPages.Add(Ciphering.GetCiphetingTab());
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 2
0
        public DLMSTranslatorForm()
        {
            InitializeComponent();
            InterfaceCb.Items.Add("");
            foreach (InterfaceType it in Enum.GetValues(typeof(InterfaceType)))
            {
                if (it != InterfaceType.HdlcWithModeE &&
                    it != InterfaceType.LPWAN &&
                    it != InterfaceType.WiSUN &&
                    it != InterfaceType.PlcPrime)
                {
                    InterfaceCb.Items.Add(it);
                }
            }
            foreach (ShowMessages it in Enum.GetValues(typeof(ShowMessages)))
            {
                ShowCb.Items.Add(it);
            }
            foreach (Follow it in Enum.GetValues(typeof(Follow)))
            {
                FollowmessagesCb.Items.Add(it);
            }
            try
            {
                InterfaceCb.SelectedIndex = Properties.Settings.Default.TranslatorInterface;
            }
            catch (Exception)
            {
                InterfaceCb.SelectedIndex = 0;
            }
            ShowCb.SelectedIndex           = Properties.Settings.Default.TranslatorShow;
            ViewFrameMnu.Checked           = Properties.Settings.Default.TranslatorFrame;
            XmlMnu.Checked                 = Properties.Settings.Default.TranslatorXml;
            FrameNumberMnu.Checked         = Properties.Settings.Default.FrameNumber;
            FollowmessagesCb.SelectedIndex = Properties.Settings.Default.TranslatorFollow;
            translator.OnKeys             += Translator_OnKeys;
            translator.Comments            = true;
            DataPdu.Text = Properties.Settings.Default.Data;
            tabControl1_SelectedIndexChanged(null, null);
            StandardMnu.Checked = Properties.Settings.Default.TranslatorStandard;
            HexMnu.Checked      = Properties.Settings.Default.TranslatorHex;
            if (!string.IsNullOrEmpty(Properties.Settings.Default.Pdu))
            {
                PduTB.Text = Properties.Settings.Default.Pdu;
            }
            if (!string.IsNullOrEmpty(Properties.Settings.Default.Message))
            {
                MessagePduTB.Text = Properties.Settings.Default.Message;
            }
            string certificates = null, keys = null;

            try
            {
                string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "GXDLMSDirector");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                certificates = Path.Combine(path, "Certificates");
                if (!Directory.Exists(certificates))
                {
                    Directory.CreateDirectory(certificates);
                }
                keys = Path.Combine(path, "Keys");
                if (!Directory.Exists(keys))
                {
                    Directory.CreateDirectory(keys);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            try
            {
                translator.SecuritySuite     = (SecuritySuite)Properties.Settings.Default.SecuritySuite;
                translator.Security          = (Security)Enum.Parse(typeof(Security), Properties.Settings.Default.Security);
                translator.SystemTitle       = GXDLMSTranslator.HexToBytes(Properties.Settings.Default.NotifySystemTitle);
                translator.ServerSystemTitle = GXDLMSTranslator.HexToBytes(Properties.Settings.Default.ServerSystemTitle);
                translator.BlockCipherKey    = GXDLMSTranslator.HexToBytes(Properties.Settings.Default.NotifyBlockCipherKey);
                translator.AuthenticationKey = GXDLMSTranslator.HexToBytes(Properties.Settings.Default.AuthenticationKey);
                translator.InvocationCounter = (UInt32)Properties.Settings.Default.InvocationCounter;
                translator.DedicatedKey      = GXDLMSTranslator.HexToBytes(Properties.Settings.Default.DedicatedKey);
            }
            catch (Exception)
            {
                //Set default settings if settings are corrupted.
                translator.Security          = Security.None;
                translator.SystemTitle       = GXDLMSTranslator.HexToBytes(Properties.Settings.Default.NotifySystemTitle);
                translator.ServerSystemTitle = GXDLMSTranslator.HexToBytes(Properties.Settings.Default.ServerSystemTitle);
                translator.BlockCipherKey    = GXDLMSTranslator.HexToBytes(Properties.Settings.Default.NotifyBlockCipherKey);
                translator.AuthenticationKey = GXDLMSTranslator.HexToBytes(Properties.Settings.Default.AuthenticationKey);
                translator.InvocationCounter = 0;
                translator.DedicatedKey      = GXDLMSTranslator.HexToBytes(Properties.Settings.Default.DedicatedKey);
            }
            Ciphering = new GXCipheringSettings(translator, keys, certificates,
                                                Properties.Settings.Default.ClientAgreementKey,
                                                Properties.Settings.Default.ClientSigningKey,
                                                Properties.Settings.Default.ServerAgreementKey,
                                                Properties.Settings.Default.ServerSigningKey);
            Ciphering.Challenge = GXDLMSTranslator.HexToBytes(Properties.Settings.Default.Challenge);
            tabControl1.TabPages.Add(Ciphering.GetCiphetingTab());
        }