Ejemplo n.º 1
0
        public static void SaveVisInstanceSettings(string dbName, VisInstanceSettings settings)
        {
            try
            {
                using (var stmDbContext = new StmDbContext())
                {
                    stmDbContext.init(dbName);

                    var current = stmDbContext.VisInstanceSettings.FirstOrDefault();
                    if (current == null)
                    {
                        stmDbContext.VisInstanceSettings.Add(settings);
                    }
                    else
                    {
                        current.ClientCertificate        = settings.ClientCertificate;
                        current.Password                 = settings.Password;
                        current.ServiceId                = settings.ServiceId;
                        current.ServiceName              = settings.ServiceName;
                        current.StmModuleUrl             = settings.StmModuleUrl;
                        current.ApiKey                   = settings.ApiKey;
                        current.ApplicationId            = settings.ApplicationId;
                        current.UseHMACAuthentication    = settings.UseHMACAuthentication;
                        current.NotImplementetOperations = settings.NotImplementetOperations;
                    }

                    stmDbContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 2
0
        public static VisInstanceSettings GetVisInstanceSettings(string dbName)
        {
            var result = new VisInstanceSettings();

            try
            {
                var stmDbContext = new StmDbContext();
                stmDbContext.init(dbName);

                result = stmDbContext.VisInstanceSettings.FirstOrDefault();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            return(result);
        }
        public void SetupVisInstanceSettings()
        {
            var instanceDbName       = "stm";
            var instanceName         = "stm";
            var instanceId           = "urn:mrn:stm:service:instance:sma:stm";
            var stmModuleUrl         = "";
            var password             = "******";
            var encruptionPassphrase = "A_vErry secret paSsw0rd#that is not easy to Re2MeMbeR!";
            var encryptedPassword    = Encryption.EncryptString(password, encruptionPassphrase);

            var dlg = new System.Windows.Forms.OpenFileDialog();

            dlg.Filter = "Certifikat | *.p12";

            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                _dbContext.init(instanceDbName);
                byte[] certBytes = File.ReadAllBytes(dlg.FileName);

                var settings = _dbContext.VisInstanceSettings.FirstOrDefault();
                if (settings == null)
                {
                    settings                   = new VisInstanceSettings();
                    settings.ServiceName       = instanceName;
                    settings.ServiceId         = instanceId;
                    settings.StmModuleUrl      = stmModuleUrl;
                    settings.ClientCertificate = certBytes;
                    settings.Password          = encryptedPassword;

                    _dbContext.VisInstanceSettings.Add(settings);
                }
                else
                {
                    settings.ServiceName       = instanceName;
                    settings.ServiceId         = instanceId;
                    settings.StmModuleUrl      = stmModuleUrl;
                    settings.ClientCertificate = certBytes;
                    settings.Password          = encryptedPassword;
                }

                _dbContext.SaveChanges();
            }
        }