MemoryFileInfo.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. using Quadarax.Foundation.Core.IO.FileSystem.Memory;
  2. using System;
  3. using System.Diagnostics.CodeAnalysis;
  4. using System.IO;
  5. using System.IO.Abstractions;
  6. namespace Quadarax.Foundation.Core.IO.FileSystem.Memory
  7. {
  8. public class MemoryFileInfo : IFileInfo
  9. {
  10. private readonly MemoryFileSystem _fileSystem;
  11. private readonly string _path;
  12. public MemoryFileInfo(MemoryFileSystem fileSystem, string path)
  13. {
  14. _fileSystem = fileSystem;
  15. _path = path;
  16. }
  17. public bool Exists => _fileSystem.FileSystemDictionary.ContainsKey(_path);
  18. public string Name => Path.GetFileName(_path);
  19. public string FullName => _path;
  20. public bool IsSymbolicLink
  21. {
  22. get
  23. {
  24. if (_fileSystem.FileSystemDictionary.TryGetValue(_path, out var entry))
  25. {
  26. return entry.IsSymbolicLink;
  27. }
  28. return false;
  29. }
  30. }
  31. public string? LinkTarget
  32. {
  33. get
  34. {
  35. if (_fileSystem.FileSystemDictionary.TryGetValue(_path, out var entry) && entry.IsSymbolicLink)
  36. {
  37. return entry.SymbolicLinkTarget;
  38. }
  39. return null;
  40. }
  41. }
  42. public IDirectoryInfo? Directory => throw new NotImplementedException();
  43. public string? DirectoryName => throw new NotImplementedException();
  44. public bool IsReadOnly { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
  45. public long Length => throw new NotImplementedException();
  46. public IFileSystem FileSystem => throw new NotImplementedException();
  47. public FileAttributes Attributes { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
  48. public DateTime CreationTime { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
  49. public DateTime CreationTimeUtc { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
  50. public string Extension => throw new NotImplementedException();
  51. public DateTime LastAccessTime { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
  52. public DateTime LastAccessTimeUtc { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
  53. public DateTime LastWriteTime { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
  54. public DateTime LastWriteTimeUtc { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
  55. public UnixFileMode UnixFileMode { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
  56. public StreamWriter AppendText()
  57. {
  58. throw new NotImplementedException();
  59. }
  60. public IFileInfo CopyTo(string destFileName)
  61. {
  62. throw new NotImplementedException();
  63. }
  64. public IFileInfo CopyTo(string destFileName, bool overwrite)
  65. {
  66. throw new NotImplementedException();
  67. }
  68. public FileSystemStream Create()
  69. {
  70. throw new NotImplementedException();
  71. }
  72. public void CreateAsSymbolicLink(string pathToTarget)
  73. {
  74. throw new NotImplementedException();
  75. }
  76. public StreamWriter CreateText()
  77. {
  78. throw new NotImplementedException();
  79. }
  80. public void Decrypt()
  81. {
  82. throw new NotImplementedException();
  83. }
  84. public void Delete()
  85. {
  86. throw new NotImplementedException();
  87. }
  88. public void Encrypt()
  89. {
  90. throw new NotImplementedException();
  91. }
  92. public void MoveTo(string destFileName)
  93. {
  94. throw new NotImplementedException();
  95. }
  96. public void MoveTo(string destFileName, bool overwrite)
  97. {
  98. throw new NotImplementedException();
  99. }
  100. public FileSystemStream Open(FileMode mode)
  101. {
  102. throw new NotImplementedException();
  103. }
  104. public FileSystemStream Open(FileMode mode, FileAccess access)
  105. {
  106. throw new NotImplementedException();
  107. }
  108. public FileSystemStream Open(FileMode mode, FileAccess access, FileShare share)
  109. {
  110. throw new NotImplementedException();
  111. }
  112. public FileSystemStream Open(FileStreamOptions options)
  113. {
  114. throw new NotImplementedException();
  115. }
  116. public FileSystemStream OpenRead()
  117. {
  118. throw new NotImplementedException();
  119. }
  120. public StreamReader OpenText()
  121. {
  122. throw new NotImplementedException();
  123. }
  124. public FileSystemStream OpenWrite()
  125. {
  126. throw new NotImplementedException();
  127. }
  128. public void Refresh()
  129. {
  130. throw new NotImplementedException();
  131. }
  132. public IFileInfo Replace(string destinationFileName, string? destinationBackupFileName)
  133. {
  134. throw new NotImplementedException();
  135. }
  136. public IFileInfo Replace(string destinationFileName, string? destinationBackupFileName, bool ignoreMetadataErrors)
  137. {
  138. throw new NotImplementedException();
  139. }
  140. public IFileSystemInfo? ResolveLinkTarget(bool returnFinalTarget)
  141. {
  142. throw new NotImplementedException();
  143. }
  144. // Implement other properties and methods as needed
  145. }
  146. public class MemoryFileInfoFactory : IFileInfoFactory
  147. {
  148. private readonly MemoryFileSystem _fileSystem;
  149. public MemoryFileInfoFactory(MemoryFileSystem fileSystem)
  150. {
  151. _fileSystem = fileSystem;
  152. }
  153. public IFileSystem FileSystem => throw new NotImplementedException();
  154. public IFileInfo New(string fileName)
  155. {
  156. return new MemoryFileInfo(_fileSystem, fileName);
  157. }
  158. [return: NotNullIfNotNull("fileInfo")]
  159. public IFileInfo? Wrap(FileInfo? fileInfo)
  160. {
  161. throw new NotImplementedException();
  162. }
  163. }
  164. public class MemoryDirectoryInfoFactory : IDirectoryInfoFactory
  165. {
  166. private readonly MemoryFileSystem _fileSystem;
  167. public MemoryDirectoryInfoFactory(MemoryFileSystem fileSystem)
  168. {
  169. _fileSystem = fileSystem;
  170. }
  171. public IFileSystem FileSystem => throw new NotImplementedException();
  172. public IDirectoryInfo New(string path)
  173. {
  174. return new MemoryDirectoryInfo(_fileSystem, path);
  175. }
  176. [return: NotNullIfNotNull("directoryInfo")]
  177. public IDirectoryInfo? Wrap(DirectoryInfo? directoryInfo)
  178. {
  179. throw new NotImplementedException();
  180. }
  181. }
  182. }