コード例 #1
0
        public async ValueTask <bool> WriteAsync(string path, RecordEnvelopeRef <TRecord> recordRef)
        {
            var sentinelPath = FileSystemPaths.GetSentinelPath(path);

            var isSuccess = await FileHelper.AcquireFileLockAsync(
                sentinelPath,
                this._clock,
                this._config.LockTimeout);

            if (!isSuccess)
            {
                this._logger.Warning($"Failed to acquire lock for record write: path={path}");

                return(false);
            }

            try
            {
                var currentRecordRef = await ReadAsync(path);

                if (currentRecordRef.Unref().ETag != recordRef.Unref().ETag)
                {
                    return(false);
                }

                this._fileSystem.Write(
                    path,
                    JsonSerializer.Serialize(
                        recordRef.Unref(),
                        this._config.JsonSerializerOptions));

                return(true);
            }
            finally
            {
                FileHelper.ReleaseFileLock(sentinelPath);
            }
        }
コード例 #2
0
        public async ValueTask <bool> SaveRecordAsync(RecordEnvelopeRef <PlayerRecord> recordRef)
        {
            var path = FileSystemPaths.GetPlayerPath(recordRef.Unref().Record.Id);

            return(await this._dbFileSystemProxy.WriteAsync(path, recordRef));
        }