Exemplo n.º 1
0
        public DbServer(string tenant)
        {
            this.Tenant = tenant;

            string provider = DbProvider.GetProviderName(tenant);

            if (provider.ToUpperInvariant().Equals("NPGSQL"))
            {
                var config = PostgreSQLConfig.Get();

                this.ProviderName            = provider;
                this.BinDirectory            = config.PostgreSQLBinDirectory;
                this.DatabaseBackupDirectory = config.DatabaseBackupDirectory;
                this.HostName   = config.Server;
                this.PortNumber = config.Port ?? 5432;
                this.UserId     = config.UserId;
                this.Password   = config.Password;
            }

            if (provider.ToUpperInvariant().Equals("SYSTEM.DATA.SQLCLIENT"))
            {
                var config = SqlServerConfig.Get();

                this.ProviderName            = provider;
                this.DatabaseBackupDirectory = config.DatabaseBackupDirectory;
                this.HostName   = config.Server;
                this.PortNumber = config.Port ?? 0;
                this.UserId     = config.UserId;
                this.Password   = config.Password;
            }


            this.Validate();
        }
Exemplo n.º 2
0
        internal static string Test(PostgreSQLConfig config)
        {
            var builder = new NpgsqlConnectionStringBuilder
            {
                Host        = config.Server,
                Port        = config.Port,
                Pooling     = config.EnablePooling,
                MinPoolSize = config.MinPoolSize,
                MaxPoolSize = config.MaxPoolSize,
                Username    = config.SuperUserId,
                Password    = config.SuperUserPassword
            };


            using (var connection = new NpgsqlConnection(builder.ConnectionString))
            {
                using (var command = new NpgsqlCommand("SELECT 1;", connection))
                {
                    try
                    {
                        connection.Open();
                        command.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        return("Error: " + ex.Message);
                    }
                }
            }

            return("Connection to PostgreSQL was successful.");
        }
Exemplo n.º 3
0
        public static string GetMetaDatabase(string tenant)
        {
            if (string.IsNullOrWhiteSpace(tenant))
            {
                return(string.Empty);
            }

            string provider = GetProviderName(tenant);
            string meta     = string.Empty;

            if (provider.ToUpperInvariant().Equals("NPGSQL"))
            {
                var config = PostgreSQLConfig.Get();
                meta = config.MetaDatabase;

                if (string.IsNullOrWhiteSpace(meta))
                {
                    meta = "postgres";
                }
            }

            if (provider.ToUpperInvariant().Equals("SYSTEM.DATA.SQLCLIENT"))
            {
                var config = SqlServerConfig.Get();
                meta = config.MetaDatabase;

                if (string.IsNullOrWhiteSpace(meta))
                {
                    meta = "master";
                }
            }

            return(meta);
        }
Exemplo n.º 4
0
        public string GetSuperUserConnectionString(string tenant, string database = "")
        {
            var config = PostgreSQLConfig.Get();

            var builder = new NpgsqlConnectionStringBuilder
            {
                Host                   = config.Server,
                Port                   = config.Port ?? 5432,
                Database               = database,
                Pooling                = config.EnablePooling ?? true,
                MinPoolSize            = config.MinPoolSize ?? 1,
                MaxPoolSize            = config.MaxPoolSize ?? 100,
                ApplicationName        = "Frapid",
                CommandTimeout         = config.Timeout ?? 120,
                InternalCommandTimeout = config.Timeout ?? 120
            };

            if (config.TrustedSuperUserConnection.To(false))
            {
                builder.IntegratedSecurity = true;
            }
            else
            {
                builder.Username = config.SuperUserId;
                builder.Password = config.SuperUserPassword;
            }

            return(builder.ConnectionString);
        }
Exemplo n.º 5
0
        public string GetConnectionString(string tenant, string database = "", string userId = "", string password = "")
        {
            var config = PostgreSQLConfig.Get();

            if (string.IsNullOrWhiteSpace(userId))
            {
                userId = config.UserId;
            }

            if (string.IsNullOrWhiteSpace(password))
            {
                password = config.Password;
            }


            return(this.GetConnectionString(tenant, config.Server, database, userId, password, config.Port ?? 5432, config.EnablePooling ?? true, config.MinPoolSize ?? 1, config.MaxPoolSize ?? 100));
        }
 public override void Connect_To_Database(StorageConfig config)
 {
     myConfig = config as PostgreSQLConfig;
     if (myConfig == null)
     {
         throw new Exception("Database Config is NULL");
     }
     try
     {
         myDBConn = new Npgsql.NpgsqlConnection(ConnectionString);
         myDBConn.Open();
         if (myDBConn.State != System.Data.ConnectionState.Open)
         {
             throw new Exception("Unable to Open Database. Storage:" + config.Name);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        private void cmdAddPostgreSQLStorage_Click(object sender, RoutedEventArgs e)
        {
            string val = "Storage_" + (grdStorages.Items.Count + 1);

            if (DotNetSiemensPLCToolBoxLibrary.General.InputBox.Show("Storage-Name", "Name of the Storage", ref val) == DialogResult.OK)
            {
                foreach (var tmp in ProtokollerConfiguration.ActualConfigInstance.Storages)
                {
                    if (tmp.Name.ToLower().Trim() == val.ToLower().Trim())
                    {
                        MessageBox.Show("A Storage with this Name already Exists!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                }
                PostgreSQLConfig storage = new PostgreSQLConfig()
                {
                    Name = val
                };
                ProtokollerConfiguration.ActualConfigInstance.Storages.Add(storage);
            }
        }
Exemplo n.º 8
0
        public string GetMetaConnectionString(string tenant)
        {
            var config = PostgreSQLConfig.Get();

            return(this.GetConnectionString(tenant, config.MetaDatabase));
        }
Exemplo n.º 9
0
        public string GetReportUserConnectionString(string tenant, string database = "")
        {
            var config = PostgreSQLConfig.Get();

            return(this.GetConnectionString(tenant, database, config.ReportUserId, config.ReportUserPassword));
        }