diff --git a/.gitignore b/.gitignore index 079a604..e1b4559 100644 --- a/.gitignore +++ b/.gitignore @@ -423,3 +423,5 @@ healthchecksdb .vscode/launch.json .vscode/tasks.json +Source Code/.vscode/tasks.json +Source Code/.vscode/launch.json diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveManager.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveManager.cs index 256ce31..2eee2fe 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveManager.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveManager.cs @@ -12,6 +12,10 @@ namespace TeamHobby.HobbyProjectGenerator.Archive _conn = dataSource; } + //public IDataSource GetConnection() + //{ + // return _conn; + //} // Create the folder where the compress file will be stored public bool CreateArchiveFolder(){ @@ -22,18 +26,25 @@ namespace TeamHobby.HobbyProjectGenerator.Archive // Find the root drive of the program string drive = Path.GetPathRoot(path: curPath); // Check if Drive exists or not - if (!Directory.Exists(drive)) - { - Console.WriteLine("Drive {0} not found", drive); - return false; - } + try { + if (!Directory.Exists(drive)) + { + Console.WriteLine("Drive {0} not found", drive); + return false; + } - string archiveFolder = curPath + folderName; - //Console.WriteLine("Creating a new folder at: {0}", archiveFolder); - if (!Directory.Exists(archiveFolder)) - { - Console.WriteLine("Creating a new folder at: {0}", archiveFolder); - Directory.CreateDirectory(archiveFolder); + string archiveFolder = curPath + folderName; + //Console.WriteLine("Creating a new folder at: {0}", archiveFolder); + if (!Directory.Exists(archiveFolder)) + { + Console.WriteLine("Creating a new folder at: {0}", archiveFolder); + Directory.CreateDirectory(archiveFolder); + //return true; + } + } + catch (Exception ex){ + // If the creating a folder failed, return false + return false; } return true; } @@ -91,7 +102,11 @@ namespace TeamHobby.HobbyProjectGenerator.Archive if (_conn.GetType() == typeof(SqlDAO)) { sqlDS = (SqlDAO)_conn; + } + // Check to make sure that Sql Data source connection is not null + if (sqlDS == null){ + return false; } // TODO: Remember to add try catch block here to make sure it is completed. @@ -103,11 +118,11 @@ namespace TeamHobby.HobbyProjectGenerator.Archive Console.WriteLine(""); // Creating a file name: - string filePath = @"C:\HobbyArchive"; + //string filePath = @"C:\HobbyArchive"; //Console.WriteLine("Creating file name ... "); //string curPath = archive.CreateOutFileName(); Console.WriteLine("Creating Output file name ..."); - string curPath = CreateOutFileName(); + string outPath = CreateOutFileName(); Console.WriteLine("Output file name created ..."); Console.WriteLine("----------------"); Console.WriteLine(""); @@ -116,46 +131,63 @@ namespace TeamHobby.HobbyProjectGenerator.Archive //string pathTemp = "C:/Temp/oldlogs10.txt"; //string pathTempBack = @"C:\Temp\oldlogs10.txt"; - //Output SQL to a text file - Console.WriteLine("Copying to a text file ..."); - sqlDS.CopyToFile(curPath); - Console.WriteLine("Copying completed ..."); - Console.WriteLine("----------------"); - Console.WriteLine(""); + // Try catch block to delete abort the compressing process + try{ + //Output SQL to a text file + Console.WriteLine("Copying to a text file ..."); + sqlDS.CopyToFile(outPath); + Console.WriteLine("Copying completed ..."); + Console.WriteLine("----------------"); + Console.WriteLine(""); - // Compress the file - Console.WriteLine("Copressing the text file ..."); - sqlDS.CompressFile(curPath); - Console.WriteLine("Copression completed ..."); - Console.WriteLine("----------------"); - Console.WriteLine(""); + // Compress the file + Console.WriteLine("Copressing the text file ..."); + sqlDS.CompressFile(outPath); + Console.WriteLine("Copression completed ..."); + Console.WriteLine("----------------"); + Console.WriteLine(""); - //Remove output file - Console.WriteLine("Removing the text file ..."); - sqlDS.RemoveOutputFile(curPath); - Console.WriteLine("Text File removal completed ..."); - Console.WriteLine("----------------"); - Console.WriteLine(""); + //Remove output file + Console.WriteLine("Removing the text file ..."); + sqlDS.RemoveOutputFile(outPath); + Console.WriteLine("Text File removal completed ..."); + Console.WriteLine("----------------"); + Console.WriteLine(""); - // Remove entries fromt the database - Console.WriteLine("Removing the text file ..."); - sqlDS.RemoveEntries(); - Console.WriteLine("Entries removal completed ..."); - Console.WriteLine("----------------"); - Console.WriteLine(""); + // Remove entries fromt the database + Console.WriteLine("Removing the text file ..."); + sqlDS.RemoveEntries(); + Console.WriteLine("Entries removal completed ..."); + Console.WriteLine("----------------"); + Console.WriteLine(""); + + // Return true if compressing sequence is successful + return true; + } + catch (Exception e){ + // Abort the compressing sequence and clean up uneccesary files. + Console.WriteLine("Archiving Sequenced failed. Cleaning up resources."); + + // Delete the text output file if any of the process failed + if (File.Exists(outPath)){ + File.Delete(outPath); + } + + // Delete the compressed file if Removing entries and removing text file output failed + string compFile = outPath + ".gz"; + if (File.Exists(compFile)){ + File.Delete(compFile); + } + + return false; + + } // Testing date time patters //string date = DateTime.Now.ToString("d"); //Console.WriteLine(date); //Console.WriteLine(DateTime.Now.ToString("M_d_yyyy_H:mm:ss")); - - return true; - } - - - - } } \ No newline at end of file diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs b/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs new file mode 100644 index 0000000..88e7b50 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs @@ -0,0 +1,123 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TeamHobby.HobbyProjectGenerator.Archive; +using TeamHobby.HobbyProjectGenerator.DataAccess; + +namespace TeamHobby.HobbyProjectGenerator.ArchiveTests +{ + public class ArchivingTests + { + //private string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" + + // "SERVER=localhost;" + + // "DATABASE=hobby;" + + // "UID=root;" + + // "PASSWORD=Teamhobby;" + + // "OPTION=3"; + + + // [TestMethod] + public void IsArchiveFolderCreated(IDataSource sqlDAO) + { + // Arrange + //SqlDAO sqlDAO = new SqlDAO(dbInfo); + ArchiveManager archiveManager = new ArchiveManager(sqlDAO); + string folderPath = @"C:/HobbyArchive"; + bool expectedVal = true; + + // Act + archiveManager.CreateArchiveFolder(); + + + // Assert + bool actualVal = Directory.Exists(folderPath); + if (expectedVal == actualVal) + { + Console.WriteLine("Expected: {0}, Actual: {1}. Folder created correctly", expectedVal, actualVal); + try + { + Directory.Delete(folderPath, true); + } + catch { + Console.WriteLine("Folder failed to be deleted"); + } + } + else + { + Console.WriteLine("Expected: {0}, Actual: {1}. Folder created incorrectly", expectedVal, actualVal); + } + } + + // [TestMethod] + public void IsFileNameCreated(IDataSource sqlDAO) + { + // Arrange + string foldPath = @"C:\HobbyArchive"; + string fileName = DateTime.Now.ToString("M_d_yyyy") + "_archive.csv"; + string expectedFilePath = System.IO.Path.Combine(foldPath, fileName); + ArchiveManager archiveManager = new ArchiveManager(sqlDAO); + + // Act + string actualFilePath = archiveManager.CreateOutFileName(); + + // Assert + bool result = String.Equals(actualFilePath, expectedFilePath); + if (result) + { + Console.WriteLine("Expected: {0}, Actual: {1}. File name created correctly", expectedFilePath, actualFilePath); + } + else + { + Console.WriteLine("Expected: {0}, Actual: {1}. File name created incorrectly", expectedFilePath, actualFilePath); + } + + } + + public void CopyingToAFileTest(IDataSource sqlDAO) + { + // Arrange + ArchiveManager archiveManager = new ArchiveManager(sqlDAO); + SqlDAO sqlDS = null; + + if (sqlDAO.GetType() == typeof(SqlDAO)) + { + sqlDS = (SqlDAO)sqlDAO; + } + + // Act + + + // Assert + + } + + public static void Main(string[] args) + { + string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" + + "SERVER=localhost;" + + "DATABASE=hobby;" + + "UID=root;" + + "PASSWORD=Teamhobby;" + + "OPTION=3"; + SqlDAO sqlDAO = new SqlDAO(dbInfo); + //ArchiveManager archiveManager = new ArchiveManager(sqlDAO); + + // Testing folder creation + ArchivingTests test = new ArchivingTests(); + test.IsArchiveFolderCreated(sqlDAO); + Console.WriteLine("-----------------"); + Console.WriteLine(""); + + // Testing file creation + test.IsFileNameCreated(sqlDAO); + Console.WriteLine("-----------------"); + Console.WriteLine(""); + + + } + + } + +} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/TeamHobby.HobbyProjectGenerator.ArchiveTests.csproj b/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/TeamHobby.HobbyProjectGenerator.ArchiveTests.csproj new file mode 100644 index 0000000..560115c --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/TeamHobby.HobbyProjectGenerator.ArchiveTests.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs index 6287a39..7a14a05 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs @@ -31,7 +31,7 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess // Getter and setter for Odbc public OdbcConnection Connection { get; set; } - public OdbcConnection getConnection() + public OdbcConnection GetConnection() { return _conn; } @@ -149,7 +149,6 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess // Get the stream of the original file using FileStream origFile = File.Open(fileName, FileMode.Open); - // Get the attribute of the file FileAttributes atrribute = File.GetAttributes(fileName); @@ -161,15 +160,16 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess using GZipStream compressor = new GZipStream(outputFile, CompressionMode.Compress); origFile.CopyTo(compressor); - return true; + return true; } return false; } catch (Exception ex) { + Console.WriteLine("Error when compressing a file !!, will be handled higher up the call stack"); Console.WriteLine(ex.Message); - return false; + throw; } } @@ -204,10 +204,10 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess return true; } - catch - { + catch (Exception ex) + { _conn.Close(); - Console.WriteLine("Error when copying query to a file !!"); + Console.WriteLine("Error when copying query to a file !!, will be handled higher up the call stack"); throw; } finally @@ -229,7 +229,7 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess } catch { Console.WriteLine("Removing file failed!!"); - return false; + throw; } } diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Contracts/ILogger.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Contracts/ILogger.cs new file mode 100644 index 0000000..75e8078 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Contracts/ILogger.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TeamHobby.HobbyProjectGenerator.Logging +{ + public interface ILogger + { + bool Log(LogEntry log); + + IList GetAllLogs(); + + } +} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Contracts/ILoggerFactory.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Contracts/ILoggerFactory.cs new file mode 100644 index 0000000..6de5ce3 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Contracts/ILoggerFactory.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TeamHobby.HobbyProjectGenerator.Logging.Contracts +{ + public interface ILoggerFactory + { + ILogger CreateLogger() + { + } + } +} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Implementations/ConsoleLogger.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Implementations/ConsoleLogger.cs new file mode 100644 index 0000000..28195f5 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Implementations/ConsoleLogger.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TeamHobby.HobbyProjectGenerator.Logging +{ + public class ConsoleLogger : ILogger + { + public IList GetAllLogs() + { + throw new NotImplementedException(); + } + + public bool Log(string description) + { + throw new NotImplementedException(); + } + } +} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Implementations/DBLogger.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Implementations/DBLogger.cs new file mode 100644 index 0000000..132ee82 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Implementations/DBLogger.cs @@ -0,0 +1,24 @@ +using System; + +namespace TeamHobby.HobbyProjectGenerator.Logging +{ + public class DBLogger : ILogger + { + public DBLogger() + { + } + + public IList GetAllLogs() + { + throw new NotImplementedException(); + } + + public bool Log(LogEntry log) + { + throw new NotImplementedException(); + } + + + } + +} \ No newline at end of file diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Implementations/DBLoggerFactory.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Implementations/DBLoggerFactory.cs new file mode 100644 index 0000000..f790cbb --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Implementations/DBLoggerFactory.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TeamHobby.HobbyProjectGenerator.Logging.Contracts; + +namespace TeamHobby.HobbyProjectGenerator.Logging.Implementations +{ + public class DBLoggerFactory : ILoggerFactory + { + public DBLoggerFactory() + { + } + public ILogger CreateLogger() + { + return new DBLogger(); + } + } +} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Implementations/FileLogger.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Implementations/FileLogger.cs new file mode 100644 index 0000000..1ca93a8 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Implementations/FileLogger.cs @@ -0,0 +1,18 @@ +using System; + +namespace TeamHobby.HobbyProjectGenerator.Logging +{ + public class FileLogger : ILogger + { + public IList GetAllLogs() + { + throw new NotImplementedException(); + } + + public bool Log(string description) + { + throw new NotImplementedException(); + } + } + +} \ No newline at end of file diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Implementations/InMemoryLogger.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Implementations/InMemoryLogger.cs new file mode 100644 index 0000000..80dacb7 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Implementations/InMemoryLogger.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +namespace TeamHobby.HobbyProjectGenerator.Logging +{ + // implementation of ILogger that stores logs as they initialize + public class InMemoryLogger : ILogger + { + // make readonly to prevent it from being changed somewhere other than in the constructor + private readonly IList _logStore; + + public InMemoryLogger() + { + // list of current logs + _logStore = new List(); + } + + + + public bool Log(string description) + { + try + { + // string interpolation to add UTC timestamp to log description + _logStore.Add($"{DateTime.UtcNow}-> {description}"); + return true; + } + catch + { + return false; + } + } + public IList GetAllLogs() + { + return _logStore; + } + } + +} \ No newline at end of file diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Logging/LogEntry.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/LogEntry.cs new file mode 100644 index 0000000..fb85775 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/LogEntry.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TeamHobby.HobbyProjectGenerator.Logging +{ + public enum LogLevel + { + Info, Debug, Warning, Error + } + + public enum LogCategory + { + View, Business, Server, Data, Datastore + } + + // LogEntry is a record type with init properties for each field + // ensures that log entries are immutable after initialization + public record LogEntry + { + public LogLevel level { get; init; } + public LogCategory category { get; init; } + public string user { get; init; } + public string description { get; init; } + public DateTime timestamp { get; init; } + + } +} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Logging/LoggingController.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/LoggingController.cs new file mode 100644 index 0000000..09de227 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/LoggingController.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TeamHobby.HobbyProjectGenerator.DataAccess; +using TeamHobby.HobbyProjectGenerator.Logging.Contracts; +using TeamHobby.HobbyProjectGenerator.Logging.Implementations; + +namespace TeamHobby.HobbyProjectGenerator.Logging +{ + internal class LoggingController + { + private readonly IDataSource _conn; + private readonly ILogger _logger; + private readonly ILoggerFactory _factory; + // private readonly LogEntry _logEntry; + + // Both Constructors take an IDataSource arg to make logging extensible to future data sources + // first constructor has no additional args - defaults to using the DBFactiry implementation + public LoggingController(IDataSource dataSource) + { + _conn = dataSource; + _factory = new DBLoggerFactory(); + _logger = _factory.CreateLogger(); + } + // second constructor takes an additional ILoggerFactory arg - allows for extensible logger types + public LoggingController(IDataSource dataSource, ILoggerFactory factory) + { + _conn = dataSource; + _factory = factory; + _logger = _factory.CreateLogger(); + + } + + public void Process() + { + _logger.Log(); + } + + + + } +} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Logging/TeamHobby - Backup.HobbyProjectGenerator.Logging.csproj b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/TeamHobby - Backup.HobbyProjectGenerator.Logging.csproj new file mode 100644 index 0000000..97db0f1 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/TeamHobby - Backup.HobbyProjectGenerator.Logging.csproj @@ -0,0 +1,20 @@ + + + + net6.0 + enable + enable + Library + AnyCPU + AnyCPU;x86 + + + + True + + + + True + + + diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Logging/TeamHobby.HobbyProjectGenerator.Logging.csproj b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/TeamHobby.HobbyProjectGenerator.Logging.csproj new file mode 100644 index 0000000..20a5fff --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/TeamHobby.HobbyProjectGenerator.Logging.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln index 5234556..0af8103 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln +++ b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln @@ -15,40 +15,101 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.Main", "..\TeamHo EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.DataAccess", "..\TeamHobby.HobbyProjectGenerator.DataAccess\TeamHobby.HobbyProjectGenerator.DataAccess.csproj", "{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.Logging", "..\TeamHobby.HobbyProjectGenerator.Logging\TeamHobby.HobbyProjectGenerator.Logging.csproj", "{C0494115-838E-43A3-8896-133E5D1E874A}" +EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.UserManagement", "..\TeamHobby.HobbyProjectGenerator.UserManagement\TeamHobby.HobbyProjectGenerator.UserManagement.csproj", "{2E7193B8-86B6-48DA-9671-CD84615A5F5D}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.Logging.Tests", "..\TeamHobby.HobbyProjectGenerator.Logging.Tests\TeamHobby.HobbyProjectGenerator.Logging.Tests.csproj", "{CA8D11CF-807C-4C90-A529-0371F73518F6}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamHobby.HobbyProjectGenerator.ArchiveTests", "..\TeamHobby.HobbyProjectGenerator.ArchiveTests\TeamHobby.HobbyProjectGenerator.ArchiveTests.csproj", "{C5EBD1F8-C806-4BF9-B2D7-8876072630FD}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C75B6909-FD9E-4382-94B6-7CA2CE371C9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C75B6909-FD9E-4382-94B6-7CA2CE371C9A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C75B6909-FD9E-4382-94B6-7CA2CE371C9A}.Debug|x86.ActiveCfg = Debug|Any CPU + {C75B6909-FD9E-4382-94B6-7CA2CE371C9A}.Debug|x86.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 + {C75B6909-FD9E-4382-94B6-7CA2CE371C9A}.Release|x86.ActiveCfg = Release|Any CPU + {C75B6909-FD9E-4382-94B6-7CA2CE371C9A}.Release|x86.Build.0 = Release|Any CPU {5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Debug|x86.ActiveCfg = Debug|Any CPU {5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Release|Any CPU.ActiveCfg = Release|Any CPU {5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Release|Any CPU.Build.0 = Release|Any CPU + {5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Release|x86.ActiveCfg = Release|Any CPU + {5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Release|x86.Build.0 = Release|Any CPU {75DED6C2-D404-4E71-A58B-0F616DB5C062}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {75DED6C2-D404-4E71-A58B-0F616DB5C062}.Debug|Any CPU.Build.0 = Debug|Any CPU + {75DED6C2-D404-4E71-A58B-0F616DB5C062}.Debug|x86.ActiveCfg = Debug|Any CPU + {75DED6C2-D404-4E71-A58B-0F616DB5C062}.Debug|x86.Build.0 = Debug|Any CPU {75DED6C2-D404-4E71-A58B-0F616DB5C062}.Release|Any CPU.ActiveCfg = Release|Any CPU {75DED6C2-D404-4E71-A58B-0F616DB5C062}.Release|Any CPU.Build.0 = Release|Any CPU + {75DED6C2-D404-4E71-A58B-0F616DB5C062}.Release|x86.ActiveCfg = Release|Any CPU + {75DED6C2-D404-4E71-A58B-0F616DB5C062}.Release|x86.Build.0 = Release|Any CPU {30C7EBF3-3957-46E5-86C1-C13356841ECA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {30C7EBF3-3957-46E5-86C1-C13356841ECA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {30C7EBF3-3957-46E5-86C1-C13356841ECA}.Debug|x86.ActiveCfg = Debug|Any CPU + {30C7EBF3-3957-46E5-86C1-C13356841ECA}.Debug|x86.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 + {30C7EBF3-3957-46E5-86C1-C13356841ECA}.Release|x86.ActiveCfg = Release|Any CPU + {30C7EBF3-3957-46E5-86C1-C13356841ECA}.Release|x86.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}.Debug|x86.ActiveCfg = Debug|Any CPU + {B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Debug|x86.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 + {B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Release|x86.ActiveCfg = Release|Any CPU + {B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Release|x86.Build.0 = Release|Any CPU {ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Debug|x86.ActiveCfg = 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 + {ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Release|x86.ActiveCfg = Release|Any CPU + {ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Release|x86.Build.0 = Release|Any CPU {AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Debug|x86.ActiveCfg = Debug|x86 + {AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Debug|x86.Build.0 = Debug|x86 {AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Release|Any CPU.ActiveCfg = Release|Any CPU {AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Release|Any CPU.Build.0 = Release|Any CPU + {AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Release|x86.ActiveCfg = Release|Any CPU + {AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Release|x86.Build.0 = Release|Any CPU + {C0494115-838E-43A3-8896-133E5D1E874A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C0494115-838E-43A3-8896-133E5D1E874A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C0494115-838E-43A3-8896-133E5D1E874A}.Debug|x86.ActiveCfg = Debug|Any CPU + {C0494115-838E-43A3-8896-133E5D1E874A}.Debug|x86.Build.0 = Debug|Any CPU + {C0494115-838E-43A3-8896-133E5D1E874A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C0494115-838E-43A3-8896-133E5D1E874A}.Release|Any CPU.Build.0 = Release|Any CPU + {C0494115-838E-43A3-8896-133E5D1E874A}.Release|x86.ActiveCfg = Release|Any CPU + {C0494115-838E-43A3-8896-133E5D1E874A}.Release|x86.Build.0 = Release|Any CPU {2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Debug|x86.ActiveCfg = Debug|Any CPU + {2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Debug|x86.Build.0 = Debug|Any CPU {2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Release|Any CPU.ActiveCfg = Release|Any CPU {2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Release|Any CPU.Build.0 = Release|Any CPU + {2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Release|x86.ActiveCfg = Release|Any CPU + {2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Release|x86.Build.0 = Release|Any CPU + {CA8D11CF-807C-4C90-A529-0371F73518F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CA8D11CF-807C-4C90-A529-0371F73518F6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CA8D11CF-807C-4C90-A529-0371F73518F6}.Debug|x86.ActiveCfg = Debug|x86 + {CA8D11CF-807C-4C90-A529-0371F73518F6}.Debug|x86.Build.0 = Debug|x86 + {CA8D11CF-807C-4C90-A529-0371F73518F6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CA8D11CF-807C-4C90-A529-0371F73518F6}.Release|Any CPU.Build.0 = Release|Any CPU + {CA8D11CF-807C-4C90-A529-0371F73518F6}.Release|x86.ActiveCfg = Release|Any CPU + {CA8D11CF-807C-4C90-A529-0371F73518F6}.Release|x86.Build.0 = Release|Any CPU + {C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.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 c293745..58e9b09 100644 --- a/Source Code/TeamHobby.Main/HobbyMain.cs +++ b/Source Code/TeamHobby.Main/HobbyMain.cs @@ -128,7 +128,7 @@ public class HobbyMain 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("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]); diff --git a/Source Code/TeamHobby.Main/MasterController.cs b/Source Code/TeamHobby.Main/MasterController.cs index be53071..838f386 100644 --- a/Source Code/TeamHobby.Main/MasterController.cs +++ b/Source Code/TeamHobby.Main/MasterController.cs @@ -1,7 +1,9 @@ -public class MasterController{ - - public static void main(string[] args){ +public class MasterController +{ + + public static void main(string[] args) + { //The main Controller of the program, It will run all services here @@ -13,12 +15,14 @@ public class MasterController{ int userInput = 0; - while (userInput != -1) { + while (userInput != -1) + { // Print the menu // - if (userInput == 1){ + if (userInput == 1) + { // 1. User Managment goes here } diff --git a/Source Code/main/Controller.cs b/Source Code/main/Controller.cs index 066b3cc..0f4e830 100644 --- a/Source Code/main/Controller.cs +++ b/Source Code/main/Controller.cs @@ -2,11 +2,26 @@ using System.Data.Odbc; using TeamHobby.HobbyProjectGenerator.Archive; using TeamHobby.HobbyProjectGenerator.DataAccess; +using TeamHobby.HobbyProjectGenerator.Logging; using TeamHobby.HobbyProjectGenerator.UserManagement; - namespace TeamHobby.HobbyProjectGenerator.Main { + public class GetCredentials + { + public string? GetUserName() + { + Console.WriteLine("Please enter a username:"); + string? userName = Console.ReadLine(); + return userName; + } + public string? GetPassword() + { + Console.WriteLine("Please enter " + + "a password:"); + string? userPassword = Console.ReadLine(); + return userPassword; + } public class Controller { public static void Main(string[] args) @@ -22,18 +37,36 @@ namespace TeamHobby.HobbyProjectGenerator.Main Console.WriteLine(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss")); // Creating the Factory class + // Logger log = new Logger(); + //Logger.PrintTest(); + //GetCredentials credentials = new GetCredentials(); + //string? username = credentials.GetUserName(); + //string? password = credentials.GetPassword(); + + + //Console.WriteLine(value: $"username is {username}\npassword is {password}"); + + // Creating the Factory class + // Creating the Factory class + string dbType = "sql"; - RDSFactory factory = new RDSFactory(); + RDSFactory dbFactory = new RDSFactory(); // Testing Data Access Layer string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" + + "TCPIP=1;" + "SERVER=localhost;" + "DATABASE=hobby;" + "UID=root;" + "PASSWORD=Teamhobby;" + "OPTION=3"; IDataSource datasource = factory.getDataSource(dbType, dbInfo); + "PORT=3306;"; + + "OPTION=3"; + + IDataSource datasource = dbFactory.getDataSource(dbType, dbInfo); // Create manager class from UserManagement SystemAccountManager manager = new SystemAccountManager(); diff --git a/Source Code/main/main.csproj b/Source Code/main/main.csproj index c203f89..18aba0a 100644 --- a/Source Code/main/main.csproj +++ b/Source Code/main/main.csproj @@ -5,6 +5,7 @@ net6.0 enable enable + x86 @@ -14,6 +15,7 @@ + diff --git a/doc/LowLevel/ArchivingWithError.png b/doc/LowLevel/ArchivingLL/ArchivingWithError.png similarity index 100% rename from doc/LowLevel/ArchivingWithError.png rename to doc/LowLevel/ArchivingLL/ArchivingWithError.png diff --git a/doc/LowLevel/ArchivingWithError.svg b/doc/LowLevel/ArchivingLL/ArchivingWithError.svg similarity index 100% rename from doc/LowLevel/ArchivingWithError.svg rename to doc/LowLevel/ArchivingLL/ArchivingWithError.svg diff --git a/doc/LowLevel/ArchivingWithError.txt b/doc/LowLevel/ArchivingLL/ArchivingWithError.txt similarity index 100% rename from doc/LowLevel/ArchivingWithError.txt rename to doc/LowLevel/ArchivingLL/ArchivingWithError.txt diff --git a/doc/LowLevel/ArchivingWithSingleton.pdf b/doc/LowLevel/ArchivingLL/ArchivingWithSingleton.pdf similarity index 100% rename from doc/LowLevel/ArchivingWithSingleton.pdf rename to doc/LowLevel/ArchivingLL/ArchivingWithSingleton.pdf diff --git a/doc/LowLevel/ArchvingMasterCon.txt b/doc/LowLevel/ArchivingLL/ArchvingMasterCon.txt similarity index 100% rename from doc/LowLevel/ArchvingMasterCon.txt rename to doc/LowLevel/ArchivingLL/ArchvingMasterCon.txt diff --git a/doc/LowLevel/archiving.pdf b/doc/LowLevel/ArchivingLL/archiving.pdf similarity index 100% rename from doc/LowLevel/archiving.pdf rename to doc/LowLevel/ArchivingLL/archiving.pdf diff --git a/doc/LowLevel/archiving.txt b/doc/LowLevel/ArchivingLL/archiving.txt similarity index 100% rename from doc/LowLevel/archiving.txt rename to doc/LowLevel/ArchivingLL/archiving.txt diff --git a/doc/LowLevel/archiving2.png b/doc/LowLevel/ArchivingLL/archiving2.png similarity index 100% rename from doc/LowLevel/archiving2.png rename to doc/LowLevel/ArchivingLL/archiving2.png diff --git a/doc/LowLevel/archiving2.txt b/doc/LowLevel/ArchivingLL/archiving2.txt similarity index 100% rename from doc/LowLevel/archiving2.txt rename to doc/LowLevel/ArchivingLL/archiving2.txt diff --git a/doc/LowLevel/archivingMasterCon.pdf b/doc/LowLevel/ArchivingLL/archivingMasterCon.pdf similarity index 100% rename from doc/LowLevel/archivingMasterCon.pdf rename to doc/LowLevel/ArchivingLL/archivingMasterCon.pdf diff --git a/doc/LowLevel/archivingSubmission.pdf b/doc/LowLevel/ArchivingLL/archivingSubmission.pdf similarity index 100% rename from doc/LowLevel/archivingSubmission.pdf rename to doc/LowLevel/ArchivingLL/archivingSubmission.pdf diff --git a/doc/LowLevel/archivingWithError.pdf b/doc/LowLevel/ArchivingLL/archivingWithError.pdf similarity index 100% rename from doc/LowLevel/archivingWithError.pdf rename to doc/LowLevel/ArchivingLL/archivingWithError.pdf diff --git a/doc/LowLevel/archivingWithError2.pdf b/doc/LowLevel/ArchivingLL/archivingWithError2.pdf similarity index 100% rename from doc/LowLevel/archivingWithError2.pdf rename to doc/LowLevel/ArchivingLL/archivingWithError2.pdf diff --git a/doc/LowLevel/archiving_5.txt b/doc/LowLevel/ArchivingLL/archiving_5.txt similarity index 100% rename from doc/LowLevel/archiving_5.txt rename to doc/LowLevel/ArchivingLL/archiving_5.txt diff --git a/doc/LowLevel/archivngWithError.txt b/doc/LowLevel/ArchivingLL/archivngWithError.txt similarity index 100% rename from doc/LowLevel/archivngWithError.txt rename to doc/LowLevel/ArchivingLL/archivngWithError.txt diff --git a/doc/LowLevel/arcvhingMasterCon.pdf b/doc/LowLevel/ArchivingLL/arcvhingMasterCon.pdf similarity index 100% rename from doc/LowLevel/arcvhingMasterCon.pdf rename to doc/LowLevel/ArchivingLL/arcvhingMasterCon.pdf diff --git a/doc/LowLevel/Logging/Logging_LLD_v6.png b/doc/LowLevel/Logging/Logging_LLD_v6.png new file mode 100644 index 0000000..9cc93b9 Binary files /dev/null and b/doc/LowLevel/Logging/Logging_LLD_v6.png differ diff --git a/src/dbCode/UserManagementDDL.txt b/src/dbCode/UserManagementDDL.txt new file mode 100644 index 0000000..a4022e6 --- /dev/null +++ b/src/dbCode/UserManagementDDL.txt @@ -0,0 +1,38 @@ +create table users +( + UserName varchar(50) charset utf8mb3 not null + primary key, + Password varchar(50) charset utf8mb3 null, + Role varchar(50) not null, + IsActive int default 1 null, + CreatedBy varchar(50) charset utf8mb3 null, + CreatedDate datetime null, + Email varchar(50) null, + constraint users_Email_uindex + unique (Email), + constraint users_UserName_uindex + unique (UserName), + constraint users_roles_Role_fk + foreign key (Role) references roles (Role) +); + +INSERT INTO hobby.users (UserName, Password, Role, IsActive, CreatedBy, CreatedDate, Email) VALUES +('Colin ', 'Waffle', 'Admin', 1, 'Jacob', '2021-12-13 04:27:42', null), +('Danny', 'Spartan', 'Admin', 1, 'Jacob', '2021-12-13 04:29:54', null), +('Jacob', 'Teamhobby1234', 'Admin', 1, 'SystemCreator', '2021-12-13 03:25:14', null), +('Long', 'Joystick', 'regular', 1, 'Jacob', '2021-12-13 04:29:57', null), +('Rifat', 'ApproveDar', 'Admin', 1, 'Jacob', '2021-12-13 04:29:55', null); + + +create table roles +( + RoleID int not null, + Role varchar(50) charset utf8mb3 not null, + CreatedBy varchar(200) charset utf8mb3 not null, + CreatedDate datetime not null, + constraint role_pk + primary key (Role) +); + +INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('Admin', 'Jacob', '2021-12-13 03:25:14'); +INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('regular', 'Colin', '2021-12-13 03:25:14'); diff --git a/src/dbCode/fullDDL.txt b/src/dbCode/fullDDL.txt new file mode 100644 index 0000000..f77d833 --- /dev/null +++ b/src/dbCode/fullDDL.txt @@ -0,0 +1,152 @@ +create database Hobby; + +use hobby; + +create table users +( + UserName varchar(50) charset utf8mb3 not null + primary key, + Password varchar(50) charset utf8mb3 null, + RoleID int auto_increment, + IsActive int default 1 null, + CreatedBy varchar(50) charset utf8mb3 null, + CreatedDate datetime null, + constraint users_UserName_uindex + unique (UserName), + constraint users_roles_RoleID_fk + foreign key (RoleID) references roles (RoleID) +); + +INSERT INTO hobby.users (UserName, Password, CreatedBy, CreatedDate) VALUES ('Colin ', 'Waffle', 'Jacob', '2021-12-13 04:27:42'); +INSERT INTO hobby.users (UserName, Password, CreatedBy, CreatedDate) VALUES ('Danny', 'Spartan', 'Jacob', '2021-12-13 04:29:54'); +INSERT INTO hobby.users (UserName, Password, CreatedBy, CreatedDate) VALUES ('Jacob', 'Teamhobby1234', 'SystemCreator', '2021-12-13 03:25:14'); +INSERT INTO hobby.users (UserName, Password, CreatedBy, CreatedDate) VALUES ('Long', 'Joystick', 'Jacob', '2021-12-13 04:29:57'); +INSERT INTO hobby.users (UserName, Password, CreatedBy, CreatedDate) VALUES ('Rifat', 'ApproveDar', 'Jacob', '2021-12-13 04:29:55'); + + +create table roles +( + RoleID int auto_increment + primary key, + Role varchar(50) charset utf8mb3 null, + CreatedBy varchar(200) charset utf8mb3 null, + CreatedDate datetime null +); + +INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('Admin', 'SystemCreator', '2021-12-13 03:25:14'); +INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('regular', 'Colin', '2021-12-13 03:25:14'); +INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('regular', 'Colin', '2021-12-13 03:25:14'); +INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('regular', 'Jacob', '2021-12-13 03:37:44'); +INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('regular', 'Jacob', '2021-12-13 03:37:46'); +INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('regular', 'Jacob', '2021-12-13 03:37:47'); +INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('regular', 'Jacob', '2021-12-13 03:37:47'); +INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('regular', 'Jacob', '2021-12-13 03:37:49'); +INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('regular', 'Jacob', '2021-12-13 03:37:50'); +INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('regular', 'Jacob', '2021-12-13 03:37:51'); + + +alter table users + add constraint users_roles_RoleID_fk + foreign key (RoleID) references roles (RoleID); + +SET Global innodb_file_per_table=ON; +-- SET GLOBAL innodb_file_format='Barracuda'; + +SET GLOBAL innodb_default_row_format='dynamic'; + +SET GLOBAL innodb_compression_algorithm='zlib'; + +-- Check for system settings +SHOW VARIABLES LIKE 'innodb_compression_algorithm'; +SHOW VARIABLES LIKE 'innodb_default_row_format'; +SHOW VARIABLES LIKE '%innodb%'; + +CREATE TABLE Persons ( + PersonID int, + LastName varchar(255), + FirstName varchar(255), + Address varchar(255), + City varchar(255) +); + +CREATE DATABASE testDB; + +-- Hobby DDL +-- Log level table +create table LogLevel +( + LvName varchar(50) not null, + LvComment varchar(500) not null, + constraint LogLevel_pk + primary key (LvName) +); + +-- Log categories table +create table LogCategories +( + catName varchar(50) not null, + catComment varchar(255) not null, + constraint LogCategories_pk primary key (catName) +); + +-- DDL for log table +create table Log +( + LtimeStamp datetime default CURRENT_TIMESTAMP null, + logID int auto_increment not null, + LvName varchar(50) not null, + catName varchar(50) not null, + userOP varchar(50) not null, + logMessage varchar(255) not null, + + constraint LogLvName_fk foreign key (LvName) references loglevel (LvName), + constraint LogCatName_fk foreign key (catName) references logcategories (catName), + constraint Log_pk primary key (logID) + +); + +create table Archive +( + LtimeStamp datetime null, + logID int not null, + LvName varchar(50) not null, + catName varchar(50) not null, + userOP varchar(50) not null, + logMessage varchar(255) not null, + + constraint Archive_pk primary key (logID) +) + ENGINE=InnoDB + PAGE_COMPRESSED=1 + PAGE_COMPRESSION_LEVEL=9; + +drop table archive; + +-- Dummy data for testing purposes +-- Log categories data +INSERT into logcategories(catName, catComment) values + ('View', 'view layer'), + ('Business', 'business layer'), + ('Server', 'server layer'), + ('Data', 'data layer'); + +-- Log level data +INSERT into loglevel(lvname, lvcomment) values + ('Info', 'some sys flow'), + ('Debug', 'info for fixing bugs'), + ('Warning', 'track system failure'), + ('Error', 'some sys errors'); + +-- Log table data +INSERT into log(lvname, catname, userop, logmessage) values + ('Info', 'View', 'create some projects', 'new account created'), + ('Info', 'Business', 'create some projects', 'new projects made'), + ('Info', 'View', 'log out', 'log out successful'), + ('Info', 'Business', 'log in', 'log in successfully'), + ('Info', 'View', 'search for projects', 'result return'); + +select * from logcategories; +select * from log; + + +