Beispiel #1
0
    public async ValueTask RemoveProperty(
        string path,
        FileHandle fileHandle,
        FileStats fileStats,
        string key)
    {
        using var transaction = new SqliteTransaction(_context, ITransaction.TransactionMode.Mutation);
        var eventBuilder = new FileChangeEventBuilder();

        if (path == "/")
        {
            // TODO
            throw new NotImplementedException();
        }

        var fileId = await IndexFile(transaction, path, fileHandle, fileStats, eventBuilder);

        if (await _databaseTable.DeleteProperty(transaction, fileId, key))
        {
            eventBuilder.PropertyUpdated(fileHandle);
        }

        await transaction.CommitAsync();

        await EmitFileChangeEvents(eventBuilder.BuildFileEvents());
    }
Beispiel #2
0
    public async ValueTask SetProperty(
        string path,
        FileHandle fileHandle,
        FileStats fileStats,
        string key,
        ReadOnlyMemory <byte> value,
        PropertyFeature feature)
    {
        using var transaction = new SqliteTransaction(_context, ITransaction.TransactionMode.Mutation);
        var eventBuilder = new FileChangeEventBuilder();

        if (path == "/")
        {
            // TODO
            throw new NotImplementedException();
        }

        var fileId = await IndexFile(transaction, path, fileHandle, fileStats, eventBuilder);

        await _databaseTable.InsertOrReplacePropertyAsync(transaction, fileId, key, value, feature);

        await transaction.CommitAsync();

        await EmitFileChangeEvents(eventBuilder.BuildFileEvents());
    }
Beispiel #3
0
    /// <summary>
    ///     Create database table.
    /// </summary>
    private async ValueTask Create()
    {
        _logger.LogDebug("Creating database table.");
        using var transaction = new SqliteTransaction(_context, ITransaction.TransactionMode.Create);
        await _databaseTable.CreateAsync(transaction);

        await transaction.CommitAsync();

        _logger.LogDebug("Create database table success.");
    }
Beispiel #4
0
    public async ValueTask HintDeleted(string path, FileHandle fileHandle)
    {
        using var transaction = new SqliteTransaction(_context, ITransaction.TransactionMode.Mutation);
        var eventBuilder = new FileChangeEventBuilder();

        await IndexDelete(transaction, path, fileHandle, eventBuilder);

        await transaction.CommitAsync();

        await EmitFileChangeEvents(eventBuilder.BuildFileEvents());
    }
Beispiel #5
0
    public async ValueTask HintDirectory(string path, FileHandle fileHandle, ImmutableArray <Dirent> contents)
    {
        using var transaction = new SqliteTransaction(_context, ITransaction.TransactionMode.Mutation);
        var eventBuilder = new FileChangeEventBuilder();

        await IndexDirectory(transaction, path, contents, eventBuilder);

        await transaction.CommitAsync();

        await EmitFileChangeEvents(eventBuilder.BuildFileEvents());
    }
Beispiel #6
0
    public async ValueTask <ReadOnlyMemory <byte>?> GetProperty(string path, FileHandle fileHandle, FileStats fileStats, string key)
    {
        using var transaction = new SqliteTransaction(_context, ITransaction.TransactionMode.Mutation);
        var eventBuilder = new FileChangeEventBuilder();
        var fileId       = await IndexFile(transaction, path, fileHandle, fileStats, eventBuilder);

        var property = await _databaseTable.SelectPropertyAsync(transaction, fileId, key);

        await transaction.CommitAsync();

        await EmitFileChangeEvents(eventBuilder.BuildFileEvents());

        return(property?.Value);
    }
        public async Task CommitAsync(IDbTransaction transaction)
        {
            SqliteTransaction sqliteTransaction = (SqliteTransaction)transaction;

            SqliteConnection connection = sqliteTransaction.Connection;

            try
            {
                await sqliteTransaction.CommitAsync().ConfigureAwait(false);
            }
            finally
            {
                await connection.CloseAsync().ConfigureAwait(false);
            }
        }
        public async Task SaveAsync()
        {
            if (!_connection.IsValueCreated)
            {
                return;
            }

            try
            {
                await _transaction.CommitAsync();
            }
            catch (Exception e)
            {
                await _transaction.RollbackAsync();

                throw new Exception("Failed to commit changes to database", e);
            }
            finally
            {
                await _transaction.DisposeAsync();

                _transaction = (SqliteTransaction)await _connection.Value.BeginTransactionAsync();
            }
        }
 public Task SaveAsync()
 {
     return(_transaction.CommitAsync());
 }