Пример #1
0
        public ActionResult <DatabaseSettings> GetDatabaseSettings()
        {
            var settings = new DatabaseSettings
            {
                db_type                  = ServerSettings.Instance.Database.Type,
                mysql_hostname           = ServerSettings.Instance.Database.Hostname,
                mysql_password           = ServerSettings.Instance.Database.Password,
                mysql_schemaname         = ServerSettings.Instance.Database.Schema,
                mysql_username           = ServerSettings.Instance.Database.Username,
                sqlite_databasefile      = ServerSettings.Instance.Database.SQLite_DatabaseFile,
                sqlserver_databasename   = ServerSettings.Instance.Database.Schema,
                sqlserver_databaseserver = ServerSettings.Instance.Database.Hostname,
                sqlserver_password       = ServerSettings.Instance.Database.Password,
                sqlserver_username       = ServerSettings.Instance.Database.Username
            };

            return(settings);
        }
Пример #2
0
        public ActionResult <DatabaseSettings> GetDatabaseSettings()
        {
            if (ServerState.Instance.ServerOnline || ServerState.Instance.ServerStarting)
            {
                return(APIStatus.BadRequest("You may only do this before server init"));
            }

            var settings = new DatabaseSettings
            {
                db_type                  = ServerSettings.Instance.Database.Type,
                mysql_hostname           = ServerSettings.Instance.Database.Hostname,
                mysql_password           = ServerSettings.Instance.Database.Password,
                mysql_schemaname         = ServerSettings.Instance.Database.Schema,
                mysql_username           = ServerSettings.Instance.Database.Username,
                sqlite_databasefile      = ServerSettings.Instance.Database.SQLite_DatabaseFile,
                sqlserver_databasename   = ServerSettings.Instance.Database.Schema,
                sqlserver_databaseserver = ServerSettings.Instance.Database.Hostname,
                sqlserver_password       = ServerSettings.Instance.Database.Password,
                sqlserver_username       = ServerSettings.Instance.Database.Username
            };

            return(settings);
        }
Пример #3
0
        public ActionResult SetDatabaseSettings(DatabaseSettings settings)
        {
            string dbtype = settings?.db_type;

            if (dbtype == null)
            {
                return(APIStatus.BadRequest("You must specify database type and use valid xml or json."));
            }
            if (dbtype == Constants.DatabaseType.MySQL)
            {
                var details = new List <(string, string)>();
                if (string.IsNullOrEmpty(settings.mysql_hostname))
                {
                    details.Add(("mysql_hostname", "Must not be empty"));
                }
                if (string.IsNullOrEmpty(settings.mysql_schemaname))
                {
                    details.Add(("mysql_schemaname", "Must not be empty"));
                }
                if (string.IsNullOrEmpty(settings.mysql_username))
                {
                    details.Add(("mysql_username", "Must not be empty"));
                }
                if (string.IsNullOrEmpty(settings.mysql_password))
                {
                    details.Add(("mysql_password", "Must not be empty"));
                }
                if (details.Count > 0)
                {
                    return(new APIMessage(HttpStatusCode.BadRequest, "An invalid setting was passed", details));
                }
                ServerSettings.Instance.Database.Type     = dbtype;
                ServerSettings.Instance.Database.Hostname = settings.mysql_hostname;
                ServerSettings.Instance.Database.Password = settings.mysql_password;
                ServerSettings.Instance.Database.Schema   = settings.mysql_schemaname;
                ServerSettings.Instance.Database.Username = settings.mysql_username;
                return(APIStatus.OK());
            }
            if (dbtype == Constants.DatabaseType.SqlServer)
            {
                var details = new List <(string, string)>();
                if (string.IsNullOrEmpty(settings.sqlserver_databaseserver))
                {
                    details.Add(("sqlserver_databaseserver", "Must not be empty"));
                }
                if (string.IsNullOrEmpty(settings.sqlserver_databasename))
                {
                    details.Add(("sqlserver_databaseserver", "Must not be empty"));
                }
                if (string.IsNullOrEmpty(settings.sqlserver_username))
                {
                    details.Add(("sqlserver_username", "Must not be empty"));
                }
                if (string.IsNullOrEmpty(settings.sqlserver_password))
                {
                    details.Add(("sqlserver_password", "Must not be empty"));
                }
                if (details.Count > 0)
                {
                    return(new APIMessage(HttpStatusCode.BadRequest, "An invalid setting was passed", details));
                }
                ServerSettings.Instance.Database.Type     = dbtype;
                ServerSettings.Instance.Database.Hostname = settings.sqlserver_databaseserver;
                ServerSettings.Instance.Database.Schema   = settings.sqlserver_databasename;
                ServerSettings.Instance.Database.Username = settings.sqlserver_username;
                ServerSettings.Instance.Database.Password = settings.sqlserver_password;
                return(APIStatus.OK());
            }
            if (dbtype == Constants.DatabaseType.Sqlite)
            {
                ServerSettings.Instance.Database.Type = dbtype;
                if (!string.IsNullOrEmpty(settings.sqlite_databasefile))
                {
                    ServerSettings.Instance.Database.SQLite_DatabaseFile = settings.sqlite_databasefile;
                }
                return(APIStatus.OK());
            }
            return(APIStatus.BadRequest("An invalid setting was passed"));
        }