From bbce5fb19c9d3cef84e3e2c5eeb12e798641384a Mon Sep 17 00:00:00 2001 From: Stanislav Mykhailenko Date: Sun, 9 Apr 2023 22:07:58 +0300 Subject: [PATCH] Add Lesson 4 Task 3 --- Lesson_4/Task_3/IWorkingWithFile.cs | 22 +++++++ Lesson_4/Task_3/Program.cs | 5 ++ Lesson_4/Task_3/Task_3.csproj | 10 +++ Lesson_4/Task_3/WorkingWithFile.cs | 97 +++++++++++++++++++++++++++++ 4 files changed, 134 insertions(+) create mode 100644 Lesson_4/Task_3/IWorkingWithFile.cs create mode 100644 Lesson_4/Task_3/Program.cs create mode 100644 Lesson_4/Task_3/Task_3.csproj create mode 100644 Lesson_4/Task_3/WorkingWithFile.cs diff --git a/Lesson_4/Task_3/IWorkingWithFile.cs b/Lesson_4/Task_3/IWorkingWithFile.cs new file mode 100644 index 0000000..4a5a132 --- /dev/null +++ b/Lesson_4/Task_3/IWorkingWithFile.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LiskovSubstitution +{ + public interface IWorkingWithFile + { + public string ReadFromFile(string filename); + public void WriteToFile(string filename); + public void DeleteFile(string filename); + public void DownloadFile(string filename); + public void CopyFile(string filename); + public void GetDataFromFile(string filename); + public void CheckFile(string filename); + public void SaveToFile(string filename); + public Guid CheckRole(Guid role); + public Guid CheckUser(Guid user); + } +} diff --git a/Lesson_4/Task_3/Program.cs b/Lesson_4/Task_3/Program.cs new file mode 100644 index 0000000..5e5ebe3 --- /dev/null +++ b/Lesson_4/Task_3/Program.cs @@ -0,0 +1,5 @@ +using LiskovSubstitution; + +(new User()).SaveToFile("test"); + +(new Administrator()).SaveToFile("test"); diff --git a/Lesson_4/Task_3/Task_3.csproj b/Lesson_4/Task_3/Task_3.csproj new file mode 100644 index 0000000..f02677b --- /dev/null +++ b/Lesson_4/Task_3/Task_3.csproj @@ -0,0 +1,10 @@ + + + + Exe + net7.0 + enable + enable + + + diff --git a/Lesson_4/Task_3/WorkingWithFile.cs b/Lesson_4/Task_3/WorkingWithFile.cs new file mode 100644 index 0000000..9345e11 --- /dev/null +++ b/Lesson_4/Task_3/WorkingWithFile.cs @@ -0,0 +1,97 @@ +namespace LiskovSubstitution +{ + public class User : IWorkingWithFile + { + public virtual Guid Role { get; } = new Guid("a65d9c1d-b8a9-4f4f-be9b-ab03856f33f4"); + + public string ReadFromFile(string filename) + { + return filename; + } + + public void WriteToFile(string filename) + { + Console.WriteLine("Access denied."); + } + + public void DeleteFile(string filename) + { + Console.WriteLine("Access denied."); + } + + public void DownloadFile(string filename) + { + Console.WriteLine("Downloaded the file."); + } + + public void CopyFile(string filename) + { + Console.WriteLine("Access denied."); + } + + public void GetDataFromFile(string filename) + { + Console.WriteLine("Got data from the file."); + } + + public void CheckFile(string filename) + { + Console.WriteLine("Checked the file."); + } + + public void SaveToFile(string filename) + { + Console.WriteLine("Access denied."); + } + + public Guid CheckRole(Guid role) + { + return new Guid("00000000-0000-0000-0000-000000000000"); + } + + public Guid CheckUser(Guid user) + { + return new Guid("00000000-0000-0000-0000-000000000000"); + } + } + + public class Administrator : User + { + public override Guid Role { get; } = new Guid("c1cfcc4a-e49e-4585-9ccb-265c35321b11"); + + public new void WriteToFile(string filename) + { + Console.WriteLine("Written to the file."); + } + + public new void DeleteFile(string filename) + { + Console.WriteLine("Deleted the file."); + } + + public new void CopyFile(string filename) + { + Console.WriteLine("Copied the file."); + } + + public new void SaveToFile(string filename) + { + Console.WriteLine("Saved to the file."); + } + } + + public class Owner : User + { + public override Guid Role { get; } = new Guid("a157c9cf-c996-46d7-9905-4cd1319a451d"); + + public new Guid CheckRole(Guid role) + { + return role; + } + + public new Guid CheckUser(Guid user) + { + return user; + } + } +}