| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502 |
- using Microsoft.Win32.SafeHandles;
- using Quadarax.Foundation.Core.IO.FileSystem.Memory;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.IO.Abstractions;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace Quadarax.Foundation.Core.IO.FileSystem.Memory
- {
- public class MemoryFile : IFile
- {
- private readonly MemoryFileSystem _fileSystem;
- public IFileSystem FileSystem => throw new NotImplementedException();
- public MemoryFile(MemoryFileSystem fileSystem)
- {
- _fileSystem = fileSystem;
- }
- public void AppendAllText(string path, string? contents)
- {
- if (!_fileSystem.FileSystemDictionary.TryGetValue(path, out var entry) || !(entry is MemoryFileEntry fileEntry))
- {
- throw new FileNotFoundException();
- }
- fileEntry.Content = Encoding.UTF8.GetBytes(Encoding.UTF8.GetString(fileEntry.Content) + contents);
- fileEntry.LastWriteTime = DateTime.Now;
- }
- public void WriteAllText(string path, string? contents)
- {
- var fileEntry = new MemoryFileEntry
- {
- Name = Path.GetFileName(path),
- FullName = path,
- CreationTime = DateTime.Now,
- LastAccessTime = DateTime.Now,
- LastWriteTime = DateTime.Now,
- Content = Encoding.UTF8.GetBytes(contents ?? string.Empty)
- };
- _fileSystem.FileSystemDictionary[path] = fileEntry;
- }
- public string ReadAllText(string path)
- {
- if (!_fileSystem.FileSystemDictionary.TryGetValue(path, out var entry) || !(entry is MemoryFileEntry fileEntry))
- {
- throw new FileNotFoundException();
- }
- fileEntry.LastAccessTime = DateTime.Now;
- return Encoding.UTF8.GetString(fileEntry.Content);
- }
- public bool Exists(string? path)
- {
- if (path == null)
- return false;
-
- return _fileSystem.FileSystemDictionary.TryGetValue(path, out var entry) && entry is MemoryFileEntry;
- }
- public Task AppendAllLinesAsync(string path, IEnumerable<string> contents, CancellationToken cancellationToken = default)
- {
- throw new NotImplementedException();
- }
- public Task AppendAllLinesAsync(string path, IEnumerable<string> contents, Encoding encoding, CancellationToken cancellationToken = default)
- {
- throw new NotImplementedException();
- }
- public Task AppendAllTextAsync(string path, string? contents, CancellationToken cancellationToken = default)
- {
- throw new NotImplementedException();
- }
- public Task AppendAllTextAsync(string path, string? contents, Encoding encoding, CancellationToken cancellationToken = default)
- {
- throw new NotImplementedException();
- }
- public Task<byte[]> ReadAllBytesAsync(string path, CancellationToken cancellationToken = default)
- {
- throw new NotImplementedException();
- }
- public Task<string[]> ReadAllLinesAsync(string path, CancellationToken cancellationToken = default)
- {
- throw new NotImplementedException();
- }
- public Task<string[]> ReadAllLinesAsync(string path, Encoding encoding, CancellationToken cancellationToken = default)
- {
- throw new NotImplementedException();
- }
- public Task<string> ReadAllTextAsync(string path, CancellationToken cancellationToken = default)
- {
- throw new NotImplementedException();
- }
- public Task<string> ReadAllTextAsync(string path, Encoding encoding, CancellationToken cancellationToken = default)
- {
- throw new NotImplementedException();
- }
- public IAsyncEnumerable<string> ReadLinesAsync(string path, CancellationToken cancellationToken = default)
- {
- throw new NotImplementedException();
- }
- public IAsyncEnumerable<string> ReadLinesAsync(string path, Encoding encoding, CancellationToken cancellationToken = default)
- {
- throw new NotImplementedException();
- }
- public Task WriteAllBytesAsync(string path, byte[] bytes, CancellationToken cancellationToken = default)
- {
- throw new NotImplementedException();
- }
- public Task WriteAllLinesAsync(string path, IEnumerable<string> contents, CancellationToken cancellationToken = default)
- {
- throw new NotImplementedException();
- }
- public Task WriteAllLinesAsync(string path, IEnumerable<string> contents, Encoding encoding, CancellationToken cancellationToken = default)
- {
- throw new NotImplementedException();
- }
- public Task WriteAllTextAsync(string path, string? contents, CancellationToken cancellationToken = default)
- {
- throw new NotImplementedException();
- }
- public Task WriteAllTextAsync(string path, string? contents, Encoding encoding, CancellationToken cancellationToken = default)
- {
- throw new NotImplementedException();
- }
- public void AppendAllLines(string path, IEnumerable<string> contents)
- {
- throw new NotImplementedException();
- }
- public void AppendAllLines(string path, IEnumerable<string> contents, Encoding encoding)
- {
- throw new NotImplementedException();
- }
- public void AppendAllText(string path, string? contents, Encoding encoding)
- {
- throw new NotImplementedException();
- }
- public StreamWriter AppendText(string path)
- {
- throw new NotImplementedException();
- }
- public void Copy(string sourceFileName, string destFileName)
- {
- throw new NotImplementedException();
- }
- public void Copy(string sourceFileName, string destFileName, bool overwrite)
- {
- throw new NotImplementedException();
- }
- public FileSystemStream Create(string path)
- {
- throw new NotImplementedException();
- }
- public FileSystemStream Create(string path, int bufferSize)
- {
- throw new NotImplementedException();
- }
- public FileSystemStream Create(string path, int bufferSize, FileOptions options)
- {
- throw new NotImplementedException();
- }
- public IFileSystemInfo CreateSymbolicLink(string path, string pathToTarget)
- {
- throw new NotImplementedException();
- }
- public StreamWriter CreateText(string path)
- {
- throw new NotImplementedException();
- }
- public void Decrypt(string path)
- {
- throw new NotImplementedException();
- }
- public void Delete(string path)
- {
- throw new NotImplementedException();
- }
- public void Encrypt(string path)
- {
- throw new NotImplementedException();
- }
- public FileAttributes GetAttributes(string path)
- {
- throw new NotImplementedException();
- }
- public FileAttributes GetAttributes(SafeFileHandle fileHandle)
- {
- throw new NotImplementedException();
- }
- public DateTime GetCreationTime(string path)
- {
- throw new NotImplementedException();
- }
- public DateTime GetCreationTime(SafeFileHandle fileHandle)
- {
- throw new NotImplementedException();
- }
- public DateTime GetCreationTimeUtc(string path)
- {
- throw new NotImplementedException();
- }
- public DateTime GetCreationTimeUtc(SafeFileHandle fileHandle)
- {
- throw new NotImplementedException();
- }
- public DateTime GetLastAccessTime(string path)
- {
- throw new NotImplementedException();
- }
- public DateTime GetLastAccessTime(SafeFileHandle fileHandle)
- {
- throw new NotImplementedException();
- }
- public DateTime GetLastAccessTimeUtc(string path)
- {
- throw new NotImplementedException();
- }
- public DateTime GetLastAccessTimeUtc(SafeFileHandle fileHandle)
- {
- throw new NotImplementedException();
- }
- public DateTime GetLastWriteTime(string path)
- {
- throw new NotImplementedException();
- }
- public DateTime GetLastWriteTime(SafeFileHandle fileHandle)
- {
- throw new NotImplementedException();
- }
- public DateTime GetLastWriteTimeUtc(string path)
- {
- throw new NotImplementedException();
- }
- public DateTime GetLastWriteTimeUtc(SafeFileHandle fileHandle)
- {
- throw new NotImplementedException();
- }
- public UnixFileMode GetUnixFileMode(string path)
- {
- throw new NotImplementedException();
- }
- public UnixFileMode GetUnixFileMode(SafeFileHandle fileHandle)
- {
- throw new NotImplementedException();
- }
- public void Move(string sourceFileName, string destFileName)
- {
- throw new NotImplementedException();
- }
- public void Move(string sourceFileName, string destFileName, bool overwrite)
- {
- throw new NotImplementedException();
- }
- public FileSystemStream Open(string path, FileMode mode)
- {
- throw new NotImplementedException();
- }
- public FileSystemStream Open(string path, FileMode mode, FileAccess access)
- {
- throw new NotImplementedException();
- }
- public FileSystemStream Open(string path, FileMode mode, FileAccess access, FileShare share)
- {
- throw new NotImplementedException();
- }
- public FileSystemStream Open(string path, FileStreamOptions options)
- {
- throw new NotImplementedException();
- }
- public FileSystemStream OpenRead(string path)
- {
- throw new NotImplementedException();
- }
- public StreamReader OpenText(string path)
- {
- throw new NotImplementedException();
- }
- public FileSystemStream OpenWrite(string path)
- {
- throw new NotImplementedException();
- }
- public byte[] ReadAllBytes(string path)
- {
- throw new NotImplementedException();
- }
- public string[] ReadAllLines(string path)
- {
- throw new NotImplementedException();
- }
- public string[] ReadAllLines(string path, Encoding encoding)
- {
- throw new NotImplementedException();
- }
- public string ReadAllText(string path, Encoding encoding)
- {
- throw new NotImplementedException();
- }
- public IEnumerable<string> ReadLines(string path)
- {
- throw new NotImplementedException();
- }
- public IEnumerable<string> ReadLines(string path, Encoding encoding)
- {
- throw new NotImplementedException();
- }
- public void Replace(string sourceFileName, string destinationFileName, string? destinationBackupFileName)
- {
- throw new NotImplementedException();
- }
- public void Replace(string sourceFileName, string destinationFileName, string? destinationBackupFileName, bool ignoreMetadataErrors)
- {
- throw new NotImplementedException();
- }
- public IFileSystemInfo? ResolveLinkTarget(string linkPath, bool returnFinalTarget)
- {
- throw new NotImplementedException();
- }
- public void SetAttributes(string path, FileAttributes fileAttributes)
- {
- throw new NotImplementedException();
- }
- public void SetAttributes(SafeFileHandle fileHandle, FileAttributes fileAttributes)
- {
- throw new NotImplementedException();
- }
- public void SetCreationTime(string path, DateTime creationTime)
- {
- throw new NotImplementedException();
- }
- public void SetCreationTime(SafeFileHandle fileHandle, DateTime creationTime)
- {
- throw new NotImplementedException();
- }
- public void SetCreationTimeUtc(string path, DateTime creationTimeUtc)
- {
- throw new NotImplementedException();
- }
- public void SetCreationTimeUtc(SafeFileHandle fileHandle, DateTime creationTimeUtc)
- {
- throw new NotImplementedException();
- }
- public void SetLastAccessTime(string path, DateTime lastAccessTime)
- {
- throw new NotImplementedException();
- }
- public void SetLastAccessTime(SafeFileHandle fileHandle, DateTime lastAccessTime)
- {
- throw new NotImplementedException();
- }
- public void SetLastAccessTimeUtc(string path, DateTime lastAccessTimeUtc)
- {
- throw new NotImplementedException();
- }
- public void SetLastAccessTimeUtc(SafeFileHandle fileHandle, DateTime lastAccessTimeUtc)
- {
- throw new NotImplementedException();
- }
- public void SetLastWriteTime(string path, DateTime lastWriteTime)
- {
- throw new NotImplementedException();
- }
- public void SetLastWriteTime(SafeFileHandle fileHandle, DateTime lastWriteTime)
- {
- throw new NotImplementedException();
- }
- public void SetLastWriteTimeUtc(string path, DateTime lastWriteTimeUtc)
- {
- throw new NotImplementedException();
- }
- public void SetLastWriteTimeUtc(SafeFileHandle fileHandle, DateTime lastWriteTimeUtc)
- {
- throw new NotImplementedException();
- }
- public void SetUnixFileMode(string path, UnixFileMode mode)
- {
- throw new NotImplementedException();
- }
- public void SetUnixFileMode(SafeFileHandle fileHandle, UnixFileMode mode)
- {
- throw new NotImplementedException();
- }
- public void WriteAllBytes(string path, byte[] bytes)
- {
- throw new NotImplementedException();
- }
- public void WriteAllLines(string path, string[] contents)
- {
- throw new NotImplementedException();
- }
- public void WriteAllLines(string path, IEnumerable<string> contents)
- {
- throw new NotImplementedException();
- }
- public void WriteAllLines(string path, string[] contents, Encoding encoding)
- {
- throw new NotImplementedException();
- }
- public void WriteAllLines(string path, IEnumerable<string> contents, Encoding encoding)
- {
- throw new NotImplementedException();
- }
- public void WriteAllText(string path, string? contents, Encoding encoding)
- {
- throw new NotImplementedException();
- }
- // Implement other methods as needed
- }
- }
|