Exemple #1
0
        private string CreateSystemDb(IConfigurationRoot configuration, string dataDirectory)
        {
            var systemDbFile = configuration.GetValue <string>("Data:SystemDb");
            var systemDbPath = Path.Join(dataDirectory, systemDbFile);

            var options = new DbContextOptionsBuilder <SystemContext>()
                          .UseSqlite($"Data Source={systemDbPath}")
                          .Options;

            var systemContext = new SystemContext(options);

            systemContext.Database.EnsureCreated();

            var resolver       = new TestStreamResolver();
            var authId         = resolver.GetStream();
            var userDbFileName = HashUtil.CreateMd5(authId) + ".db";

            if (!systemContext.Users.Any(e => e.AuthIdentifier == authId))
            {
                systemContext.Users.Add(new User()
                {
                    AuthIdentifier = authId,
                    EventDbFile    = userDbFileName
                });
                systemContext.SaveChanges();
            }

            return(userDbFileName);
        }
Exemple #2
0
        private string CreateUserDb(string userId)
        {
            var dbFile = "events_" + HashUtil.CreateMd5(userId) + ".db";

            _systemContext.Users.Add(new User()
            {
                AuthIdentifier = userId,
                EventDbFile    = dbFile
            });
            _systemContext.SaveChanges();

            var fullPath = Path.Join(_dbBaseDirectory, dbFile);

            var options = new DbContextOptionsBuilder <DomainContext>()
                          .UseSqlite($"Data Source={fullPath}")
                          .Options;

            var domainContext = new DomainContext(options);

            domainContext.Database.EnsureCreated();

            return(fullPath);
        }