diff --git a/.gitignore b/.gitignore index 188ceee..079a604 100644 --- a/.gitignore +++ b/.gitignore @@ -421,3 +421,5 @@ FodyWeavers.xsd # BeatPulse healthcheck temp database healthchecksdb +.vscode/launch.json +.vscode/tasks.json diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs index 9e39fb8..365fe4c 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs @@ -2,6 +2,35 @@ { public class ArchiveController { + private IDataSource _conn; + + // Constructor to take in the connection. + public ArchiveController(IDataSource dataSource) { + _conn = dataSource; + } + + public IDataSource GetDataSource(){ + return _conn; + } + + // Create the folder where the compress file will be stored + public bool CreateArchiveFolder(){ + return true; + } + + // Return the name of the new output file with Path + public string CreateOutFileName(){ + return "hello"; + } + + // put everything toget here + public bool Controller(){ + return true; + } + + + + } } \ 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 index c2fcd16..a5d61f5 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Contracts/IDataSource.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Contracts/IDataSource.cs @@ -7,18 +7,18 @@ using System.Threading.Tasks; //namespace TeamHobby.HobbyProjectGenerator.Archive.Contracts namespace TeamHobby.HobbyProjectGenerator.Archive { - public interface IDataSource + public interface IDataSource { // Method for reading data, return 0 for sucessful operation - Object ReadData(string cmd); + Object ReadData(T model); // Method for Writing data to a data source - bool WriteData(string cmd); + bool WriteData(T model); //Method for deleteing data from a data source, 0 for successful - bool DeleteData(string cmd); + bool DeleteData(T model); // Method for updating data from a data source, 0 for sucessful - bool UpdateData(string cmd); + bool UpdateData(T model); } } diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Implementations/SQLSource.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Implementations/SQLSource.cs index f9c22e4..6ecbb93 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Implementations/SQLSource.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Implementations/SQLSource.cs @@ -10,7 +10,7 @@ using System.IO.Compression; namespace TeamHobby.HobbyProjectGenerator.Archive { - public class SQLSource : IDataSource, IRelationArchivable + public class SQLSource : IDataSource { //private SqlConnection conn; @@ -22,12 +22,6 @@ namespace TeamHobby.HobbyProjectGenerator.Archive // // conn.Open(); //} - // The also Identical to update data, maybe only one method is enough - public bool DeleteData(string cmd) - { - throw new NotImplementedException(); - } - // Makre sure to Check for instanceof() before casting to a SQLReader in the controller public Object ReadData(string cmd) { @@ -58,6 +52,13 @@ namespace TeamHobby.HobbyProjectGenerator.Archive } } + // The also Identical to update data, maybe only one method is enough + public bool DeleteData(string cmd) + { + throw new NotImplementedException(); + } + + // TODO: No idea how to check if the command is valid or where to check it public bool UpdateData(string cmd) { @@ -88,11 +89,6 @@ namespace TeamHobby.HobbyProjectGenerator.Archive throw new NotImplementedException(); } - // Method to archive data - public bool CreateArchived(string fileName) - { - throw new NotImplementedException(); - } public bool CompressFile(string fileName) { @@ -125,6 +121,30 @@ namespace TeamHobby.HobbyProjectGenerator.Archive } } + // Copy the Sql data to the a text file + public bool CopyToFile(string filePath){ + return true; + } + + public bool RemoveOutputFile(string filePath){ + return true; + } + + // Remove data from the database, if failed, let the controller handle it. + public bool RemoveEntries() { + + string sqlCmd = "DELETE FROM log WHERE DATE_DIFF(current_timestamp, log.LtimeStamp) > 30"; + + try{ + DeleteData(sqlCmd); + return true; + } + catch { + Console.WriteLine("Eeep! an error in Remove Entries, not to worry, will be handled higher up the call stack"); + throw; + } + } + //public Object ReadPreparedStmt(string table){ // //conn.Open(); // //SqlCommand command = new SqlCommand(null, conn); diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/RelationalDataSourceFactory.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/RelationalDataSourceFactory.cs index 08f602a..94c44fc 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/RelationalDataSourceFactory.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/RelationalDataSourceFactory.cs @@ -10,7 +10,7 @@ namespace TeamHobby.HobbyProjectGenerator.Archive public class RelationalDataSourceFactory { // Mehthod to create a specific data source suitable to the need - public IDataSource? getDataSource(string name) + public IDataSource getDataSource(string name) { try { diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby.HobbyProjectGenerator.Archive.csproj b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby.HobbyProjectGenerator.Archive.csproj index ac029dc..8ec85f5 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby.HobbyProjectGenerator.Archive.csproj +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby.HobbyProjectGenerator.Archive.csproj @@ -7,6 +7,9 @@ + + + diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln index b67123b..d235326 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln +++ b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln @@ -13,7 +13,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGener EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "main", "..\main\main.csproj", "{30C7EBF3-3957-46E5-86C1-C13356841ECA}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.Archive", "..\TeamHobby.HobbyProjectGenerator.Archive\TeamHobby.HobbyProjectGenerator.Archive.csproj", "{7F4B93F8-27D6-4A2F-9E14-04385BF2D875}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.Archive", "..\TeamHobby.HobbyProjectGenerator.Archive\TeamHobby.HobbyProjectGenerator.Archive.csproj", "{B88ED0D9-72E2-4245-BD8F-856FF42E500C}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.Main", "..\TeamHobby.Main\TeamHobby.Main.csproj", "{ED126EFB-B337-42F9-BE4B-65A5AE90503B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -37,10 +39,14 @@ Global {30C7EBF3-3957-46E5-86C1-C13356841ECA}.Debug|Any CPU.Build.0 = Debug|Any CPU {30C7EBF3-3957-46E5-86C1-C13356841ECA}.Release|Any CPU.ActiveCfg = Release|Any CPU {30C7EBF3-3957-46E5-86C1-C13356841ECA}.Release|Any CPU.Build.0 = Release|Any CPU - {7F4B93F8-27D6-4A2F-9E14-04385BF2D875}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7F4B93F8-27D6-4A2F-9E14-04385BF2D875}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7F4B93F8-27D6-4A2F-9E14-04385BF2D875}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7F4B93F8-27D6-4A2F-9E14-04385BF2D875}.Release|Any CPU.Build.0 = Release|Any CPU + {B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Release|Any CPU.Build.0 = Release|Any CPU + {ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Source Code/TeamHobby.Main/HobbyMain.cs b/Source Code/TeamHobby.Main/HobbyMain.cs index 7e6146d..9b83548 100644 --- a/Source Code/TeamHobby.Main/HobbyMain.cs +++ b/Source Code/TeamHobby.Main/HobbyMain.cs @@ -1,30 +1,147 @@ // See https://aka.ms/new-console-template for more information -using System.Data.SqlClient; +//using System.Data.SqlClient; using System.IO.Compression; using TeamHobby.HobbyProjectGenerator.Archive; +//using MySql.Data.MySqlClient; +using Microsoft.Data.SqlClient; +using System.Data.Odbc; public class HobbyMain { static void Main(string[] args) { - Console.WriteLine("Hello World!"); + // Testing file compression Start + //Console.WriteLine("Hello World!"); - // Testing Compressing a file - string fileName = @"C:\Users\Chunchunmaru\Documents\csulbFall2021\HobbyProject\Source Code\TeamHobby.Main\rando"; - //string fileName = @"arhiving2.txt"; - FileInfo fileInfo = new FileInfo(fileName); + //// Testing Compressing a file + //string fileName = @"C:\Users\Chunchunmaru\Documents\csulbFall2021\HobbyProject\Source Code\TeamHobby.Main\rando"; + ////string fileName = @"arhiving2.txt"; + //FileInfo fileInfo = new FileInfo(fileName); - Console.WriteLine("File Name: {0}", fileInfo.FullName); + //Console.WriteLine("File Name: {0}", fileInfo.FullName); - SQLSource sqlSource = new SQLSource(); - bool res = sqlSource.CompressFile(fileName); - //bool res = CompressFile(fileName); - Console.WriteLine(res); + //SQLSource sqlSource = new SQLSource(); + //bool res = sqlSource.CompressFile(fileName); + ////bool res = CompressFile(fileName); + //Console.WriteLine(res); - Console.WriteLine(CreateFileName()); + //Console.WriteLine(CreateFileName()); + // Testing File compression end + + // testing end + + // Testing connection to MariaDB + + string connString = "user id=root;" + "password=Teamhobby;server=localhost;" + "Trusted_Connection=yes;" + "database=Alatreon; " + "connection timeout=5"; + string connMariaDB = "server=localhost;port=3306;uid=root;pwd=Teamhobby;connection timeout=5"; + var conn = new SqlConnection(connString); + + + + + //// SqlConnection conn = new SqlConnection(connString); + string sqlQ = "Select * from log;"; + + //MySql.Data.MySqlClient.MySqlConnection connect; + + //try + //{ + // Console.WriteLine("Open connection: "); + // //connect = new MySql.Data.MySqlClient.MySqlConnection(); + // //connect.ConnectionString = connMariaDB; + // //connect.Open(); + // conn.Open(); + + // SqlCommand cmd = new SqlCommand(sqlQ, conn); + + // SqlDataReader myReader = cmd.ExecuteReader(); + // while (myReader.Read()) + // { + // Console.WriteLine(myReader["Column1"].ToString()); + // Console.WriteLine(myReader["Column2"].ToString()); + // } + // conn.Close(); + + // //if (connect.State == System.Data.ConnectionState.Open) + // //{ + // // Console.WriteLine("Connection established"); + // //} + // //connect.Close(); + + //} + try + { + Console.WriteLine("Opening connection: "); + //Connection string for Connector/ODBC 3.51 + string MyConString = "DRIVER={MariaDB ODBC 3.1 Driver};" + + "SERVER=localhost;" + + "DATABASE=hobby;" + + "UID=root;" + + "PASSWORD=Teamhobby;" + + "OPTION=3"; + + //Connect to MySQL using Connector/ODBC + //OdbcConnection MyConnection = new OdbcConnection(MyConString); + //MyConnection.Open(); + + //Console.WriteLine("\n !!! success, connected successfully !!!\n"); + + ////Display connection information + //Console.WriteLine("Connection Information:"); + //Console.WriteLine("\tConnection String:" + + // MyConnection.ConnectionString); + //Console.WriteLine("\tConnection Timeout:" + + // MyConnection.ConnectionTimeout); + //Console.WriteLine("\tDatabase:" + + // MyConnection.Database); + //Console.WriteLine("\tDataSource:" + + // MyConnection.DataSource); + //Console.WriteLine("\tDriver:" + + // MyConnection.Driver); + //Console.WriteLine("\tServerVersion:" + + // MyConnection.ServerVersion); + + //Console.WriteLine("Connection Successful"); + + ReadData(MyConString); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + Console.WriteLine("COnnection failed"); + + } } - + + public static void ReadData(string connectionString) + { + string queryString = "SELECT logID from log;"; + + using (OdbcConnection connection = new OdbcConnection(connectionString)) + { + OdbcCommand command = new OdbcCommand(queryString, connection); + + connection.Open(); + + // Execute the DataReader and access the data. + OdbcDataReader reader = command.ExecuteReader(); + Console.WriteLine("Read the database"); + while (reader.Read()) + { + //Console.WriteLine("Date={0} {1} {2} {3} {4} {5}", reader[0], reader[1], reader[2], reader[3],reader[4], reader[5]); + Console.WriteLine("Col A: {0} ", reader[0]); + //Console.WriteLine("Column: " + reader.FieldCount); + //Console.WriteLine("Column={1}", reader[1]); + + } + + // Call Close when done reading. + reader.Close(); + connection.Close(); + } + } + public static string CreateFileName() { return DateTime.Now.ToString() + "archive.txt"; diff --git a/Source Code/TeamHobby.Main/MasterController.cs b/Source Code/TeamHobby.Main/MasterController.cs new file mode 100644 index 0000000..be53071 --- /dev/null +++ b/Source Code/TeamHobby.Main/MasterController.cs @@ -0,0 +1,33 @@ + +public class MasterController{ + + public static void main(string[] args){ + + //The main Controller of the program, It will run all services here + + // While loop to run everything + + // 1. Initialize the Data Factory here + + // 2. Create the SqlConnection object + + int userInput = 0; + + while (userInput != -1) { + + // Print the menu + + // + if (userInput == 1){ + // 1. User Managment goes here + } + + // Trigger Archiving automatically + // Create new ArchiveManager object + // if (currentDate == 1){ + // ArchiveManager.Controller() + + // Logging also automatic + } + } +} \ No newline at end of file diff --git a/Source Code/TeamHobby.Main/TeamHobby.Main.csproj b/Source Code/TeamHobby.Main/TeamHobby.Main.csproj index 00d7d1d..9791008 100644 --- a/Source Code/TeamHobby.Main/TeamHobby.Main.csproj +++ b/Source Code/TeamHobby.Main/TeamHobby.Main.csproj @@ -9,6 +9,7 @@ + diff --git a/doc/LowLevel/archivingSubmission.pdf b/doc/LowLevel/archivingSubmission.pdf new file mode 100644 index 0000000..10b2a50 Binary files /dev/null and b/doc/LowLevel/archivingSubmission.pdf differ