public FileMetaServiceFixture()
        {
            serviceProvider = new ServiceCollection()
                              .AddOptions()
                              .Configure <FileMetaServiceSettings>(
                fileMetaServiceSettings => new ConfigurationBuilder()
                .AddJsonFile("appsettings.json", false, false)
                .Build()
                .GetSection("FileMetaService")
                .Bind(fileMetaServiceSettings)
                )
                              .AddSingleton(Assembly.GetExecutingAssembly())
                              .AddSingleton <IEmbeddedResourceResolver, EmbeddedResourceResolver>()
                              .AddSingleton <IFileMetaDbFactory, FileMetaDbFactoryImpl>()
                              .AddSingleton <IFileRegistry, FileRegistryImpl>()
                              .AddSingleton <IFileMetaService, FileMetaServiceImpl>()
                              .BuildServiceProvider();

            embeddedResourceResolver = serviceProvider.GetService <IEmbeddedResourceResolver>();
            fileMetaDbFactory        = serviceProvider.GetService <IFileMetaDbFactory>();

            using (var stream = embeddedResourceResolver.GetStream($"sql/mysql_init.sql"))
                using (var connection = fileMetaDbFactory.CreateConnection())
                {
                    connection.Open();

                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText = new StreamReader(stream).ReadToEnd();
                        command.ExecuteNonQuery();
                    }
                }
        }
Beispiel #2
0
        /// <inheritxmldoc/>
        public File GetFile(int fileId)
        {
            using (var connection = fileMetaDbFactory.CreateConnection())
            {
                connection.Open();

                using (var transaction = connection.BeginTransaction())
                {
                    var resultfile = GetFile(
                        fileId,
                        connection,
                        transaction
                        );

                    transaction.Commit();

                    return(resultfile);
                }
            }
        }
        public void Dispose()
        {
            using (var stream = embeddedResourceResolver.GetStream($"sql/cleanup.sql"))
                using (var connection = fileMetaDbFactory.CreateConnection())
                {
                    connection.Open();

                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText = new StreamReader(stream).ReadToEnd();
                        command.ExecuteNonQuery();
                    }
                }
        }
Beispiel #4
0
        /// <inheritxmldoc/>
        public int CreateFileRecord(File file)
        {
            if (file == null)
            {
                throw new ArgumentException("File argument must not be null");
            }

            using (var connection = fileMetaDbFactory.CreateConnection())
            {
                connection.Open();

                using (var transaction = connection.BeginTransaction())
                {
                    fileRepository.RegisterFile(
                        file,
                        connection,
                        transaction
                        );

                    var newFileId = fileRepository.LastFile(
                        connection,
                        transaction
                        ).Id;

                    fileRepository.RegisterParts(
                        newFileId,
                        file.Parts,
                        connection,
                        transaction
                        );

                    transaction.Commit();

                    return(newFileId);
                }
            }
        }