File system supports
Creation
reading
writing
deleting files and directories
Should handle permissions, different types of files, and provide a hierarchial directory structure
Concurrent connections are expected for reads, writes,
a user may delete which another is reading.
Based on the requirements and use cases, identify the main objects of the system and analyze how they interact and relate to each other...
public abstract class FileSystemNode
{
public Guid Id { get; init; }
public string Name { get; set; }
public Directory Parent { get; set; }
public User CreatedBy { get; init; }
public User LastModifiedBy { get; set; }
public DateTime CreatedOn { get; init; }
public DateTime LastModifiedOn { get; set; }
internal object SyncRoot {get; } = new ();
}
public class Directory : FileSystemNode
{
public List<Directory> ChildDirectories { get; } = [];
public List<File> Files { get; } = [];
}
public class File : FileSystemNode
{
public string Extension { get; set; }
public byte[] Content { private get; private set; }
public Content GetData() => return this.Content;
public long GetSize() => return this.Content.Length;
public bool WriteContent(byte[] data)
{
this.Content.Append(data);
return true;
}
public byte[] GetContent() => return this.Content;
}
public interface IDirecotryService
{
bool CreateDirectory(Directory Parent, string Name);
bool DeleteDirectory(string path);
Directory ReadDirectory(Directory path);
}
public class DefaultDirectoryService : IDirectoryService {
SearchByPath
}
public interface FileService
{
File Create(string path, string fileName, string fileType);
Content Read(string path);
bool Write(string path, string content);
bool Delete(string path);
}
public class FileService : IFileService { }
public interface ISearchService
{
SearchByPath(string path);
}
public class SearchService : ISearchService { }
public class User
{
int id
string Name
List
}
public enum Permissions
{
Create,
Read,
Write,
Delete,
All
}
public interface IUserPermissionsReader
{
public bool IsUserAlllowed(string path, enum permission, int userId);
}
public class UserPermissionReader : IUserPermissionReader
{
}
For each class, define the attributes (data) it will hold and the methods (functions) that operate on the attributes. Ensure they align with the object's responsibilities and adhere to the principle of encapsulation. Write your code in the code editor below.
the operations are highl y concurrent. To enable multi level concurrency without having locks for each operation, use Syncroot that would be in the base class and lock the syncroot for each CRUD operations.
Since objects are not supposed to be exposed, make the objects Readonlycollections and create methods to add/remove /modify any objects. that way you are hiding unnecessary details
the search strategy might vary. whle the current approach is out of strategy, the implementation works.