示例#1
0
        public static void SaveSpisInstanceSettings(string dbName, SpisInstanceSettings settings)
        {
            try
            {
                using (var stmDbContext = new StmDbContext())
                {
                    stmDbContext.init(dbName);

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

                    stmDbContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#2
0
        public static bool AddInstance(string dbName)
        {
            try
            {
                var conString = ConfigurationManager.ConnectionStrings["StmConnectionString"].ConnectionString;
                using (var con = new SqlConnection(conString.Replace("Initial Catalog={database};", "")))
                {
                    con.Open();
                    using (var command = new SqlCommand())
                    {
                        command.Connection     = con;
                        command.CommandTimeout = 180;
                        var sql = string.Format(
                            "CREATE DATABASE " + dbName);
                        command.CommandText = sql;
                        command.ExecuteNonQuery();
                    }
                }

                var stmDbContext = new StmDbContext();
                stmDbContext.init(dbName);
                stmDbContext.ReInitializeDatabase();

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error when creating database" + Environment.NewLine + ex.Message, "Add instance", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
        }
        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();
            }
        }
示例#4
0
        public static SpisInstanceSettings GetSpisInstanceSettings(string dbName)
        {
            var result = new SpisInstanceSettings();

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

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

            return(result);
        }