Exemplo n.º 1
0
        /// <summary>
        /// See base docs.
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        public override string[] ValidateOptions(DatabaseEngineOptions options)
        {
            var result    = new List <string>();
            var direction = options.IsSource ? "source" : "target";

            var fileName = options.ConnectionString;

            if (String.IsNullOrWhiteSpace(fileName))
            {
                result.Add($"You must specify the name of the {direction} SQLite file");
            }
            else if (options.IsSource)
            {
                if (!File.Exists(fileName))
                {
                    result.Add($"The {direction} SQLite file {fileName} does not exist");
                }
            }
            else if (options.IsTarget)
            {
                var path = Path.GetDirectoryName(fileName);
                if (!Directory.Exists(path))
                {
                    result.Add($"The {direction} SQLite file {fileName} specifies a folder that does not exist");
                }
            }

            if (options.CommandTimeoutSeconds != null)
            {
                result.Add("VRS does not support command timeouts for SQLite databases");
            }

            return(result.ToArray());
        }
Exemplo n.º 2
0
 /// <summary>
 /// See base docs.
 /// </summary>
 /// <param name="options"></param>
 /// <returns></returns>
 public override string[] UpdateSchema(DatabaseEngineOptions options)
 {
     using (var repository = CreateRepository(options)) {
         repository.CreateDatabaseIfMissing(repository.FileName);
         return(new string[] { $"{repository.FileName} created / updated" });
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// See base docs.
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        public override IBaseStationDatabase CreateRepository(DatabaseEngineOptions options)
        {
            var result = Factory.Resolve <IBaseStationDatabaseSQLite>();

            result.FileName            = options.ConnectionString;
            result.WriteSupportEnabled = options.IsTarget;

            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// See base docs.
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        public override IBaseStationDatabase CreateRepository(DatabaseEngineOptions options)
        {
            var result = Factory.Resolve <IBaseStationDatabaseSqlServer>();

            result.ConnectionString    = options.ConnectionString;
            result.WriteSupportEnabled = options.IsTarget;
            result.CanUpdateSchema     = options.IsTarget;
            if (options.CommandTimeoutSeconds != null)
            {
                result.CommandTimeoutSeconds = options.CommandTimeoutSeconds.Value;
            }

            return(result);
        }
Exemplo n.º 5
0
        protected void ValidateDatabaseEngine(DatabaseEngineOptions engineOptions, Engine engine)
        {
            var direction = engineOptions.IsSource ? "source" : "target";

            if (engine == null)
            {
                OptionsParser.Usage($"Missing {direction} database engine type");
            }

            var validationErrors = engine.ValidateOptions(engineOptions);

            if (validationErrors.Length > 0)
            {
                var joinedErrors = String.Join(Environment.NewLine, validationErrors);
                OptionsParser.Usage(joinedErrors);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates a database engine.
        /// </summary>
        /// <param name="engineOptions"></param>
        /// <returns></returns>
        public static Engine Build(DatabaseEngineOptions engineOptions)
        {
            Engine result = null;

            switch (engineOptions.Engine)
            {
            case DatabaseEngine.None:       result = null; break;

            case DatabaseEngine.SQLite:     result = new SQLiteEngine(); break;

            case DatabaseEngine.SqlServer:  result = new SqlServerEngine(); break;

            default:                        throw new NotImplementedException();
            }

            return(result);
        }
Exemplo n.º 7
0
        /// <summary>
        /// See base docs.
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        public override string[] ValidateOptions(DatabaseEngineOptions options)
        {
            var result    = new List <string>();
            var direction = options.IsSource ? "source" : "target";

            if (!Factory.HasImplementation <IBaseStationDatabaseSqlServer>())
            {
                result.Add("The SQL Server plugin has not been installed or could not be loaded");
            }
            else
            {
                if (String.IsNullOrEmpty(options.ConnectionString))
                {
                    result.Add($"You must specify the connection string for the {direction} SQL Server connection");
                }
                else
                {
                    try {
                        using (var repository = Factory.Resolve <IBaseStationDatabaseSqlServer>()) {
                            repository.ConnectionString = options.ConnectionString;

                            if (!repository.TestConnection())
                            {
                                result.Add($"A connection to the {direction} SQL Server could not be established");
                            }
                        }
                    } catch (Exception ex) {
                        result.Add($"Could not connect to the {direction} SQL Server: {ex.Message}");
                    }
                }

                if (options.CommandTimeoutSeconds < 0)
                {
                    result.Add("SQL Server timeouts must be at least 0 seconds");
                }
            }

            return(result.ToArray());
        }
Exemplo n.º 8
0
 /// <summary>
 /// See base docs.
 /// </summary>
 /// <param name="options"></param>
 /// <returns></returns>
 public override string[] UpdateSchema(DatabaseEngineOptions options)
 {
     using (var repository = (IBaseStationDatabaseSqlServer)CreateRepository(options)) {
         return(repository.UpdateSchema());
     }
 }
Exemplo n.º 9
0
 /// <summary>
 /// Updates the schema and returns the response from the engine.
 /// </summary>
 /// <param name="options"></param>
 /// <returns></returns>
 public abstract string[] UpdateSchema(DatabaseEngineOptions options);
Exemplo n.º 10
0
 /// <summary>
 /// Returns an implementation of <see cref="IBaseStationDatabase"/> for the engine.
 /// </summary>
 /// <param name="options"></param>
 /// <returns></returns>
 public abstract IBaseStationDatabase CreateRepository(DatabaseEngineOptions options);
Exemplo n.º 11
0
 /// <summary>
 /// Returns a list of issues with the options passed across. If there are no obvious problems then an empty array is returned.
 /// </summary>
 /// <param name="options"></param>
 /// <returns></returns>
 public abstract string[] ValidateOptions(DatabaseEngineOptions options);