Esempio n. 1
0
        /// <summary>
        /// Configures the options of a schema-aware database context.
        /// </summary>
        /// <param name="optionsBuilder">The unconfigured options builder.</param>
        /// <typeparam name="TContext">The context type.</typeparam>
        public void ConfigureSchemaAwareContext <TContext>(DbContextOptionsBuilder optionsBuilder)
            where TContext : SchemaAwareDbContext
        {
            EnsureSchemaIsCached <TContext>();
            var schema = _knownSchemas[typeof(TContext)];

            var getCredentialStream = _content.GetDatabaseCredentialStream();

            if (!getCredentialStream.IsSuccess)
            {
                throw new InvalidOperationException("Failed to get the database credential stream.");
            }

            DatabaseCredentials?credentials;

            using (var credentialStream = new StreamReader(getCredentialStream.Entity))
            {
                var content = credentialStream.ReadToEnd();
                if (!DatabaseCredentials.TryParse(content, out credentials))
                {
                    throw new InvalidOperationException("Failed to parse the database credentials.");
                }
            }

            optionsBuilder
            .UseLazyLoadingProxies()
            .UseNpgsql
            (
                credentials.GetConnectionString(),
                b => b.MigrationsHistoryTable(HistoryRepository.DefaultTableName + schema)
            );

            _schemaAwareDbContextService.ConfigureSchemaAwareContext(optionsBuilder);
        }
        public RetrieveSecureDatabaseCredentials()
        {
            var configs = GetConfiguration.GetConfigs;

            DatabaseCredentials = configs.Configuration.GetSection("DatabaseCredentials")
                                  .Get <DatabaseCredentials>();
        }
Esempio n. 3
0
    /// <summary>
    /// Attempts to parse a <see cref="DatabaseCredentials"/> object from the contents of the file at the given
    /// path.
    /// </summary>
    /// <param name="value">The string to parse.</param>
    /// <param name="credentials">The resulting credentials.</param>
    /// <returns>true if the credentials were successfully parsed; otherwise, false.</returns>
    public static bool TryParse(string value, [NotNullWhen(true)] out DatabaseCredentials?credentials)
    {
        credentials = null;

        var parts = value.Split(':');

        if (parts.Length != 5)
        {
            return(false);
        }

        var hostname = parts[0];

        if (!ushort.TryParse(parts[1], out var port))
        {
            return(false);
        }

        var database = parts[2];
        var username = parts[3];
        var password = parts[4];

        credentials = new DatabaseCredentials(hostname, port, database, username, password);
        return(true);
    }
        public static async Task <FortnoxMessageDispatcher> Create(
            ILogger logger,
            WebcrmClientFactory webcrmClientFactory,
            DatabaseCredentials databaseCredentials)
        {
            var fortnoxConfigService = await FortnoxConfigService.Create(databaseCredentials);

            return(new FortnoxMessageDispatcher(logger, webcrmClientFactory, fortnoxConfigService));
        }
Esempio n. 5
0
        public static async Task <FortnoxChangeTracker> Create(
            ILogger logger,
            WebcrmClientFactory webcrmClientFactory,
            string storageAccountConnectionString,
            DatabaseCredentials databaseCredentials)
        {
            var fortnoxConfigService = await FortnoxConfigService.Create(databaseCredentials);

            return(new FortnoxChangeTracker(logger, webcrmClientFactory, storageAccountConnectionString, fortnoxConfigService));
        }
Esempio n. 6
0
        public static async Task <PowerofficeMessageDispatcher> Create(
            ILogger logger,
            WebcrmClientFactory webcrmClientFactory,
            DatabaseCredentials databaseCredentials,
            PowerofficeClientFactory powerofficeClientFactory)
        {
            var powerofficeConfigService = await PowerofficeConfigService.Create(databaseCredentials);

            return(new PowerofficeMessageDispatcher(logger, webcrmClientFactory, powerofficeClientFactory, powerofficeConfigService));
        }
Esempio n. 7
0
        private DatabaseCredentials GetDatabaseCredentialsFromSettings()
        {
            DatabaseCredentials databaseCredentials = new DatabaseCredentials()
            {
                Database = this.DefaultSettings["Initial Catalog"],
                Password = this.DefaultSettings["Password"],
                Server   = this.DefaultSettings["Data Source"],
                UserId   = this.DefaultSettings["User Id"]
            };

            return(databaseCredentials);
        }
        public static async Task Initialize(
            DatabaseCredentials databaseCredentials)
        {
            lock (CreateDatabaseLock)
            {
                if (Client == null)
                {
                    Client = new DocumentClient(databaseCredentials.Endpoint, databaseCredentials.AccountKey);
                }
            }

            await Client.CreateDatabaseIfNotExistsAsync(new Database { Id = DatabaseId });
        }
Esempio n. 9
0
        }// end struct

        public static DatabaseCredentials get_DatabaseCredentials(string xpath)
        {
            DatabaseCredentials res = new DatabaseCredentials();

            ConfigurationLayer.ConfigurationService theConfigService =
                new ConfigurationLayer.ConfigurationService(
                    xpath);
            res.hostname_sql_instance = theConfigService.GetStringValue("hostname_sql_instance");
            res.db_name      = theConfigService.GetStringValue("db_name");
            res.sql_instance = theConfigService.GetStringValue("sql_instance");
            res.usr          = theConfigService.GetStringValue("usr");
            res.pwd          = theConfigService.GetStringValue("pwd");
            return(res);
        } // end get_DatabaseCredentials
        public static async Task <ConfigurationsCollection <TConfiguration> > Create(
            DatabaseCredentials databaseCredentials,
            string collectionId)
        {
            await IntegrationsDatabase.Initialize(databaseCredentials);

            var integrationsCollection = new ConfigurationsCollection <TConfiguration>(collectionId);
            await IntegrationsDatabase.Client.CreateDocumentCollectionIfNotExistsAsync(
                IntegrationsDatabase.DatabaseUri,
                new DocumentCollection { Id = collectionId },
                new RequestOptions { OfferThroughput = 400 }
                );

            return(integrationsCollection);
        }
Esempio n. 11
0
        }// end struct


        public static DatabaseCredentials get_DatabaseCredentials(string xpath)
        {
            DatabaseCredentials res = new DatabaseCredentials();

            System.Collections.Specialized.NameValueCollection databaseCredentialsCouples =
                ConfigurationLayer2008.CustomSectionInOneShot.GetCustomSectionInOneShot(
                    xpath);
            if (null == databaseCredentialsCouples)
            {
                return(res);                                   // the struct will contain empty fields.
            }
            res.hostname_sql_instance = (string)(databaseCredentialsCouples["hostname_sql_instance"]);
            res.db_name      = (string)(databaseCredentialsCouples["db_name"]);
            res.sql_instance = (string)(databaseCredentialsCouples["sql_instance"]);
            res.usr          = (string)(databaseCredentialsCouples["usr"]);
            res.pwd          = (string)(databaseCredentialsCouples["pwd"]);
            return(res);
        }// end get_DatabaseCredentials
        public static DatabaseCredentials Parse(string connectionString)
        {
            DatabaseCredentials credentials = new DatabaseCredentials();

            string[] configs = connectionString.Split(';');

            foreach (string config in configs)
            {
                string[] keyValue = config.Split('=');
                if (keyValue[0].Equals("server", StringComparison.OrdinalIgnoreCase))
                {
                    credentials.Server = keyValue[1];
                }
                else if (keyValue[0].Equals("database", StringComparison.OrdinalIgnoreCase))
                {
                    credentials.Database = keyValue[1];
                }
                else if (keyValue[0].Equals("user id", StringComparison.OrdinalIgnoreCase))
                {
                    credentials.UserId = keyValue[1];
                }
                else if (keyValue[0].Equals("password", StringComparison.OrdinalIgnoreCase))
                {
                    credentials.Password = keyValue[1];
                }
                else if (keyValue[0].Equals("initial catalog", StringComparison.OrdinalIgnoreCase))
                {
                    credentials.Database = keyValue[1];
                }
                else if (keyValue[0].Equals("data source", StringComparison.OrdinalIgnoreCase))
                {
                    credentials.Server = keyValue[1];
                }
            }

            return(credentials);
        }
 public DatabaseUtil(DatabaseCredentials credentials)
 {
     this.connectionString = "server=" + credentials.hostname + ";uid=" + credentials.username
                             + ";pwd=" + credentials.password + ";database=" + credentials.database + ";";
 }
Esempio n. 14
0
 public Task <DatabaseConnectionResult> Connect(DatabaseCredentials credentials)
 {
     throw new NotImplementedException();
 }
Esempio n. 15
0
        public static async Task <PowerofficeConfigService> Create(DatabaseCredentials databaseCredentials)
        {
            var powerofficeCollection = await ConfigurationsCollection <PowerofficeConfiguration> .Create(databaseCredentials, CollectionId);

            return(new PowerofficeConfigService(powerofficeCollection));
        }
Esempio n. 16
0
        public static async Task <FortnoxConfigService> Create(DatabaseCredentials databaseCredentials)
        {
            var fortnoxCollection = await ConfigurationsCollection <FortnoxConfiguration> .Create(databaseCredentials, CollectionId);

            return(new FortnoxConfigService(fortnoxCollection));
        }
 public SQLServerGatherer(string connectionString)
 {
     this.Credentials = Parse(connectionString);
     this.SqlServer   = new Data.SqlServer(connectionString);
 }
 public SQLServerGatherer(DatabaseCredentials credentials)
 {
     this.Credentials = credentials;
     this.SqlServer   = new Data.SqlServer(this.Credentials.ToSqlServerConnectionString());
 }