From 92ad047db28444f333336e935c12c62951952207 Mon Sep 17 00:00:00 2001 From: Lunastra Date: Sat, 4 Dec 2021 00:30:24 -0800 Subject: [PATCH] Added some file for Archiving and Dataaccess --- .../ArchiveController.cs | 7 +++ .../Contracts/IDataSource.cs | 24 +++++++++ .../DataSourceFactory.cs | 33 ++++++++++++ .../Implementations/SQLSource.cs | 54 +++++++++++++++++++ ...Hobby.HobbyProjectGenerator.Archive.csproj | 9 ++++ .../TeamHobby.HobbyProjectGenerator.sln | 8 ++- 6 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs create mode 100644 Source Code/TeamHobby.HobbyProjectGenerator.Archive/Contracts/IDataSource.cs create mode 100644 Source Code/TeamHobby.HobbyProjectGenerator.Archive/DataSourceFactory.cs create mode 100644 Source Code/TeamHobby.HobbyProjectGenerator.Archive/Implementations/SQLSource.cs create mode 100644 Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby.HobbyProjectGenerator.Archive.csproj diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs new file mode 100644 index 0000000..9e39fb8 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs @@ -0,0 +1,7 @@ +namespace TeamHobby.HobbyProjectGenerator.Archive +{ + public class ArchiveController + { + + } +} \ No newline at end of file diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Contracts/IDataSource.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Contracts/IDataSource.cs new file mode 100644 index 0000000..d8bc317 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Contracts/IDataSource.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +//namespace TeamHobby.HobbyProjectGenerator.Archive.Contracts +namespace TeamHobby.HobbyProjectGenerator.Archive +{ + public interface IDataSource + { + // Method for reading data, return 0 for sucessful operation + int ReadData(string cmd); + + // Method for Writing data to a data source + int WriteData(string cmd); + + //Method for deleteing data from a data source, 0 for successful + int DeleteData(); + + // Method for updating data from a data source, 0 for sucessful + int UpdateData(); + } +} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/DataSourceFactory.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/DataSourceFactory.cs new file mode 100644 index 0000000..4bdb695 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/DataSourceFactory.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TeamHobby.HobbyProjectGenerator.Archive.Implementations; + +namespace TeamHobby.HobbyProjectGenerator.Archive +{ + public class DataSourceFactory + { + // Mehthod to create a specific data source suitable to the need + public IDataSource? getDataSource(string name) + { + try + { + if (String.Equals(name, "SQL", StringComparison.OrdinalIgnoreCase)) + { + return new SQLSource(); + } + else + { + return null; + } + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + return null; + } + } + } +} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Implementations/SQLSource.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Implementations/SQLSource.cs new file mode 100644 index 0000000..557f229 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Implementations/SQLSource.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TeamHobby.HobbyProjectGenerator.Archive.Implementations +{ + public class SQLSource : IDataSource + { + private SqlConnection conn; + + public SQLSource(string info) + { + conn = new SqlConnection(info); + } + public int DeleteData() + { + throw new NotImplementedException(); + } + + public int ReadData(string cmd) + { + try + { + // conn.open(); + // conn.Execute(); + Console.WriteLine("Access a SQL database"); + Console.WriteLine("Select * from archive"); + + // while (myReader) + // Print to console + // conn.close(); + return 0; + } + catch (Exception e) + { + Console.WriteLine(e.Message); + return -1; + } + } + + public int UpdateData() + { + throw new NotImplementedException(); + } + + public int WriteData(string cmd) + { + throw new NotImplementedException(); + } + } +} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby.HobbyProjectGenerator.Archive.csproj b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby.HobbyProjectGenerator.Archive.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby.HobbyProjectGenerator.Archive.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln index 65b0f5b..b76ca88 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln +++ b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.0.31919.166 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamHobby.HobbyProjectGenerator", "TeamHobby.HobbyProjectGenerator.csproj", "{C75B6909-FD9E-4382-94B6-7CA2CE371C9A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator", "TeamHobby.HobbyProjectGenerator.csproj", "{C75B6909-FD9E-4382-94B6-7CA2CE371C9A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamHobby.HobbyProjectGenerator.Archive", "..\TeamHobby.HobbyProjectGenerator.Archive\TeamHobby.HobbyProjectGenerator.Archive.csproj", "{F0E39503-E55A-4EB8-AA98-98D74A79D7D6}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +17,10 @@ Global {C75B6909-FD9E-4382-94B6-7CA2CE371C9A}.Debug|Any CPU.Build.0 = Debug|Any CPU {C75B6909-FD9E-4382-94B6-7CA2CE371C9A}.Release|Any CPU.ActiveCfg = Release|Any CPU {C75B6909-FD9E-4382-94B6-7CA2CE371C9A}.Release|Any CPU.Build.0 = Release|Any CPU + {F0E39503-E55A-4EB8-AA98-98D74A79D7D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F0E39503-E55A-4EB8-AA98-98D74A79D7D6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F0E39503-E55A-4EB8-AA98-98D74A79D7D6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F0E39503-E55A-4EB8-AA98-98D74A79D7D6}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE