Ejemplo n.º 1
0
        public async ValueTask <bool> InitializeAsync(ConnectorSettings connectorSettings)
        {
            Connector = new Connector {
                Settings = connectorSettings
            };
            entityBuilder = new EntityBuilder(this);

            try
            {
                Connector.Load();

                // Extended caching that requires connector info.
                CacheManager.Instance.CacheQueryBuilders(Connector);

                if (connectorSettings.ConnectionMode == ConnectionMode.Database)
                {
                    using var connection = await CreateConnectionAsync();

                    // Set the database name.
                    Connector.Settings.DatabaseName = connection.Database;

                    return(connection.State == ConnectionState.Open);
                }
                else
                {
                    apiClient = new ApiClient(connectorSettings.ApiHost);
                    ApiMode   = true;
                }
            }
            catch (Exception ex)
            {
                Log.Message(LogTypes.Error, ex.ToString());

                return(false);
            }

            // Always return true for ConnectionMode.Api
            return(true);
        }
Ejemplo n.º 2
0
        public async Task <bool> InitializeAsync(string connString, DatabaseType type, bool loadConnectorFromFile = true)
        {
            Type = type;

            connectionString = connString;
            connectorQuery   = new ConnectorQuery(type);

            entityBuilder = new EntityBuilder(this);

            try
            {
                connector.Load(type, loadConnectorFromFile);

                using (var connection = await CreateConnectionAsync())
                    return(connection.State == ConnectionState.Open);
            }
            catch (Exception ex)
            {
                Log.Message(LogTypes.Error, ex.ToString());

                return(false);
            }
        }