コード例 #1
0
        private void EnsureReaded()
        {
            if (_content != null)
            {
                return;
            }

            lock (_lock)
            {
                _content = NativeFormatProvider.ReadAllBytes(_filePath, _stream);
                _stream  = null;
            }
        }
コード例 #2
0
        public IntPtr Acquire(DbRecordId txRecordId)
        {
            if (!Indices.TryGetResourcePath(txRecordId, out var resourcePath))
            {
                throw new FileNotFoundException($"Cannot load unknown text resource: {txRecordId}");
            }

            lock (_lock)
            {
                if (_byId.TryGetValue(txRecordId, out var cachedData))
                {
                    cachedData.Acquire();
                    return(cachedData.Pointer);
                }
            }

            Byte[] fileContent = NativeFormatProvider.ReadAllBytes(resourcePath);

            IntPtr result;

            lock (_lock)
            {
                if (_byId.TryGetValue(txRecordId, out var cachedData))
                {
                    cachedData.Acquire();
                    return(cachedData.Pointer);
                }

                cachedData = new TxCachedData(txRecordId, resourcePath, fileContent);
                result     = cachedData.Pointer;

                _byId.Add(txRecordId, cachedData);
                _byPtr.Add(result, cachedData);
            }

            Log.Message($"Loaded resource [0x{txRecordId}, {resourcePath}].");
            return(result);
        }