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..e76171b 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs @@ -1,7 +1,39 @@ -namespace TeamHobby.HobbyProjectGenerator.Archive + +using TeamHobby.HobbyProjectGenerator.DataAccess; + +namespace TeamHobby.HobbyProjectGenerator.Archive { 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/Implementations/SQLSource.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Implementations/SQLSource.cs deleted file mode 100644 index ab5b34a..0000000 --- a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Implementations/SQLSource.cs +++ /dev/null @@ -1,96 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data.SqlClient; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.IO.Compression; - - -namespace TeamHobby.HobbyProjectGenerator.Archive -{ - public class SQLSource : IDataSource, IRelationArchivable - { - //private SqlConnection conn; - - //public SQLSource(string info) - //{ - // conn = new SqlConnection(info); - //} - - public bool DeleteData() - { - throw new NotImplementedException(); - } - - public Object 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 null; - } - catch (Exception e) - { - Console.WriteLine(e.Message); - return null; - } - } - - public bool UpdateData() - { - throw new NotImplementedException(); - } - - public bool WriteData(string cmd) - { - throw new NotImplementedException(); - } - - // Method to archive data - public bool CreateArchived(string fileName) - { - throw new NotImplementedException(); - } - - public bool CompressFile(string fileName) - { - try - { - // 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); - - // Check to see if the file is hidden or already compressed before compressing the file. - if (atrribute != FileAttributes.Hidden && atrribute != FileAttributes.Compressed) - { - using FileStream outputFile = File.Create(fileName + ".gz"); - - using GZipStream compressor = new GZipStream(outputFile, CompressionMode.Compress); - origFile.CopyTo(compressor); - - return true; - } - - return true; - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - return false; - } - } - - } -} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby.HobbyProjectGenerator.Archive.csproj b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby.HobbyProjectGenerator.Archive.csproj index ac029dc..09da541 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby.HobbyProjectGenerator.Archive.csproj +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby.HobbyProjectGenerator.Archive.csproj @@ -7,7 +7,18 @@ + + + + + + + + + + + diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.DAL/IRepository.cs b/Source Code/TeamHobby.HobbyProjectGenerator.DAL/IRepository.cs new file mode 100644 index 0000000..35d317d --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.DAL/IRepository.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TeamHobby.HobbyProjectGenerator.DAL +{ + public interface IRepository + { + bool Create(T model); + + T Read(); + + bool Update(T model); + + bool Delete(T model); + } +} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.DAL/SqlDAO.cs b/Source Code/TeamHobby.HobbyProjectGenerator.DAL/SqlDAO.cs new file mode 100644 index 0000000..8e331a7 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.DAL/SqlDAO.cs @@ -0,0 +1,50 @@ +using Microsoft.Data.SqlClient; +using TeamHobby.HobbyProjectGenerator.Models; + +namespace TeamHobby.HobbyProjectGenerator.DAL +{ + public class SqlDAO + { + public IList GetUserData(string username) + { + // Sql server connection string, needs to be changed accordingly to connect + var connString = "server=localhost;userid=root;password=Plop20;database=users"; // Using @" " makes the string literal + + // ADO.NET - ODBC + using (var conn = new SqlConnection(connString)) + { + // More complex sql commands are done in this method instead + var sql = "Select * from roles"; + using (var command = new SqlCommand(sql, conn)) + { + // Get the results from the query + SqlDataReader r = command.ExecuteReader(); + + // If you wanted to get a singular value back such as a count of a certain item + //command.ExecuteScalar(); + + // To execute something that doesn't expect results to come back + // Use this method instead, IE. Update command + //command.ExecuteNonQuery(); + + // Read data from query + while (r.Read()) + { + Console.WriteLine(r.ToString()); + } + return null; + } + + /*// this is meant for specific basic sql commands + using (var adapter = new SqlDataAdapter()) + { + adapter.UpdateCommand + adapter.DeleteCommand + adapter.InsertCommand + adapter.SelectCommand + }*/ + + } + } + } +} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.DAL/TeamHobby.HobbyProjectGenerator.DAL.csproj b/Source Code/TeamHobby.HobbyProjectGenerator.DAL/TeamHobby.HobbyProjectGenerator.DAL.csproj new file mode 100644 index 0000000..26710ee --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.DAL/TeamHobby.HobbyProjectGenerator.DAL.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Class1.cs b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Class1.cs new file mode 100644 index 0000000..e92f039 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Class1.cs @@ -0,0 +1,7 @@ +namespace TeamHobby.HobbyProjectGenerator.DataAccess +{ + public class Class1 + { + + } +} \ No newline at end of file diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Contracts/IDataSource.cs b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Contracts/IDataSource.cs similarity index 59% rename from Source Code/TeamHobby.HobbyProjectGenerator.Archive/Contracts/IDataSource.cs rename to Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Contracts/IDataSource.cs index f173ba6..29dae3e 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Contracts/IDataSource.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Contracts/IDataSource.cs @@ -4,21 +4,21 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -//namespace TeamHobby.HobbyProjectGenerator.Archive.Contracts -namespace TeamHobby.HobbyProjectGenerator.Archive + +namespace TeamHobby.HobbyProjectGenerator.DataAccess { - 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(); + bool DeleteData(T model); // Method for updating data from a data source, 0 for sucessful - bool UpdateData(); + bool UpdateData(T model); } } diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs new file mode 100644 index 0000000..d68b6bf --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs @@ -0,0 +1,224 @@ +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.IO.Compression; +using System.Data.Odbc; + +namespace TeamHobby.HobbyProjectGenerator.DataAccess +{ + public class SqlDAO : IDataSource + { + private OdbcConnection _conn; + + public SqlDAO(string info) + { + try { + Console.WriteLine("Establising Connection"); + _conn = new OdbcConnection(info); + Console.WriteLine("Connection established"); + } + catch { + //_conn = null; + Console.WriteLine("Error when creating a connection"); + throw; + } + } + + // Getter and setter for Odbc + public OdbcConnection Connection { get; set; } + + public OdbcConnection getConnection() + { + return _conn; + } + + // Closing a connection here will cause a problem + // Make sure whoever called this need to close the connection until we can fixed it. + public Object? ReadData(string cmd) + { + try + { + _conn.Open(); + OdbcCommand command = new OdbcCommand(cmd, _conn); + OdbcDataReader reader = command.ExecuteReader(); + + //_conn.Close(); + return reader; + + } + catch (Exception e) + { + Console.WriteLine("Error when Reading data from databse."); + Console.WriteLine(e.Message); + return null; + } + //finally + //{ + // _conn.Close(); + //} + } + + // The also Identical to update data, maybe only one method is enough + public bool DeleteData(string cmd) + { + try + { + _conn.Open(); + + OdbcCommand command = new OdbcCommand(cmd, _conn); + command.ExecuteNonQuery(); + + _conn.Close(); + + return true; + } + catch (Exception e) + { + Console.WriteLine("Error when deleting data from database!!"); + Console.WriteLine(e.Message); + return false; + } + finally + { + _conn.Close(); + } + } + + + // TODO: No idea how to check if the command is valid or where to check it + public bool UpdateData(string cmd) + { + try + { + _conn.Open(); + + OdbcCommand command = new OdbcCommand(cmd, _conn); + command.ExecuteNonQuery(); + + _conn.Close(); + + return true; + } + catch (Exception e) + { + Console.WriteLine("Error when updating data from database!!"); + Console.WriteLine(e.Message); + return false; + } + finally + { + _conn.Close(); + } + } + + // Very similar to UpdataData if not identical + public bool WriteData(string cmd) + { + try + { + _conn.Open(); + + OdbcCommand command = new OdbcCommand(cmd, _conn); + command.ExecuteNonQuery(); + + _conn.Close(); + + return true; + } + catch (Exception e) + { + Console.WriteLine("Error when Writing data from database!!"); + Console.WriteLine(e.Message); + return false; + } + finally + { + _conn.Close(); + } + } + + + public bool CompressFile(string fileName) + { + try + { + // 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); + + // Check to see if the file is hidden or already compressed before compressing the file. + if (atrribute != FileAttributes.Hidden && atrribute != FileAttributes.Compressed) + { + using FileStream outputFile = File.Create(fileName + ".gz"); + + using GZipStream compressor = new GZipStream(outputFile, CompressionMode.Compress); + origFile.CopyTo(compressor); + + return true; + } + + return false; + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + return false; + } + } + + // 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); + // SqlCommand command = new SqlCommand("SELECT * from @table;", conn); + // SqlParameter tableParam = new SqlParameter("@table", System.Data.SqlDbType.Text, 50); + + // tableParam.Value = table; + // command.Parameters.Add(tableParam); + + // // conn.Execute(); + // Console.WriteLine("Access a SQL database"); + // Console.WriteLine("Select * from archive"); + + // // Make the Prepare statement and excute the query: + // command.Prepare(); + // SqlDataReader sqlReader = command.ExecuteReader(); + + // // while (myReader) + // // Print to console + // // conn.close(); + // return sqlReader; + //} + + } +} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/RelationalDataSourceFactory.cs b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/RelationalDataSourceFactory.cs similarity index 62% rename from Source Code/TeamHobby.HobbyProjectGenerator.Archive/RelationalDataSourceFactory.cs rename to Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/RelationalDataSourceFactory.cs index 08f602a..656ebd1 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/RelationalDataSourceFactory.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/RelationalDataSourceFactory.cs @@ -3,28 +3,26 @@ 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.Archive +namespace TeamHobby.HobbyProjectGenerator.DataAccess { public class RelationalDataSourceFactory { // Mehthod to create a specific data source suitable to the need - public IDataSource? getDataSource(string name) + public IDataSource getDataSource(string name, string info) { try { if (String.Equals(name, "SQL", StringComparison.OrdinalIgnoreCase)) { - return new SQLSource(); - } - else - { - return null; + return new SqlDAO(info); } + return null; } catch (Exception ex) { + Console.WriteLine("RelationDataFactory: Data Access object creation failed!"); Console.WriteLine(ex.Message); return null; } diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/TeamHobby.HobbyProjectGenerator.DataAccess.csproj b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/TeamHobby.HobbyProjectGenerator.DataAccess.csproj new file mode 100644 index 0000000..b7a95b0 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/TeamHobby.HobbyProjectGenerator.DataAccess.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Models/Credentials.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Models/Credentials.cs new file mode 100644 index 0000000..2670e8f --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Models/Credentials.cs @@ -0,0 +1,10 @@ +namespace TeamHobby.HobbyProjectGenerator.Models +{ + public class Credentials + { + public string userName { get; set; } + + // Syntactic sugar + public string Password { get; set; } + } +} \ No newline at end of file diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Models/TeamHobby.HobbyProjectGenerator.Models.csproj b/Source Code/TeamHobby.HobbyProjectGenerator.Models/TeamHobby.HobbyProjectGenerator.Models.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Models/TeamHobby.HobbyProjectGenerator.Models.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/Class1.cs b/Source Code/TeamHobby.HobbyProjectGenerator/Class1.cs deleted file mode 100644 index 77436d6..0000000 --- a/Source Code/TeamHobby.HobbyProjectGenerator/Class1.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace TeamHobby.HobbyProjectGenerator -{ - public class Class1 - { - static void Main(string[] args) - { - Console.WriteLine("Hello World!"); - } - } -} \ No newline at end of file diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/Contracts/IDataSource.cs b/Source Code/TeamHobby.HobbyProjectGenerator/Contracts/IDataSource.cs new file mode 100644 index 0000000..7db156f --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator/Contracts/IDataSource.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TeamHobby.HobbyProjectGenerator.Contracts +{ + internal interface IDataSource + { + } +} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/Contracts/IUserService.cs b/Source Code/TeamHobby.HobbyProjectGenerator/Contracts/IUserService.cs new file mode 100644 index 0000000..96fff23 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator/Contracts/IUserService.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TeamHobby.HobbyProjectGenerator +{ + public interface IUserService + { + // Public methods shouldn't be void so it can be tested + bool User(string username); + IList GetAllUsers(); + } +} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/Database_Users.cs b/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/Database_Users.cs new file mode 100644 index 0000000..29bf72b --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/Database_Users.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TeamHobby.HobbyProjectGenerator.Implementations +{ + internal class Database_Users : IUserService + { + public IList GetAllUsers() + { + throw new NotImplementedException(); + } + + public bool User(string username) + { + throw new NotImplementedException(); + } + } +} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/InMemoryUserService.cs b/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/InMemoryUserService.cs new file mode 100644 index 0000000..3b14f48 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/InMemoryUserService.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TeamHobby.HobbyProjectGenerator.Implementations +{ + public class InMemoryUserService : IUserService + { + // Make it readonly so it can't be changed + private readonly IList _logstore; + + public InMemoryUserService() + { + _logstore = new List(); + } + + public IList GetAllUsers() + { + return _logstore; + } + + public bool User(string username) + { + try + { + //DateTime.UtcNow.ToString() + "->" + username; old way of doing it + _logstore.Add($"{DateTime.UtcNow}->{username}"); // New way of doing it + return true; + } + catch + { + return false; + } + } + /* + public bool User(DateTime timestamp, string username) + { + try + { + //DateTime.UtcNow.ToString() + "->" + username; old way of doing it + _logstore.Add($"{timestamp.ToUniversalTime()}->{username}"); // New way of doing it + return true; + } + catch + { + return false; + } + } + */ + } +} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/User_Authentication.cs b/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/User_Authentication.cs new file mode 100644 index 0000000..718f331 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/User_Authentication.cs @@ -0,0 +1,17 @@ +namespace TeamHobby.HobbyProjectGenerator +{ + public class User_Authentication : IUserService + { + public IList GetAllUsers() + { + throw new NotImplementedException(); + } + + public bool User(string username) + { + //Console.WriteLine("Hello World!"); + //Console.WriteLine("Testing console"); + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/User_Manager.cs b/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/User_Manager.cs new file mode 100644 index 0000000..56b859f --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/User_Manager.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TeamHobby.HobbyProjectGenerator.Implementations +{ + public class User_Manager : IUserService + { + public IList GetAllUsers() + { + throw new NotImplementedException(); + } + + public bool User(string username) + { + throw new NotImplementedException(); + } + } +} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln index 6ae835b..2e9cc83 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln +++ b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln @@ -5,9 +5,17 @@ VisualStudioVersion = 17.0.31919.166 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator", "TeamHobby.HobbyProjectGenerator.csproj", "{C75B6909-FD9E-4382-94B6-7CA2CE371C9A}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.Archive", "..\TeamHobby.HobbyProjectGenerator.Archive\TeamHobby.HobbyProjectGenerator.Archive.csproj", "{F0E39503-E55A-4EB8-AA98-98D74A79D7D6}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.UserManagement.Tests", "..\TeamHobby.UserManagement.Tests\TeamHobby.UserManagement.Tests.csproj", "{5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamHobby.Main", "..\TeamHobby.Main\TeamHobby.Main.csproj", "{6E9DCCDB-B7E3-4530-B20D-5B86BA86A905}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.Models", "..\TeamHobby.HobbyProjectGenerator.Models\TeamHobby.HobbyProjectGenerator.Models.csproj", "{75DED6C2-D404-4E71-A58B-0F616DB5C062}" +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", "{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 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamHobby.HobbyProjectGenerator.DataAccess", "..\TeamHobby.HobbyProjectGenerator.DataAccess\TeamHobby.HobbyProjectGenerator.DataAccess.csproj", "{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -16,17 +24,30 @@ Global 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}.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 - {6E9DCCDB-B7E3-4530-B20D-5B86BA86A905}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6E9DCCDB-B7E3-4530-B20D-5B86BA86A905}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6E9DCCDB-B7E3-4530-B20D-5B86BA86A905}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6E9DCCDB-B7E3-4530-B20D-5B86BA86A905}.Release|Any CPU.Build.0 = Release|Any CPU + {5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Debug|Any CPU.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 + {75DED6C2-D404-4E71-A58B-0F616DB5C062}.Debug|Any CPU.ActiveCfg = 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 + {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}.Release|Any CPU.ActiveCfg = Release|Any CPU + {30C7EBF3-3957-46E5-86C1-C13356841ECA}.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 + {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}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.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 6d30a27..c293745 100644 --- a/Source Code/TeamHobby.Main/HobbyMain.cs +++ b/Source Code/TeamHobby.Main/HobbyMain.cs @@ -1,62 +1,148 @@ // 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 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\archiving2.txt"; - //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); - //Console.WriteLine("Starting file compression: "); - //Compress(fileInfo); - //Console.WriteLine("Ending compression"); - //SqlConnection myconn = new SqlConnection(); + //SQLSource sqlSource = new SQLSource(); + //bool res = sqlSource.CompressFile(fileName); + ////bool res = CompressFile(fileName); + //Console.WriteLine(res); + + //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); - //IDataSource dataSource = new SQLSource(); - - SQLSource sqlSource = new SQLSource(); - bool res = sqlSource.CompressFile(fileName); - //bool res = CompressFile(fileName); - Console.WriteLine(res); - } + //// SqlConnection conn = new SqlConnection(connString); + string sqlQ = "Select * from log;"; + //MySql.Data.MySqlClient.MySqlConnection connect; - public static void Compress(FileInfo fi) - { - // Get the stream of the source file. - using (FileStream inFile = fi.OpenRead()) + //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 { - // Prevent compressing hidden and - // already compressed files. - if ((File.GetAttributes(fi.FullName) & FileAttributes.Hidden) != FileAttributes.Hidden & fi.Extension != ".gz") - { - // Create the compressed file. - using (FileStream outFile = - File.Create(fi.FullName + ".gz")) - { - using (GZipStream Compress = new GZipStream(outFile, CompressionMode.Compress)) - { - // Copy the source file into - // the compression stream. - inFile.CopyTo(Compress); + 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"); - Console.WriteLine("Compressed {0} from {1} to {2} bytes.", - fi.Name, fi.Length.ToString(), outFile.Length.ToString()); - } - } - } } } + + public static void ReadData(string connectionString) + { + string queryString = "SELECT * 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/Source Code/TeamHobby.Main/rando b/Source Code/TeamHobby.Main/rando new file mode 100644 index 0000000..a2ba694 --- /dev/null +++ b/Source Code/TeamHobby.Main/rando @@ -0,0 +1,46 @@ +title Use Case: Archiving + +participant ArchiveController.cs +participant DataConnection +participant DataSourceFactory +participant SQLSource +participant MariaDB + +activate ArchiveController.cs +activate DataConnection +ArchiveController.cs ->DataConnection:static DataConnection getDataConnection() +DataConnection -->ArchiveController.cs:return DataConnection +deactivate DataConnection + +activate DataSourceFactory +ArchiveController.cs ->DataSourceFactory: new DataSourceFactory() +DataSourceFactory ->DataSourceFactory:DataSourceFactory()\nconstructor +ArchiveController.cs <-- DataSourceFactory:return DataSourceFactory +deactivate DataSourceFactory + +activate SQLSource +ArchiveController.cs->SQLSource: IDataSource DataSourceFact.GetDataSource(String sourceName, string info) +SQLSource->SQLSource: SQLSource(string info)\nconstructor +SQLSource --> ArchiveController.cs :return SQLSource + +loop #lightblue while true +alt #lightgreen date == 1 +ArchiveController.cs ->ArchiveController.cs: string fileName = string CreateFileName( ) +ArchiveController.cs -> SQLSource: int Compress(string fileName) +activate MariaDB + +SQLSource -> MariaDB: int createArchive(string fileLocation) +MariaDB -->SQLSource:return 0 + +SQLSource ->MariaDB: int RemoveEntries() +MariaDB-->SQLSource:return 0 +end + + +deactivate MariaDB + +SQLSource-->ArchiveController.cs:return 0 +end + +deactivate ArchiveController.cs +deactivate SQLSource \ No newline at end of file diff --git a/Source Code/TeamHobby.Main/text.cs b/Source Code/TeamHobby.Main/text.cs new file mode 100644 index 0000000..85362c8 --- /dev/null +++ b/Source Code/TeamHobby.Main/text.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TeamHobby.Main +{ + internal class text + { + } +} diff --git a/Source Code/TeamHobby.UserManagement.Tests/InMemeoryUserServiceShould.cs b/Source Code/TeamHobby.UserManagement.Tests/InMemeoryUserServiceShould.cs new file mode 100644 index 0000000..3f32476 --- /dev/null +++ b/Source Code/TeamHobby.UserManagement.Tests/InMemeoryUserServiceShould.cs @@ -0,0 +1,69 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TeamHobby.HobbyProjectGenerator; +using TeamHobby.HobbyProjectGenerator.Implementations; + +namespace TeamHobby.UserManagement.Tests +{ + [TestClass] + public class InMemeoryUserServiceShould + { + [TestMethod] + public void GetNoLogs() + { + // Triple A Format + // Arrange + var userService = new InMemoryUserService(); + var expectedCount = 0; + + // Act + var actualFetch = userService.GetAllUsers(); + + // Assert + // This is the best format + Assert.IsTrue(actualFetch.Count == expectedCount); + + } + + [TestMethod] + public void AllowValidUserInput() + { + // Triple A Format + // Arrange + var userService = new InMemoryUserService(); + var expectedCount = 1; + var expectedUserMessage = "Test log entry"; + + // Act + var actual = userService.User("Test log entry"); + var actualFetch = userService.GetAllUsers(); + + // Assert + // This is the best format + Assert.IsTrue(actualFetch.Count == expectedCount); + Assert.IsTrue(actualFetch[0].Contains(expectedUserMessage)); + + } + + /* + [TestMethod] + public void Users() + { + // Triple A Format + // Arrange + var inMemoryUserService = new InMemoryUserService(); + var expected = true; + + // Act + var actual = inMemoryUserService.User("Potato"); + + + // Assert + // This is the best format + Assert.IsTrue(expected == actual); + // Alternate is + //Assert.AreEqual(expected, actual); + + } + */ + } +} \ No newline at end of file diff --git a/Source Code/TeamHobby.UserManagement.Tests/TeamHobby.UserManagement.Tests.csproj b/Source Code/TeamHobby.UserManagement.Tests/TeamHobby.UserManagement.Tests.csproj new file mode 100644 index 0000000..ec4c663 --- /dev/null +++ b/Source Code/TeamHobby.UserManagement.Tests/TeamHobby.UserManagement.Tests.csproj @@ -0,0 +1,21 @@ + + + + net6.0 + enable + + false + + + + + + + + + + + + + + diff --git a/Source Code/TeamHobby/Class1.cs b/Source Code/TeamHobby/Class1.cs new file mode 100644 index 0000000..dd20082 --- /dev/null +++ b/Source Code/TeamHobby/Class1.cs @@ -0,0 +1,7 @@ +namespace TeamHobby +{ + public class Class1 + { + + } +} \ No newline at end of file diff --git a/Source Code/TeamHobby/TeamHobby.csproj b/Source Code/TeamHobby/TeamHobby.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/Source Code/TeamHobby/TeamHobby.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/Source Code/main/Controller.cs b/Source Code/main/Controller.cs new file mode 100644 index 0000000..1932939 --- /dev/null +++ b/Source Code/main/Controller.cs @@ -0,0 +1,170 @@ +using main; +using System; +using System.Data.Odbc; +using TeamHobby.HobbyProjectGenerator.DataAccess; + + +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) + { + //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 + string dbType = "sql"; + RelationalDataSourceFactory dbFactory = new RelationalDataSourceFactory(); + + // Testing Data Access Layer + string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" + + "SERVER=localhost;" + + "DATABASE=hobby;" + + "UID=root;" + + "PASSWORD=Teamhobby;" + + "OPTION=3"; + IDataSource datasource = dbFactory.getDataSource(dbType,dbInfo); + + string sqlQuery = "Select * from log;"; + Object result = datasource.ReadData(sqlQuery); + Console.WriteLine("type of Result: " + result.GetType()); + OdbcDataReader reader = null; + + if (result.GetType() == typeof(OdbcDataReader)) + { + reader = (OdbcDataReader)result; + + } + + Console.WriteLine("Reading from 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]); + } + SqlDAO sqlDS = (SqlDAO)datasource; + + // Closing the connection + sqlDS.getConnection().Close(); + + // 2.Inserting Data into the database: + //string sqlWrite = "INSERT into log(lvname, catname, userop, logmessage) values " + + // "('Info', 'View', 'Testing DAL stuffs', 'new DAL method tested');"; + + //Console.WriteLine("Writing to the database... "); + //datasource.WriteData(sqlWrite); + //Console.WriteLine("Writing completed. "); + + // 3. Removing from a database + //string sqlRemove = "DELETE from log where logID = 28;"; + //Console.WriteLine("Writing to the database... "); + //datasource.WriteData(sqlRemove); + //Console.WriteLine("Writing completed. "); + + + + + + /* ExampleDAO z = new ExampleDAO(); + z.UserData("Tomato"); + Console.Read();*/ + /*bool MainMenu = true; + + // Set up menu loop + while (MainMenu == true) + { + // Console customization + // Change the look of the console + Console.Title = "HobbyProjectGenerator"; + // Change console text color + Console.ForegroundColor = ConsoleColor.Green; + // Change terminal height + Console.WindowHeight = 40; + + + // Create class objects + UiPrint menu = new UiPrint(); + UserAccount user = new UserAccount(); + + + // Print main menu + menu.InitialMenu(); + + // Set up try-catch for invalid inputs + try + { + // Get user choice + string initialChoice = Console.ReadLine(); + // Convert to integer + int Choice = Convert.ToInt32(initialChoice); + + switch (Choice) + { + case 0: + MainMenu = false; + break; + // Create a new account + case 1: + user.newUser(); + break; + // Access Admin features + case 2: + // Ask for Admin login credentials + Console.WriteLine("Please enter a username:"); + string AdminUser = Console.ReadLine(); + Console.WriteLine("Please enter the password for" + AdminUser); + string AdminPsswrd = Console.ReadLine(); + + // Check if the username and password match a record within the administrators + + + // Show new administrator menu + int AdminNum = 0; + Console.WriteLine("Welcome" + AdminUser); + Console.WriteLine("What would you like to do?"); + Console.WriteLine("1.View normal user records."); + Console.WriteLine("2.View Administrator user records."); + Console.WriteLine("3.View log files."); + Console.WriteLine(""); + Console.WriteLine(""); + Console.WriteLine(""); + Console.WriteLine(""); + Console.WriteLine(""); + + + break; + default: + Console.WriteLine("Invalid choice, please enter a valid number."); + break; + }; + } + // Catch invalid keys such as spamming enter + catch + { + MainMenu = false; + }; + }*/ + + } + } +} diff --git a/Source Code/main/ExampleDAO.cs b/Source Code/main/ExampleDAO.cs new file mode 100644 index 0000000..64e3b63 --- /dev/null +++ b/Source Code/main/ExampleDAO.cs @@ -0,0 +1,51 @@ +using Microsoft.Data.SqlClient; + +namespace TeamHobby.HobbyProjectGenerator.Main +{ + public class ExampleDAO + { + + public void UserData(string username) + { + // Sql server connection string, needs to be changed accordingly to connect + var connString = "server=localhost,3316;user=root;database=users;password=Plop20"; // Using @" " makes the string literal + + // ADO.NET - ODBC + using var conn = new SqlConnection(connString); + { + // More complex sql commands are done in this method instead + var sql = "Select * from roles"; + using (var command = new SqlCommand(sql, conn)) + { + conn.Open(); + // Get the results from the query + SqlDataReader r = command.ExecuteReader(); + + // If you wanted to get a singular value back such as a count of a certain item + //command.ExecuteScalar(); + + // To execute something that doesn't expect results to come back + // Use this method instead, IE. Update command + //command.ExecuteNonQuery(); + + // Read data from query + while (r.Read()) + { + Console.WriteLine(r.ToString()); + } + conn.Close(); + + } + // Console.Read(); + /* + * this is meant for specific basic sql commands + using (var adapter = new SqlDataAdapter()) + { + adapter.SelectCommand + } + */ + //return null; + } + } + } +} diff --git a/Source Code/main/MainMenu.cs b/Source Code/main/MainMenu.cs new file mode 100644 index 0000000..64a8930 --- /dev/null +++ b/Source Code/main/MainMenu.cs @@ -0,0 +1,134 @@ +using System; + +namespace TeamHobby.HobbyProjectGenerator.Main +{ + public class MainMenu + { + /*static void Main(string[] args) + { + /* ExampleDAO z = new ExampleDAO(); + z.UserData("Tomato"); + Console.Read();*/ + /*bool menu = true; + + // Set up menu loop + while (menu == true) + { + // Console customization + // Change the look of the console + Console.Title = "HobbyProjectGenerator"; + // Change console text color + Console.ForegroundColor = ConsoleColor.Green; + // Change terminal height + Console.WindowHeight = 40; + + + // Create intial menu + Console.WriteLine("What would you like to do?"); + int num = 1; + Console.WriteLine(num + ".Create a new user account."); + num += 1; + Console.WriteLine(num + ".Acess Admin Features."); + + // Set up try-catch for invalid inputs + try + { + // Get user choice + string initialChoice = Console.ReadLine(); + // Convert to integer + int Choice = Convert.ToInt32(initialChoice); + + switch (Choice) + { + // Create a new account + case 1: + // Get username + Console.WriteLine("Please enter a username:"); + string userName = Console.ReadLine(); + + // Get Password + Console.WriteLine("Please enter a password:"); + string userPassword = Console.ReadLine(); + + // Create bool value for password confirm loop + bool conPsswrd = true; + // Loop until password is confirmed + while (conPsswrd == true) + { + // Confirm Password + Console.WriteLine("Please re-enter the password:"); + string checkPsswd = Console.ReadLine(); + // Check if passwords match + if (userPassword == checkPsswd) + { + // Get Security question for password reset + Console.WriteLine("Please enter a security question.\n" + + "(EX: What is your favorite food?"); + string SecQuest = Console.ReadLine(); + // Get Security question answer + Console.WriteLine("Please enter the answer for your security question:"); + String SecAnswer = Console.ReadLine(); + + // Call user manager method to create the new user + //int userCreateConfirm = new CreateUser(userName,userPassword,SecQuest,SecAnswer); + + // Check if user creation was successful + /* if (userCreateConfirm = 1) + { + + // Confirm to user that the account has been created + Console.WriteLine("Account created succesfully with the username of" + userName); + } + else + { + + }*/ + /* conPsswrd = false; + } + else + { + Console.WriteLine("Passwords did not match, please try again."); + } + } + break; + // Access Admin features + case 2: + // Ask for Admin login credentials + Console.WriteLine("Please enter a username:"); + string AdminUser = Console.ReadLine(); + Console.WriteLine("Please enter the password for" + AdminUser); + string AdminPsswrd = Console.ReadLine(); + + // Check if the username and password match a record within the administrators + + + // Show new administrator menu + int AdminNum = 0; + Console.WriteLine("Welcome" + AdminUser); + Console.WriteLine("What would you like to do?"); + Console.WriteLine("1.View normal user records."); + Console.WriteLine("2.View Administrator user records."); + Console.WriteLine("3."); + Console.WriteLine(""); + Console.WriteLine(""); + Console.WriteLine(""); + Console.WriteLine(""); + Console.WriteLine(""); + + + break; + default: + menu = false; + break; + }; + } + // Catch invalid keys such as spamming enter + catch + { + menu = false; + }; + }*/ + + //} + } +} diff --git a/Source Code/main/SystemAccountManager.cs b/Source Code/main/SystemAccountManager.cs new file mode 100644 index 0000000..78a9ff3 --- /dev/null +++ b/Source Code/main/SystemAccountManager.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace main +{ + internal class SystemAccountManager + { + /*public NewUserName() + { + + } + public NewPassword() + { + // Create bool value for password confirm loop + bool conPsswrd = true; + // Loop until password is confirmed + while (conPsswrd == true) + { + // Confirm Password + Console.WriteLine("Please re-enter the password:"); + string checkPsswd = Console.ReadLine(); + // Check if passwords match + if (userPassword == checkPsswd) + { + // Get Security question for password reset + Console.WriteLine("Please enter a security question.\n" + + "(EX: What is your favorite food?"); + string SecQuest = Console.ReadLine(); + // Get Security question answer + Console.WriteLine("Please enter the answer for your security question:"); + String SecAnswer = Console.ReadLine(); + + // Call user manager method to create the new user + //int userCreateConfirm = new CreateUser(userName,userPassword,SecQuest,SecAnswer); + + // Check if user creation was successful + /*if (userCreateConfirm = 1) + { + + // Confirm to user that the account has been created + Console.WriteLine("Account created succesfully with the username of" + userName); + } + else + { + + }*/ + /*conPsswrd = false; + } + else + { + Console.WriteLine("Passwords did not match, please try again."); + } + } + return true; + }*/ + + public void AccountController() + { + // Create objects + UserAccount user = new UserAccount(); + UiPrint ui = new UiPrint(); + + bool foo = true; + + while (foo == true) + { + // sub menu + ui.SystemAccountMenu(); + // + + } + + } + + } +} diff --git a/Source Code/main/UiPrint.cs b/Source Code/main/UiPrint.cs new file mode 100644 index 0000000..98378f8 --- /dev/null +++ b/Source Code/main/UiPrint.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +// Print Statements used throughout the program. + +namespace main +{ + internal class UiPrint + { + public void InitialMenu() + { + // Create intial menu + Console.WriteLine("What would you like to access?"); + int num = 1; + Console.WriteLine(num + ".User Management"); + num += 1; + Console.WriteLine(num + ".Logging"); + } + public void SystemAccountMenu() + { + // Create intial menu + Console.WriteLine("What would you like to do?"); + int num = 1; + Console.WriteLine(num + ".Create a new account."); + num += 1; + Console.WriteLine(num + ".Access Admin Features"); + } + } +} diff --git a/Source Code/main/UserAccount.cs b/Source Code/main/UserAccount.cs new file mode 100644 index 0000000..92e0c55 --- /dev/null +++ b/Source Code/main/UserAccount.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace main +{ + public class UserAccount + { + /* private string username; + private string password; + private string role; + + public UserAccount(string un,string pwd,string rol) + { + username = un; + password = pwd; + role = rol; + + } + + public void UserAccount() + { + password = "1234"; + role = "Regular"; + } + + public void newUser() + { + + }*/ + } +} diff --git a/Source Code/main/main.csproj b/Source Code/main/main.csproj new file mode 100644 index 0000000..63f5952 --- /dev/null +++ b/Source Code/main/main.csproj @@ -0,0 +1,18 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + + + + + diff --git a/doc/Business Docs/Testing_Library_Tech_Approval.pdf b/doc/Business Docs/Testing_Library_Tech_Approval.pdf new file mode 100644 index 0000000..cad277f Binary files /dev/null and b/doc/Business Docs/Testing_Library_Tech_Approval.pdf differ diff --git a/doc/LowLevel/ArchivingWithError.png b/doc/LowLevel/ArchivingWithError.png new file mode 100644 index 0000000..34d1db8 Binary files /dev/null and b/doc/LowLevel/ArchivingWithError.png differ diff --git a/doc/LowLevel/ArchivingWithError.svg b/doc/LowLevel/ArchivingWithError.svg new file mode 100644 index 0000000..ab49cd2 --- /dev/null +++ b/doc/LowLevel/ArchivingWithError.svg @@ -0,0 +1 @@ +%0Atitle%20Use%20Case%3A%20Archiving%0A%0Aparticipant%20Controller.cs%20%2390EE90%0Aparticipant%20RDSFactory%20%2326abff%0Aparticipant%20ArchiveManager%20%23ffffe0%0Aparticipant%20SqlDAO%20%23D3D3D3%0Aparticipant%20MariaDB%20%2300FFFF%0A%0Aactivate%20Controller.cs%20%2390EE90%0A%2F%2F%20Create%20a%20new%20factory%20%0AController.cs-%3ERDSFactory%3Afactory%20%3D%20new%20RDSFactory()%0Aactivate%20RDSFactory%20%2326abff%0ARDSFactory-%3ERDSFactory%3AConstructor()%0AController.cs%3C--RDSFactory%3Areturn%20RDSFactory%0Adeactivate%20RDSFactory%0AController.cs-%3ESqlDAO%3A%20%2B%2BIDataSource%20factory.GetDataSource(string%20name%2C%20string%20connInfo)%2B%2B%0Aactivate%20SqlDAO%20%23D3D3D3%0ASqlDAO-%3ESqlDAO%3A%2B%2BConstructor(string%20connInfo)%2B%2B%0AController.cs%3C--SqlDAO%3A%20%2B%2Breturn%20SqlDAO%2B%2B%0A%0A%0Aalt%20%23red%20%0ASqlDAO%20-%3ESqlDAO%3A%20Catch%20Exception%0ASqlDAO%20--%3EController.cs%3Areturn%20%22DataSourceTimeOut%22%0Aend%20%0Adeactivate%20SqlDAO%0A%0A%2F%2F%20Create%20Archive%20Manager%0A%0Aactivate%20ArchiveManager%20%23ffffe0%0Agroup%20%23lightblue%20Connection%20to%20DataSource%20successful%0AController.cs%20-%3EArchiveManager%3Anew%20ArchiveManager(IDataSource%20conn)%0AArchiveManager%20-%3EArchiveManager%3A%20ArchiveManager(IDatasSource%20conn)%0A%0A%2F%2F%20Calling%20the%20main%3A%0AArchiveManager%20--%3EController.cs%3A%20return%20ArchiveManager%0Aloop%20%23lightblue%20while%20true%0Aalt%20%23lightgreen%20The%20First%20Day%20of%20the%20month%20at%2000%3A00%3A00%20AM%0AController.cs%20-%3EArchiveManager%3A%20bool%20ArchiveManager.Controller(%20)%0A%0A%2F%2F%20Keep%20looping%0A%0A%2F%2F%20Check%20if%20the%20directory%20exist%20or%20not%0Aalt%20%23lightgreen%20Archive%20folder%20does%20not%20exist%20already%20in%20the%20current%20directory%0AArchiveManager%20-%3E%20ArchiveManager%3Abool%20CreateArchiveFolder(string%20path)%0A%0Aend%20%0A%2F%2F%20Create%20the%20file%20name%20%0AArchiveManager%20-%3EArchiveManager%3Astring%20filePath%20%3D%20string%20CreateOutFileName(%20)%0AArchiveManager%20-%3ESqlDAO%3Abool%20Compress(string%20filePath)%0A%0Aactivate%20SqlDAO%20%23D3D3D3%0Aactivate%20MariaDB%20%2300FFFF%0ASqlDAO%20-%3EMariaDB%3A%20bool%20CopyToArchive(string%20filePath)%0A%2F%2F%20Sql%20Command%20to%20add%20data%20to%20the%20table%0AMariaDB%20-%3EMariaDB%3A%20SELECT%20'LtimeStamp'%2C%20'logID'%2C%20'LvName'%2C%20'catName'%2C%20'userOP'%2C%20'logMessage'%20%5CnUNION%20ALL%5CnSELECT%20*%20FROM%20log%5CnWHERE%20DATEDIFF(CURRENT_TIMESTAMP%2C%20log.LtimeStamp)%20%3E%2030%5CnINTO%20OUTFILE%20%40filePath%5CnFIELDS%20ENCLOSED%20BY%20''%5CnTERMINATED%20BY%20'%2C'%5CnESCAPED%20BY%20'%22'%5CnLINES%20TERMINATED%20BY%20'%5Cr%5C%5Cn'%3B%0Aalt%20%23lightgreen%20No%20error%20when%20doing%20executing%20copy%20SQL%20command%0AMariaDB%20--%3E%20SqlDAO%3A%20return%20True%0ASqlDAO%20--%3EArchiveManager%3A%20return%20True%0Aend%20%0A%0Aalt%20%23red%20Error%20occur%20when%20executing%20copy%20SQL%20command%20on%20Database%0AMariaDB%20--%3ESqlDAO%3A%20throw%20SQLException%0Adeactivate%20MariaDB%0ASqlDAO%20--%3EArchiveManager%3A%20throw%20SqlException%0Adeactivate%20SqlDAO%0A%0A%0AArchiveManager%20-%3EArchiveManager%3A%20Catch%20Exception%0A%2F%2F%20Removing%20created%20files%20if%20the%20process%20failed%0Aalt%20%23red%20Log%20output%20text%20file%20exist%0AArchiveManager%20-%3EArchiveManager%3A%20File.Delete(string%20filePath)%0Aend%0Aalt%20%23red%20Compressed%20file%20exist%0AArchiveManager%20-%3EArchiveManager%3A%20File.Delete(string%20comFilePath)%0Aend%0Aend%20%0A%0Aactivate%20SqlDAO%20%23D3D3D3%0A%2F%2F%20Compress%20the%20file%20%0ASqlDAO%20-%3ESqlDAO%3A%20bool%20CompressArchive(string%20filePath)%0Aalt%20%23lightgreen%20File%20Compression%20was%20successful%0ASqlDAO%20--%3EArchiveManager%3A%20return%20True%0Aend%20%0Aalt%20%23red%20File%20Compresssion%20failed%0ASqlDAO%20--%3EArchiveManager%3A%20throw%20FileException%0AArchiveManager%20-%3EArchiveManager%3A%20Catch%20Exception%0Aalt%20%23red%20Log%20output%20text%20file%20exist%0AArchiveManager%20-%3EArchiveManager%3A%20File.Delete(filePath)%0Aend%0Aalt%20%23red%20Compressed%20file%20exist%0AArchiveManager%20-%3EArchiveManager%3A%20File.Delete(string%20comFilePath)%0Aend%0Aend%0A%2F%2F%20Remove%20output%20file%0ASqlDAO%20-%3ESqlDAO%3Abool%20RemoveOutputFile(string%20filePath)%0Aalt%20%23lightgreen%20UncompressFile%20was%20removed%20successfully%0ASqlDAO%20--%3EArchiveManager%3A%20return%20true%0Aend%20%0A%0Aalt%20%23red%20Uncompressfile%20failed%20to%20be%20removed%0ASqlDAO%20--%3EArchiveManager%3A%20throw%20FileException%0Adeactivate%20SqlDAO%0AArchiveManager%20-%3EArchiveManager%3A%20catch%20Exception%0A%0Aalt%20%23red%20Log%20output%20text%20file%20exist%0AArchiveManager%20-%3EArchiveManager%3A%20File.Delete(string%20filePath)%0Aend%0Aalt%20%23red%20Compressed%20file%20exist%0AArchiveManager%20-%3EArchiveManager%3A%20File.Delete(string%20comFilePath)%0Aend%0Aend%20%0A%0Aactivate%20SqlDAO%20%23D3D3D3%0Aactivate%20MariaDB%20%2300FFFF%0ASqlDAO%20-%3EMariaDB%3A%20bool%20RemoveEntries(%20)%0AMariaDB%20-%3EMariaDB%3A%20DELETE%20from%20log%20%5CnWHERE%20%5CnDATEDIFF(CURRENT_TIMESTAMP%2C%20log.LtimeStamp)%20%3E%2030%3B%0A%0Aalt%20%23lightgreen%20No%20error%20when%20doing%20executing%20remove%20old%20logs%20SQL%20command%0AMariaDB--%3ESqlDAO%3Areturn%20True%0ASqlDAO%20--%3EArchiveManager%3A%20return%20True%0Aend%0A%0Aalt%20%23red%20Error%20occur%20when%20executing%20removing%20SQL%20command%20on%20Database%0AMariaDB%20--%3ESqlDAO%3A%20throw%20SQLException%0Adeactivate%20MariaDB%0ASqlDAO--%3EArchiveManager%3A%20throw%20SQLException%0Adeactivate%20SqlDAO%0AArchiveManager%20-%3EArchiveManager%3ACatch%20Exception%0Aalt%20%23red%20Log%20output%20text%20file%20exist%0AArchiveManager%20-%3EArchiveManager%3A%20File.Delete(string%20filePath)%0Aend%0Aalt%20%23red%20Compressed%20file%20exist%0AArchiveManager%20-%3EArchiveManager%3A%20File.Delete(string%20comFilePath)%0Aend%0Aend%20%0A%0A%0AArchiveManager%20--%3E%20Controller.cs%3Areturn%20True%0Adeactivate%20ArchiveManager%0Aend%0A%0Aend%20%0Aend%20%0A%0AUse Case: ArchivingController.csRDSFactoryArchiveManagerSqlDAOMariaDBfactory = new RDSFactory()Constructor()return RDSFactoryIDataSource factory.GetDataSource(string name, string connInfo)Constructor(string connInfo)return SqlDAOCatch Exceptionreturn "DataSourceTimeOut"new ArchiveManager(IDataSource conn)ArchiveManager(IDatasSource conn)return ArchiveManagerbool ArchiveManager.Controller( )bool CreateArchiveFolder(string path)string filePath = string CreateOutFileName( )bool Compress(string filePath)bool CopyToArchive(string filePath)SELECT 'LtimeStamp', 'logID', 'LvName', 'catName', 'userOP', 'logMessage' UNION ALLSELECT * FROM logWHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30INTO OUTFILE @filePathFIELDS ENCLOSED BY ''TERMINATED BY ','ESCAPED BY '"'LINES TERMINATED BY '\r\n';return Truereturn Truethrow SQLExceptionthrow SqlExceptionCatch ExceptionFile.Delete(string filePath)File.Delete(string comFilePath)bool CompressArchive(string filePath)return Truethrow FileExceptionCatch ExceptionFile.Delete(filePath)File.Delete(string comFilePath)bool RemoveOutputFile(string filePath)return truethrow FileExceptioncatch ExceptionFile.Delete(string filePath)File.Delete(string comFilePath)bool RemoveEntries( )DELETE from log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;return Truereturn Truethrow SQLExceptionthrow SQLExceptionCatch ExceptionFile.Delete(string filePath)File.Delete(string comFilePath)return TruealtConnection to DataSource successfulloop[while true]alt[The First Day of the month at 00:00:00 AM]alt[Archive folder does not exist already in the current directory]alt[No error when doing executing copy SQL command]alt[Error occur when executing copy SQL command on Database]alt[Log output text file exist]alt[Compressed file exist]alt[File Compression was successful]alt[File Compresssion failed]alt[Log output text file exist]alt[Compressed file exist]alt[UncompressFile was removed successfully]alt[Uncompressfile failed to be removed]alt[Log output text file exist]alt[Compressed file exist]alt[No error when doing executing remove old logs SQL command]alt[Error occur when executing removing SQL command on Database]alt[Log output text file exist]alt[Compressed file exist] \ No newline at end of file diff --git a/doc/LowLevel/ArchivingWithError.txt b/doc/LowLevel/ArchivingWithError.txt new file mode 100644 index 0000000..8265491 --- /dev/null +++ b/doc/LowLevel/ArchivingWithError.txt @@ -0,0 +1,146 @@ + +title Use Case: Archiving + +participant Controller.cs #90EE90 +participant RDSFactory #26abff +participant ArchiveManager #ffffe0 +participant SqlDAO #D3D3D3 +participant MariaDB #00FFFF + +activate Controller.cs #90EE90 +// Create a new factory +Controller.cs->RDSFactory:factory = new RDSFactory() +activate RDSFactory #26abff +RDSFactory->RDSFactory:Constructor() +Controller.cs<--RDSFactory:return RDSFactory +deactivate RDSFactory +Controller.cs->SqlDAO: ++IDataSource factory.GetDataSource(string name, string connInfo)++ +activate SqlDAO #D3D3D3 +SqlDAO->SqlDAO:++Constructor(string connInfo)++ +Controller.cs<--SqlDAO: ++return SqlDAO++ + + +alt #red +SqlDAO ->SqlDAO: Catch Exception +SqlDAO -->Controller.cs:return "DataSourceTimeOut" +end +deactivate SqlDAO + +// Create Archive Manager + +activate ArchiveManager #ffffe0 +group #lightblue Connection to DataSource successful +Controller.cs ->ArchiveManager:new ArchiveManager(IDataSource conn) +ArchiveManager ->ArchiveManager: ArchiveManager(IDatasSource conn) + +// Calling the main: +ArchiveManager -->Controller.cs: return ArchiveManager +loop #lightblue while true +alt #lightgreen The First Day of the month at 00:00:00 AM +Controller.cs ->ArchiveManager: bool ArchiveManager.Controller( ) + +// Keep looping + +// Check if the directory exist or not +alt #lightgreen Archive folder does not exist already in the current directory +ArchiveManager -> ArchiveManager:bool CreateArchiveFolder(string path) + +end +// Create the file name +ArchiveManager ->ArchiveManager:string filePath = string CreateOutFileName( ) +ArchiveManager ->SqlDAO:bool Compress(string filePath) + +activate SqlDAO #D3D3D3 +activate MariaDB #00FFFF +SqlDAO ->MariaDB: bool CopyToArchive(string filePath) +// Sql Command to add data to the table +MariaDB ->MariaDB: SELECT 'LtimeStamp', 'logID', 'LvName', 'catName', 'userOP', 'logMessage' \nUNION ALL\nSELECT * FROM log\nWHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30\nINTO OUTFILE @filePath\nFIELDS ENCLOSED BY ''\nTERMINATED BY ','\nESCAPED BY '"'\nLINES TERMINATED BY '\r\\n'; +alt #lightgreen No error when doing executing copy SQL command +MariaDB --> SqlDAO: return True +SqlDAO -->ArchiveManager: return True +end + +alt #red Error occur when executing copy SQL command on Database +MariaDB -->SqlDAO: throw SQLException +deactivate MariaDB +SqlDAO -->ArchiveManager: throw SqlException +deactivate SqlDAO + + +ArchiveManager ->ArchiveManager: Catch Exception +// Removing created files if the process failed +alt #red Log output text file exist +ArchiveManager ->ArchiveManager: File.Delete(string filePath) +end +alt #red Compressed file exist +ArchiveManager ->ArchiveManager: File.Delete(string comFilePath) +end +end + +activate SqlDAO #D3D3D3 +// Compress the file +SqlDAO ->SqlDAO: bool CompressArchive(string filePath) +alt #lightgreen File Compression was successful +SqlDAO -->ArchiveManager: return True +end +alt #red File Compresssion failed +SqlDAO -->ArchiveManager: throw FileException +ArchiveManager ->ArchiveManager: Catch Exception +alt #red Log output text file exist +ArchiveManager ->ArchiveManager: File.Delete(filePath) +end +alt #red Compressed file exist +ArchiveManager ->ArchiveManager: File.Delete(string comFilePath) +end +end +// Remove output file +SqlDAO ->SqlDAO:bool RemoveOutputFile(string filePath) +alt #lightgreen UncompressFile was removed successfully +SqlDAO -->ArchiveManager: return true +end + +alt #red Uncompressfile failed to be removed +SqlDAO -->ArchiveManager: throw FileException +deactivate SqlDAO +ArchiveManager ->ArchiveManager: catch Exception + +alt #red Log output text file exist +ArchiveManager ->ArchiveManager: File.Delete(string filePath) +end +alt #red Compressed file exist +ArchiveManager ->ArchiveManager: File.Delete(string comFilePath) +end +end + +activate SqlDAO #D3D3D3 +activate MariaDB #00FFFF +SqlDAO ->MariaDB: bool RemoveEntries( ) +MariaDB ->MariaDB: DELETE from log \nWHERE \nDATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30; + +alt #lightgreen No error when doing executing remove old logs SQL command +MariaDB-->SqlDAO:return True +SqlDAO -->ArchiveManager: return True +end + +alt #red Error occur when executing removing SQL command on Database +MariaDB -->SqlDAO: throw SQLException +deactivate MariaDB +SqlDAO-->ArchiveManager: throw SQLException +deactivate SqlDAO +ArchiveManager ->ArchiveManager:Catch Exception +alt #red Log output text file exist +ArchiveManager ->ArchiveManager: File.Delete(string filePath) +end +alt #red Compressed file exist +ArchiveManager ->ArchiveManager: File.Delete(string comFilePath) +end +end + + +ArchiveManager --> Controller.cs:return True +deactivate ArchiveManager +end + +end +end + diff --git a/doc/LowLevel/ArchivingWithSingleton.pdf b/doc/LowLevel/ArchivingWithSingleton.pdf new file mode 100644 index 0000000..bcc6af0 Binary files /dev/null and b/doc/LowLevel/ArchivingWithSingleton.pdf differ diff --git a/doc/LowLevel/ArchvingMasterCon.txt b/doc/LowLevel/ArchvingMasterCon.txt new file mode 100644 index 0000000..008c1e9 --- /dev/null +++ b/doc/LowLevel/ArchvingMasterCon.txt @@ -0,0 +1,99 @@ + +title Use Case: Archiving + +participant Controller.cs #90EE90 +participant RDSFactory #26abff +participant ArchiveManager #ffffe0 +participant SqlDAO #D3D3D3 +participant MariaDB + +activate Controller.cs +// Create a new factory +Controller.cs->RDSFactory:factory = new RDSFactory() +activate RDSFactory #26abff +RDSFactory->RDSFactory:Constructor() +Controller.cs<--RDSFactory:return RDSFactory +deactivate RDSFactory +Controller.cs->SqlDAO: ++IDataSource factory.GetDataSource(string name, string connInfo)++ +activate SqlDAO #D3D3D3 +SqlDAO->SqlDAO:++Constructor(string connInfo)++ +Controller.cs<--SqlDAO: ++return SqlDAO++ +deactivate SqlDAO + +// Create Archive Manager +activate ArchiveManager +Controller.cs ->ArchiveManager:new ArchiveManager(IDataSource conn) +ArchiveManager ->ArchiveManager: ArchiveManager(IDatasSource conn) + +// Calling the main: +ArchiveManager -->Controller.cs: return ArchiveManager +Controller.cs ->ArchiveManager: bool ArchiveManager.Controller( ) + +// Keep looping + +loop #lightblue while true +alt #lightgreen The First Day of the month at 00:00:00 AM +// Check if the directory exist or not +alt #lightgreen Archive folder does not exist already in the current directory +ArchiveManager -> ArchiveManager:int CreateArchiveFolder(string path) + +end +// Create the file name +ArchiveManager ->ArchiveManager: string filePath = string CreateFileName( ) +ArchiveManager ->SqlDAO:bool Compress(string filePath) + +activate SqlDAO +activate MariaDB +SqlDAO ->MariaDB: bool CopyToArchive(string filePath) +alt #red No error when doing executing copy SQL command +MariaDB --> SqlDAO: return True + +else #red Error occur when executing copy SQL command on Database +MariaDB -->SqlDAO: throw SQLException +deactivate MariaDB +SqlDAO -->ArchiveManager: throw SqlException +deactivate SqlDAO + +ArchiveManager ->ArchiveManager: Catch SqlException +end + +activate SqlDAO +// Compress the file +SqlDAO ->SqlDAO: bool CompressArchive(string filePath) +// Remove output file +SqlDAO ->SqlDAO:bool RemoveOutputFile(string filePath) +alt #red File was created succesffuly +SqlDAO -->SqlDAO: new file +else File Exception +SqlDAO ->SqlDAO: Catch FileException +SqlDAO -->ArchiveManager: throw FileException +deactivate SqlDAO +ArchiveManager ->ArchiveManager: catch FileException +end + +activate SqlDAO + +SqlDAO ->MariaDB: bool RemoveEntries( ) +activate MariaDB +alt #red No error when doing executing remove old logs SQL command +MariaDB-->SqlDAO:return True + + +else Error occur when executing removing SQL command on Database +MariaDB -->SqlDAO: throw SQLException +deactivate MariaDB +SqlDAO-->ArchiveManager: throw SQLException +deactivate SqlDAO +ArchiveManager ->ArchiveManager:Catch SqlException +end +activate SqlDAO +SqlDAO-->ArchiveManager:return True +deactivate SqlDAO +end + + +deactivate MariaDB + +end +deactivate ArchiveManager +deactivate SqlDAO \ No newline at end of file diff --git a/doc/LowLevel/UMLforArchving.png b/doc/LowLevel/UMLforArchving.png new file mode 100644 index 0000000..1017095 Binary files /dev/null and b/doc/LowLevel/UMLforArchving.png differ diff --git a/doc/LowLevel/UserManagement/UserManagementCreateAccount.png b/doc/LowLevel/UserManagement/UserManagementCreateAccount.png new file mode 100644 index 0000000..78cae0d Binary files /dev/null and b/doc/LowLevel/UserManagement/UserManagementCreateAccount.png differ diff --git a/doc/LowLevel/UserManagement/UserManagementCreateAccount.txt b/doc/LowLevel/UserManagement/UserManagementCreateAccount.txt new file mode 100644 index 0000000..259284b --- /dev/null +++ b/doc/LowLevel/UserManagement/UserManagementCreateAccount.txt @@ -0,0 +1,172 @@ +title Create User Record +actor User +participant Controller.cs #90EE90 +participant RDSFactory #26abff +participant UserAccount #CBC3E3 +participant SystemAccountManager #ffffe0 +participant AccountService #ff8b3d +participant SqlDAO #D3D3D3 +//SqlDAO +database SqlServer(MariaDB) #00FFFF + +//activate User +activate Controller.cs #90EE90 +User->Controller.cs: ++Create new User++ + +//RelatDSFactory +Controller.cs->RDSFactory:++factory = new RDSFactory()++ +activate RDSFactory #26abff +RDSFactory->RDSFactory:++Constructor()++ +Controller.cs<--RDSFactory:++return RDSFactory++ +deactivate RDSFactory +Controller.cs->SqlDAO:++IDataSource factory.GetDataSource(string DbName, string connInfo)++ +activate SqlDAO #D3D3D3 +SqlDAO->SqlDAO:++Constructor(string connInfo)++ +group #red Data Store Timed Out #white +SqlDAO->SqlDAO: ++Catch SqlException++ +Controller.cs<--SqlDAO:++return "Data Source Timed Out"++ +end +group #blue Data Store Online #white +Controller.cs<--SqlDAO: ++return SqlDAO++ +deactivate SqlDAO + + +// Create new Admin +Controller.cs->SystemAccountManager:++ manager = new SystemAccountManager(IDataSource conn)++ +activate SystemAccountManager #ffffe0 +SystemAccountManager->SystemAccountManager:++Constructor(IDataSource conn)++ +Controller.cs<--SystemAccountManager:++ New SystemAccountManager++ +deactivate SystemAccountManager + +// GetUserName +Controller.cs->Controller.cs:++string GetUserName()++ + +// GetPassword +Controller.cs->Controller.cs:++string GetPassword()++ +// +Controller.cs->UserAccount:++ new UserAccount(string username,\n string password,\n DateTime TimeStamp)++ +activate UserAccount #CBC3E3 +UserAccount->UserAccount:++Constructor(string username,\n string password,\n DateTime TimeStamp)++ +Controller.cs<--UserAccount:++New UserAccount++ +deactivate UserAccount +// +Controller.cs->SystemAccountManager:++manager.CreateUserRecord(user:UserAccount)++ +activate SystemAccountManager #ffffe0 +SystemAccountManager->SystemAccountManager:++isInputValid(user: UserAccount)++ + +group #red Invalid Information #white +Controller.cs<--SystemAccountManager:++return "Invalid input"++ +User<--Controller.cs:++ return "Invalid input"++ +end +group #green Information Valid #white + +//check if there is an admin user +SystemAccountManager->SqlDAO:++bool isAdmin(user:UserAccount)++ +activate SqlDAO #D3D3D3 +SqlDAO->SqlServer(MariaDB):++SqlRead confirmAdmin()++ +activate SqlServer(MariaDB)#00FFFF +//authorized +SqlServer(MariaDB)->SqlServer(MariaDB):++Select * from Admins\n where Username = @UserName \nand Password = @Pwd++ +//Unauthorized role section +group #red Unauthorized User #white +SqlDAO<--SqlServer(MariaDB):++SqlException++ +SqlDAO->SqlDAO: ++Catch\nSqlException++ +SystemAccountManager<--SqlDAO:++return false++ +Controller.cs<--SystemAccountManager:++ return "Access Denied: \nUnauthorized"++ +User<--Controller.cs:++return "Access Denied: \nUnauthorized"++ +end +//Unauthorized role section +group #red Unauthorized User #white +SqlDAO<--SqlServer(MariaDB):++return false++ +SystemAccountManager<--SqlDAO:++return false++ +Controller.cs<--SystemAccountManager:++ return "Access Denied: \nUnauthorized"++ +User<--Controller.cs:++return "Access Denied: \nUnauthorized"++ +end + + +//Authorized role section +group #blue Authorized User #white +SqlDAO<--SqlServer(MariaDB):++return true++ +deactivate SqlServer(MariaDB) +SystemAccountManager<--SqlDAO:++return true++ +deactivate SqlDAO +deactivate SystemAccountManager + +group #green Valid Information #white +activate SystemAccountManager #ffffe0 +// GetUserName +SystemAccountManager->SystemAccountManager:++string NewUserName()++ +// Enter UserName +User->SystemAccountManager:++string NewUserName++ +// GetPassword +SystemAccountManager->SystemAccountManager:++string NewPassword()++ +// Enter Password +User->SystemAccountManager:++string NewPassword++ +// GetEmail +SystemAccountManager->SystemAccountManager:++string NewEmail()++ +// Enter Email +User->SystemAccountManager:++string NewEmail++ +// GetRole +SystemAccountManager->SystemAccountManager:++string NewRole()++ +// Enter Role +User->SystemAccountManager:++string NewRole++ +// Create NewUser object +UserAccount<-SystemAccountManager:++new NewUser(\nstring NewUserName,\nstring NewPassword,\nstring New Email,\nDateTime TimeStamp)++ +activate UserAccount #CBC3E3 +UserAccount->UserAccount:++Constructor(string NewUserName,\nstring NewPassword,\nstring New Email,\nDateTime TimeStamp)++ +UserAccount-->SystemAccountManager:++return NewUser++ +deactivate UserAccount +//Create User Record +SystemAccountManager->AccountService:++AccountService\n.CreateUserRecord(user:NewUser)++ +activate AccountService #ff8b3d +AccountService->SqlDAO:++SqlDAO\n.CreateUserRecord(user:NewUser)++ +activate SqlDAO #D3D3D3 +SqlDAO->SqlServer(MariaDB):++SqlRead \nisUser(user:NewUser)++ +activate SqlServer(MariaDB) #00FFFF +SqlServer(MariaDB)->SqlServer(MariaDB):++ Select *\nFrom Users\nwhere Username\n= @UserName OR\nemail = @Email++ +group #red data store timed out #white +SqlDAO<--SqlServer(MariaDB):++SqlException++ +deactivate SqlServer(MariaDB) +SqlDAO->SqlDAO: ++Catch\nSqlException++ +AccountService<--SqlDAO:++return "Database timed out"++ + +SystemAccountManager<--AccountService:++ return "Database timed out"++ +Controller.cs<--SystemAccountManager:++ return "Database timed out"++ +User<--Controller.cs:++ return "Database timed out"++ +end +group #blue data store is online #white +// User exists +group #green User does exist #white +activate SqlServer(MariaDB) #00FFFF +SqlDAO<--SqlServer(MariaDB):++ return True++ +deactivate SqlServer(MariaDB) +AccountService<--SqlDAO:++return "User is already registered"++ +SystemAccountManager<--AccountService:++return "User is already registered"++ +Controller.cs<--SystemAccountManager:++return "User is already registered"++ +User<--Controller.cs:++ return \n"User is already registered"++ + +end +// User doesn't exist +group #green User does not exist #white +activate SqlServer(MariaDB) #00FFFF +SqlDAO<--SqlServer(MariaDB):++ return False++ +SqlDAO->SqlServer(MariaDB):++ SQL insert\nuser credentials++ +SqlDAO<--SqlServer(MariaDB):++ return 1++ +deactivate SqlServer(MariaDB) +AccountService<--SqlDAO:++return "User is now registered"++ +deactivate SqlDAO +SystemAccountManager<--AccountService:++return "User is now registered"++ +deactivate AccountService +Controller.cs<--SystemAccountManager:++return "User is now registered"++ +deactivate SystemAccountManager +User<--Controller.cs:++ return \n"User is now registered"++ + +deactivate Controller.cs +end +//deactivate User +end +end +end +end + +end \ No newline at end of file diff --git a/doc/LowLevel/UserManagement/UserManagementDeleteUser.png b/doc/LowLevel/UserManagement/UserManagementDeleteUser.png new file mode 100644 index 0000000..1af07b9 Binary files /dev/null and b/doc/LowLevel/UserManagement/UserManagementDeleteUser.png differ diff --git a/doc/LowLevel/UserManagement/UserManagementDeleteUser.txt b/doc/LowLevel/UserManagement/UserManagementDeleteUser.txt new file mode 100644 index 0000000..c3edf8f --- /dev/null +++ b/doc/LowLevel/UserManagement/UserManagementDeleteUser.txt @@ -0,0 +1,161 @@ +title Delete User Record +actor User +participant Controller.cs #90EE90 +participant RDSFactory #26abff +participant UserAccount #CBC3E3 +participant SystemAccountManager #ffffe0 +participant AccountService #ff8b3d +participant SqlDAO #D3D3D3 +//SqlDAO +database SqlServer(MariaDB) #00FFFF + +//activate User +activate Controller.cs #90EE90 +User->Controller.cs: ++Request to delete user++ + +//RelatDSFactory +Controller.cs->RDSFactory:++factory = new RDSFactory()++ +activate RDSFactory #26abff +RDSFactory->RDSFactory:++Constructor()++ +Controller.cs<--RDSFactory:++return RDSFactory++ +deactivate RDSFactory +Controller.cs->SqlDAO:++IDataSource factory.GetDataSource(string DbName, string connInfo)++ +activate SqlDAO #D3D3D3 +SqlDAO->SqlDAO:++Constructor(string connInfo)++ +group #red Data Store Timed Out #white +SqlDAO->SqlDAO: ++Catch SqlException++ +Controller.cs<--SqlDAO:++return "Data Source Timed Out"++ +end +group #blue Data Store Online #white +Controller.cs<--SqlDAO: ++return SqlDAO++ +deactivate SqlDAO + +// Create new Admin +Controller.cs->SystemAccountManager:++ manager = new SystemAccountManager(IDataSource conn)++ +activate SystemAccountManager #ffffe0 +SystemAccountManager->SystemAccountManager:++Constructor(IDataSource conn)++ +Controller.cs<--SystemAccountManager:++ New SystemAccountManager++ +deactivate SystemAccountManager + +// GetUserName +Controller.cs->Controller.cs:++string GetUserName()++ + +// GetPassword +Controller.cs->Controller.cs:++string GetPassword()++ + +// +Controller.cs->UserAccount:++ new UserAccount(string username,\n string password\n DateTime RegistrationTimeStamp)++ +activate UserAccount #CBC3E3 +UserAccount->UserAccount: ++Constructor(string username,\n string password,\n DateTime RegistrationTimeStamp)++ +Controller.cs<--UserAccount:++New UserAccount++ +deactivate UserAccount +Controller.cs->SystemAccountManager: ++manager.DeleteUserRecord(user:UserAccount)++ +activate SystemAccountManager #ffffe0 +SystemAccountManager->SystemAccountManager:++isInputValid(user: UserAccount)++ +group #red Invalid Information #white +Controller.cs<--SystemAccountManager:++return "Invalid input"++ +User<--Controller.cs:++ return "Invalid input"++ +end + +// +group #green Information Valid #white +//check if there is an admin user +SystemAccountManager->SqlDAO:++isAdmin(user:UserAccount)++ +activate SqlDAO #D3D3D3 +SqlDAO->SqlServer(MariaDB):++SqlRead confirmAdmin()++ +activate SqlServer(MariaDB)#00FFFF +SqlServer(MariaDB)->SqlServer(MariaDB):++Select * from Admins\n where Username = @UserName \nand Password = @Pwd++ +//Unauthorized role section +group #red Unauthorized User #white +SqlDAO<--SqlServer(MariaDB):++SqlException++ +SqlDAO->SqlDAO: ++Catch\nSqlException++ +SystemAccountManager<--SqlDAO:++return false++ +Controller.cs<--SystemAccountManager:++ return "Access Denied: \nUnauthorized"++ +User<--Controller.cs:++return "Access Denied: \nUnauthorized"++ +end +//Unauthorized role section +group #red Unauthorized User #white +SqlDAO<--SqlServer(MariaDB):++return false++ +SystemAccountManager<--SqlDAO:++return false++ +Controller.cs<--SystemAccountManager:++ return "Access Denied: \nUnauthorized"++ +User<--Controller.cs:++return "Access Denied: \nUnauthorized"++ +end + + +//Authorized role section +group #blue Authorized User #white +SqlDAO<--SqlServer(MariaDB):++return true++ +deactivate SqlServer(MariaDB) +SystemAccountManager<--SqlDAO:++return true++ +deactivate SqlDAO +deactivate SystemAccountManager +group #green Valid Information #white +activate SystemAccountManager #ffffe0 +// GetUserName +SystemAccountManager->SystemAccountManager:++string NewUserName()++ +// Enter UserName +User->SystemAccountManager:++string NewUserName++ +// GetPassword +SystemAccountManager->SystemAccountManager:++string NewPassword()++ +// Enter Password +User->SystemAccountManager:++string NewPassword++ +// GetRole +SystemAccountManager->SystemAccountManager:++string NewRole()++ +// Enter Role +User->SystemAccountManager:++string NewRole++ +// Create NewUser object +UserAccount<-SystemAccountManager:++new NewUser(\nstring NewUserName,\nstring NewPassword,\nstring role,\nDateTime TimeStamp)++ +activate UserAccount #CBC3E3 +UserAccount->UserAccount:++Constructor(\nstring NewUserName,\nstring NewPassword,\nstring role,\nDateTime TimeStamp)++ +UserAccount-->SystemAccountManager:++return NewUser++ +deactivate UserAccount +SystemAccountManager->AccountService:++AccountService\n.DeleteUserRecord(user:NewUser,\nUpdateType: userDelete)++ +activate AccountService #ff8b3d +AccountService->SqlDAO:++SqlDAO\n.DeleteUserRecord(user:NewUser,\nUpdateType: userDelete)++ +activate SqlDAO #D3D3D3 +SqlDAO->SqlServer(MariaDB):++isUser(user:NewUser)++ +activate SqlServer(MariaDB) #00FFFF +SqlServer(MariaDB)->SqlServer(MariaDB):++ Select *\nFrom Users\nwhere Username\n= @UserName OR\nemail = @Email++ +group #red data store timed out #white +SqlDAO<--SqlServer(MariaDB):++SqlException++ +deactivate SqlServer(MariaDB) +SqlDAO->SqlDAO: ++Catch\nSqlException++ +AccountService<--SqlDAO:++return "Database timed out"++ + +SystemAccountManager<--AccountService:++ return "Database timed out"++ +Controller.cs<--SystemAccountManager:++ return "Database timed out"++ +User<--Controller.cs:++ return "Database timed out"++ +end +group #blue data store is online #white +// User exists +group #green User does exist #white +activate SqlServer(MariaDB) #00FFFF +SqlDAO<--SqlServer(MariaDB):++ return True++ +SqlDAO->SqlServer(MariaDB):++Delete from users\nwhere Username = @UserName \nand Password = @PWD++ +SqlDAO<--SqlServer(MariaDB):++ return 1++ +AccountService<--SqlDAO:++return "User deleted successfully"++ +SystemAccountManager<--AccountService:++return "User deleted successfully"++ +Controller.cs<--SystemAccountManager:++return "User deleted successfully"++ +User<--Controller.cs:++ return \n"User deleted successfully"++ +deactivate SqlServer(MariaDB) +end +// User doesn't exist +group #red User does not exist #white +activate SqlServer(MariaDB) #00FFFF +SqlDAO<--SqlServer(MariaDB):++ return False++ +AccountService<--SqlDAO:++return "User does not exist"++ +SystemAccountManager<--AccountService:++return "User does not exist"++ +Controller.cs<--SystemAccountManager:++return "User does not exist"++ +User<--Controller.cs:++ return \n"User does not exist"++ +deactivate AccountService +deactivate SqlDAO +deactivate SqlServer(MariaDB) +deactivate SystemAccountManager +deactivate Controller.cs +end +//deactivate User +end +end +end +end +end \ No newline at end of file diff --git a/doc/LowLevel/UserManagement/UserManagementDisableUser.png b/doc/LowLevel/UserManagement/UserManagementDisableUser.png new file mode 100644 index 0000000..252cc76 Binary files /dev/null and b/doc/LowLevel/UserManagement/UserManagementDisableUser.png differ diff --git a/doc/LowLevel/UserManagement/UserManagementDisableUser.txt b/doc/LowLevel/UserManagement/UserManagementDisableUser.txt new file mode 100644 index 0000000..45c777d --- /dev/null +++ b/doc/LowLevel/UserManagement/UserManagementDisableUser.txt @@ -0,0 +1,160 @@ +title Disable Specfied User +actor User +participant Controller.cs #90EE90 +participant RDSFactory #26abff +participant UserAccount #CBC3E3 +participant SystemAccountManager #ffffe0 +participant AccountService #ff8b3d +participant SqlDAO #D3D3D3 +//SqlDAO +database SqlServer(MariaDB) #00FFFF + +//activate User +activate Controller.cs #90EE90 +User->Controller.cs: ++Request to disable user\n by a different user++ + +//RelatDSFactory +Controller.cs->RDSFactory:++factory = new RDSFactory()++ +activate RDSFactory #26abff +RDSFactory->RDSFactory:++Constructor()++ +Controller.cs<--RDSFactory:++return RDSFactory++ +deactivate RDSFactory +Controller.cs->SqlDAO:++IDataSource factory.GetDataSource(string DbName, string connInfo)++ +activate SqlDAO #D3D3D3 +SqlDAO->SqlDAO:++Constructor(string connInfo)++ +group #red Data Store Timed Out #white +SqlDAO->SqlDAO: ++Catch SqlException++ +Controller.cs<--SqlDAO:++return "Data Source Timed Out"++ +end +group #blue Data Store Online #white +Controller.cs<--SqlDAO: ++return SqlDAO++ +deactivate SqlDAO + +// Create new Admin +Controller.cs->SystemAccountManager:++ manager = new SystemAccountManager(IDataSource conn)++ +activate SystemAccountManager #ffffe0 +SystemAccountManager->SystemAccountManager:++Constructor(IDataSource conn)++ +Controller.cs<--SystemAccountManager:++ New SystemAccountManager++ +deactivate SystemAccountManager + +// GetUserName +Controller.cs->Controller.cs:++string GetUserName()++ + +// GetPassword +Controller.cs->Controller.cs:++string GetPassword()++ + +// Pass object +Controller.cs->UserAccount:++ new UserAccount(string username,\n string password\n DateTime RegistrationTimeStamp)++ +activate UserAccount #CBC3E3 +UserAccount->UserAccount: ++Constructor(string username,\n string password,\n DateTime RegistrationTimeStamp)++ +Controller.cs<--UserAccount:++New UserAccount++ +deactivate UserAccount +Controller.cs->SystemAccountManager: ++manager.DisableUserRecord(user:UserAccount)++ +activate SystemAccountManager #ffffe0 +SystemAccountManager->SystemAccountManager:++isInputValid(user: UserAccount)++ +group #red Invalid Information #white +Controller.cs<--SystemAccountManager:++return "Invalid input"++ +User<--Controller.cs:++ return "Invalid input"++ +end +group #green Information Valid #white + +// + +//check if there is an admin user + +SystemAccountManager->SqlDAO:++isAdmin(user:UserAccount)++ +activate SqlDAO #D3D3D3 +SqlDAO->SqlServer(MariaDB):++SqlRead confirmAdmin()++ +activate SqlServer(MariaDB)#00FFFF +SqlServer(MariaDB)->SqlServer(MariaDB):++Select * from Admins\n where Username = @UserName \nand Password = @Pwd++ +//Unauthorized role section +group #red Unauthorized User #white +SqlDAO<--SqlServer(MariaDB):++SqlException++ +SqlDAO->SqlDAO: ++Catch\nSqlException++ +SystemAccountManager<--SqlDAO:++return false++ +Controller.cs<--SystemAccountManager:++ return "Access Denied: \nUnauthorized"++ +User<--Controller.cs:++return "Access Denied: \nUnauthorized"++ +//Unauthorized role section +end +group #red Unauthorized User #white +SqlDAO<--SqlServer(MariaDB):++return false++ +SystemAccountManager<--SqlDAO:++return false++ +Controller.cs<--SystemAccountManager:++ return "Access Denied: \nUnauthorized"++ +User<--Controller.cs:++return "Access Denied: \nUnauthorized"++ +end + + +//Authorized role section +group #blue Authorized User #white +SqlDAO<--SqlServer(MariaDB):++return true++ +deactivate SqlServer(MariaDB) +SystemAccountManager<--SqlDAO:++return true++ +deactivate SqlDAO +deactivate SystemAccountManager + +group #green Valid Information #white +activate SystemAccountManager #ffffe0 +// GetUserName +SystemAccountManager->SystemAccountManager:++string NewUserName()++ +// Enter UserName +User->SystemAccountManager:++string NewUserName++ +// GetRole +SystemAccountManager->SystemAccountManager:++string NewRole()++ +// Enter Role +User->SystemAccountManager:++string NewRole++ +// Create NewUser object +UserAccount<-SystemAccountManager:++new NewUser(\nstring NewUserName,\nstring role,\nDateTime TimeStamp)++ +activate UserAccount #CBC3E3 +UserAccount->UserAccount:++Constructor(\nstring NewUserName,\nstring role,\nDateTime TimeStamp)++ +UserAccount-->SystemAccountManager:++return NewUser++ +deactivate UserAccount +SystemAccountManager->AccountService:++AccountService\n.DisableUserRecord(user:NewUser,\nUpdateType:userDisable)++ +activate AccountService #ff8b3d +AccountService->SqlDAO:++SqlDAO\n.DisableUser(user:NewUser,\nUpdateType:userDisable)++ +activate SqlDAO #D3D3D3 +SqlDAO->SqlServer(MariaDB):++isUser(user:NewUser)++ +activate SqlServer(MariaDB) #00FFFF +SqlServer(MariaDB)->SqlServer(MariaDB):++ Select *\nFrom Users\nwhere Username\n= @UserName and\nRole = @UserRole\n +group #red data store timed out #white +SqlDAO<--SqlServer(MariaDB):++SqlException++ +deactivate SqlServer(MariaDB) +SqlDAO->SqlDAO: ++Catch\nSqlException++ +AccountService<--SqlDAO:++return "Database timed out"++ + +SystemAccountManager<--AccountService:++ return "Database timed out"++ +Controller.cs<--SystemAccountManager:++ return "Database timed out"++ +User<--Controller.cs:++ return "Database timed out"++ +end +group #blue data store is online #white +// User exists +group #green User does exist #white +activate SqlServer(MariaDB) #00FFFF +SqlDAO<--SqlServer(MariaDB):++ return True++ +SqlDAO->SqlServer(MariaDB):++Update users Set isActive = 0\nwhere UserName = @UserName++ +SqlDAO<--SqlServer(MariaDB):++ return 1++ +deactivate SqlServer(MariaDB) +AccountService<--SqlDAO:++return "User is now disabled"++ +SystemAccountManager<--AccountService:++return "User is now disabled"++ +Controller.cs<--SystemAccountManager:++return "User is now disabled"++ +User<--Controller.cs:++ return \n"User is now disabled"++ +end +// User doesn't exist +group #red User does not exist #white +activate SqlServer(MariaDB) #00FFFF +SqlDAO<--SqlServer(MariaDB):++ return False++ +deactivate SqlServer(MariaDB) +AccountService<--SqlDAO:++return "User does not exist"++ +deactivate SqlDAO +SystemAccountManager<--AccountService:++return "User does not exist"++ +deactivate AccountService +Controller.cs<--SystemAccountManager:++return "User does not exist"++ +deactivate SystemAccountManager +User<--Controller.cs:++ return \n"User does not exist"++ +deactivate Controller.cs +end +//deactivate User +end +end +end +end +end \ No newline at end of file diff --git a/doc/LowLevel/UserManagement/UserManagementEditUserRecords.png b/doc/LowLevel/UserManagement/UserManagementEditUserRecords.png new file mode 100644 index 0000000..0332df7 Binary files /dev/null and b/doc/LowLevel/UserManagement/UserManagementEditUserRecords.png differ diff --git a/doc/LowLevel/UserManagement/UserManagementEditUserRecords.txt b/doc/LowLevel/UserManagement/UserManagementEditUserRecords.txt new file mode 100644 index 0000000..2e830ed --- /dev/null +++ b/doc/LowLevel/UserManagement/UserManagementEditUserRecords.txt @@ -0,0 +1,170 @@ +title Edit User Record +actor User +participant Controller.cs #90EE90 +participant RDSFactory #26abff +participant UserAccount #CBC3E3 +participant SystemAccountManager #ffffe0 +participant AccountService #ff8b3d +participant SqlDAO #D3D3D3 +//SqlDAO +database SqlServer(MariaDB) #00FFFF + +//activate User +activate Controller.cs #90EE90 +User->Controller.cs: ++Request to edit user\nby a different user++ + +//RelatDSFactory +Controller.cs->RDSFactory:++factory = new RDSFactory()++ +activate RDSFactory #26abff +RDSFactory->RDSFactory:++Constructor()++ +Controller.cs<--RDSFactory:++return RDSFactory++ +deactivate RDSFactory +Controller.cs->SqlDAO:++IDataSource factory.GetDataSource(string DbName, string connInfo)++ +activate SqlDAO #D3D3D3 +SqlDAO->SqlDAO:++Constructor(string connInfo)++ +group #red Data Store Timed Out #white +SqlDAO->SqlDAO: ++Catch Exception++ +Controller.cs<--SqlDAO:++return "Data Source Timed Out"++ +end +group #blue Data Store Online #white +Controller.cs<--SqlDAO: ++return SqlDAO++ +deactivate SqlDAO + +// Create new Admin +Controller.cs->SystemAccountManager:++ manager = new SystemAccountManager(IDataSource conn)++ +activate SystemAccountManager #ffffe0 +SystemAccountManager->SystemAccountManager:++Constructor(IDataSource conn)++ +Controller.cs<--SystemAccountManager:++ New SystemAccountManager++ +deactivate SystemAccountManager + +// GetUserName +Controller.cs->Controller.cs:++string GetUserName()++ + +// GetPassword +Controller.cs->Controller.cs:++string GetPassword()++ + +// + +Controller.cs->UserAccount:++ new UserAccount(string username,\n string password,\n DateTime RegistrationTimeStamp)++ +activate UserAccount #CBC3E3 +UserAccount->UserAccount: ++string username,\n string password,\n DateTime RegistrationTimeStamp++ +Controller.cs<--UserAccount:++New UserAccount++ +deactivate UserAccount +Controller.cs->SystemAccountManager:++manager.UpdateUserRecord(user:UserAccount)++ +activate SystemAccountManager #ffffe0 +SystemAccountManager->SystemAccountManager:++isInputValid(user: UserAccount)++ +group #red Invalid Information #white +Controller.cs<--SystemAccountManager:++return "Invalid input"++ +User<--Controller.cs:++ return "Invalid input"++ +end +group #green Information Valid #white + +//look over + +//check if there is an admin user +SystemAccountManager->SqlDAO:++bool isAdmin(user:UserAccount)++ +activate SqlDAO #D3D3D3 +SqlDAO->SqlServer(MariaDB):++SqlRead confirmAdmin()++ +activate SqlServer(MariaDB)#00FFFF +//authorized +SqlServer(MariaDB)->SqlServer(MariaDB):++Select * from Admins\n where Username = @UserName \nand Password = @Pwd++ +//Unauthorized role section +group #red Unauthorized User #white +SqlDAO<--SqlServer(MariaDB):++SqlException++ +SqlDAO->SqlDAO: ++Catch\nSqlException++ +SystemAccountManager<--SqlDAO:++return false++ +Controller.cs<--SystemAccountManager:++ return "Access Denied: \nUnauthorized"++ +User<--Controller.cs:++return "Access Denied: \nUnauthorized"++ +end +//Unauthorized role section +group #red Unauthorized User #white +SqlDAO<--SqlServer(MariaDB):++return false++ +SystemAccountManager<--SqlDAO:++return false++ +Controller.cs<--SystemAccountManager:++ return "Access Denied: \nUnauthorized"++ +User<--Controller.cs:++return "Access Denied: \nUnauthorized"++ +end + + +//Authorized role section +group #blue Authorized User #white +SqlDAO<--SqlServer(MariaDB):++return true++ +deactivate SqlServer(MariaDB) +SystemAccountManager<--SqlDAO:++return true++ +deactivate SqlDAO +deactivate SystemAccountManager +group #green Valid Information #white +activate SystemAccountManager #ffffe0 +// GetUserName +SystemAccountManager->SystemAccountManager:++string NewUserName()++ +// Enter UserName +User->SystemAccountManager:++string NewUserName++ +// GetPassword +SystemAccountManager->SystemAccountManager:++string NewPassword()++ +// Enter Password +User->SystemAccountManager:++string NewPassword++ +// GetEmail +SystemAccountManager->SystemAccountManager:++string NewEmail()++ +// Enter Email +User->SystemAccountManager:++string NewEmail++ +// GetRole +SystemAccountManager->SystemAccountManager:++string NewRole()++ +// Enter Role +User->SystemAccountManager:++string NewRole++ +// Create NewUser object +UserAccount<-SystemAccountManager:++new NewUser(\nstring NewUserName,\nstring NewPassword,\nstring New Email,\nstring NewRole\nDateTime TimeStamp)++ +activate UserAccount #CBC3E3 +UserAccount->UserAccount:++Constructor(\nstring NewUserName,\nstring NewPassword,\nstring New Email,\nstring NewRole\nDateTime TimeStamp)++ +UserAccount-->SystemAccountManager:++return NewUser++ +deactivate UserAccount +SystemAccountManager->AccountService:++AccountService\n.UpdateUserRecord(user:NewUser,\nUpdateType: userUpdate)++ +activate AccountService #ff8b3d +AccountService->SqlDAO:++SqlDAO\n.UpdateUserRecord(user:NewUser,\nUpdateType: userUpdate)++ +activate SqlDAO #D3D3D3 +SqlDAO->SqlServer(MariaDB):++isUser(user:NewUser)++ +activate SqlServer(MariaDB) #00FFFF +SqlServer(MariaDB)->SqlServer(MariaDB):++Update *\nFrom Users\nwhere Username\n= @UserName OR\nemail = @Email++ +group #red data store timed out #white +SqlDAO<--SqlServer(MariaDB):++SqlException++ +deactivate SqlServer(MariaDB) +SqlDAO->SqlDAO: ++Catch\nSqlException++ +AccountService<--SqlDAO:++return "Database timed out"++ + +SystemAccountManager<--AccountService:++ return "Database timed out"++ +Controller.cs<--SystemAccountManager:++ return "Database timed out"++ +User<--Controller.cs:++ return "Database timed out"++ +end +group #blue data store is online #white +// User exists +group #green User does exist #white +activate SqlServer(MariaDB) #00FFFF +SqlDAO<--SqlServer(MariaDB):++ return True++ +SqlDAO->SqlServer(MariaDB):++ SQL insert\nupdate credentials++ +SqlDAO<--SqlServer(MariaDB):++ return 1++ +AccountService<--SqlDAO:++return "User information updated successfully"++ +SystemAccountManager<--AccountService:++return "User information updated successfully"++ +Controller.cs<--SystemAccountManager:++return "User information updated successfully"++ +User<--Controller.cs:++ return "User information\n updated successfully"++ +deactivate SqlServer(MariaDB) +end +// User doesn't exist +group #green User does not exist #white +activate SqlServer(MariaDB) #00FFFF +SqlDAO<--SqlServer(MariaDB):++ return False++ +SqlDAO->SqlServer(MariaDB):++ SQL insert\nuser credentials++ +SqlDAO<--SqlServer(MariaDB):++ return 1++ +AccountService<--SqlDAO:++return "User is now registered"++ +SystemAccountManager<--AccountService:++return "User is now registered"++ +Controller.cs<--SystemAccountManager:++return "User is now registered"++ +User<--Controller.cs:++ return \n"User is now registered"++ +deactivate AccountService +deactivate SqlDAO +deactivate SqlServer(MariaDB) +deactivate SystemAccountManager +deactivate Controller.cs +end +//deactivate User +end +end +end +end +end \ No newline at end of file diff --git a/doc/LowLevel/UserManagement/UserManagementEnableUser.png b/doc/LowLevel/UserManagement/UserManagementEnableUser.png new file mode 100644 index 0000000..5b158db Binary files /dev/null and b/doc/LowLevel/UserManagement/UserManagementEnableUser.png differ diff --git a/doc/LowLevel/UserManagement/UserManagementEnableUser.txt b/doc/LowLevel/UserManagement/UserManagementEnableUser.txt new file mode 100644 index 0000000..0258e15 --- /dev/null +++ b/doc/LowLevel/UserManagement/UserManagementEnableUser.txt @@ -0,0 +1,158 @@ +title Disable Specfied User +actor User +participant Controller.cs #90EE90 +participant RDSFactory #26abff +participant UserAccount #CBC3E3 +participant SystemAccountManager #ffffe0 +participant AccountService #ff8b3d +participant SqlDAO #D3D3D3 +//SqlDAO +database SqlServer(MariaDB) #00FFFF + +//activate User +activate Controller.cs #90EE90 +User->Controller.cs: ++Request to enable user\n by a different user++ + +//RelatDSFactory +Controller.cs->RDSFactory:++factory = new RDSFactory()++ +activate RDSFactory #26abff +RDSFactory->RDSFactory:++Constructor()++ +Controller.cs<--RDSFactory:++return RDSFactory++ +deactivate RDSFactory +Controller.cs->SqlDAO:++IDataSource factory.GetDataSource(string DbName, string connInfo)++ +activate SqlDAO #D3D3D3 +SqlDAO->SqlDAO:++Constructor(string connInfo)++ +group #red Data Store Timed Out #white +SqlDAO->SqlDAO: ++Catch SqlException++ +Controller.cs<--SqlDAO:++return "Data Source Timed Out"++ +end +group #blue Data Store Online #white +Controller.cs<--SqlDAO: ++return SqlDAO++ +deactivate SqlDAO +// Create new Admin +Controller.cs->SystemAccountManager:++ manager = new SystemAccountManager(IDataSource conn)++ +activate SystemAccountManager #ffffe0 +SystemAccountManager->SystemAccountManager:++Constructor(IDataSource conn)++ +Controller.cs<--SystemAccountManager:++ New SystemAccountManager++ +deactivate SystemAccountManager + +// GetUserName +Controller.cs->Controller.cs:++string GetUserName()++ + +// GetPassword +Controller.cs->Controller.cs:++string GetPassword()++ + +// Pass object +Controller.cs->UserAccount:++ new UserAccount(string username,\n string password\n DateTime RegistrationTimeStamp)++ +activate UserAccount #CBC3E3 +UserAccount->UserAccount: ++Constructor(string username,\n string password,\n DateTime RegistrationTimeStamp)++ +Controller.cs<--UserAccount:++New UserAccount++ +deactivate UserAccount +Controller.cs->SystemAccountManager:++manager.EnableUserRecord(user:UserAccount)++ +activate SystemAccountManager #ffffe0 +SystemAccountManager->SystemAccountManager:++isInputValid(user: UserAccount)++ +group #red Invalid Information #white +Controller.cs<--SystemAccountManager:++return "Invalid input"++ +User<--Controller.cs:++ return "Invalid input"++ +end + +// + +group #green Information Valid #white +//check if there is an admin user +SystemAccountManager->SqlDAO:++isAdmin(user:UserAccount)++ +activate SqlDAO #D3D3D3 +SqlDAO->SqlServer(MariaDB):++SqlRead confirmAdmin()++ +activate SqlServer(MariaDB)#00FFFF +SqlServer(MariaDB)->SqlServer(MariaDB):++Select * from Admins\n where Username = @UserName \nand Password = @Pwd++ +//Unauthorized role section +group #red Unauthorized User #white +SqlDAO<--SqlServer(MariaDB):++SqlException++ +SqlDAO->SqlDAO: ++Catch\nSqlException++ +SystemAccountManager<--SqlDAO:++return false++ +Controller.cs<--SystemAccountManager:++ return "Access Denied: \nUnauthorized"++ +User<--Controller.cs:++return "Access Denied: \nUnauthorized"++ +//Unauthorized role section +end +group #red Unauthorized User #white +SqlDAO<--SqlServer(MariaDB):++return false++ +SystemAccountManager<--SqlDAO:++return false++ +Controller.cs<--SystemAccountManager:++ return "Access Denied: \nUnauthorized"++ +User<--Controller.cs:++return "Access Denied: \nUnauthorized"++ +end + + +//Authorized role section +group #blue Authorized User #white +SqlDAO<--SqlServer(MariaDB):++return true++ +deactivate SqlServer(MariaDB) +SystemAccountManager<--SqlDAO:++return true++ +deactivate SqlDAO +deactivate SystemAccountManager + +group #green Valid Information #white +activate SystemAccountManager #ffffe0 +// GetUserName +SystemAccountManager->SystemAccountManager:++string NewUserName()++ +// Enter UserName +User->SystemAccountManager:++string NewUserName++ +// GetRole +SystemAccountManager->SystemAccountManager:++string NewRole()++ +// Enter Role +User->SystemAccountManager:++string NewRole++ +// Create NewUser object +UserAccount<-SystemAccountManager:++new NewUser(\nstring NewUserName,\nstring role,\nDateTime TimeStamp)++ +activate UserAccount #CBC3E3 +UserAccount->UserAccount:++Constructor(\nstring NewUserName,\nstring role,\nDateTime TimeStamp)++ +UserAccount-->SystemAccountManager:++return NewUser++ +deactivate UserAccount +SystemAccountManager->AccountService:++AccountService\n.EnableUserRecord(user:NewUser,\nUpdateType:userEnable)++ +activate AccountService #ff8b3d +AccountService->SqlDAO:++SqlDAO\n.EnableUser(user:NewUser,\nUpdateType:userEnable)++ +activate SqlDAO #D3D3D3 +SqlDAO->SqlServer(MariaDB):++isUser(user:NewUser)++ +activate SqlServer(MariaDB) #00FFFF +SqlServer(MariaDB)->SqlServer(MariaDB):++ Select *\nFrom Users\nwhere Username\n= @UserName and\nRole = @UserRole +group #red data store timed out #white +SqlDAO<--SqlServer(MariaDB):++SqlException++ +deactivate SqlServer(MariaDB) +SqlDAO->SqlDAO: ++Catch\nSqlException++ +AccountService<--SqlDAO:++return "Database timed out"++ + +SystemAccountManager<--AccountService:++ return "Database timed out"++ +Controller.cs<--SystemAccountManager:++ return "Database timed out"++ +User<--Controller.cs:++ return "Database timed out"++ +end +group #blue data store is online #white +// User exists +group #green User does exist #white +activate SqlServer(MariaDB) #00FFFF +SqlDAO<--SqlServer(MariaDB):++ return True++ +SqlDAO->SqlServer(MariaDB):++Update users Set isActive = 1\nwhere UserName = @UserName++ +SqlDAO<--SqlServer(MariaDB):++ return 1++ +deactivate SqlServer(MariaDB) +AccountService<--SqlDAO:++return "User is now enabled"++ +SystemAccountManager<--AccountService:++return "User is now enabled"++ +Controller.cs<--SystemAccountManager:++return "User is now enabled"++ +User<--Controller.cs:++ return \n"User is now enabled"++ +end +// User doesn't exist +group #red User does not exist #white +activate SqlServer(MariaDB) #00FFFF +SqlDAO<--SqlServer(MariaDB):++ return False++ +deactivate SqlServer(MariaDB) +AccountService<--SqlDAO:++return "User does not exist"++ +deactivate SqlDAO +SystemAccountManager<--AccountService:++return "User does not exist"++ +deactivate AccountService +Controller.cs<--SystemAccountManager:++return "User does not exist"++ +deactivate SystemAccountManager +User<--Controller.cs:++ return \n"User does not exist"++ +deactivate Controller.cs +end +//deactivate User +end +end +end +end +end \ No newline at end of file diff --git a/doc/LowLevel/archivingMasterCon.pdf b/doc/LowLevel/archivingMasterCon.pdf new file mode 100644 index 0000000..7773c3d Binary files /dev/null and b/doc/LowLevel/archivingMasterCon.pdf differ 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 diff --git a/doc/LowLevel/arcvhingMasterCon.pdf b/doc/LowLevel/arcvhingMasterCon.pdf new file mode 100644 index 0000000..b5e4564 Binary files /dev/null and b/doc/LowLevel/arcvhingMasterCon.pdf differ diff --git a/src/dbCode/ExportingRows.txt b/src/dbCode/ExportingRows.txt new file mode 100644 index 0000000..f7b2027 --- /dev/null +++ b/src/dbCode/ExportingRows.txt @@ -0,0 +1,64 @@ + +select * from log; + +-- Find logs that are older than 30 days of current time. +SELECT * FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30; + +-- Output logs to a file +SELECT * FROM log +WHERE + DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30 +INTO OUTFILE 'C:/Temp/oldlogs.csv' +FIELDS ENCLOSED BY '"' +TERMINATED BY ';' +ESCAPED BY '"' +LINES TERMINATED BY '\r\n'; + +-- Output into comma separated file +SELECT * INTO OUTFILE 'C:/Temp/oldlogs2.csv' +FIELDS ENCLOSED BY '"' +TERMINATED BY ',' +ESCAPED BY '"' +LINES TERMINATED BY '\r\n' +FROM log +WHERE + DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30; + +-- Output into comma separated file +SELECT * +INTO OUTFILE 'C:/Temp/oldlogs4.csv' + FIELDS ENCLOSED BY '' + TERMINATED BY ',' + ESCAPED BY '"' + LINES TERMINATED BY '\r\n' +FROM log +WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30; + +-- Find the name of each columns +SELECT `COLUMN_NAME` +FROM `information_schema`.`COLUMNS` +WHERE `TABLE_SCHEMA` = 'hobby' AND `TABLE_NAME` = 'log'; + +-- Add the column names to the heading of the file +SELECT 'LtimeStamp', 'logID', 'LvName', 'catName', 'userOP', 'logMessage' +UNION ALL +SELECT * FROM log +WHERE + DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30 +INTO OUTFILE 'C:/Temp/oldlogs5.csv' +FIELDS ENCLOSED BY '' +TERMINATED BY ',' +ESCAPED BY '"' +LINES TERMINATED BY '\r\n'; + +-- Remove old logs from the log table +DELETE from log where DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30; + +show columns from log; + +SELECT COLUMN_NAME FROM information_schema.COLUMNS; + + +-- Remove logs from the table + +SELECT DATEDIFF('2021-08-07 23:00:00', current_timestamp); \ No newline at end of file