Compare commits
1 Commits
master
...
Danny's_br
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
03fbd9972c |
4
.gitignore
vendored
4
.gitignore
vendored
@ -425,7 +425,3 @@ healthchecksdb
|
|||||||
.vscode/tasks.json
|
.vscode/tasks.json
|
||||||
Source Code/.vscode/tasks.json
|
Source Code/.vscode/tasks.json
|
||||||
Source Code/.vscode/launch.json
|
Source Code/.vscode/launch.json
|
||||||
Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.Archiving.xTests/bin/Debug/net6.0/CoverletSourceRootsMapping
|
|
||||||
Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.UserManagement.xTests/bin/Debug/net6.0/CoverletSourceRootsMapping
|
|
||||||
Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.Archiving.xTests/bin/Debug/net6.0/CoverletSourceRootsMapping
|
|
||||||
Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.UserManagement.xTests/bin/Debug/net6.0/CoverletSourceRootsMapping
|
|
||||||
|
|||||||
26
Source Code/.vscode/launch.json
vendored
Normal file
26
Source Code/.vscode/launch.json
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
// Use IntelliSense to find out which attributes exist for C# debugging
|
||||||
|
// Use hover for the description of the existing attributes
|
||||||
|
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
|
||||||
|
"name": ".NET Core Launch (console)",
|
||||||
|
"type": "coreclr",
|
||||||
|
"request": "launch",
|
||||||
|
"preLaunchTask": "build",
|
||||||
|
// If you have changed target frameworks, make sure to update the program path.
|
||||||
|
"program": "${workspaceFolder}/main/bin/Debug/net6.0/main.dll",
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}/main",
|
||||||
|
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
|
||||||
|
"console": "internalConsole",
|
||||||
|
"stopAtEntry": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": ".NET Core Attach",
|
||||||
|
"type": "coreclr",
|
||||||
|
"request": "attach"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
42
Source Code/.vscode/tasks.json
vendored
Normal file
42
Source Code/.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
{
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "build",
|
||||||
|
"command": "dotnet",
|
||||||
|
"type": "process",
|
||||||
|
"args": [
|
||||||
|
"build",
|
||||||
|
"${workspaceFolder}/main/main.csproj",
|
||||||
|
"/property:GenerateFullPaths=true",
|
||||||
|
"/consoleloggerparameters:NoSummary"
|
||||||
|
],
|
||||||
|
"problemMatcher": "$msCompile"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "publish",
|
||||||
|
"command": "dotnet",
|
||||||
|
"type": "process",
|
||||||
|
"args": [
|
||||||
|
"publish",
|
||||||
|
"${workspaceFolder}/main/main.csproj",
|
||||||
|
"/property:GenerateFullPaths=true",
|
||||||
|
"/consoleloggerparameters:NoSummary"
|
||||||
|
],
|
||||||
|
"problemMatcher": "$msCompile"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "watch",
|
||||||
|
"command": "dotnet",
|
||||||
|
"type": "process",
|
||||||
|
"args": [
|
||||||
|
"watch",
|
||||||
|
"run",
|
||||||
|
"${workspaceFolder}/main/main.csproj",
|
||||||
|
"/property:GenerateFullPaths=true",
|
||||||
|
"/consoleloggerparameters:NoSummary"
|
||||||
|
],
|
||||||
|
"problemMatcher": "$msCompile"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -1,41 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TeamHobby.HobbyProjectGenerator.DataAccess;
|
|
||||||
using TeamHobby.HobbyProjectGenerator.UserManagement;
|
|
||||||
|
|
||||||
namespace main
|
|
||||||
{
|
|
||||||
internal class FileExtract
|
|
||||||
{
|
|
||||||
public static void Main(string[] args)
|
|
||||||
{
|
|
||||||
string[] lines = { "First line", "Second line", "Third line" };
|
|
||||||
using StreamWriter file = new ("BulkRequest.txt");
|
|
||||||
|
|
||||||
var serviceTest = new AccountService();
|
|
||||||
string dbType = "sql";
|
|
||||||
RDSFactory dbFactory = new RDSFactory();
|
|
||||||
|
|
||||||
|
|
||||||
// Testing Data Access Layer
|
|
||||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
|
||||||
"TCPIP=1;" +
|
|
||||||
"SERVER=localhost;" +
|
|
||||||
"DATABASE=hobby;" +
|
|
||||||
"UID=root;" +
|
|
||||||
"PASSWORD=hobby;" +
|
|
||||||
"OPTION=3";
|
|
||||||
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
|
|
||||||
|
|
||||||
// Create a file
|
|
||||||
for (int i = 0; i < 10000; i++)
|
|
||||||
{
|
|
||||||
var TestAcc = new UserAccount("newUser" + $"{i}", "4567", $"email{i}@a.com", "regular", DateTime.Now);
|
|
||||||
file.Write(serviceTest.CreateUserRecord(TestAcc, "Rifat", datasource));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
using TeamHobby.HobbyProjectGenerator.DataAccessLayer;
|
using TeamHobby.HobbyProjectGenerator.DataAccess;
|
||||||
|
|
||||||
namespace TeamHobby.HobbyProjectGenerator.ServiceLayer
|
namespace TeamHobby.HobbyProjectGenerator.Archive
|
||||||
{
|
{
|
||||||
public class ArchiveManager
|
public class ArchiveManager
|
||||||
{
|
{
|
||||||
@ -72,6 +72,29 @@ namespace TeamHobby.HobbyProjectGenerator.ServiceLayer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Method overload to take in a specific path
|
||||||
|
public string CreateOutFileName(string archivePath)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//string path = archivePath + "\\HobbyArchive";
|
||||||
|
Console.WriteLine("The current directory is {0}", archivePath);
|
||||||
|
//string date = DateTime.Now.ToString("M_d_yyyy_H:mm:ss");
|
||||||
|
string date = DateTime.Now.ToString("M_d_yyyy");
|
||||||
|
string fileName = date + "_archive.csv";
|
||||||
|
string filePath = Path.Combine(archivePath, fileName);
|
||||||
|
|
||||||
|
Console.WriteLine("Date: {0}", date);
|
||||||
|
Console.WriteLine("Filepath: {0}", filePath);
|
||||||
|
return filePath;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
Console.WriteLine("ArchiveCon: Creating a file name failed. ");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// put everything toget here
|
// put everything toget here
|
||||||
public bool Controller(){
|
public bool Controller(){
|
||||||
|
|
||||||
@ -4,7 +4,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace TeamHobby.HobbyProjectGenerator.ServiceLayer
|
namespace TeamHobby.HobbyProjectGenerator.Archive
|
||||||
{
|
{
|
||||||
public interface IRelationArchivable
|
public interface IRelationArchivable
|
||||||
{
|
{
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<Platforms>AnyCPU;x86</Platforms>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Data.SqlClient" Version="4.0.0" />
|
||||||
|
<PackageReference Include="MySql.Data" Version="8.0.27" />
|
||||||
|
<PackageReference Include="System.Data.Odbc" Version="6.0.0" />
|
||||||
|
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Implementations\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.DataAccess\TeamHobby.HobbyProjectGenerator.DataAccess.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Data.SqlClient" Version="4.0.0" />
|
||||||
|
<PackageReference Include="MySql.Data" Version="8.0.27" />
|
||||||
|
<PackageReference Include="System.Data.Odbc" Version="6.0.0" />
|
||||||
|
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Implementations\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.DataAccess\TeamHobby.HobbyProjectGenerator.DataAccess.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@ -0,0 +1,344 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data.Odbc;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using TeamHobby.HobbyProjectGenerator.Archive;
|
||||||
|
using TeamHobby.HobbyProjectGenerator.DataAccess;
|
||||||
|
|
||||||
|
namespace TeamHobby.HobbyProjectGenerator.ArchiveTests
|
||||||
|
{
|
||||||
|
public class ArchivingTests
|
||||||
|
{
|
||||||
|
//private string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
||||||
|
// "SERVER=localhost;" +
|
||||||
|
// "DATABASE=hobby;" +
|
||||||
|
// "UID=root;" +
|
||||||
|
// "PASSWORD=Teamhobby;" +
|
||||||
|
// "OPTION=3";
|
||||||
|
|
||||||
|
|
||||||
|
// [TestMethod]
|
||||||
|
public void IsArchiveFolderCreated(IDataSource<string> sqlDAO)
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
//SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||||
|
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||||
|
string folderPath = @"C:/HobbyArchive";
|
||||||
|
bool expectedVal = true;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
archiveManager.CreateArchiveFolder();
|
||||||
|
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
bool actualVal = Directory.Exists(folderPath);
|
||||||
|
if (expectedVal == actualVal)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Expected: {0}, Actual: {1}. Folder created correctly", expectedVal, actualVal);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Directory.Delete(folderPath, true);
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Console.WriteLine("Folder failed to be deleted");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("Expected: {0}, Actual: {1}. Folder created incorrectly", expectedVal, actualVal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// [TestMethod]
|
||||||
|
public void IsFileNameCreated(IDataSource<string> sqlDAO)
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
string foldPath = @"C:\HobbyArchive";
|
||||||
|
string fileName = DateTime.Now.ToString("M_d_yyyy") + "_archive.csv";
|
||||||
|
string expectedFilePath = System.IO.Path.Combine(foldPath, fileName);
|
||||||
|
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
string actualFilePath = archiveManager.CreateOutFileName();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
bool result = String.Equals(actualFilePath, expectedFilePath);
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Expected: {0}, Actual: {1}. File name created correctly", expectedFilePath, actualFilePath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("Expected: {0}, Actual: {1}. File name created incorrectly", expectedFilePath, actualFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// [Test Method]
|
||||||
|
public void IsCSVFileExist(IDataSource<string> sqlDAO)
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||||
|
SqlDAO sqlDS = null;
|
||||||
|
string folderPath = @"C:/HobbyArchive";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bool folderRes = archiveManager.CreateArchiveFolder();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Folder creation for copying failed");
|
||||||
|
}
|
||||||
|
string filePath = archiveManager.CreateOutFileName();
|
||||||
|
bool expectedVal = true;
|
||||||
|
|
||||||
|
if (sqlDAO.GetType() == typeof(SqlDAO))
|
||||||
|
{
|
||||||
|
sqlDS = (SqlDAO)sqlDAO;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Act
|
||||||
|
bool actualVal = false;
|
||||||
|
if (sqlDS != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
actualVal = sqlDS.CopyToFile(filePath);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Copying to a file failed !!");
|
||||||
|
Console.WriteLine(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Assert
|
||||||
|
bool result = File.Exists(filePath);
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Expected: {0}, Actual: {1}. CSV file created correctly", expectedVal, actualVal);
|
||||||
|
// Clean up the folder use to test.
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Directory.Delete(folderPath, true);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
Console.WriteLine("Folder failed to be deleted");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("Expected: {0}, Actual: {1}. CSV file created incorrectly", expectedVal, actualVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// [Test Method]
|
||||||
|
public void IsProcessFlowCompleted(IDataSource<string> sqlDAO)
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
ArchiveManager archive = new ArchiveManager(sqlDAO);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
// Testing archive Manager
|
||||||
|
int i = -10;
|
||||||
|
while (i < 20)
|
||||||
|
{
|
||||||
|
DateTime date1 = new DateTime(2021, 12, 1, 0, 0, 0);
|
||||||
|
//Console.WriteLine("Testing first of month: {0}", date1.ToString("dd"));
|
||||||
|
//string currentDate = DateTime.Now.ToString("dd");
|
||||||
|
//string currentTime = DateTime.Now.ToString("T");
|
||||||
|
string currentTime = "00:00:00 AM";
|
||||||
|
string currentDate = i.ToString();
|
||||||
|
|
||||||
|
if (i == 1)
|
||||||
|
{
|
||||||
|
currentDate = date1.ToString("dd");
|
||||||
|
//ArchiveManager archive = new ArchiveManager(sqlDAO);
|
||||||
|
//archive.Controller();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Console.WriteLine("Current date: {0}, Current Time: {1}", currentDate, currentTime);
|
||||||
|
Console.WriteLine("Current date: {0}, Current Time: {1}", currentDate, currentTime);
|
||||||
|
if (String.Equals(currentDate, "01") && String.Equals(currentTime, "00:00:00 AM"))
|
||||||
|
{
|
||||||
|
Console.WriteLine("Archiving process Start");
|
||||||
|
//ArchiveManager archive = new ArchiveManager(sqlDAO);
|
||||||
|
archive.Controller();
|
||||||
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void IsCleaningUpCompleted(IDataSource<string> sqlDAO)
|
||||||
|
{
|
||||||
|
//Arrange
|
||||||
|
ArchiveManager archive = new ArchiveManager(sqlDAO);
|
||||||
|
bool actualVal = false;
|
||||||
|
bool expectedVal = false;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
actualVal = archive.Controller();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
//bool result = !(actualVal && expectedVal);
|
||||||
|
if (expectedVal == actualVal)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Expected: {0}, Actual: {1}. Error handle correctly", expectedVal, actualVal);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("Expected: {0}, Actual: {1}. Error handle incorrectly", expectedVal, actualVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveEntriesTest(IDataSource<string> sqlDAO)
|
||||||
|
{
|
||||||
|
Console.WriteLine("TESTING - REMOVE ENTRIES");
|
||||||
|
|
||||||
|
// Arrange
|
||||||
|
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||||
|
SqlDAO sqlDS = null;
|
||||||
|
|
||||||
|
if (sqlDAO.GetType() == typeof(SqlDAO))
|
||||||
|
{
|
||||||
|
sqlDS = (SqlDAO)sqlDAO;
|
||||||
|
//sqlDS.GetConnection().Open();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
Console.WriteLine("\nInserting into archive...");
|
||||||
|
sqlDS.WriteData("INSERT into log(LtimeStamp, LvName, catname, userop, logmessage) values " +
|
||||||
|
"('2021-08-07 23:00:00', 'Info', 'View', 'create some projects', 'new account created')," +
|
||||||
|
"('2021-06-04 23:00:00', 'Info', 'Business', 'create some projects', 'new projects made')," +
|
||||||
|
"('2021-07-02 23:00:00', 'Info', 'View', 'log out', 'log out successful')," +
|
||||||
|
"('2021-09-03 23:00:00', 'Info', 'Business', 'log in', 'log in successfully')," +
|
||||||
|
"('2021-10-20 23:00:00', 'Info', 'View', 'search for projects', 'result return')," +
|
||||||
|
"('2021-09-03 23:00:00', 'Info', 'Business', 'log in', 'log in successfully');");
|
||||||
|
|
||||||
|
OdbcDataReader odbcObj = (OdbcDataReader)sqlDS.ReadData("SELECT * FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;");
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
while (odbcObj.Read()) { ++count; }
|
||||||
|
Console.WriteLine("Number of entries > 30 days old: " + count);
|
||||||
|
sqlDS.GetConnection().Close();
|
||||||
|
|
||||||
|
Console.WriteLine("\nRemoving entries from archive...");
|
||||||
|
sqlDS.RemoveEntries();
|
||||||
|
|
||||||
|
odbcObj = (OdbcDataReader)sqlDS.ReadData("SELECT * FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;");
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
while (odbcObj.Read()) { ++count; }
|
||||||
|
Console.WriteLine("Number of entries > 30 days old: " + count);
|
||||||
|
sqlDS.GetConnection().Close();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
bool expectedVal = true;
|
||||||
|
bool actualVal = !Convert.ToBoolean(count);
|
||||||
|
|
||||||
|
if (expectedVal == actualVal)
|
||||||
|
{
|
||||||
|
Console.WriteLine("\nExpected: {0}, Actual: {0}. Entries removed correctly.", expectedVal, actualVal);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("\nExpected: {0}, Actual: {1}. Entries not removed.", expectedVal, actualVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
//sqlDS.GetConnection().Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveOutputFileTest(IDataSource<string> sqlDAO)
|
||||||
|
{
|
||||||
|
Console.WriteLine("TESTING - REMOVE OUTPUT FILE\n");
|
||||||
|
|
||||||
|
// Arrange
|
||||||
|
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||||
|
SqlDAO sqlDS = null;
|
||||||
|
|
||||||
|
if (sqlDAO.GetType() == typeof(SqlDAO))
|
||||||
|
{
|
||||||
|
sqlDS = (SqlDAO)sqlDAO;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Act
|
||||||
|
string filepath = archiveManager.CreateOutFileName();
|
||||||
|
Console.WriteLine("\nRemoving file...");
|
||||||
|
sqlDS.RemoveOutputFile(filepath);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
bool expectedVal = false;
|
||||||
|
bool actualVal = File.Exists(filepath);
|
||||||
|
Console.WriteLine("Checking if file exists: " + actualVal);
|
||||||
|
|
||||||
|
if (expectedVal == actualVal)
|
||||||
|
{
|
||||||
|
Console.WriteLine("\nExpected: {0}, Actual: {0}. Output file removed correctly.", expectedVal, actualVal);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("\nExpected: {0}, Actual: {1}. Output file NOT removed.", expectedVal, actualVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
|
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
||||||
|
"SERVER=localhost;" +
|
||||||
|
"DATABASE=hobby;" +
|
||||||
|
"UID=root;" +
|
||||||
|
"PASSWORD=Teamhobby;" +
|
||||||
|
"OPTION=3";
|
||||||
|
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||||
|
sqlDAO.GetConnection().Open();
|
||||||
|
//ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||||
|
|
||||||
|
// Testing folder creation
|
||||||
|
ArchivingTests test = new ArchivingTests();
|
||||||
|
test.IsArchiveFolderCreated(sqlDAO);
|
||||||
|
Console.WriteLine("-----------------");
|
||||||
|
Console.WriteLine("");
|
||||||
|
|
||||||
|
// Testing file creation
|
||||||
|
test.IsFileNameCreated(sqlDAO);
|
||||||
|
Console.WriteLine("-----------------");
|
||||||
|
Console.WriteLine("");
|
||||||
|
|
||||||
|
|
||||||
|
// Testing file creation
|
||||||
|
test.IsCSVFileExist(sqlDAO);
|
||||||
|
Console.WriteLine("-----------------");
|
||||||
|
Console.WriteLine("");
|
||||||
|
|
||||||
|
|
||||||
|
// Testing clean up sequence
|
||||||
|
//test.IsCleaningUpCompleted(sqlDAO);
|
||||||
|
//Console.WriteLine("-----------------");
|
||||||
|
//Console.WriteLine("");
|
||||||
|
|
||||||
|
// Testing remove entries
|
||||||
|
test.RemoveEntriesTest(sqlDAO);
|
||||||
|
Console.WriteLine("-----------------");
|
||||||
|
Console.WriteLine("");
|
||||||
|
|
||||||
|
// Testing remove output file
|
||||||
|
test.RemoveOutputFileTest(sqlDAO);
|
||||||
|
Console.WriteLine("-----------------");
|
||||||
|
Console.WriteLine("");
|
||||||
|
sqlDAO.GetConnection().Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.Archive\TeamHobby.HobbyProjectGenerator.Archive.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@ -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<T>
|
||||||
|
{
|
||||||
|
bool Create(T model);
|
||||||
|
|
||||||
|
T Read();
|
||||||
|
|
||||||
|
bool Update(T model);
|
||||||
|
|
||||||
|
bool Delete(T model);
|
||||||
|
}
|
||||||
|
}
|
||||||
50
Source Code/TeamHobby.HobbyProjectGenerator.DAL/SqlDAO.cs
Normal file
50
Source Code/TeamHobby.HobbyProjectGenerator.DAL/SqlDAO.cs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
using Microsoft.Data.SqlClient;
|
||||||
|
using TeamHobby.HobbyProjectGenerator.Models;
|
||||||
|
|
||||||
|
namespace TeamHobby.HobbyProjectGenerator.DAL
|
||||||
|
{
|
||||||
|
public class SqlDAO
|
||||||
|
{
|
||||||
|
public IList<Credentials> 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
|
||||||
|
}*/
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -7,11 +7,11 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="UserManagement\Contracts\" />
|
<PackageReference Include="Microsoft.Data.SqlClient" Version="4.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\TeamHobby.HobbyProjectGenerator.DataAccessLayer\TeamHobby.HobbyProjectGenerator.DataAccessLayer.csproj" />
|
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.Models\TeamHobby.HobbyProjectGenerator.Models.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
namespace TeamHobby.HobbyProjectGenerator.DataAccess
|
||||||
|
{
|
||||||
|
public class Class1
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -5,7 +5,7 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
|
||||||
namespace TeamHobby.HobbyProjectGenerator.DataAccessLayer
|
namespace TeamHobby.HobbyProjectGenerator.DataAccess
|
||||||
{
|
{
|
||||||
public interface IDataSource<T>
|
public interface IDataSource<T>
|
||||||
{
|
{
|
||||||
@ -8,7 +8,7 @@ using System.Threading.Tasks;
|
|||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Data.Odbc;
|
using System.Data.Odbc;
|
||||||
|
|
||||||
namespace TeamHobby.HobbyProjectGenerator.DataAccessLayer
|
namespace TeamHobby.HobbyProjectGenerator.DataAccess
|
||||||
{
|
{
|
||||||
public class SqlDAO : IDataSource<string>
|
public class SqlDAO : IDataSource<string>
|
||||||
{
|
{
|
||||||
@ -17,9 +17,9 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccessLayer
|
|||||||
public SqlDAO(string info)
|
public SqlDAO(string info)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
//Console.WriteLine("Establising Connection...");
|
Console.WriteLine("Establising Connection...");
|
||||||
_conn = new OdbcConnection(info);
|
_conn = new OdbcConnection(info);
|
||||||
//Console.WriteLine("Connection established.");
|
Console.WriteLine("Connection established.");
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
//_conn = null;
|
//_conn = null;
|
||||||
@ -42,7 +42,7 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccessLayer
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_conn.Open();
|
//_conn.Open();
|
||||||
OdbcCommand command = new OdbcCommand(cmd, _conn);
|
OdbcCommand command = new OdbcCommand(cmd, _conn);
|
||||||
OdbcDataReader reader = command.ExecuteReader();
|
OdbcDataReader reader = command.ExecuteReader();
|
||||||
|
|
||||||
@ -67,12 +67,12 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccessLayer
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_conn.Open();
|
//_conn.Open();
|
||||||
|
|
||||||
OdbcCommand command = new OdbcCommand(cmd, _conn);
|
OdbcCommand command = new OdbcCommand(cmd, _conn);
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
|
|
||||||
_conn.Close();
|
//_conn.Close();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccessLayer
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
_conn.Close();
|
//_conn.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,12 +94,12 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccessLayer
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_conn.Open();
|
//_conn.Open();
|
||||||
|
|
||||||
OdbcCommand command = new OdbcCommand(cmd, _conn);
|
OdbcCommand command = new OdbcCommand(cmd, _conn);
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
|
|
||||||
_conn.Close();
|
//_conn.Close();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -111,7 +111,7 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccessLayer
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
_conn.Close();
|
//_conn.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,12 +120,12 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccessLayer
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_conn.Open();
|
//_conn.Open();
|
||||||
|
|
||||||
OdbcCommand command = new OdbcCommand(cmd, _conn);
|
OdbcCommand command = new OdbcCommand(cmd, _conn);
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
|
|
||||||
_conn.Close();
|
//_conn.Close();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -137,7 +137,7 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccessLayer
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
_conn.Close();
|
//_conn.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,10 +155,8 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccessLayer
|
|||||||
// Check to see if the file is hidden or already compressed before compressing the file.
|
// Check to see if the file is hidden or already compressed before compressing the file.
|
||||||
if (atrribute != FileAttributes.Hidden && atrribute != FileAttributes.Compressed)
|
if (atrribute != FileAttributes.Hidden && atrribute != FileAttributes.Compressed)
|
||||||
{
|
{
|
||||||
var compFileName = Path.ChangeExtension(fileName, ".gz");
|
using FileStream outputFile = File.Create(fileName + ".gz");
|
||||||
//using FileStream outputFile = File.Create(fileName + ".gz");
|
|
||||||
using FileStream outputFile = File.Create(compFileName);
|
|
||||||
|
|
||||||
using GZipStream compressor = new GZipStream(outputFile, CompressionMode.Compress);
|
using GZipStream compressor = new GZipStream(outputFile, CompressionMode.Compress);
|
||||||
origFile.CopyTo(compressor);
|
origFile.CopyTo(compressor);
|
||||||
|
|
||||||
@ -179,7 +177,7 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccessLayer
|
|||||||
public bool CopyToFile(string filePath){
|
public bool CopyToFile(string filePath){
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_conn.Open();
|
//_conn.Open();
|
||||||
// Conver backward slash in to forward slash
|
// Conver backward slash in to forward slash
|
||||||
filePath = filePath.Replace("\\", "/");
|
filePath = filePath.Replace("\\", "/");
|
||||||
string sqlQuery = "SELECT 'LtimeStamp', 'logID', 'LvName', 'catName', 'userOP', 'logMessage' " +
|
string sqlQuery = "SELECT 'LtimeStamp', 'logID', 'LvName', 'catName', 'userOP', 'logMessage' " +
|
||||||
@ -202,19 +200,19 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccessLayer
|
|||||||
Console.WriteLine("Output to a file completed. ");
|
Console.WriteLine("Output to a file completed. ");
|
||||||
|
|
||||||
|
|
||||||
_conn.Close();
|
//_conn.Close();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_conn.Close();
|
//_conn.Close();
|
||||||
Console.WriteLine("Error when copying query to a file !!, will be handled higher up the call stack");
|
Console.WriteLine("Error when copying query to a file !!, will be handled higher up the call stack");
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
_conn.Close();
|
//_conn.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1,18 +1,23 @@
|
|||||||
// Print Statements used throughout the program.
|
// Print Statements used throughout the program.
|
||||||
|
|
||||||
namespace TeamHobby.HobbyProjectGenerator.DataAccessLayer
|
namespace TeamHobby.HobbyProjectGenerator.DataAccess
|
||||||
{
|
{
|
||||||
public class UiPrint
|
public 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 UserManagementMenu(string username)
|
public void UserManagementMenu(string username)
|
||||||
{
|
{
|
||||||
// File must be within the main folder path
|
|
||||||
// Get the current directory.
|
|
||||||
string path = Directory.GetCurrentDirectory();
|
|
||||||
// Menu for all UserManagement options
|
// Menu for all UserManagement options
|
||||||
int menu = 0;
|
int menu = 0;
|
||||||
Console.WriteLine("-------------------------------------\n");
|
Console.WriteLine($"Welcome {username} to User Management.\n");
|
||||||
Console.WriteLine($"\nWelcome {username} to User Management.\n");
|
|
||||||
Console.WriteLine("What would you like to do?\n");
|
Console.WriteLine("What would you like to do?\n");
|
||||||
Console.WriteLine(menu + ") To exit User Management.\n");
|
Console.WriteLine(menu + ") To exit User Management.\n");
|
||||||
menu += 1;
|
menu += 1;
|
||||||
@ -26,11 +31,9 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccessLayer
|
|||||||
menu += 1;
|
menu += 1;
|
||||||
Console.WriteLine(menu + ") Enable an account.\n");
|
Console.WriteLine(menu + ") Enable an account.\n");
|
||||||
menu += 1;
|
menu += 1;
|
||||||
Console.WriteLine(menu + $") Bulk operation from file within the directory.\n{path}\\BulkOps\n");
|
Console.WriteLine(menu + ") View logs.\n");
|
||||||
menu += 1;
|
menu += 1;
|
||||||
Console.WriteLine(menu + ") View log path.\n");
|
Console.WriteLine(menu + ") View archive.\n");
|
||||||
menu += 1;
|
|
||||||
Console.WriteLine(menu + ") View archive path.\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3,9 +3,9 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using TeamHobby.HobbyProjectGenerator.DataAccessLayer;
|
using TeamHobby.HobbyProjectGenerator.DataAccess;
|
||||||
|
|
||||||
namespace TeamHobby.HobbyProjectGenerator.DataAccessLayer
|
namespace TeamHobby.HobbyProjectGenerator.DataAccess
|
||||||
{
|
{
|
||||||
public class RDSFactory
|
public class RDSFactory
|
||||||
{
|
{
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace TeamHobby.HobbyProjectGenerator.Logging
|
||||||
|
{
|
||||||
|
public interface ILogger
|
||||||
|
{
|
||||||
|
bool Log(LogEntry log);
|
||||||
|
|
||||||
|
// IList<string> GetAllLogs();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,13 +4,13 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace TeamHobby.HobbyProjectGenerator.ServiceLayer.Contracts
|
namespace TeamHobby.HobbyProjectGenerator.Logging.Contracts
|
||||||
{
|
{
|
||||||
public interface ILoggerFactory
|
public interface ILoggerFactory
|
||||||
{
|
{
|
||||||
|
ILogger CreateLogger()
|
||||||
ILogger CreateLogger();
|
{
|
||||||
|
return new DBLogger();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
// using System;
|
||||||
|
// using System.Collections.Generic;
|
||||||
|
// using System.Linq;
|
||||||
|
// using System.Text;
|
||||||
|
// using System.Threading.Tasks;
|
||||||
|
|
||||||
|
// namespace TeamHobby.HobbyProjectGenerator.Logging
|
||||||
|
// {
|
||||||
|
// public class ConsoleLogger : ILogger
|
||||||
|
// {
|
||||||
|
// public bool Log(LogEntry log)
|
||||||
|
// {
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
@ -1,12 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using TeamHobby.HobbyProjectGenerator.Logging.Contracts;
|
|
||||||
using TeamHobby.HobbyProjectGenerator.ServiceLayer.Contracts;
|
|
||||||
|
|
||||||
namespace TeamHobby.HobbyProjectGenerator.ServiceLayer
|
namespace TeamHobby.HobbyProjectGenerator.Logging
|
||||||
{
|
{
|
||||||
public class FileLogger : ILogger
|
public class DBLogger : ILogger
|
||||||
{
|
{
|
||||||
public FileLogger()
|
public DBLogger()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,6 +18,7 @@ namespace TeamHobby.HobbyProjectGenerator.ServiceLayer
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -3,18 +3,17 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using TeamHobby.HobbyProjectGenerator.ServiceLayer.Contracts;
|
using TeamHobby.HobbyProjectGenerator.Logging.Contracts;
|
||||||
|
|
||||||
namespace TeamHobby.HobbyProjectGenerator.ServiceLayer.Implementations
|
namespace TeamHobby.HobbyProjectGenerator.Logging.Implementations
|
||||||
{
|
{
|
||||||
public class DBLoggerFactory : ILoggerFactory
|
public class DBLoggerFactory : ILoggerFactory
|
||||||
{
|
{
|
||||||
public DBLoggerFactory()
|
public DBLoggerFactory()
|
||||||
{
|
{
|
||||||
//this._logDatabase = logDatabase;
|
|
||||||
}
|
}
|
||||||
|
public ILogger CreateLogger()
|
||||||
public ILogger CreateLogger() {
|
{
|
||||||
return new DBLogger();
|
return new DBLogger();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
// using System;
|
||||||
|
|
||||||
|
// namespace TeamHobby.HobbyProjectGenerator.Logging
|
||||||
|
// {
|
||||||
|
// public class FileLogger : Ilogger
|
||||||
|
// {
|
||||||
|
// public FileLogger()
|
||||||
|
// {
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public IList<string> GetAllLogs()
|
||||||
|
// {
|
||||||
|
// throw new NotImplementedException();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public bool Log(LogEntry log)
|
||||||
|
// {
|
||||||
|
// throw new NotImplementedException();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }
|
||||||
@ -0,0 +1,58 @@
|
|||||||
|
// using System;
|
||||||
|
// using System.Collections.Generic;
|
||||||
|
// namespace TeamHobby.HobbyProjectGenerator.Logging
|
||||||
|
// {
|
||||||
|
// // implementation of ILogger that stores logs as they initialize
|
||||||
|
// public class InMemoryLogger : ILogger
|
||||||
|
// {
|
||||||
|
// // make readonly to prevent it from being changed somewhere other than in the constructor
|
||||||
|
// private readonly IList<string> _logStore;
|
||||||
|
|
||||||
|
// public InMemoryLogger()
|
||||||
|
// {
|
||||||
|
// // list of current logs
|
||||||
|
// _logStore = new List<string>();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public InMemoryLogger(IList<string> logStore)
|
||||||
|
// {
|
||||||
|
// _logStore = logStore;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public bool Log(LogEntry entry)
|
||||||
|
// {
|
||||||
|
// if (entry is null)
|
||||||
|
// {
|
||||||
|
// throw new ArgumentNullException(nameof(entry));
|
||||||
|
// }
|
||||||
|
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// // string interpolation to add UTC timestamp to log description
|
||||||
|
// //_logStore.Add($"{DateTime.UtcNow}-> {description}");
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
// catch
|
||||||
|
// {
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// public IList<string> GetAllLogs()
|
||||||
|
// {
|
||||||
|
// return _logStore;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
// public override bool Equals(object? obj)
|
||||||
|
// {
|
||||||
|
// return obj is InMemoryLogger logger &&
|
||||||
|
// EqualityComparer<IList<string>>.Default.Equals(_logStore, logger._logStore);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public override int GetHashCode()
|
||||||
|
// {
|
||||||
|
// return HashCode.Combine(_logStore);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }
|
||||||
@ -0,0 +1,54 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace TeamHobby.HobbyProjectGenerator.Logging
|
||||||
|
{
|
||||||
|
public enum LogLevel
|
||||||
|
{
|
||||||
|
Info, Debug, Warning, Error
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum LogCategory
|
||||||
|
{
|
||||||
|
View, Business, Server, Data, Datastore
|
||||||
|
}
|
||||||
|
|
||||||
|
// LogEntry is a record type with init properties for each field
|
||||||
|
// ensures that log entries are immutable after initialization
|
||||||
|
public record LogEntry
|
||||||
|
{
|
||||||
|
public LogLevel level { get; init; }
|
||||||
|
public LogCategory category { get; init; }
|
||||||
|
public string user { get; init; }
|
||||||
|
public string description { get; init; }
|
||||||
|
public DateTime timestamp { get; init; }
|
||||||
|
|
||||||
|
|
||||||
|
// Constructor requireing only the description as an arg
|
||||||
|
// Assigns default values for LogLevel (Info), LogCategory (Server), user ("System"), and the UTC time at initialization for timestamp
|
||||||
|
public LogEntry(string description)
|
||||||
|
{
|
||||||
|
this.level = LogLevel.Info;
|
||||||
|
this.category = LogCategory.Server;
|
||||||
|
this.user = "System";
|
||||||
|
this.description = description;
|
||||||
|
this.timestamp = DateTime.UtcNow;
|
||||||
|
}
|
||||||
|
// Constructor with args for all fields except timestamp
|
||||||
|
// timestamp is always set to the UTC time at the time of initialization
|
||||||
|
public LogEntry(LogLevel level, string user, LogCategory category, string description)
|
||||||
|
{
|
||||||
|
this.level = level;
|
||||||
|
this.category = category;
|
||||||
|
this.user = user;
|
||||||
|
this.description = description;
|
||||||
|
this.timestamp = DateTime.UtcNow;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using TeamHobby.HobbyProjectGenerator.DataAccess;
|
||||||
|
using TeamHobby.HobbyProjectGenerator.Logging.Contracts;
|
||||||
|
using TeamHobby.HobbyProjectGenerator.Logging.Implementations;
|
||||||
|
|
||||||
|
namespace TeamHobby.HobbyProjectGenerator.Logging
|
||||||
|
{
|
||||||
|
internal class LoggingManager
|
||||||
|
{
|
||||||
|
private readonly IDataSource<string> _conn;
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly ILoggerFactory _factory;
|
||||||
|
private readonly LogEntry _logEntry;
|
||||||
|
|
||||||
|
// Both Constructors take an IDataSource arg to make logging extensible to future data sources
|
||||||
|
// first constructor has no additional args - defaults to using the DBFactiry implementation
|
||||||
|
public LoggingManager(IDataSource<string> dataSource)
|
||||||
|
{
|
||||||
|
_conn = dataSource;
|
||||||
|
_factory = new DBLoggerFactory();
|
||||||
|
_logger = _factory.CreateLogger();
|
||||||
|
}
|
||||||
|
// second constructor takes an additional ILoggerFactory arg - allows for extensible logger types
|
||||||
|
public LoggingManager(IDataSource<string> dataSource, ILoggerFactory factory)
|
||||||
|
{
|
||||||
|
_conn = dataSource;
|
||||||
|
_factory = factory;
|
||||||
|
_logger = _factory.CreateLogger();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Process()
|
||||||
|
{
|
||||||
|
_logger.Log(_logEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<Platforms>AnyCPU;x86</Platforms>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
|
<Optimize>True</Optimize>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'">
|
||||||
|
<Optimize>True</Optimize>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<Platforms>AnyCPU;x86</Platforms>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.Archive\TeamHobby.HobbyProjectGenerator.Archive.csproj" />
|
||||||
|
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.DataAccess\TeamHobby.HobbyProjectGenerator.DataAccess.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
namespace TeamHobby.HobbyProjectGenerator.Models
|
||||||
|
{
|
||||||
|
public class Credentials
|
||||||
|
{
|
||||||
|
public string userName { get; set; }
|
||||||
|
|
||||||
|
// Syntactic sugar
|
||||||
|
public string Password { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,81 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Data.Odbc;
|
||||||
|
using TeamHobby.HobbyProjectGenerator.DataAccess;
|
||||||
|
|
||||||
|
namespace TeamHobby.HobbyProjectGenerator.UserManagement
|
||||||
|
{
|
||||||
|
public class AccountService
|
||||||
|
{
|
||||||
|
public bool CreateUserRecord(UserAccount newUser, string CreatedBy, IDataSource<string> dbSource)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Insert into users table
|
||||||
|
string sqlUser = $"INSERT INTO users (UserName, Password, Role, IsActive," +
|
||||||
|
$"CreatedBy, CreatedDate, Email) VALUES ('{newUser.username}', " +
|
||||||
|
$"'{newUser.password}','{newUser.role}', 1," +
|
||||||
|
$"'{CreatedBy}', NOW(),'{newUser.email}');";
|
||||||
|
|
||||||
|
bool insertNewUser = dbSource.WriteData(sqlUser);
|
||||||
|
return insertNewUser;
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public bool EditUserRecord(UserAccount newUser, string CreatedBy, IDataSource<string> dbSource)
|
||||||
|
{
|
||||||
|
/* // Insert into users table
|
||||||
|
string sqlUser = $"UPDATE hobby.roles r SET r.Role = 'regular',r.CreatedBy = 'colin'WHERE r.RoleID = 5; ";
|
||||||
|
|
||||||
|
Object insertNewUser = dbSource.WriteData(sqlUser);
|
||||||
|
// Insert into users table
|
||||||
|
string sqlRoles = $"INSERT INTO roles (Role, CreatedBy, CreatedDate) " +
|
||||||
|
$"VALUES ('{newUser.NewRole}', '{CreatedBy}', NOW());";
|
||||||
|
Object insertNewRole = dbSource.WriteData(sqlUser);
|
||||||
|
// Create string for confirming user account
|
||||||
|
string confirmUser = $"Select * from users where username = {newUser.NewUserName} " +
|
||||||
|
$"and password = {newUser.NewPassword};";
|
||||||
|
Object conUser = dbSource.ReadData(confirmUser);
|
||||||
|
|
||||||
|
//Console.WriteLine("type of Reesult:" + confirmAdmin.GetType());
|
||||||
|
OdbcDataReader reader = null;
|
||||||
|
|
||||||
|
if (conUser.GetType() == typeof(OdbcDataReader))
|
||||||
|
{
|
||||||
|
reader = (OdbcDataReader)conUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read Sql query results
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
Console.WriteLine(reader.GetString(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
SqlDAO sqlDS = (SqlDAO)dbSource;
|
||||||
|
Console.WriteLine("");
|
||||||
|
|
||||||
|
// Closing the connection
|
||||||
|
sqlDS.getConnection().Close();*/
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool DeleteUserRecord(UserAccount newUser, IDataSource<string> dbSource)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool DisableUser(UserAccount newUser, IDataSource<string> dbSource)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool EnableUser(UserAccount newUser, IDataSource<string> dbSource)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,9 +4,10 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Data.Odbc;
|
using System.Data.Odbc;
|
||||||
using TeamHobby.HobbyProjectGenerator.DataAccessLayer;
|
using TeamHobby.HobbyProjectGenerator.UserManagement;
|
||||||
|
using TeamHobby.HobbyProjectGenerator.DataAccess;
|
||||||
|
|
||||||
namespace TeamHobby.HobbyProjectGenerator.ServiceLayer
|
namespace TeamHobby.HobbyProjectGenerator.UserManagement
|
||||||
{
|
{
|
||||||
public class SystemAccountManager
|
public class SystemAccountManager
|
||||||
{
|
{
|
||||||
@ -170,11 +171,10 @@ namespace TeamHobby.HobbyProjectGenerator.ServiceLayer
|
|||||||
Console.WriteLine("");
|
Console.WriteLine("");
|
||||||
|
|
||||||
// Closing the connection
|
// Closing the connection
|
||||||
sqlDS.GetConnection().Close();
|
sqlDS.getConnection().Close();
|
||||||
|
|
||||||
if (checkSql == "Admin")
|
if (checkSql == "Admin")
|
||||||
{
|
{
|
||||||
Console.WriteLine("-- Logged in successfully.");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -204,12 +204,12 @@ namespace TeamHobby.HobbyProjectGenerator.ServiceLayer
|
|||||||
AccountService accountService = new AccountService();
|
AccountService accountService = new AccountService();
|
||||||
// Create credentials object for new inptus
|
// Create credentials object for new inptus
|
||||||
GetCredentials newCredentials = new GetCredentials();
|
GetCredentials newCredentials = new GetCredentials();
|
||||||
|
// Print User Management menu
|
||||||
|
ui.UserManagementMenu(user.username);
|
||||||
// Create bool object for menu loop
|
// Create bool object for menu loop
|
||||||
bool menuLoop = true;
|
bool menuLoop = true;
|
||||||
// Create loop for menu
|
// Create loop for menu
|
||||||
while (menuLoop is true) {
|
while (menuLoop is true) {
|
||||||
// Print User Management menu
|
|
||||||
ui.UserManagementMenu(user.username);
|
|
||||||
// Get user choice
|
// Get user choice
|
||||||
int menuChoice = Convert.ToInt32(Console.ReadLine());
|
int menuChoice = Convert.ToInt32(Console.ReadLine());
|
||||||
// Complete the appropriate action
|
// Complete the appropriate action
|
||||||
@ -217,149 +217,53 @@ namespace TeamHobby.HobbyProjectGenerator.ServiceLayer
|
|||||||
{
|
{
|
||||||
// Exit menu
|
// Exit menu
|
||||||
case 0:
|
case 0:
|
||||||
return "Back to Login";
|
return "Exiting UserManagement.\n";
|
||||||
|
break;
|
||||||
// Create account
|
// Create account
|
||||||
case 1:
|
case 1:
|
||||||
// Get all credentials and create newUser
|
|
||||||
UserAccount newUser = new UserAccount(newCredentials.GetUserName(),
|
UserAccount newUser = new UserAccount(newCredentials.GetUserName(),
|
||||||
newCredentials.ConfirmPassword(), newCredentials.GetEmail(),
|
newCredentials.GetPassword(), newCredentials.GetEmail(),
|
||||||
newCredentials.GetRole(), DateTime.UtcNow);
|
newCredentials.GetRole(), DateTime.UtcNow);
|
||||||
bool accountValid = accountService.CreateUserRecord(newUser, user.username, dbSource);
|
accountService.CreateUserRecord(newUser,user.username, dbSource);
|
||||||
if (accountValid is true)
|
break;
|
||||||
{
|
|
||||||
Console.WriteLine("\nAccount created Successfully");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return "Database Timed out";
|
|
||||||
}
|
|
||||||
// Edit account
|
// Edit account
|
||||||
case 2:
|
case 2:
|
||||||
// State what account is being edited
|
/* UserAccount newEditUser = new UserAccount(newCredentials.GetUserName(),
|
||||||
string userName = newCredentials.GetUserName();
|
newCredentials.GetPassword(), DateTime.UtcNow);
|
||||||
|
accountService.EditUserRecord(newEditUser, dbSource);*/
|
||||||
// Notify the user of what can be edited
|
|
||||||
Console.WriteLine($"\n****The following information will be used to update {userName}");
|
|
||||||
|
|
||||||
// Get updated parameters
|
|
||||||
UserAccount newEditUser = new UserAccount(userName,
|
|
||||||
newCredentials.GetPassword(), newCredentials.GetEmail(),
|
|
||||||
newCredentials.GetRole(), DateTime.UtcNow);
|
|
||||||
bool editValid = accountService.EditUserRecord(newEditUser, user.username, dbSource);
|
|
||||||
if (editValid is true)
|
|
||||||
{
|
|
||||||
Console.WriteLine("\nAccount updated Successfully");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return "Database Timed out";
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
// Delete account
|
// Delete account
|
||||||
case 3:
|
case 3:
|
||||||
UserAccount newDeleteUser = new UserAccount(newCredentials.GetUserName(),
|
UserAccount newDeleteUser = new UserAccount(newCredentials.GetUserName(),
|
||||||
newCredentials.GetPassword(), DateTime.UtcNow);
|
newCredentials.GetPassword(), DateTime.UtcNow);
|
||||||
bool deleteValid = accountService.DeleteUserRecord(newDeleteUser, user.username , dbSource);
|
accountService.DeleteUserRecord(newDeleteUser, dbSource);
|
||||||
if (deleteValid is true)
|
|
||||||
{
|
|
||||||
Console.WriteLine("\nAccount deleted Successfully");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return "User does not exist";
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
// Disable account
|
// Disable account
|
||||||
case 4:
|
case 4:
|
||||||
UserAccount newDisableUser = new UserAccount(newCredentials.GetUserName(),
|
UserAccount newDisableUser = new UserAccount(newCredentials.GetUserName(),
|
||||||
newCredentials.GetRole());
|
newCredentials.GetPassword(), DateTime.UtcNow);
|
||||||
bool disableValid = accountService.DisableUser(newDisableUser, user.username , dbSource);
|
accountService.DisableUser(newDisableUser, dbSource);
|
||||||
if (disableValid is true)
|
|
||||||
{
|
|
||||||
Console.WriteLine("\nAccount disabled Successfully");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return "User does not exist";
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
// Enable account
|
// Enable account
|
||||||
case 5:
|
case 5:
|
||||||
UserAccount newEnableUser = new UserAccount(newCredentials.GetUserName(),
|
UserAccount newEnableUser = new UserAccount(newCredentials.GetUserName(),
|
||||||
newCredentials.GetRole());
|
newCredentials.GetPassword(), DateTime.UtcNow);
|
||||||
bool enableValid = accountService.EnableUser(newEnableUser, user.username , dbSource);
|
accountService.EnableUser(newEnableUser, dbSource);
|
||||||
if (enableValid is true)
|
|
||||||
{
|
|
||||||
Console.WriteLine("\nAccount enabled Successfully");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return "User does not exist";
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
// Bulk operation through file
|
|
||||||
case 6:
|
|
||||||
AccountService bulkOP = new AccountService();
|
|
||||||
// Get path to defualt bin location
|
|
||||||
string path = Directory.GetCurrentDirectory();
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
// Get name of file and update path to correct folder
|
|
||||||
Console.WriteLine("Please input the name of the file:(Example.txt)");
|
|
||||||
string filename = $"{path}\\{Console.ReadLine()}";
|
|
||||||
//Console.WriteLine(filename)
|
|
||||||
|
|
||||||
// Get filesize
|
|
||||||
long fileSize = filename.Length;
|
|
||||||
long fileSizeGB = fileSize / (1024 * 1024);
|
|
||||||
//Console.WriteLine($"File size is {fileSize}kb");
|
|
||||||
|
|
||||||
// Check if input is empty
|
|
||||||
if (filename == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Invalid file name.\n");
|
|
||||||
}
|
|
||||||
// Check if file is over 2GB
|
|
||||||
else if (fileSizeGB > 2)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"File size is {fileSizeGB}GB\n");
|
|
||||||
Console.WriteLine("File is too large, please enter a smaller file.\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Begin bulk operation
|
|
||||||
Console.WriteLine("Running bulk operation...");
|
|
||||||
bool bulkReq = bulkOP.BulkOperation(user.username, filename, dbSource);
|
|
||||||
if (bulkReq is true)
|
|
||||||
{
|
|
||||||
Console.WriteLine("\nBulk operation complete");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return "Bulk operation failed";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
// View logs
|
// View logs
|
||||||
case 7:
|
case 6:
|
||||||
break;
|
break;
|
||||||
// View archive
|
// View archive
|
||||||
case 8:
|
case 7:
|
||||||
Console.WriteLine("C:/HobbyArchive");
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Console.WriteLine("Invalid input.\nPlease enter a valid option.\n");
|
Console.WriteLine("Invalid input.\nPlease enter a valid option.\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "Back to Login";
|
|
||||||
|
string dbAction = user.username;
|
||||||
|
return dbAction;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -6,4 +6,8 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.DataAccess\TeamHobby.HobbyProjectGenerator.DataAccess.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@ -0,0 +1,75 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace TeamHobby.HobbyProjectGenerator.UserManagement
|
||||||
|
{
|
||||||
|
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 string ConfirmPassword()
|
||||||
|
{
|
||||||
|
Console.WriteLine();
|
||||||
|
string confirmPassword = newUser.NewPassword;
|
||||||
|
}*/
|
||||||
|
public string GetEmail()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Please enter an email:");
|
||||||
|
return Console.ReadLine();
|
||||||
|
}
|
||||||
|
public string GetRole()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Please enter the role of the user:");
|
||||||
|
return Console.ReadLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class UserAccount
|
||||||
|
{
|
||||||
|
// Admin Credentials
|
||||||
|
private string _userName;
|
||||||
|
private string _password;
|
||||||
|
private DateTime _Time;
|
||||||
|
// New User Credentials
|
||||||
|
private string _Email;
|
||||||
|
private string _Role;
|
||||||
|
|
||||||
|
public UserAccount(string un, string pwd, DateTime TimeStamp)
|
||||||
|
{
|
||||||
|
_userName = un;
|
||||||
|
_password = pwd;
|
||||||
|
_Time = TimeStamp;
|
||||||
|
}
|
||||||
|
public UserAccount(string newUN, string newPWD, string Email, string role, DateTime newTime)
|
||||||
|
{
|
||||||
|
_userName = newUN;
|
||||||
|
_password = newPWD;
|
||||||
|
_Role = role;
|
||||||
|
_Email = Email;
|
||||||
|
_Time = newTime;
|
||||||
|
}
|
||||||
|
public UserAccount()
|
||||||
|
{
|
||||||
|
_Role = "regular";
|
||||||
|
_Time= DateTime.Now;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string username { get { return _userName; } }
|
||||||
|
public string password { get { return _password; } }
|
||||||
|
public string email { get { return _Email; } }
|
||||||
|
public string role { get { return _Role; } }
|
||||||
|
public DateTime Time { get { return _Time; } }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,378 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Data.Odbc;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
|
||||||
using System.Threading;
|
|
||||||
using TeamHobby.HobbyProjectGenerator.Archive;
|
|
||||||
using TeamHobby.HobbyProjectGenerator.DataAccess;
|
|
||||||
using Xunit;
|
|
||||||
using Xunit.Abstractions;
|
|
||||||
|
|
||||||
namespace TeamHobby.Archiving.xTests
|
|
||||||
|
|
||||||
|
|
||||||
{
|
|
||||||
public class ArchivingXUnitTest
|
|
||||||
{
|
|
||||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
|
||||||
"SERVER=localhost;" +
|
|
||||||
"DATABASE=hobby;" +
|
|
||||||
"UID=root;" +
|
|
||||||
"PASSWORD=Teamhobby;" +
|
|
||||||
"OPTION=3";
|
|
||||||
|
|
||||||
ITestOutputHelper output;
|
|
||||||
public ArchivingXUnitTest(ITestOutputHelper output)
|
|
||||||
{
|
|
||||||
this.output = output;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void IsArchiveFolderCreated()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
|
||||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
|
||||||
string folderPath = @"C:/HobbyArchive";
|
|
||||||
bool expectedVal = true;
|
|
||||||
|
|
||||||
// Act
|
|
||||||
archiveManager.CreateArchiveFolder();
|
|
||||||
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
bool actualVal = Directory.Exists(folderPath);
|
|
||||||
output.WriteLine("Actual value: {0}, Expected value: {1}", actualVal, expectedVal);
|
|
||||||
Assert.Equal(expectedVal, actualVal);
|
|
||||||
// Cleaning up directory after test
|
|
||||||
output.WriteLine("Cleaning up Folder and File used for testing... ");
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Directory.Delete(folderPath, true);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
Console.WriteLine("Folder failed to be deleted");
|
|
||||||
}
|
|
||||||
output.WriteLine("Cleaning up completed. ");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void IsFileNameCreated()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
|
||||||
string foldPath = @"C:\HobbyArchive";
|
|
||||||
string fileName = DateTime.Now.ToString("M_d_yyyy") + "_archive.csv";
|
|
||||||
string expectedFilePath = System.IO.Path.Combine(foldPath, fileName);
|
|
||||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
string actualFilePath = archiveManager.CreateOutFileName();
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
|
|
||||||
Assert.Equal(expectedFilePath, actualFilePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void IsCSVFileExist()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
|
||||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
|
||||||
SqlDAO sqlDS = null;
|
|
||||||
string folderPath = @"C:/HobbyArchive";
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
bool folderRes = archiveManager.CreateArchiveFolder();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Folder creation for copying failed");
|
|
||||||
}
|
|
||||||
string filePath = archiveManager.CreateOutFileName();
|
|
||||||
bool expectedVal = true;
|
|
||||||
|
|
||||||
if (sqlDAO.GetType() == typeof(SqlDAO))
|
|
||||||
{
|
|
||||||
sqlDS = (SqlDAO)sqlDAO;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Act
|
|
||||||
if (sqlDS != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
sqlDS.CopyToFile(filePath);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Copying to a file failed !!");
|
|
||||||
Console.WriteLine(ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
bool actualVal = File.Exists(filePath);
|
|
||||||
output.WriteLine("Actual value: {0}, Expected value: {1}", actualVal, expectedVal);
|
|
||||||
Assert.Equal(expectedVal, actualVal);
|
|
||||||
output.WriteLine("Cleaning up Folder and File used for testing... ");
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Directory.Delete(folderPath, true);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
Console.WriteLine("Folder failed to be deleted");
|
|
||||||
}
|
|
||||||
output.WriteLine("Cleaning up completed. ");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void IsEntriesRemoved()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
|
||||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
|
||||||
OdbcDataReader odbcObj = null;
|
|
||||||
Object resultData = null;
|
|
||||||
bool expectedVal = false;
|
|
||||||
|
|
||||||
sqlDAO.WriteData("INSERT into log(LtimeStamp, LvName, catname, userop, logmessage) values" +
|
|
||||||
"('2021-08-07 23:00:00', 'Info', 'View', 'create some projects', 'new account created')," +
|
|
||||||
"('2021-06-04 23:00:00', 'Info', 'Business', 'create some projects', 'new projects made')," +
|
|
||||||
"('2021-07-02 23:00:00', 'Info', 'View', 'log out', 'log out successful')," +
|
|
||||||
"('2021-09-03 23:00:00', 'Info', 'Business', 'log in', 'log in successfully')," +
|
|
||||||
"('2021-10-20 23:00:00', 'Info', 'View', 'search for projects', 'result return');");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
sqlDAO.RemoveEntries();
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
bool actualVal;
|
|
||||||
|
|
||||||
resultData = sqlDAO.ReadData("SELECT * FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;");
|
|
||||||
if ((resultData != null) && (resultData.GetType() == typeof(OdbcDataReader)))
|
|
||||||
{
|
|
||||||
odbcObj = (OdbcDataReader)resultData;
|
|
||||||
}
|
|
||||||
OdbcConnection conn = sqlDAO.GetConnection();
|
|
||||||
actualVal = odbcObj.HasRows;
|
|
||||||
conn.Close();
|
|
||||||
|
|
||||||
output.WriteLine("Actual value: {0}, Expected value: {1}", actualVal, expectedVal);
|
|
||||||
Assert.Equal(expectedVal, actualVal);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void IsOutputFileRemoved()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
|
||||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
|
||||||
bool expectedVal = false;
|
|
||||||
//Thread.Sleep(5000);
|
|
||||||
|
|
||||||
// Create the folder and the csv file for compressing
|
|
||||||
archiveManager.CreateArchiveFolder();
|
|
||||||
string filepath = archiveManager.CreateOutFileName();
|
|
||||||
sqlDAO.CopyToFile(filepath);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
if (sqlDAO != null)
|
|
||||||
{
|
|
||||||
sqlDAO.RemoveOutputFile(filepath);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
bool actualVal = File.Exists(filepath);
|
|
||||||
Assert.Equal(expectedVal, actualVal);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void IsFileCompressed()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
|
||||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
|
||||||
|
|
||||||
// Create the folder and the csv file to be compressed.
|
|
||||||
archiveManager.CreateArchiveFolder();
|
|
||||||
string filePath = archiveManager.CreateOutFileName();
|
|
||||||
sqlDAO.CopyToFile(filePath);
|
|
||||||
FileAttributes expectedAttribute = FileAttributes.Archive;
|
|
||||||
string compFilePath = Path.ChangeExtension(filePath, ".gz");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
sqlDAO.CompressFile(filePath);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
FileAttributes actualAttribute = File.GetAttributes(compFilePath);
|
|
||||||
output.WriteLine("Actual value: {0}, Expected value: {1}", actualAttribute, expectedAttribute);
|
|
||||||
Assert.Equal(expectedAttribute, actualAttribute);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void IsArchive_Under_60s_10kRecords()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
|
||||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
|
||||||
var timer = new Stopwatch();
|
|
||||||
double expectedVal = 60;
|
|
||||||
string folderPath = @"C:/HobbyArchive";
|
|
||||||
|
|
||||||
sqlDAO.WriteData("INSERT into log(LtimeStamp, LvName, catname, userop, logmessage) values" +
|
|
||||||
"('2021-08-07 23:00:00', 'Info', 'View', 'create some projects', 'new account created')," +
|
|
||||||
"('2021-06-04 23:00:00', 'Info', 'Business', 'create some projects', 'new projects made')," +
|
|
||||||
"('2021-07-02 23:00:00', 'Info', 'View', 'log out', 'log out successful')," +
|
|
||||||
"('2021-09-03 23:00:00', 'Info', 'Business', 'log in', 'log in successfully')," +
|
|
||||||
"('2021-10-20 23:00:00', 'Info', 'View', 'search for projects', 'result return');");
|
|
||||||
|
|
||||||
for (int i = 0; i <= 11; i++)
|
|
||||||
{
|
|
||||||
sqlDAO.WriteData("INSERT INTO log(LtimeStamp, LvName, catName, userOP, logMessage) " +
|
|
||||||
"SELECT LtimeStamp, LvName, catName, userOP, logMessage FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Act
|
|
||||||
timer.Start();
|
|
||||||
archiveManager.Controller();
|
|
||||||
timer.Stop();
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
var actualVal = timer.Elapsed.Seconds;
|
|
||||||
output.WriteLine("Actual value: {0}s, Expected value: {1}s", actualVal, expectedVal);
|
|
||||||
Assert.True(actualVal < expectedVal);
|
|
||||||
|
|
||||||
// Clean up resources after testing
|
|
||||||
output.WriteLine("Cleaning up Folder and File used for testing... ");
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Directory.Delete(folderPath, true);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
Console.WriteLine("Folder failed to be deleted");
|
|
||||||
}
|
|
||||||
output.WriteLine("Cleaning up completed... ");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void IsArchive_Under_60s_1mRecords()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
|
||||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
|
||||||
var timer = new Stopwatch();
|
|
||||||
double expectedVal = 60;
|
|
||||||
string folderPath = @"C:/HobbyArchive";
|
|
||||||
|
|
||||||
sqlDAO.WriteData("INSERT into log(LtimeStamp, LvName, catname, userop, logmessage) values" +
|
|
||||||
"('2021-08-07 23:00:00', 'Info', 'View', 'create some projects', 'new account created')," +
|
|
||||||
"('2021-06-04 23:00:00', 'Info', 'Business', 'create some projects', 'new projects made')," +
|
|
||||||
"('2021-07-02 23:00:00', 'Info', 'View', 'log out', 'log out successful')," +
|
|
||||||
"('2021-09-03 23:00:00', 'Info', 'Business', 'log in', 'log in successfully')," +
|
|
||||||
"('2021-10-20 23:00:00', 'Info', 'View', 'search for projects', 'result return');");
|
|
||||||
|
|
||||||
for (int i = 0; i <= 18; i++)
|
|
||||||
{
|
|
||||||
sqlDAO.WriteData("INSERT INTO log(LtimeStamp, LvName, catName, userOP, logMessage) " +
|
|
||||||
"SELECT LtimeStamp, LvName, catName, userOP, logMessage FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Act
|
|
||||||
timer.Start();
|
|
||||||
archiveManager.Controller();
|
|
||||||
timer.Stop();
|
|
||||||
|
|
||||||
// Arrange
|
|
||||||
double actualVal = timer.Elapsed.Seconds;
|
|
||||||
output.WriteLine("Actual value: {0}s, Expected value: {1}s", actualVal, expectedVal);
|
|
||||||
Assert.True(actualVal < expectedVal);
|
|
||||||
|
|
||||||
output.WriteLine("Cleaning up Folder and File used for testing... ");
|
|
||||||
//Clean up resources after testing
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Directory.Delete(folderPath, true);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
Console.WriteLine("Folder failed to be deleted");
|
|
||||||
}
|
|
||||||
output.WriteLine("Cleaning up completed... ");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
// [Test Method]
|
|
||||||
public void IsProcessFlowCompleted()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
|
||||||
ArchiveManager archive = new ArchiveManager(sqlDAO);
|
|
||||||
bool expectedVal = true;
|
|
||||||
bool actualVal = false;
|
|
||||||
string folderPath = @"C:/HobbyArchive";
|
|
||||||
|
|
||||||
// Adding 10000 records to database for testing
|
|
||||||
sqlDAO.WriteData("INSERT into log(LtimeStamp, LvName, catname, userop, logmessage) values" +
|
|
||||||
"('2021-08-07 23:00:00', 'Info', 'View', 'create some projects', 'new account created')," +
|
|
||||||
"('2021-06-04 23:00:00', 'Info', 'Business', 'create some projects', 'new projects made')," +
|
|
||||||
"('2021-07-02 23:00:00', 'Info', 'View', 'log out', 'log out successful')," +
|
|
||||||
"('2021-09-03 23:00:00', 'Info', 'Business', 'log in', 'log in successfully')," +
|
|
||||||
"('2021-10-20 23:00:00', 'Info', 'View', 'search for projects', 'result return');");
|
|
||||||
|
|
||||||
for (int j = 0; j <= 11; j++)
|
|
||||||
{
|
|
||||||
sqlDAO.WriteData("INSERT INTO log(LtimeStamp, LvName, catName, userOP, logMessage) " +
|
|
||||||
"SELECT LtimeStamp, LvName, catName, userOP, logMessage FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Act
|
|
||||||
// Testing archive Manager
|
|
||||||
int i = -10;
|
|
||||||
while (i < 20)
|
|
||||||
{
|
|
||||||
DateTime date1 = new DateTime(2021, 12, 1, 0, 0, 0);
|
|
||||||
string currentTime = "00:00:00 AM";
|
|
||||||
string currentDate = i.ToString();
|
|
||||||
|
|
||||||
if (i == 1)
|
|
||||||
{
|
|
||||||
currentDate = date1.ToString("dd");
|
|
||||||
}
|
|
||||||
|
|
||||||
//Console.WriteLine("Current date: {0}, Current Time: {1}", currentDate, currentTime);
|
|
||||||
Console.WriteLine("Current date: {0}, Current Time: {1}", currentDate, currentTime);
|
|
||||||
if (String.Equals(currentDate, "01") && String.Equals(currentTime, "00:00:00 AM"))
|
|
||||||
{
|
|
||||||
Console.WriteLine("Archiving process Start");
|
|
||||||
actualVal = archive.Controller();
|
|
||||||
}
|
|
||||||
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
output.WriteLine("Actual value: {0}, Expected value: {1}", actualVal, expectedVal);
|
|
||||||
Assert.Equal(expectedVal, actualVal);
|
|
||||||
output.WriteLine("Cleaning up Folder and File used for testing... ");
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Directory.Delete(folderPath, true);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
Console.WriteLine("Folder failed to be deleted");
|
|
||||||
}
|
|
||||||
output.WriteLine("Cleaning up completed... ");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
|
|
||||||
<IsPackable>false</IsPackable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
|
|
||||||
<PackageReference Include="xunit" Version="2.4.1" />
|
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
||||||
<PrivateAssets>all</PrivateAssets>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="coverlet.collector" Version="3.1.0">
|
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
||||||
<PrivateAssets>all</PrivateAssets>
|
|
||||||
</PackageReference>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\..\TeamHobby.HobbyProjectGenerator.Archive\TeamHobby.HobbyProjectGenerator.Archive.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
Binary file not shown.
@ -1,22 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TeamHobby.HobbyProjectGenerator.Logging.Contracts;
|
|
||||||
|
|
||||||
namespace TeamHobby.HobbyProjectGenerator.ServiceLayer
|
|
||||||
{
|
|
||||||
public interface ILogger
|
|
||||||
{
|
|
||||||
// private IDataSource<string> _datasource = T;
|
|
||||||
// attempts to connect to the data source provided by the type T
|
|
||||||
// returns true if the connection is successful
|
|
||||||
|
|
||||||
// public bool Connect();
|
|
||||||
public bool Log(LogEntry Log);
|
|
||||||
|
|
||||||
// IList<string> GetAllLogs();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,17 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TeamHobby.HobbyProjectGenerator.Logging.Contracts;
|
|
||||||
|
|
||||||
namespace TeamHobby.HobbyProjectGenerator.ServiceLayer
|
|
||||||
{
|
|
||||||
public class ConsoleLogger : ILogger
|
|
||||||
{
|
|
||||||
public bool Log(LogEntry log)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,200 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Data.Odbc;
|
|
||||||
using TeamHobby.HobbyProjectGenerator.DataAccessLayer;
|
|
||||||
using TeamHobby.HobbyProjectGenerator.Logging.Contracts;
|
|
||||||
|
|
||||||
namespace TeamHobby.HobbyProjectGenerator.ServiceLayer
|
|
||||||
{
|
|
||||||
public class DBLogger : ILogger
|
|
||||||
{
|
|
||||||
private SqlDAO _datasource;
|
|
||||||
public DBLogger()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// SELECT * FROM log
|
|
||||||
// public IList<LogEntry> GetAllLogs()
|
|
||||||
// {
|
|
||||||
// throw new NotImplementedException();
|
|
||||||
// }
|
|
||||||
|
|
||||||
//INSERT INTO log(LvName, catName, userOP, logMessage) VALUES ('Debug','Data', 'SYSTEM', 'testing insert method')
|
|
||||||
|
|
||||||
// public bool Connect(SqlDAO logDatabase) {
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
public bool IsActive() {
|
|
||||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
|
||||||
"TCPIP=1;" +
|
|
||||||
"SERVER=ocalhost;" +
|
|
||||||
"DATABASE=hbby;" +
|
|
||||||
"UID=ot;" + // omit password to force SQLException for incorrect passeword
|
|
||||||
"PASSWORD=wrong" +
|
|
||||||
"OPTION=3";
|
|
||||||
// bool isActive = true;
|
|
||||||
OdbcConnection active = new OdbcConnection(dbInfo);
|
|
||||||
try {
|
|
||||||
active.Open();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
catch (OdbcException ex) {
|
|
||||||
// Console.WriteLine(ex.Message);
|
|
||||||
if (ex.ErrorCode == -2146232009 ) {
|
|
||||||
//Console.WriteLine(ex.ErrorCode);
|
|
||||||
Console.WriteLine("Database is active");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Console.WriteLine("Database is inactive");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
// Console.WriteLine("closed1");
|
|
||||||
active.Close();
|
|
||||||
}
|
|
||||||
// return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsAccessible() {
|
|
||||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
|
||||||
"TCPIP=1;" +
|
|
||||||
"SERVER=localhost;" +
|
|
||||||
"DATABASE=hobby;" +
|
|
||||||
"UID=root;" +
|
|
||||||
"PASSWORD=Teamhobby;" +
|
|
||||||
"OPTION=3";
|
|
||||||
OdbcConnection access = new OdbcConnection(dbInfo);
|
|
||||||
try {
|
|
||||||
access.Open();
|
|
||||||
Console.WriteLine("Database is active and accessible by the system");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
Console.WriteLine("Database is active but inaccessible to the system at this time.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
access.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool HasCapacity() {
|
|
||||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
|
||||||
"TCPIP=1;" +
|
|
||||||
"SERVER=localhost;" +
|
|
||||||
"DATABASE=hobby;" +
|
|
||||||
"UID=root;" +
|
|
||||||
"PASSWORD=Teamhobby;" +
|
|
||||||
"OPTION=3";
|
|
||||||
OdbcConnection conn = new OdbcConnection(dbInfo);
|
|
||||||
|
|
||||||
// get the current capacity of the database in MB using the query:
|
|
||||||
// SELECT SUM(storage.MB) as CURRENT_CAPACITY_MB FROM (SELECT table_schema as name, ROUND(SUM(data_length + index_length)/1024/1024,1) as MB FROM information_schema.tables GROUP BY table_schema) as storage;
|
|
||||||
|
|
||||||
string sqlCurrentCap = $"SELECT SUM(storage.mb) as currentCap FROM (SELECT table_schema as name, ROUND(SUM(data_length + index_length)/1024/1024,1) as mb FROM information_schema.tables GROUP BY table_schema) as storage;";
|
|
||||||
|
|
||||||
// get the max capacity in GB; too big to be shown as MB
|
|
||||||
string sqlMaxCap = $"SELECT SUM(storage.mb) as maxCap FROM (SELECT table_schema as name, ROUND(SUM(max_data_length + max_index_length)/1024,1) as mb FROM information_schema.tables GROUP BY table_schema) as storage;";
|
|
||||||
|
|
||||||
// query the data base to get currentCap; the current storage capacity of the system's database (in megabytes)
|
|
||||||
conn.Open();
|
|
||||||
OdbcCommand command1 = new OdbcCommand(sqlCurrentCap, conn);
|
|
||||||
OdbcDataReader result1 = command1.ExecuteReader();
|
|
||||||
double currentCap = 0;
|
|
||||||
while (result1.Read()) {
|
|
||||||
//Console.WriteLine(result1[0].GetType());
|
|
||||||
//Console.WriteLine("currentCap = {0}", result1[0]);
|
|
||||||
currentCap = result1.GetDouble(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Console.WriteLine(currentCap);
|
|
||||||
//float currentCap1 = (float) currentCap;
|
|
||||||
result1.Close();
|
|
||||||
command1.Dispose();
|
|
||||||
conn.Close();
|
|
||||||
// Console.WriteLine("close conn");
|
|
||||||
|
|
||||||
// query the data base again to get maxCap; the maximum possible storage capacity of the system's database (in megabytes)
|
|
||||||
conn.Open();
|
|
||||||
// Console.WriteLine("open conn");
|
|
||||||
OdbcCommand command2 = new OdbcCommand(sqlMaxCap, conn);
|
|
||||||
OdbcDataReader result2 = command2.ExecuteReader();
|
|
||||||
// Console.WriteLine("open reader 1");
|
|
||||||
double maxCap = 0;
|
|
||||||
try {
|
|
||||||
while (result2.Read()) {
|
|
||||||
//Console.WriteLine(result2[0].GetType());
|
|
||||||
maxCap = result2.GetDouble(0);
|
|
||||||
// Console.WriteLine("maxCap = {0}", result2[0]);
|
|
||||||
}
|
|
||||||
// compare currentCap to maxCap
|
|
||||||
// return true if there is at least 1MB of free space available
|
|
||||||
// decrement max by 1 MB to allow for any required space from new logs
|
|
||||||
if ( (currentCap * 1024) < (maxCap - 1024) ) {
|
|
||||||
// Console.WriteLine(maxCap);
|
|
||||||
Console.WriteLine("Database has sufficient storage capacity to be written to at this time.\n Current Capacity: {0} MB\n Max Capacity: {1} MB\n", currentCap, maxCap);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
Console.WriteLine("Insufficient Storage Capacity to log entry to database.\n Current Capacity: {0} MB \n Max Capacity: {1} MB \n", currentCap, maxCap);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
result2.Close();
|
|
||||||
command2.Dispose();
|
|
||||||
conn.Close();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Console.WriteLine("close conn 2");
|
|
||||||
//Console.WriteLine(maxCap);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public bool Log(LogEntry log)
|
|
||||||
{
|
|
||||||
log.ShowLog();
|
|
||||||
|
|
||||||
//bool status = HasCapacity();
|
|
||||||
if ( (IsActive() == false || IsAccessible() == false) || (HasCapacity() == false) ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
|
||||||
// SqlDAO sqlDS = (SqlDAO)_datasource;
|
|
||||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
|
||||||
"TCPIP=1;" +
|
|
||||||
"SERVER=localhost;" +
|
|
||||||
"DATABASE=hobby;" +
|
|
||||||
"UID=root;" +
|
|
||||||
"PASSWORD=Teamhobby;" +
|
|
||||||
"OPTION=3";
|
|
||||||
_datasource = new SqlDAO(dbInfo);
|
|
||||||
|
|
||||||
//bool storage = HasCapacity();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// once connection is confirmed, try inserting the log via SQL statements
|
|
||||||
string sqlLog = $"INSERT INTO log (Lvname, catName, userOP, logMessage) VALUES ('{log.GetLevel()}','{log.GetCategory()}', " + $"'{log.GetUser()}', '{log.GetDescription()}');";
|
|
||||||
|
|
||||||
bool insertNewLog = _datasource.WriteData(sqlLog);
|
|
||||||
//Console.WriteLine($"Logging Succeeded: The following entry was written to the database: {log}");
|
|
||||||
// Console.WriteLine(_datasource.ReadData($"SELECT * FROM log;"));
|
|
||||||
return insertNewLog;
|
|
||||||
}
|
|
||||||
// if failed, that means the connection was a sucess but actually writing to the database failed
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
Console.WriteLine("Failed to write log to database; likely due to error in SQL syntax");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,74 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
|
|
||||||
public enum LogLevel
|
|
||||||
{
|
|
||||||
Info, Debug, Warning, Error
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum LogCategory
|
|
||||||
{
|
|
||||||
View, Business, Server, Data, Datastore
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
namespace TeamHobby.HobbyProjectGenerator.Logging.Contracts
|
|
||||||
{
|
|
||||||
// LogEntry is a record type with init properties for each field
|
|
||||||
// ensures that log entries are immutable after initialization
|
|
||||||
// LogEntry is a record type with init properties for each field
|
|
||||||
// ensures that log entries are immutable after initialization
|
|
||||||
public record LogEntry
|
|
||||||
{
|
|
||||||
private LogLevel _level { get; init; }
|
|
||||||
private LogCategory _category { get; init; }
|
|
||||||
private string _user { get; init; }
|
|
||||||
private string _description { get; init; }
|
|
||||||
|
|
||||||
// Constructor with args for all fields except timestamp
|
|
||||||
// timestamp is always set to the UTC time at the time of initialization
|
|
||||||
public LogEntry(LogLevel level, LogCategory category, string user, string description)
|
|
||||||
{
|
|
||||||
this._level = level;
|
|
||||||
this._category = category;
|
|
||||||
this._user = user;
|
|
||||||
this._description = description;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Constructor requiring only the description as an arg
|
|
||||||
// Assigns default values for LogLevel (Info), LogCategory (Server), user ("System"), and the UTC time at initialization for timestamp
|
|
||||||
// public LogEntry(string description)
|
|
||||||
// {
|
|
||||||
// this._level = LogLevel.Debug;
|
|
||||||
// this._category = LogCategory.Server;
|
|
||||||
// this._user = "SYSTEM";
|
|
||||||
// this._description = description;
|
|
||||||
// }
|
|
||||||
|
|
||||||
public LogLevel GetLevel() {
|
|
||||||
return this._level;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LogCategory GetCategory() {
|
|
||||||
return this._category;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string GetUser() {
|
|
||||||
return this._user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string GetDescription() {
|
|
||||||
return this._description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ShowLog() {
|
|
||||||
Console.WriteLine("Timestamp: {0} | Level: {1}, | Category: {2}, | User: {3}, | Description: '{4}' ", DateTime.Now, this._level.ToString(),this._category.ToString(), this._user, this._description);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,91 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TeamHobby.HobbyProjectGenerator.DataAccessLayer;
|
|
||||||
using TeamHobby.HobbyProjectGenerator.Logging.Contracts;
|
|
||||||
using TeamHobby.HobbyProjectGenerator.ServiceLayer.Contracts;
|
|
||||||
using TeamHobby.HobbyProjectGenerator.ServiceLayer.Implementations;
|
|
||||||
|
|
||||||
|
|
||||||
namespace TeamHobby.HobbyProjectGenerator.ServiceLayer
|
|
||||||
{
|
|
||||||
|
|
||||||
public class LoggingManager
|
|
||||||
{
|
|
||||||
// private static IDataSource<string> _datasource;
|
|
||||||
private ILogger _logger;
|
|
||||||
private ILoggerFactory _factory;
|
|
||||||
private LogEntry _logEntry;
|
|
||||||
|
|
||||||
// assign default values for LogEntry fields
|
|
||||||
// these are not readonly because they can be overwritten to specify logging at specific field(s) from the main controller by using the public setters for each field
|
|
||||||
private LogLevel _level = LogLevel.Debug;
|
|
||||||
private LogCategory _category = LogCategory.Server;
|
|
||||||
private string _user = "System";
|
|
||||||
|
|
||||||
// Both Constructors take an IDataSource arg to make logging extensible to future data sources
|
|
||||||
// first constructor has no additional args - defaults to using a DBLoggerFactory to log to database
|
|
||||||
public LoggingManager()
|
|
||||||
{
|
|
||||||
// _datasource = datasource;
|
|
||||||
_logEntry = new LogEntry(_level, _category, _user, "Logging Manager instantiated");
|
|
||||||
_factory = new DBLoggerFactory();
|
|
||||||
_logger = _factory.CreateLogger();
|
|
||||||
}
|
|
||||||
// second constructor takes an additional ILoggerFactory arg - allows for extensible logger types
|
|
||||||
public LoggingManager(ILoggerFactory factory)
|
|
||||||
{
|
|
||||||
//_datasource = datasource;
|
|
||||||
_logEntry = new LogEntry(_level, _category, _user, "Logging Manager instantiated");
|
|
||||||
_factory = factory;
|
|
||||||
_logger = _factory.CreateLogger();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// // used to create a template entry with the desired fields to write entries at
|
|
||||||
// public void CreateLog(LogLevel level, LogCategory category, string user, string description) {
|
|
||||||
// _logEntry = new LogEntry(level,
|
|
||||||
// category, user, description);
|
|
||||||
// _logger.Log(_logEntry);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// creates a LogEntry object using a description arg
|
|
||||||
// uses whateever the current assignments for the other fields ares
|
|
||||||
public bool CreateLog(string description) {
|
|
||||||
// creates a LogEntry using the passed in description and current assignements from the necessary fields
|
|
||||||
_logEntry = new LogEntry(_level, _category, _user, description);
|
|
||||||
|
|
||||||
// attempt to log the LogEntry by calling the _logger's Log() method
|
|
||||||
try {
|
|
||||||
_logger.Log(_logEntry);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Level(LogLevel level) {
|
|
||||||
this._level = level;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Category(LogCategory category) {
|
|
||||||
this._category = category;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void User(string user) {
|
|
||||||
this._user = user;
|
|
||||||
}
|
|
||||||
|
|
||||||
// public static void Source(IDataSource<string> datasource) {
|
|
||||||
// _datasource = datasource;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public static IDataSource<string> GetDataSource() {
|
|
||||||
// return _datasource;
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,301 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Data.Odbc;
|
|
||||||
using TeamHobby.HobbyProjectGenerator.DataAccessLayer;
|
|
||||||
|
|
||||||
namespace TeamHobby.HobbyProjectGenerator.ServiceLayer
|
|
||||||
{
|
|
||||||
public class AccountService
|
|
||||||
{
|
|
||||||
public bool CreateUserRecord(UserAccount newUser, string CreatedBy, IDataSource<string> dbSource)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Insert into users table
|
|
||||||
if (newUser.email == null || newUser.email == "NULL")
|
|
||||||
{
|
|
||||||
string sqlUser = $"INSERT INTO users (UserName, Password, Role, IsActive," +
|
|
||||||
$"CreatedBy, CreatedDate, Email) VALUES ('{newUser.username}', " +
|
|
||||||
$"'{newUser.password}','{newUser.role}', 1," +
|
|
||||||
$"'{CreatedBy}', NOW(),{newUser.email});";
|
|
||||||
|
|
||||||
bool insertNewUser = dbSource.WriteData(sqlUser);
|
|
||||||
return insertNewUser;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
string sqlUser = $"INSERT INTO users (UserName, Password, Role, IsActive," +
|
|
||||||
$"CreatedBy, CreatedDate, Email) VALUES ('{newUser.username}', " +
|
|
||||||
$"'{newUser.password}','{newUser.role}', 1," +
|
|
||||||
$"'{CreatedBy}', NOW(),'{newUser.email}');";
|
|
||||||
|
|
||||||
bool insertNewUser = dbSource.WriteData(sqlUser);
|
|
||||||
return insertNewUser;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public bool EditUserRecord(UserAccount editUser, string CreatedBy, IDataSource<string> dbSource)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Insert into users table
|
|
||||||
if (editUser.email == null || editUser.email == "NULL")
|
|
||||||
{
|
|
||||||
string sqlUser = $"UPDATE users t SET t.Password = '{editUser.password}', " +
|
|
||||||
$"t.Role = '{editUser.role}',t.Email = '{editUser.email}' " +
|
|
||||||
$"WHERE t.UserName = {editUser.username};";
|
|
||||||
|
|
||||||
bool updateNewUser = dbSource.UpdateData(sqlUser);
|
|
||||||
return updateNewUser;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
string sqlUser = $"UPDATE users t SET t.Password = '{editUser.password}', " +
|
|
||||||
$"t.Role = '{editUser.role}',t.Email = '{editUser.email}' " +
|
|
||||||
$"WHERE t.UserName = '{editUser.username}';";
|
|
||||||
|
|
||||||
bool updateNewUser = dbSource.UpdateData(sqlUser);
|
|
||||||
return updateNewUser;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public bool DeleteUserRecord(UserAccount deleteUser, string CreatedBy, IDataSource<string> dbSource)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Insert into users table
|
|
||||||
string sqlUser = $"DELETE from users WHERE UserName = '{deleteUser.username}' " +
|
|
||||||
$"and Password = '{deleteUser.password}';";
|
|
||||||
|
|
||||||
bool deleteNewUser = dbSource.DeleteData(sqlUser);
|
|
||||||
return deleteNewUser;
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public bool DisableUser(UserAccount disableUser, string CreatedBy, IDataSource<string> dbSource)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Insert into users table
|
|
||||||
string sqlUser = $"UPDATE users u SET u.IsActive = 0 WHERE u.UserName = '{disableUser.username}'" +
|
|
||||||
$"and u.Role = '{disableUser.role}';";
|
|
||||||
|
|
||||||
bool disableNewUser = dbSource.UpdateData(sqlUser);
|
|
||||||
return disableNewUser;
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public bool EnableUser(UserAccount enableUser, string CreatedBy, IDataSource<string> dbSource)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Insert into users table
|
|
||||||
string sqlUser = $"UPDATE users u SET u.IsActive = 1 WHERE u.UserName = '{enableUser.username}'" +
|
|
||||||
$"and u.Role = '{enableUser.role}';";
|
|
||||||
|
|
||||||
bool disableNewUser = dbSource.UpdateData(sqlUser);
|
|
||||||
return disableNewUser;
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public bool BulkOperation(string signedUser, string path, IDataSource<string> dbSource)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Get the current directory.
|
|
||||||
//string path = Directory.GetCurrentDirectory();
|
|
||||||
// Open file reader stream
|
|
||||||
using StreamReader fileRead = new(path); // path + + "\\BulkOps\\Bulk.txt"
|
|
||||||
// Show location of the file being written
|
|
||||||
//Console.WriteLine(path);
|
|
||||||
|
|
||||||
// List choices of operations
|
|
||||||
List<string> ops = new List<string> {"Create Account", "Edit Account",
|
|
||||||
"Delete Account", "Disable Account", "Enable Account"};
|
|
||||||
|
|
||||||
// List to hold file operation and credentials
|
|
||||||
List<string> fileList = new List<string>();
|
|
||||||
string operation = "";
|
|
||||||
string UN = "";
|
|
||||||
string PWD = "";
|
|
||||||
string Role = "";
|
|
||||||
string Email = "";
|
|
||||||
|
|
||||||
// Loop through file rows
|
|
||||||
while (!fileRead.EndOfStream)
|
|
||||||
{
|
|
||||||
// Create variable to hold current line
|
|
||||||
string line = fileRead.ReadLine();
|
|
||||||
|
|
||||||
// Check if line is not empty and contains the separator
|
|
||||||
if (line != null && line.Contains(":"))
|
|
||||||
{
|
|
||||||
// Assign value to hold current line parameter
|
|
||||||
string value = line.Split(':')[1].Trim();
|
|
||||||
|
|
||||||
// Check what operation is being called
|
|
||||||
if (ops.Contains(value))
|
|
||||||
{
|
|
||||||
// Add operation into temp
|
|
||||||
//Console.WriteLine("Found operation");
|
|
||||||
//Console.WriteLine(value);
|
|
||||||
operation = value;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
string checkCredential = line.Split(':')[0].Trim();
|
|
||||||
//Console.WriteLine("Found credential");
|
|
||||||
switch (checkCredential)
|
|
||||||
{
|
|
||||||
case "Username":
|
|
||||||
UN = value;
|
|
||||||
break;
|
|
||||||
case "Password":
|
|
||||||
PWD = value;
|
|
||||||
break;
|
|
||||||
case "Role":
|
|
||||||
Role = value;
|
|
||||||
break;
|
|
||||||
case "Email":
|
|
||||||
Email = value;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(line != null)
|
|
||||||
{
|
|
||||||
switch (operation)
|
|
||||||
{
|
|
||||||
case "Create Account":
|
|
||||||
//Console.WriteLine(operation);
|
|
||||||
if (!String.IsNullOrEmpty(UN))
|
|
||||||
{
|
|
||||||
// Create UserAccount object
|
|
||||||
UserAccount user = new UserAccount(UN, PWD, Email, DateTime.UtcNow);
|
|
||||||
// Create Account service object
|
|
||||||
AccountService serviceTest = new AccountService();
|
|
||||||
serviceTest.CreateUserRecord(user, signedUser, dbSource);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "Edit Account":
|
|
||||||
//Console.WriteLine(operation);
|
|
||||||
//Console.WriteLine(operation);
|
|
||||||
if (String.IsNullOrEmpty(UN))
|
|
||||||
{
|
|
||||||
// Create UserAccount object
|
|
||||||
UserAccount user = new UserAccount(UN, PWD, Email, DateTime.UtcNow);
|
|
||||||
// Create Account service object
|
|
||||||
AccountService serviceTest = new AccountService();
|
|
||||||
serviceTest.CreateUserRecord(user, signedUser, dbSource);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "Delete Account":
|
|
||||||
//Console.WriteLine(operation);
|
|
||||||
//Console.WriteLine(operation);
|
|
||||||
if (String.IsNullOrEmpty(UN))
|
|
||||||
{
|
|
||||||
// Create UserAccount object
|
|
||||||
UserAccount user = new UserAccount(UN, PWD, Email, DateTime.UtcNow);
|
|
||||||
// Create Account service object
|
|
||||||
AccountService serviceTest = new AccountService();
|
|
||||||
serviceTest.CreateUserRecord(user, signedUser, dbSource);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "Disable Account":
|
|
||||||
//Console.WriteLine(operation);
|
|
||||||
//Console.WriteLine(operation);
|
|
||||||
if (String.IsNullOrEmpty(Role) && UN != null)
|
|
||||||
{
|
|
||||||
// Create UserAccount object
|
|
||||||
UserAccount user = new UserAccount(UN, PWD, Email, DateTime.UtcNow);
|
|
||||||
// Create Account service object
|
|
||||||
AccountService serviceTest = new AccountService();
|
|
||||||
serviceTest.CreateUserRecord(user, signedUser, dbSource);
|
|
||||||
}
|
|
||||||
else if (String.IsNullOrEmpty(Email) && UN != null)
|
|
||||||
{
|
|
||||||
// Create UserAccount object
|
|
||||||
UserAccount user = new UserAccount(UN, PWD, Role);
|
|
||||||
// Create Account service object
|
|
||||||
AccountService serviceTest = new AccountService();
|
|
||||||
serviceTest.CreateUserRecord(user, signedUser, dbSource);
|
|
||||||
}
|
|
||||||
else if (String.IsNullOrEmpty(Role) && String.IsNullOrEmpty(Email) && UN != null)
|
|
||||||
{
|
|
||||||
// Create UserAccount object
|
|
||||||
UserAccount user = new UserAccount(UN, PWD, DateTime.UtcNow);
|
|
||||||
// Create Account service object
|
|
||||||
AccountService serviceTest = new AccountService();
|
|
||||||
serviceTest.CreateUserRecord(user, signedUser, dbSource);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "Enable Account":
|
|
||||||
//Console.WriteLine(operation);
|
|
||||||
//Console.WriteLine(operation);
|
|
||||||
if (String.IsNullOrEmpty(Role) && UN != null)
|
|
||||||
{
|
|
||||||
// Create UserAccount object
|
|
||||||
UserAccount user = new UserAccount(UN, PWD, Email, DateTime.UtcNow);
|
|
||||||
// Create Account service object
|
|
||||||
AccountService serviceTest = new AccountService();
|
|
||||||
serviceTest.CreateUserRecord(user, signedUser, dbSource);
|
|
||||||
}
|
|
||||||
else if (String.IsNullOrEmpty(Email) && UN != null)
|
|
||||||
{
|
|
||||||
// Create UserAccount object
|
|
||||||
UserAccount user = new UserAccount(UN, PWD, Role);
|
|
||||||
// Create Account service object
|
|
||||||
AccountService serviceTest = new AccountService();
|
|
||||||
serviceTest.CreateUserRecord(user, signedUser, dbSource);
|
|
||||||
}
|
|
||||||
else if (String.IsNullOrEmpty(Role) && String.IsNullOrEmpty(Email) && UN != null)
|
|
||||||
{
|
|
||||||
// Create UserAccount object
|
|
||||||
UserAccount user = new UserAccount(UN, PWD, DateTime.UtcNow);
|
|
||||||
// Create Account service object
|
|
||||||
AccountService serviceTest = new AccountService();
|
|
||||||
serviceTest.CreateUserRecord(user, signedUser, dbSource);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fileRead.Close();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Error reading file");
|
|
||||||
Console.WriteLine(e.Message);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,150 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace TeamHobby.HobbyProjectGenerator.ServiceLayer
|
|
||||||
{ // Class for getting user credentials
|
|
||||||
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 string ConfirmPassword()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Please enter a password:");
|
|
||||||
string? userPassword = Console.ReadLine();
|
|
||||||
// Confirm Password
|
|
||||||
Console.WriteLine("Please re-enter the password:");
|
|
||||||
string checkPsswd = Console.ReadLine();
|
|
||||||
// Check if passwords match
|
|
||||||
if (userPassword == checkPsswd)
|
|
||||||
{
|
|
||||||
return userPassword;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("Passwords do not match.\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public string GetEmail()
|
|
||||||
{
|
|
||||||
Console.WriteLine("Please enter an email:");
|
|
||||||
return Console.ReadLine();
|
|
||||||
}
|
|
||||||
public string GetRole()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
// List of possible roles
|
|
||||||
List<string> roles = new List<string> {"Admin", "regular" };
|
|
||||||
// Get role
|
|
||||||
Console.WriteLine("Please enter the role of the user:(Admin or regular)");
|
|
||||||
string? userRole = Console.ReadLine();
|
|
||||||
// Check if passwords match
|
|
||||||
if (roles.Contains(userRole))
|
|
||||||
{
|
|
||||||
return userRole;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("Not an available role.\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return Console.ReadLine();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public class UserAccount
|
|
||||||
{
|
|
||||||
// Admin Credentials
|
|
||||||
private string _userName;
|
|
||||||
private string _password;
|
|
||||||
private DateTime _Time;
|
|
||||||
// New User Credentials
|
|
||||||
private string _Email;
|
|
||||||
private string _Role;
|
|
||||||
|
|
||||||
public UserAccount(string un, string pwd, DateTime TimeStamp)
|
|
||||||
{
|
|
||||||
_userName = un;
|
|
||||||
_password = pwd;
|
|
||||||
_Role = "regular";
|
|
||||||
_Email = "NULL";
|
|
||||||
_Time = TimeStamp;
|
|
||||||
}
|
|
||||||
public UserAccount(string un, string pwd, string role)
|
|
||||||
{
|
|
||||||
if (String.IsNullOrEmpty(role))
|
|
||||||
{
|
|
||||||
_Role = "regular";
|
|
||||||
}
|
|
||||||
else { _Role = role; }
|
|
||||||
_userName = un;
|
|
||||||
_password = pwd;
|
|
||||||
_Email = "NULL";
|
|
||||||
_Time = DateTime.UtcNow;
|
|
||||||
}
|
|
||||||
public UserAccount(string un, string role)
|
|
||||||
{
|
|
||||||
_userName = un;
|
|
||||||
_Role = role;
|
|
||||||
_Email = "NULL";
|
|
||||||
_Time = DateTime.UtcNow;
|
|
||||||
}
|
|
||||||
public UserAccount(string un, string pwd, string Email, DateTime TimeStamp)
|
|
||||||
{
|
|
||||||
if (String.IsNullOrEmpty(Email))
|
|
||||||
{
|
|
||||||
_Email = "NULL";
|
|
||||||
}
|
|
||||||
else { _Email = Email; }
|
|
||||||
_userName = un;
|
|
||||||
_password = pwd;
|
|
||||||
_Role = "regular";
|
|
||||||
_Time = TimeStamp;
|
|
||||||
}
|
|
||||||
public UserAccount(string newUN, string newPWD, string Email, string role, DateTime newTime)
|
|
||||||
{
|
|
||||||
if (String.IsNullOrEmpty(role))
|
|
||||||
{
|
|
||||||
_Role = "regular";
|
|
||||||
}
|
|
||||||
else { _Role = role; }
|
|
||||||
if (String.IsNullOrEmpty(Email))
|
|
||||||
{
|
|
||||||
_Email = "NULL";
|
|
||||||
}
|
|
||||||
else { _Email = Email; }
|
|
||||||
_userName = newUN;
|
|
||||||
_password = newPWD;
|
|
||||||
_Time = newTime;
|
|
||||||
}
|
|
||||||
public UserAccount()
|
|
||||||
{
|
|
||||||
_Role = "regular";
|
|
||||||
_Email = "NULL";
|
|
||||||
_Time = DateTime.Now;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string username { get { return _userName; } }
|
|
||||||
public string password { get { return _password; } }
|
|
||||||
public string email { get { return _Email; } }
|
|
||||||
public string role { get { return _Role; } }
|
|
||||||
public DateTime Time { get { return _Time; } }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,378 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Data.Odbc;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
|
||||||
using System.Threading;
|
|
||||||
using TeamHobby.HobbyProjectGenerator.ServiceLayer;
|
|
||||||
using TeamHobby.HobbyProjectGenerator.DataAccessLayer;
|
|
||||||
using Xunit;
|
|
||||||
using Xunit.Abstractions;
|
|
||||||
|
|
||||||
namespace TeamHobby.Archiving.xTests
|
|
||||||
|
|
||||||
|
|
||||||
{
|
|
||||||
public class ArchivingXUnitTest
|
|
||||||
{
|
|
||||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
|
||||||
"SERVER=localhost;" +
|
|
||||||
"DATABASE=hobby;" +
|
|
||||||
"UID=root;" +
|
|
||||||
"PASSWORD=Teamhobby;" +
|
|
||||||
"OPTION=3";
|
|
||||||
|
|
||||||
ITestOutputHelper output;
|
|
||||||
public ArchivingXUnitTest(ITestOutputHelper output)
|
|
||||||
{
|
|
||||||
this.output = output;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void IsArchiveFolderCreated()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
|
||||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
|
||||||
string folderPath = @"C:/HobbyArchive";
|
|
||||||
bool expectedVal = true;
|
|
||||||
|
|
||||||
// Act
|
|
||||||
archiveManager.CreateArchiveFolder();
|
|
||||||
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
bool actualVal = Directory.Exists(folderPath);
|
|
||||||
output.WriteLine("Actual value: {0}, Expected value: {1}", actualVal, expectedVal);
|
|
||||||
Assert.Equal(expectedVal, actualVal);
|
|
||||||
// Cleaning up directory after test
|
|
||||||
output.WriteLine("Cleaning up Folder and File used for testing... ");
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Directory.Delete(folderPath, true);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
Console.WriteLine("Folder failed to be deleted");
|
|
||||||
}
|
|
||||||
output.WriteLine("Cleaning up completed. ");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void IsFileNameCreated()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
|
||||||
string foldPath = @"C:\HobbyArchive";
|
|
||||||
string fileName = DateTime.Now.ToString("M_d_yyyy") + "_archive.csv";
|
|
||||||
string expectedFilePath = System.IO.Path.Combine(foldPath, fileName);
|
|
||||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
string actualFilePath = archiveManager.CreateOutFileName();
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
|
|
||||||
Assert.Equal(expectedFilePath, actualFilePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void IsCSVFileExist()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
|
||||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
|
||||||
SqlDAO sqlDS = null;
|
|
||||||
string folderPath = @"C:/HobbyArchive";
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
bool folderRes = archiveManager.CreateArchiveFolder();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Folder creation for copying failed");
|
|
||||||
}
|
|
||||||
string filePath = archiveManager.CreateOutFileName();
|
|
||||||
bool expectedVal = true;
|
|
||||||
|
|
||||||
if (sqlDAO.GetType() == typeof(SqlDAO))
|
|
||||||
{
|
|
||||||
sqlDS = (SqlDAO)sqlDAO;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Act
|
|
||||||
if (sqlDS != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
sqlDS.CopyToFile(filePath);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Copying to a file failed !!");
|
|
||||||
Console.WriteLine(ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
bool actualVal = File.Exists(filePath);
|
|
||||||
output.WriteLine("Actual value: {0}, Expected value: {1}", actualVal, expectedVal);
|
|
||||||
Assert.Equal(expectedVal, actualVal);
|
|
||||||
output.WriteLine("Cleaning up Folder and File used for testing... ");
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Directory.Delete(folderPath, true);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
Console.WriteLine("Folder failed to be deleted");
|
|
||||||
}
|
|
||||||
output.WriteLine("Cleaning up completed. ");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void IsEntriesRemoved()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
|
||||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
|
||||||
OdbcDataReader odbcObj = null;
|
|
||||||
Object resultData = null;
|
|
||||||
bool expectedVal = false;
|
|
||||||
|
|
||||||
sqlDAO.WriteData("INSERT into log(LtimeStamp, LvName, catname, userop, logmessage) values" +
|
|
||||||
"('2021-08-07 23:00:00', 'Info', 'View', 'create some projects', 'new account created')," +
|
|
||||||
"('2021-06-04 23:00:00', 'Info', 'Business', 'create some projects', 'new projects made')," +
|
|
||||||
"('2021-07-02 23:00:00', 'Info', 'View', 'log out', 'log out successful')," +
|
|
||||||
"('2021-09-03 23:00:00', 'Info', 'Business', 'log in', 'log in successfully')," +
|
|
||||||
"('2021-10-20 23:00:00', 'Info', 'View', 'search for projects', 'result return');");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
sqlDAO.RemoveEntries();
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
bool actualVal;
|
|
||||||
|
|
||||||
resultData = sqlDAO.ReadData("SELECT * FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;");
|
|
||||||
if ((resultData != null) && (resultData.GetType() == typeof(OdbcDataReader)))
|
|
||||||
{
|
|
||||||
odbcObj = (OdbcDataReader)resultData;
|
|
||||||
}
|
|
||||||
OdbcConnection conn = sqlDAO.GetConnection();
|
|
||||||
actualVal = odbcObj.HasRows;
|
|
||||||
conn.Close();
|
|
||||||
|
|
||||||
output.WriteLine("Actual value: {0}, Expected value: {1}", actualVal, expectedVal);
|
|
||||||
Assert.Equal(expectedVal, actualVal);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void IsOutputFileRemoved()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
|
||||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
|
||||||
bool expectedVal = false;
|
|
||||||
//Thread.Sleep(5000);
|
|
||||||
|
|
||||||
// Create the folder and the csv file for compressing
|
|
||||||
archiveManager.CreateArchiveFolder();
|
|
||||||
string filepath = archiveManager.CreateOutFileName();
|
|
||||||
sqlDAO.CopyToFile(filepath);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
if (sqlDAO != null)
|
|
||||||
{
|
|
||||||
sqlDAO.RemoveOutputFile(filepath);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
bool actualVal = File.Exists(filepath);
|
|
||||||
Assert.Equal(expectedVal, actualVal);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void IsFileCompressed()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
|
||||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
|
||||||
|
|
||||||
// Create the folder and the csv file to be compressed.
|
|
||||||
archiveManager.CreateArchiveFolder();
|
|
||||||
string filePath = archiveManager.CreateOutFileName();
|
|
||||||
sqlDAO.CopyToFile(filePath);
|
|
||||||
FileAttributes expectedAttribute = FileAttributes.Archive;
|
|
||||||
string compFilePath = Path.ChangeExtension(filePath, ".gz");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
sqlDAO.CompressFile(filePath);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
FileAttributes actualAttribute = File.GetAttributes(compFilePath);
|
|
||||||
output.WriteLine("Actual value: {0}, Expected value: {1}", actualAttribute, expectedAttribute);
|
|
||||||
Assert.Equal(expectedAttribute, actualAttribute);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void IsArchive_Under_60s_10kRecords()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
|
||||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
|
||||||
var timer = new Stopwatch();
|
|
||||||
double expectedVal = 60;
|
|
||||||
string folderPath = @"C:/HobbyArchive";
|
|
||||||
|
|
||||||
sqlDAO.WriteData("INSERT into log(LtimeStamp, LvName, catname, userop, logmessage) values" +
|
|
||||||
"('2021-08-07 23:00:00', 'Info', 'View', 'create some projects', 'new account created')," +
|
|
||||||
"('2021-06-04 23:00:00', 'Info', 'Business', 'create some projects', 'new projects made')," +
|
|
||||||
"('2021-07-02 23:00:00', 'Info', 'View', 'log out', 'log out successful')," +
|
|
||||||
"('2021-09-03 23:00:00', 'Info', 'Business', 'log in', 'log in successfully')," +
|
|
||||||
"('2021-10-20 23:00:00', 'Info', 'View', 'search for projects', 'result return');");
|
|
||||||
|
|
||||||
for (int i = 0; i <= 11; i++)
|
|
||||||
{
|
|
||||||
sqlDAO.WriteData("INSERT INTO log(LtimeStamp, LvName, catName, userOP, logMessage) " +
|
|
||||||
"SELECT LtimeStamp, LvName, catName, userOP, logMessage FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Act
|
|
||||||
timer.Start();
|
|
||||||
archiveManager.Controller();
|
|
||||||
timer.Stop();
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
var actualVal = timer.Elapsed.Seconds;
|
|
||||||
output.WriteLine("Actual value: {0}s, Expected value: {1}s", actualVal, expectedVal);
|
|
||||||
Assert.True(actualVal < expectedVal);
|
|
||||||
|
|
||||||
// Clean up resources after testing
|
|
||||||
output.WriteLine("Cleaning up Folder and File used for testing... ");
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Directory.Delete(folderPath, true);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
Console.WriteLine("Folder failed to be deleted");
|
|
||||||
}
|
|
||||||
output.WriteLine("Cleaning up completed... ");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void IsArchive_Under_60s_1mRecords()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
|
||||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
|
||||||
var timer = new Stopwatch();
|
|
||||||
double expectedVal = 60;
|
|
||||||
string folderPath = @"C:/HobbyArchive";
|
|
||||||
|
|
||||||
sqlDAO.WriteData("INSERT into log(LtimeStamp, LvName, catname, userop, logmessage) values" +
|
|
||||||
"('2021-08-07 23:00:00', 'Info', 'View', 'create some projects', 'new account created')," +
|
|
||||||
"('2021-06-04 23:00:00', 'Info', 'Business', 'create some projects', 'new projects made')," +
|
|
||||||
"('2021-07-02 23:00:00', 'Info', 'View', 'log out', 'log out successful')," +
|
|
||||||
"('2021-09-03 23:00:00', 'Info', 'Business', 'log in', 'log in successfully')," +
|
|
||||||
"('2021-10-20 23:00:00', 'Info', 'View', 'search for projects', 'result return');");
|
|
||||||
|
|
||||||
for (int i = 0; i <= 18; i++)
|
|
||||||
{
|
|
||||||
sqlDAO.WriteData("INSERT INTO log(LtimeStamp, LvName, catName, userOP, logMessage) " +
|
|
||||||
"SELECT LtimeStamp, LvName, catName, userOP, logMessage FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Act
|
|
||||||
timer.Start();
|
|
||||||
archiveManager.Controller();
|
|
||||||
timer.Stop();
|
|
||||||
|
|
||||||
// Arrange
|
|
||||||
double actualVal = timer.Elapsed.Seconds;
|
|
||||||
output.WriteLine("Actual value: {0}s, Expected value: {1}s", actualVal, expectedVal);
|
|
||||||
Assert.True(actualVal < expectedVal);
|
|
||||||
|
|
||||||
output.WriteLine("Cleaning up Folder and File used for testing... ");
|
|
||||||
//Clean up resources after testing
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Directory.Delete(folderPath, true);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
Console.WriteLine("Folder failed to be deleted");
|
|
||||||
}
|
|
||||||
output.WriteLine("Cleaning up completed... ");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
// [Test Method]
|
|
||||||
public void IsProcessFlowCompleted()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
|
||||||
ArchiveManager archive = new ArchiveManager(sqlDAO);
|
|
||||||
bool expectedVal = true;
|
|
||||||
bool actualVal = false;
|
|
||||||
string folderPath = @"C:/HobbyArchive";
|
|
||||||
|
|
||||||
// Adding 10000 records to database for testing
|
|
||||||
sqlDAO.WriteData("INSERT into log(LtimeStamp, LvName, catname, userop, logmessage) values" +
|
|
||||||
"('2021-08-07 23:00:00', 'Info', 'View', 'create some projects', 'new account created')," +
|
|
||||||
"('2021-06-04 23:00:00', 'Info', 'Business', 'create some projects', 'new projects made')," +
|
|
||||||
"('2021-07-02 23:00:00', 'Info', 'View', 'log out', 'log out successful')," +
|
|
||||||
"('2021-09-03 23:00:00', 'Info', 'Business', 'log in', 'log in successfully')," +
|
|
||||||
"('2021-10-20 23:00:00', 'Info', 'View', 'search for projects', 'result return');");
|
|
||||||
|
|
||||||
for (int j = 0; j <= 11; j++)
|
|
||||||
{
|
|
||||||
sqlDAO.WriteData("INSERT INTO log(LtimeStamp, LvName, catName, userOP, logMessage) " +
|
|
||||||
"SELECT LtimeStamp, LvName, catName, userOP, logMessage FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Act
|
|
||||||
// Testing archive Manager
|
|
||||||
int i = -10;
|
|
||||||
while (i < 20)
|
|
||||||
{
|
|
||||||
DateTime date1 = new DateTime(2021, 12, 1, 0, 0, 0);
|
|
||||||
string currentTime = "00:00:00 AM";
|
|
||||||
string currentDate = i.ToString();
|
|
||||||
|
|
||||||
if (i == 1)
|
|
||||||
{
|
|
||||||
currentDate = date1.ToString("dd");
|
|
||||||
}
|
|
||||||
|
|
||||||
//Console.WriteLine("Current date: {0}, Current Time: {1}", currentDate, currentTime);
|
|
||||||
Console.WriteLine("Current date: {0}, Current Time: {1}", currentDate, currentTime);
|
|
||||||
if (String.Equals(currentDate, "01") && String.Equals(currentTime, "00:00:00 AM"))
|
|
||||||
{
|
|
||||||
Console.WriteLine("Archiving process Start");
|
|
||||||
actualVal = archive.Controller();
|
|
||||||
}
|
|
||||||
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
output.WriteLine("Actual value: {0}, Expected value: {1}", actualVal, expectedVal);
|
|
||||||
Assert.Equal(expectedVal, actualVal);
|
|
||||||
output.WriteLine("Cleaning up Folder and File used for testing... ");
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Directory.Delete(folderPath, true);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
Console.WriteLine("Folder failed to be deleted");
|
|
||||||
}
|
|
||||||
output.WriteLine("Cleaning up completed... ");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
|
|
||||||
<IsPackable>false</IsPackable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
|
|
||||||
<PackageReference Include="xunit" Version="2.4.1" />
|
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
||||||
<PrivateAssets>all</PrivateAssets>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="coverlet.collector" Version="3.1.0">
|
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
||||||
<PrivateAssets>all</PrivateAssets>
|
|
||||||
</PackageReference>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\..\main\TeamHobby.HobbyProjectGenerator.Main.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@ -1,264 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Xunit;
|
|
||||||
using Xunit.Abstractions;
|
|
||||||
using System.Threading;
|
|
||||||
using TeamHobby.HobbyProjectGenerator.ServiceLayer;
|
|
||||||
using TeamHobby.HobbyProjectGenerator.DataAccessLayer;
|
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
namespace TeamHobby.UserManagement.xTests
|
|
||||||
{
|
|
||||||
public class UseerManagementTests
|
|
||||||
{
|
|
||||||
|
|
||||||
ITestOutputHelper output;
|
|
||||||
public UseerManagementTests(ITestOutputHelper output)
|
|
||||||
{
|
|
||||||
this.output = output;
|
|
||||||
}
|
|
||||||
// User is able to perform any single UM operation within 5 seconds upon invocation.A system message displays “UM operation was successful”
|
|
||||||
[Fact]
|
|
||||||
public void SingleOperationinFiveSec()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
DateTime sTime = DateTime.Now;
|
|
||||||
var TestAcc = new UserAccount("newUser", "4567", "email@a.com", "regular", sTime);
|
|
||||||
var serviceTest = new AccountService();
|
|
||||||
string dbType = "sql";
|
|
||||||
RDSFactory dbFactory = new RDSFactory();
|
|
||||||
|
|
||||||
// Testing Data Access Layer
|
|
||||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
|
||||||
"TCPIP=1;" +
|
|
||||||
"SERVER=localhost;" +
|
|
||||||
"DATABASE=hobby;" +
|
|
||||||
"UID=root;" +
|
|
||||||
"PASSWORD=Teamhobby;" +
|
|
||||||
"OPTION=3";
|
|
||||||
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
// Create a file
|
|
||||||
serviceTest.CreateUserRecord(TestAcc, "Rifat", datasource);
|
|
||||||
DateTime eTime = DateTime.Now;
|
|
||||||
TimeSpan timeDiff = (eTime - sTime);
|
|
||||||
var sec = timeDiff.TotalSeconds;
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
if (sec > 5)
|
|
||||||
{
|
|
||||||
output.WriteLine("Single Operation was unsuccessful");
|
|
||||||
Assert.True(false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Assert.True(true);
|
|
||||||
output.WriteLine("Single Operation was successful");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Single UM operation takes longer than 5 seconds
|
|
||||||
[Fact]
|
|
||||||
public void FailSingleOperationinFiveSec()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
DateTime sTime = DateTime.Now;
|
|
||||||
var TestAcc = new UserAccount("newUser", "4567", "email@a.com", "regular", sTime);
|
|
||||||
var serviceTest = new AccountService();
|
|
||||||
string dbType = "sql";
|
|
||||||
RDSFactory dbFactory = new RDSFactory();
|
|
||||||
|
|
||||||
// Testing Data Access Layer
|
|
||||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
|
||||||
"TCPIP=1;" +
|
|
||||||
"SERVER=localhost;" +
|
|
||||||
"DATABASE=hobby;" +
|
|
||||||
"UID=root;" +
|
|
||||||
"PASSWORD=Teamhobby;" +
|
|
||||||
"OPTION=3";
|
|
||||||
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
// Create a file
|
|
||||||
serviceTest.CreateUserRecord(TestAcc, "Rifat", datasource);
|
|
||||||
Thread.Sleep(6000);
|
|
||||||
DateTime eTime = DateTime.Now;
|
|
||||||
TimeSpan timeDiff = (eTime - sTime);
|
|
||||||
var sec = timeDiff.TotalSeconds;
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
if (sec > 5)
|
|
||||||
{
|
|
||||||
output.WriteLine("Single Operation was unsuccessful");
|
|
||||||
Assert.False(false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Assert.True(false);
|
|
||||||
output.WriteLine("Single Operation was successful");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Single UM operation completes within 5 seconds, but no system message is shown or inaccurate system message is shown
|
|
||||||
[Fact]
|
|
||||||
public void SingleOperationwithMessage()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
DateTime sTime = DateTime.Now;
|
|
||||||
var TestAcc = new UserAccount("newUserMessage", "4567", "email@a.com", "regular", sTime);
|
|
||||||
var serviceTest = new AccountService();
|
|
||||||
string dbType = "sql";
|
|
||||||
RDSFactory dbFactory = new RDSFactory();
|
|
||||||
var checkMess = false;
|
|
||||||
// Testing Data Access Layer
|
|
||||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
|
||||||
"TCPIP=1;" +
|
|
||||||
"SERVER=localhost;" +
|
|
||||||
"DATABASE=hobby;" +
|
|
||||||
"UID=root;" +
|
|
||||||
"PASSWORD=Teamhobby;" +
|
|
||||||
"OPTION=3";
|
|
||||||
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
// Create a file
|
|
||||||
serviceTest.CreateUserRecord(TestAcc, "Rifat", datasource);
|
|
||||||
DateTime eTime = DateTime.Now;
|
|
||||||
TimeSpan timeDiff = (eTime - sTime);
|
|
||||||
var sec = timeDiff.TotalSeconds;
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
if (sec > 5)
|
|
||||||
{
|
|
||||||
var message = "Single Operation was unsuccessful";
|
|
||||||
Assert.False(true);
|
|
||||||
output.WriteLine(message);
|
|
||||||
if (checkMess)
|
|
||||||
{
|
|
||||||
Assert.False(true);
|
|
||||||
throw new Exception("Message was not printed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Assert.True(true);
|
|
||||||
var message2 = "Single Operation was successful";
|
|
||||||
output.WriteLine(message2);
|
|
||||||
if (!checkMess)
|
|
||||||
{
|
|
||||||
output.WriteLine("Message was printed");
|
|
||||||
Assert.True(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Bulk UM operations completes within 60 seconds, but no system message is shown or inaccurate system message is shown
|
|
||||||
[Fact]
|
|
||||||
public void BulkOperationwithMessage()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
DateTime sTime = DateTime.Now;
|
|
||||||
var checkMess = false;
|
|
||||||
var serviceTest = new AccountService();
|
|
||||||
string dbType = "sql";
|
|
||||||
RDSFactory dbFactory = new RDSFactory();
|
|
||||||
string path = Directory.GetCurrentDirectory();
|
|
||||||
|
|
||||||
|
|
||||||
// Testing Data Access Layer
|
|
||||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
|
||||||
"TCPIP=1;" +
|
|
||||||
"SERVER=localhost;" +
|
|
||||||
"DATABASE=hobby;" +
|
|
||||||
"UID=root;" +
|
|
||||||
"PASSWORD=Teamhobby;" +
|
|
||||||
"OPTION=3";
|
|
||||||
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
// Create a file
|
|
||||||
//for (int i = 0; i < 10000; i++)
|
|
||||||
//{
|
|
||||||
//var TestAcc = new UserAccount("newUser" + $"{i}", "4567", $"email{i}@a.com", "regular", sTime);
|
|
||||||
serviceTest.BulkOperation("Rifat", path + "\\Bulk.txt", datasource);
|
|
||||||
//}
|
|
||||||
|
|
||||||
DateTime eTime = DateTime.Now;
|
|
||||||
TimeSpan timeDiff = (eTime - sTime);
|
|
||||||
var sec = timeDiff.TotalSeconds;
|
|
||||||
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
if (sec > 60)
|
|
||||||
{
|
|
||||||
var message = "Bulk Operation was unsuccessful";
|
|
||||||
Assert.True(false);
|
|
||||||
output.WriteLine(message);
|
|
||||||
if (checkMess)
|
|
||||||
{
|
|
||||||
Assert.True(false);
|
|
||||||
throw new Exception("Message was not printed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Assert.True(true);
|
|
||||||
var message2 = "Bulk Operation was successful";
|
|
||||||
output.WriteLine(message2);
|
|
||||||
if (!checkMess)
|
|
||||||
{
|
|
||||||
output.WriteLine("Message was printed");
|
|
||||||
Assert.True(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// User is able to perform less than 10K UM operations in bulk within 60 seconds. A system message displays “Bulk UM operation was successful”
|
|
||||||
[Fact]
|
|
||||||
public void BulkOperationforSixty()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
DateTime sTime = DateTime.Now;
|
|
||||||
|
|
||||||
var serviceTest = new AccountService();
|
|
||||||
string dbType = "sql";
|
|
||||||
RDSFactory dbFactory = new RDSFactory();
|
|
||||||
string dir = Directory.GetCurrentDirectory();
|
|
||||||
string path = dir + "\\Bulk.txt";
|
|
||||||
output.WriteLine(path);
|
|
||||||
|
|
||||||
|
|
||||||
// Testing Data Access Layer
|
|
||||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
|
||||||
"TCPIP=1;" +
|
|
||||||
"SERVER=localhost;" +
|
|
||||||
"DATABASE=hobby;" +
|
|
||||||
"UID=root;" +
|
|
||||||
"PASSWORD=Teamhobby;" +
|
|
||||||
"OPTION=3";
|
|
||||||
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
// Create a file
|
|
||||||
//for (int i = 0; i < 10000; i++)
|
|
||||||
//{
|
|
||||||
//var TestAcc = new UserAccount("newUser" + $"{i}", "4567", $"email{i}@a.com", "regular", sTime);
|
|
||||||
serviceTest.BulkOperation("Rifat", path, datasource);
|
|
||||||
//}
|
|
||||||
|
|
||||||
DateTime eTime = DateTime.Now;
|
|
||||||
TimeSpan timeDiff = (eTime - sTime);
|
|
||||||
var sec = timeDiff.TotalSeconds;
|
|
||||||
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
if (sec > 60)
|
|
||||||
{
|
|
||||||
output.WriteLine("Bulk Operation was unsuccessful");
|
|
||||||
Assert.True(false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Assert.True(true);
|
|
||||||
output.WriteLine("Bulk Operation was successful");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
namespace TeamHobby.HobbyProjectGenerator.View
|
|
||||||
{
|
|
||||||
public class Class1
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
namespace TeamHobby.HobbyProjectGenerator.ViewModel
|
|
||||||
{
|
|
||||||
public class Class1
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -3,79 +3,70 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.0.31919.166
|
VisualStudioVersion = 17.0.31919.166
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.Main", "..\main\TeamHobby.HobbyProjectGenerator.Main.csproj", "{30C7EBF3-3957-46E5-86C1-C13356841ECA}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.UserManagement.Tests", "..\TeamHobby.UserManagement.Tests\TeamHobby.UserManagement.Tests.csproj", "{5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D29D9225-3748-4067-AF07-E677A525EF39}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.Models", "..\TeamHobby.HobbyProjectGenerator.Models\TeamHobby.HobbyProjectGenerator.Models.csproj", "{75DED6C2-D404-4E71-A58B-0F616DB5C062}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
|
||||||
TeamHobby.HobbyProjectGenerator.csproj = TeamHobby.HobbyProjectGenerator.csproj
|
|
||||||
EndProjectSection
|
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.Tests", "TeamHobby.HobbyProjectGenerator.Tests\TeamHobby.HobbyProjectGenerator.Tests.csproj", "{2E9DC0A0-D9A1-40A5-9684-ECC8EDCD8DAD}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "main", "..\main\main.csproj", "{30C7EBF3-3957-46E5-86C1-C13356841ECA}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.ServiceLayer", "TeamHobby.HobbyProjectGenerator.ServiceLayer\TeamHobby.HobbyProjectGenerator.ServiceLayer.csproj", "{EF90CC6C-0C44-4E39-AAB6-96F9F34F0784}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.Archive", "..\TeamHobby.HobbyProjectGenerator.Archive\TeamHobby.HobbyProjectGenerator.Archive.csproj", "{B88ED0D9-72E2-4245-BD8F-856FF42E500C}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.DataAccessLayer", "..\TeamHobby.HobbyProjectGenerator.DataAccessLayer\TeamHobby.HobbyProjectGenerator.DataAccessLayer.csproj", "{6DBAC411-AC0E-4129-AE57-C8D1DA1DF9B2}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.Main", "..\TeamHobby.Main\TeamHobby.Main.csproj", "{ED126EFB-B337-42F9-BE4B-65A5AE90503B}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamHobby.HobbyProjectGenerator.ViewModel", "TeamHobby.HobbyProjectGenerator.ViewModel\TeamHobby.HobbyProjectGenerator.ViewModel.csproj", "{092F7372-3CBA-49A2-A7A8-EC3FF97E3082}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.DataAccess", "..\TeamHobby.HobbyProjectGenerator.DataAccess\TeamHobby.HobbyProjectGenerator.DataAccess.csproj", "{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamHobby.HobbyProjectGenerator.View", "TeamHobby.HobbyProjectGenerator.View\TeamHobby.HobbyProjectGenerator.View.csproj", "{2E401E9D-731B-425D-B0BD-FF1E72D5D23C}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.Logging", "..\TeamHobby.HobbyProjectGenerator.Logging\TeamHobby.HobbyProjectGenerator.Logging.csproj", "{C0494115-838E-43A3-8896-133E5D1E874A}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.UserManagement", "..\TeamHobby.HobbyProjectGenerator.UserManagement\TeamHobby.HobbyProjectGenerator.UserManagement.csproj", "{2E7193B8-86B6-48DA-9671-CD84615A5F5D}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.Logging.Tests", "..\TeamHobby.HobbyProjectGenerator.Logging.Tests\TeamHobby.HobbyProjectGenerator.Logging.Tests.csproj", "{CA8D11CF-807C-4C90-A529-0371F73518F6}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.ArchiveTests", "..\TeamHobby.HobbyProjectGenerator.ArchiveTests\TeamHobby.HobbyProjectGenerator.ArchiveTests.csproj", "{C5EBD1F8-C806-4BF9-B2D7-8876072630FD}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
Debug|x86 = Debug|x86
|
|
||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
Release|x86 = Release|x86
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{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}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{75DED6C2-D404-4E71-A58B-0F616DB5C062}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{75DED6C2-D404-4E71-A58B-0F616DB5C062}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Debug|x86.ActiveCfg = Debug|Any CPU
|
|
||||||
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Debug|x86.Build.0 = Debug|Any CPU
|
|
||||||
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Release|Any CPU.Build.0 = Release|Any CPU
|
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Release|x86.ActiveCfg = Release|Any CPU
|
{B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Release|x86.Build.0 = Release|Any CPU
|
{B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{2E9DC0A0-D9A1-40A5-9684-ECC8EDCD8DAD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{2E9DC0A0-D9A1-40A5-9684-ECC8EDCD8DAD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{2E9DC0A0-D9A1-40A5-9684-ECC8EDCD8DAD}.Debug|x86.ActiveCfg = Debug|Any CPU
|
{ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{2E9DC0A0-D9A1-40A5-9684-ECC8EDCD8DAD}.Debug|x86.Build.0 = Debug|Any CPU
|
{ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{2E9DC0A0-D9A1-40A5-9684-ECC8EDCD8DAD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{2E9DC0A0-D9A1-40A5-9684-ECC8EDCD8DAD}.Release|Any CPU.Build.0 = Release|Any CPU
|
{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{2E9DC0A0-D9A1-40A5-9684-ECC8EDCD8DAD}.Release|x86.ActiveCfg = Release|Any CPU
|
{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{2E9DC0A0-D9A1-40A5-9684-ECC8EDCD8DAD}.Release|x86.Build.0 = Release|Any CPU
|
{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{EF90CC6C-0C44-4E39-AAB6-96F9F34F0784}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{EF90CC6C-0C44-4E39-AAB6-96F9F34F0784}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{C0494115-838E-43A3-8896-133E5D1E874A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{EF90CC6C-0C44-4E39-AAB6-96F9F34F0784}.Debug|x86.ActiveCfg = Debug|Any CPU
|
{C0494115-838E-43A3-8896-133E5D1E874A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{EF90CC6C-0C44-4E39-AAB6-96F9F34F0784}.Debug|x86.Build.0 = Debug|Any CPU
|
{C0494115-838E-43A3-8896-133E5D1E874A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{EF90CC6C-0C44-4E39-AAB6-96F9F34F0784}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{C0494115-838E-43A3-8896-133E5D1E874A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{EF90CC6C-0C44-4E39-AAB6-96F9F34F0784}.Release|Any CPU.Build.0 = Release|Any CPU
|
{2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{EF90CC6C-0C44-4E39-AAB6-96F9F34F0784}.Release|x86.ActiveCfg = Release|Any CPU
|
{2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{EF90CC6C-0C44-4E39-AAB6-96F9F34F0784}.Release|x86.Build.0 = Release|Any CPU
|
{2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{6DBAC411-AC0E-4129-AE57-C8D1DA1DF9B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{6DBAC411-AC0E-4129-AE57-C8D1DA1DF9B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{CA8D11CF-807C-4C90-A529-0371F73518F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{6DBAC411-AC0E-4129-AE57-C8D1DA1DF9B2}.Debug|x86.ActiveCfg = Debug|Any CPU
|
{CA8D11CF-807C-4C90-A529-0371F73518F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{6DBAC411-AC0E-4129-AE57-C8D1DA1DF9B2}.Debug|x86.Build.0 = Debug|Any CPU
|
{CA8D11CF-807C-4C90-A529-0371F73518F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{6DBAC411-AC0E-4129-AE57-C8D1DA1DF9B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{CA8D11CF-807C-4C90-A529-0371F73518F6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{6DBAC411-AC0E-4129-AE57-C8D1DA1DF9B2}.Release|Any CPU.Build.0 = Release|Any CPU
|
{C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{6DBAC411-AC0E-4129-AE57-C8D1DA1DF9B2}.Release|x86.ActiveCfg = Release|Any CPU
|
{C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{6DBAC411-AC0E-4129-AE57-C8D1DA1DF9B2}.Release|x86.Build.0 = Release|Any CPU
|
{C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{092F7372-3CBA-49A2-A7A8-EC3FF97E3082}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{092F7372-3CBA-49A2-A7A8-EC3FF97E3082}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{092F7372-3CBA-49A2-A7A8-EC3FF97E3082}.Debug|x86.ActiveCfg = Debug|Any CPU
|
|
||||||
{092F7372-3CBA-49A2-A7A8-EC3FF97E3082}.Debug|x86.Build.0 = Debug|Any CPU
|
|
||||||
{092F7372-3CBA-49A2-A7A8-EC3FF97E3082}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{092F7372-3CBA-49A2-A7A8-EC3FF97E3082}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{092F7372-3CBA-49A2-A7A8-EC3FF97E3082}.Release|x86.ActiveCfg = Release|Any CPU
|
|
||||||
{092F7372-3CBA-49A2-A7A8-EC3FF97E3082}.Release|x86.Build.0 = Release|Any CPU
|
|
||||||
{2E401E9D-731B-425D-B0BD-FF1E72D5D23C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{2E401E9D-731B-425D-B0BD-FF1E72D5D23C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{2E401E9D-731B-425D-B0BD-FF1E72D5D23C}.Debug|x86.ActiveCfg = Debug|Any CPU
|
|
||||||
{2E401E9D-731B-425D-B0BD-FF1E72D5D23C}.Debug|x86.Build.0 = Debug|Any CPU
|
|
||||||
{2E401E9D-731B-425D-B0BD-FF1E72D5D23C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{2E401E9D-731B-425D-B0BD-FF1E72D5D23C}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{2E401E9D-731B-425D-B0BD-FF1E72D5D23C}.Release|x86.ActiveCfg = Release|Any CPU
|
|
||||||
{2E401E9D-731B-425D-B0BD-FF1E72D5D23C}.Release|x86.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@ -1,28 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
|
|
||||||
<IsPackable>false</IsPackable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
|
|
||||||
<PackageReference Include="xunit" Version="2.4.1" />
|
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
||||||
<PrivateAssets>all</PrivateAssets>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="coverlet.collector" Version="3.1.0">
|
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
||||||
<PrivateAssets>all</PrivateAssets>
|
|
||||||
</PackageReference>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\..\TeamHobby.HobbyProjectGenerator.DataAccess\TeamHobby.HobbyProjectGenerator.DataAccess.csproj" />
|
|
||||||
<ProjectReference Include="..\..\TeamHobby.HobbyProjectGenerator.UserManagement\TeamHobby.HobbyProjectGenerator.UserManagement.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@ -1,264 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Xunit;
|
|
||||||
using Xunit.Abstractions;
|
|
||||||
using System.Threading;
|
|
||||||
using TeamHobby.HobbyProjectGenerator.UserManagement;
|
|
||||||
using TeamHobby.HobbyProjectGenerator.DataAccess;
|
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
namespace TeamHobby.UserManagement.xTests
|
|
||||||
{
|
|
||||||
public class UseerManagementTests
|
|
||||||
{
|
|
||||||
|
|
||||||
ITestOutputHelper output;
|
|
||||||
public UseerManagementTests(ITestOutputHelper output)
|
|
||||||
{
|
|
||||||
this.output = output;
|
|
||||||
}
|
|
||||||
// User is able to perform any single UM operation within 5 seconds upon invocation.A system message displays “UM operation was successful”
|
|
||||||
[Fact]
|
|
||||||
public void SingleOperationinFiveSec()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
DateTime sTime = DateTime.Now;
|
|
||||||
var TestAcc = new UserAccount("newUser", "4567", "email@a.com", "regular", sTime);
|
|
||||||
var serviceTest = new AccountService();
|
|
||||||
string dbType = "sql";
|
|
||||||
RDSFactory dbFactory = new RDSFactory();
|
|
||||||
|
|
||||||
// Testing Data Access Layer
|
|
||||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
|
||||||
"TCPIP=1;" +
|
|
||||||
"SERVER=localhost;" +
|
|
||||||
"DATABASE=hobby;" +
|
|
||||||
"UID=root;" +
|
|
||||||
"PASSWORD=Teamhobby;" +
|
|
||||||
"OPTION=3";
|
|
||||||
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
// Create a file
|
|
||||||
serviceTest.CreateUserRecord(TestAcc, "Rifat", datasource);
|
|
||||||
DateTime eTime = DateTime.Now;
|
|
||||||
TimeSpan timeDiff = (eTime - sTime);
|
|
||||||
var sec = timeDiff.TotalSeconds;
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
if (sec > 5)
|
|
||||||
{
|
|
||||||
output.WriteLine("Single Operation was unsuccessful");
|
|
||||||
Assert.True(false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Assert.True(true);
|
|
||||||
output.WriteLine("Single Operation was successful");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Single UM operation takes longer than 5 seconds
|
|
||||||
[Fact]
|
|
||||||
public void FailSingleOperationinFiveSec()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
DateTime sTime = DateTime.Now;
|
|
||||||
var TestAcc = new UserAccount("newUser", "4567", "email@a.com", "regular", sTime);
|
|
||||||
var serviceTest = new AccountService();
|
|
||||||
string dbType = "sql";
|
|
||||||
RDSFactory dbFactory = new RDSFactory();
|
|
||||||
|
|
||||||
// Testing Data Access Layer
|
|
||||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
|
||||||
"TCPIP=1;" +
|
|
||||||
"SERVER=localhost;" +
|
|
||||||
"DATABASE=hobby;" +
|
|
||||||
"UID=root;" +
|
|
||||||
"PASSWORD=Teamhobby;" +
|
|
||||||
"OPTION=3";
|
|
||||||
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
// Create a file
|
|
||||||
serviceTest.CreateUserRecord(TestAcc, "Rifat", datasource);
|
|
||||||
Thread.Sleep(6000);
|
|
||||||
DateTime eTime = DateTime.Now;
|
|
||||||
TimeSpan timeDiff = (eTime - sTime);
|
|
||||||
var sec = timeDiff.TotalSeconds;
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
if (sec > 5)
|
|
||||||
{
|
|
||||||
output.WriteLine("Single Operation was unsuccessful");
|
|
||||||
Assert.False(false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Assert.True(false);
|
|
||||||
output.WriteLine("Single Operation was successful");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Single UM operation completes within 5 seconds, but no system message is shown or inaccurate system message is shown
|
|
||||||
[Fact]
|
|
||||||
public void SingleOperationwithMessage()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
DateTime sTime = DateTime.Now;
|
|
||||||
var TestAcc = new UserAccount("newUserMessage", "4567", "email@a.com", "regular", sTime);
|
|
||||||
var serviceTest = new AccountService();
|
|
||||||
string dbType = "sql";
|
|
||||||
RDSFactory dbFactory = new RDSFactory();
|
|
||||||
var checkMess = false;
|
|
||||||
// Testing Data Access Layer
|
|
||||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
|
||||||
"TCPIP=1;" +
|
|
||||||
"SERVER=localhost;" +
|
|
||||||
"DATABASE=hobby;" +
|
|
||||||
"UID=root;" +
|
|
||||||
"PASSWORD=Teamhobby;" +
|
|
||||||
"OPTION=3";
|
|
||||||
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
// Create a file
|
|
||||||
serviceTest.CreateUserRecord(TestAcc, "Rifat", datasource);
|
|
||||||
DateTime eTime = DateTime.Now;
|
|
||||||
TimeSpan timeDiff = (eTime - sTime);
|
|
||||||
var sec = timeDiff.TotalSeconds;
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
if (sec > 5)
|
|
||||||
{
|
|
||||||
var message = "Single Operation was unsuccessful";
|
|
||||||
Assert.False(true);
|
|
||||||
output.WriteLine(message);
|
|
||||||
if (checkMess)
|
|
||||||
{
|
|
||||||
Assert.False(true);
|
|
||||||
throw new Exception("Message was not printed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Assert.True(true);
|
|
||||||
var message2 = "Single Operation was successful";
|
|
||||||
output.WriteLine(message2);
|
|
||||||
if (!checkMess)
|
|
||||||
{
|
|
||||||
output.WriteLine("Message was printed");
|
|
||||||
Assert.True(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Bulk UM operations completes within 60 seconds, but no system message is shown or inaccurate system message is shown
|
|
||||||
[Fact]
|
|
||||||
public void BulkOperationwithMessage()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
DateTime sTime = DateTime.Now;
|
|
||||||
var checkMess = false;
|
|
||||||
var serviceTest = new AccountService();
|
|
||||||
string dbType = "sql";
|
|
||||||
RDSFactory dbFactory = new RDSFactory();
|
|
||||||
string path = Directory.GetCurrentDirectory();
|
|
||||||
|
|
||||||
|
|
||||||
// Testing Data Access Layer
|
|
||||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
|
||||||
"TCPIP=1;" +
|
|
||||||
"SERVER=localhost;" +
|
|
||||||
"DATABASE=hobby;" +
|
|
||||||
"UID=root;" +
|
|
||||||
"PASSWORD=Teamhobby;" +
|
|
||||||
"OPTION=3";
|
|
||||||
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
// Create a file
|
|
||||||
//for (int i = 0; i < 10000; i++)
|
|
||||||
//{
|
|
||||||
//var TestAcc = new UserAccount("newUser" + $"{i}", "4567", $"email{i}@a.com", "regular", sTime);
|
|
||||||
serviceTest.BulkOperation("Rifat", path + "\\Bulk.txt", datasource);
|
|
||||||
//}
|
|
||||||
|
|
||||||
DateTime eTime = DateTime.Now;
|
|
||||||
TimeSpan timeDiff = (eTime - sTime);
|
|
||||||
var sec = timeDiff.TotalSeconds;
|
|
||||||
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
if (sec > 60)
|
|
||||||
{
|
|
||||||
var message = "Bulk Operation was unsuccessful";
|
|
||||||
Assert.True(false);
|
|
||||||
output.WriteLine(message);
|
|
||||||
if (checkMess)
|
|
||||||
{
|
|
||||||
Assert.True(false);
|
|
||||||
throw new Exception("Message was not printed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Assert.True(true);
|
|
||||||
var message2 = "Bulk Operation was successful";
|
|
||||||
output.WriteLine(message2);
|
|
||||||
if (!checkMess)
|
|
||||||
{
|
|
||||||
output.WriteLine("Message was printed");
|
|
||||||
Assert.True(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// User is able to perform less than 10K UM operations in bulk within 60 seconds. A system message displays “Bulk UM operation was successful”
|
|
||||||
[Fact]
|
|
||||||
public void BulkOperationforSixty()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
DateTime sTime = DateTime.Now;
|
|
||||||
|
|
||||||
var serviceTest = new AccountService();
|
|
||||||
string dbType = "sql";
|
|
||||||
RDSFactory dbFactory = new RDSFactory();
|
|
||||||
string dir = Directory.GetCurrentDirectory();
|
|
||||||
string path = dir + "\\Bulk.txt";
|
|
||||||
output.WriteLine(path);
|
|
||||||
|
|
||||||
|
|
||||||
// Testing Data Access Layer
|
|
||||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
|
||||||
"TCPIP=1;" +
|
|
||||||
"SERVER=localhost;" +
|
|
||||||
"DATABASE=hobby;" +
|
|
||||||
"UID=root;" +
|
|
||||||
"PASSWORD=Teamhobby;" +
|
|
||||||
"OPTION=3";
|
|
||||||
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
// Create a file
|
|
||||||
//for (int i = 0; i < 10000; i++)
|
|
||||||
//{
|
|
||||||
//var TestAcc = new UserAccount("newUser" + $"{i}", "4567", $"email{i}@a.com", "regular", sTime);
|
|
||||||
serviceTest.BulkOperation("Rifat", path, datasource);
|
|
||||||
//}
|
|
||||||
|
|
||||||
DateTime eTime = DateTime.Now;
|
|
||||||
TimeSpan timeDiff = (eTime - sTime);
|
|
||||||
var sec = timeDiff.TotalSeconds;
|
|
||||||
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
if (sec > 60)
|
|
||||||
{
|
|
||||||
output.WriteLine("Bulk Operation was unsuccessful");
|
|
||||||
Assert.True(false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Assert.True(true);
|
|
||||||
output.WriteLine("Bulk Operation was successful");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Binary file not shown.
148
Source Code/TeamHobby.Main/HobbyMain.cs
Normal file
148
Source Code/TeamHobby.Main/HobbyMain.cs
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
// See https://aka.ms/new-console-template for more information
|
||||||
|
//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)
|
||||||
|
{
|
||||||
|
// Testing file compression Start
|
||||||
|
//Console.WriteLine("Hello World!");
|
||||||
|
|
||||||
|
//// Testing Compressing a file
|
||||||
|
//string fileName = @"C:\Users\Chunchunmaru\Documents\csulbFall2021\HobbyProject\Source Code\TeamHobby.Main\rando";
|
||||||
|
////string fileName = @"arhiving2.txt";
|
||||||
|
//FileInfo fileInfo = new FileInfo(fileName);
|
||||||
|
|
||||||
|
//Console.WriteLine("File Name: {0}", fileInfo.FullName);
|
||||||
|
|
||||||
|
//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);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//// SqlConnection conn = new SqlConnection(connString);
|
||||||
|
string sqlQ = "Select * from log;";
|
||||||
|
|
||||||
|
//MySql.Data.MySqlClient.MySqlConnection connect;
|
||||||
|
|
||||||
|
//try
|
||||||
|
//{
|
||||||
|
// Console.WriteLine("Open connection: ");
|
||||||
|
// //connect = new MySql.Data.MySqlClient.MySqlConnection();
|
||||||
|
// //connect.ConnectionString = connMariaDB;
|
||||||
|
// //connect.Open();
|
||||||
|
// conn.Open();
|
||||||
|
|
||||||
|
// SqlCommand cmd = new SqlCommand(sqlQ, conn);
|
||||||
|
|
||||||
|
// SqlDataReader myReader = cmd.ExecuteReader();
|
||||||
|
// while (myReader.Read())
|
||||||
|
// {
|
||||||
|
// Console.WriteLine(myReader["Column1"].ToString());
|
||||||
|
// Console.WriteLine(myReader["Column2"].ToString());
|
||||||
|
// }
|
||||||
|
// conn.Close();
|
||||||
|
|
||||||
|
// //if (connect.State == System.Data.ConnectionState.Open)
|
||||||
|
// //{
|
||||||
|
// // Console.WriteLine("Connection established");
|
||||||
|
// //}
|
||||||
|
// //connect.Close();
|
||||||
|
|
||||||
|
//}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.WriteLine("Opening connection: ");
|
||||||
|
//Connection string for Connector/ODBC 3.51
|
||||||
|
string MyConString = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
||||||
|
"SERVER=localhost;" +
|
||||||
|
"DATABASE=hobby;" +
|
||||||
|
"UID=root;" +
|
||||||
|
"PASSWORD=Teamhobby;" +
|
||||||
|
"OPTION=3";
|
||||||
|
|
||||||
|
//Connect to MySQL using Connector/ODBC
|
||||||
|
//OdbcConnection MyConnection = new OdbcConnection(MyConString);
|
||||||
|
//MyConnection.Open();
|
||||||
|
|
||||||
|
//Console.WriteLine("\n !!! success, connected successfully !!!\n");
|
||||||
|
|
||||||
|
////Display connection information
|
||||||
|
//Console.WriteLine("Connection Information:");
|
||||||
|
//Console.WriteLine("\tConnection String:" +
|
||||||
|
// MyConnection.ConnectionString);
|
||||||
|
//Console.WriteLine("\tConnection Timeout:" +
|
||||||
|
// MyConnection.ConnectionTimeout);
|
||||||
|
//Console.WriteLine("\tDatabase:" +
|
||||||
|
// MyConnection.Database);
|
||||||
|
//Console.WriteLine("\tDataSource:" +
|
||||||
|
// MyConnection.DataSource);
|
||||||
|
//Console.WriteLine("\tDriver:" +
|
||||||
|
// MyConnection.Driver);
|
||||||
|
//Console.WriteLine("\tServerVersion:" +
|
||||||
|
// MyConnection.ServerVersion);
|
||||||
|
|
||||||
|
//Console.WriteLine("Connection Successful");
|
||||||
|
|
||||||
|
ReadData(MyConString);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.Message);
|
||||||
|
Console.WriteLine("COnnection failed");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ReadData(string connectionString)
|
||||||
|
{
|
||||||
|
string queryString = "SELECT * 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";
|
||||||
|
}
|
||||||
|
}
|
||||||
37
Source Code/TeamHobby.Main/MasterController.cs
Normal file
37
Source Code/TeamHobby.Main/MasterController.cs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
20
Source Code/TeamHobby.Main/TeamHobby.Main.csproj
Normal file
20
Source Code/TeamHobby.Main/TeamHobby.Main.csproj
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<StartupObject>HobbyMain</StartupObject>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="System.Data.Odbc" Version="6.0.0" />
|
||||||
|
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.Archive\TeamHobby.HobbyProjectGenerator.Archive.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
46
Source Code/TeamHobby.Main/archiving2.txt
Normal file
46
Source Code/TeamHobby.Main/archiving2.txt
Normal file
@ -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
|
||||||
46
Source Code/TeamHobby.Main/rando
Normal file
46
Source Code/TeamHobby.Main/rando
Normal file
@ -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
|
||||||
12
Source Code/TeamHobby.Main/text.cs
Normal file
12
Source Code/TeamHobby.Main/text.cs
Normal file
@ -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
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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);
|
||||||
|
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
|
||||||
|
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
|
||||||
|
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
|
||||||
|
<PackageReference Include="coverlet.collector" Version="3.1.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@ -1,11 +1,30 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Data.Odbc;
|
using System.Data.Odbc;
|
||||||
using TeamHobby.HobbyProjectGenerator.ServiceLayer;
|
using TeamHobby.HobbyProjectGenerator.Archive;
|
||||||
using TeamHobby.HobbyProjectGenerator.DataAccessLayer;
|
using TeamHobby.HobbyProjectGenerator.DataAccess;
|
||||||
|
using TeamHobby.HobbyProjectGenerator.Logging;
|
||||||
|
using TeamHobby.HobbyProjectGenerator.UserManagement;
|
||||||
|
|
||||||
namespace TeamHobby.HobbyProjectGenerator.Main
|
namespace TeamHobby.HobbyProjectGenerator.Main
|
||||||
{
|
{
|
||||||
public class Controller
|
|
||||||
|
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)
|
public static void Main(string[] args)
|
||||||
@ -18,91 +37,227 @@ namespace TeamHobby.HobbyProjectGenerator.Main
|
|||||||
// Change terminal height
|
// Change terminal height
|
||||||
Console.WindowHeight = 40;
|
Console.WindowHeight = 40;
|
||||||
|
|
||||||
|
Console.WriteLine(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"));
|
||||||
|
|
||||||
// Creating the Factory class
|
// Creating the Factory class
|
||||||
// Logger log = new Logger();
|
// Logger log = new Logger();
|
||||||
//Logger.PrintTest();
|
//Logger.PrintTest();
|
||||||
|
//GetCredentials credentials = new GetCredentials();
|
||||||
|
//string? username = credentials.GetUserName();
|
||||||
|
//string? password = credentials.GetPassword();
|
||||||
|
// 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;
|
||||||
|
//Console.WriteLine(value: $"username is {username}\npassword is {password}");
|
||||||
|
|
||||||
// Loop login terminal
|
// Creating the Factory class
|
||||||
bool mainMenu = true;
|
// Creating the Factory class
|
||||||
|
|
||||||
// Loop Admin login
|
string dbType = "sql";
|
||||||
while (mainMenu is true)
|
RDSFactory dbFactory = new RDSFactory();
|
||||||
|
|
||||||
|
// Testing Data Access Layer
|
||||||
|
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
||||||
|
"TCPIP=1;" +
|
||||||
|
"SERVER=localhost;" +
|
||||||
|
"DATABASE=hobby;" +
|
||||||
|
"UID=root;" +
|
||||||
|
"PASSWORD=Teamhobby;" +
|
||||||
|
"OPTION=3";
|
||||||
|
IDataSource<string> datasource = factory.getDataSource(dbType, dbInfo);
|
||||||
|
"PORT=3306;";
|
||||||
|
|
||||||
|
|
||||||
|
"OPTION=3";
|
||||||
|
|
||||||
|
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
|
||||||
|
// Create manager class from UserManagement
|
||||||
|
SystemAccountManager manager = new SystemAccountManager();
|
||||||
|
|
||||||
|
// Admin Sign in
|
||||||
|
GetCredentials credentials = new GetCredentials();
|
||||||
|
string? username = credentials.GetUserName();
|
||||||
|
string? password = credentials.GetPassword();
|
||||||
|
|
||||||
|
// Get time of login attempt
|
||||||
|
DateTime TimeStamp = DateTime.UtcNow;
|
||||||
|
|
||||||
|
// Create UserAccount class
|
||||||
|
UserAccount user = new UserAccount(username, password, TimeStamp);
|
||||||
|
|
||||||
|
Console.Write(manager.CreateUserRecord(user, datasource));
|
||||||
|
|
||||||
|
//Console.WriteLine(value: $"Welcome {username}\n");
|
||||||
|
|
||||||
|
/* 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))
|
||||||
{
|
{
|
||||||
// Create credentials object
|
reader = (OdbcDataReader)result;
|
||||||
GetCredentials credentials = new GetCredentials();
|
|
||||||
|
|
||||||
// Get DB credentials ***Both values currently hard coded, will update to user input later on.***
|
|
||||||
string dbUserName = "root";
|
|
||||||
string dbPassword = "Teamhobby";
|
|
||||||
|
|
||||||
// Admin Sign in
|
|
||||||
Console.WriteLine("\nPlease Enter Admin Credentials " +
|
|
||||||
"or enter 0 to exit the machine\n");
|
|
||||||
string? username = credentials.GetUserName();
|
|
||||||
//int menuExit = Convert.ToInt32(username);
|
|
||||||
// Exit Infinite Menu
|
|
||||||
if (username == "0")
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
string? password = credentials.GetPassword();
|
|
||||||
|
|
||||||
// Get time of login attempt
|
|
||||||
DateTime TimeStamp = DateTime.UtcNow;
|
|
||||||
|
|
||||||
// String for checking query return type
|
|
||||||
string dbType = "sql";
|
|
||||||
// Creating the Factory class
|
|
||||||
RDSFactory dbFactory = new RDSFactory();
|
|
||||||
|
|
||||||
// Testing Data Access Layer
|
|
||||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
|
||||||
"TCPIP=1;" +
|
|
||||||
"SERVER=localhost;" +
|
|
||||||
"DATABASE=hobby;" +
|
|
||||||
$"UID={dbUserName};" +
|
|
||||||
$"PASSWORD={dbPassword};" +
|
|
||||||
"OPTION=3";
|
|
||||||
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
|
|
||||||
|
|
||||||
// While loop to keep this running forever with UserManagement
|
|
||||||
// Testing archive Manager
|
|
||||||
//while (true)
|
|
||||||
//{
|
|
||||||
string currentDate = DateTime.Now.ToString("dd");
|
|
||||||
string currentTime = DateTime.Now.ToString("T");
|
|
||||||
//Console.WriteLine("Current date: {0}, Current Time: {1}", currentDate, currentTime);
|
|
||||||
if (String.Equals(currentDate, "01") && String.Equals(currentTime, "00:00:00 AM"))
|
|
||||||
{
|
|
||||||
ArchiveManager archive = new ArchiveManager(datasource);
|
|
||||||
archive.Controller();
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
|
|
||||||
// Create manager class from UserManagement
|
|
||||||
SystemAccountManager manager = new SystemAccountManager();
|
|
||||||
|
|
||||||
// Create UserAccount class
|
|
||||||
UserAccount user = new UserAccount(username, password, TimeStamp);
|
|
||||||
// Call user object and wait for return string
|
|
||||||
string isLogin = manager.CreateUserRecord(user, datasource);
|
|
||||||
|
|
||||||
// If login is not incorrect and user is returning to login menu
|
|
||||||
if (isLogin != "Access Denied: Unauthorized\n")
|
|
||||||
{
|
|
||||||
Console.WriteLine("Returning to login...\n");
|
|
||||||
Console.WriteLine("-------------------------------------\n");
|
|
||||||
}
|
|
||||||
// If login is incorrect
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("******Access Denied: Unauthorized******");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// [Logname, loglevel, date, time, ...]
|
||||||
|
|
||||||
|
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;
|
||||||
|
Console.WriteLine("");
|
||||||
|
|
||||||
|
// Closing the connection
|
||||||
|
sqlDS.GetConnection().Close();
|
||||||
|
|
||||||
|
// While loop to keep this running forever with UserManagement
|
||||||
|
//Testing archive Manager
|
||||||
|
//while (true)
|
||||||
|
//{
|
||||||
|
//string currentDate = DateTime.Now.ToString("dd");
|
||||||
|
//string currentTime = DateTime.Now.ToString("T");
|
||||||
|
//string activateDate = "01";
|
||||||
|
//string activateTime = "00:00:00 AM";
|
||||||
|
//Console.WriteLine("Current date: {0}, Current Time: {1}", currentDate, currentTime);
|
||||||
|
//if (String.Equals(currentDate, activateDate) && String.Equals(currentTime, activateTime))
|
||||||
|
//{
|
||||||
|
//ArchiveManager archive = new ArchiveManager(datasource);
|
||||||
|
//archive.Controller();
|
||||||
|
//}
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//Creating the folder Archive
|
||||||
|
//Console.WriteLine("Creating a new folder ...");
|
||||||
|
//archive.CreateArchiveFolder();
|
||||||
|
//Console.WriteLine("");
|
||||||
|
|
||||||
|
//// Creating a file name:
|
||||||
|
//string filePath = @"C:\HobbyArchive";
|
||||||
|
////Console.WriteLine("Creating file name ... ");
|
||||||
|
////string curPath = archive.CreateOutFileName();
|
||||||
|
//string curPath = archive.CreateOutFileName(filePath);
|
||||||
|
|
||||||
|
////string pathForward = @"C:\Users\Chunchunmaru\Documents\csulbFall2021\HobbyProject\Source Code\main\bin\Debug\net6.0\HobbyArchive";
|
||||||
|
////string pathTemp = "C:/Temp/oldlogs10.txt";
|
||||||
|
////string pathTempBack = @"C:\Temp\oldlogs10.txt";
|
||||||
|
//Console.WriteLine("----------------");
|
||||||
|
|
||||||
|
////Output SQL to a text file
|
||||||
|
//sqlDS.CopyToFile(curPath);
|
||||||
|
|
||||||
|
//// Compress the file
|
||||||
|
//sqlDS.CompressFile(curPath);
|
||||||
|
|
||||||
|
////Remove output file
|
||||||
|
//sqlDS.RemoveOutputFile(curPath);
|
||||||
|
|
||||||
|
//// Remove entries fromt the database
|
||||||
|
//sqlDS.RemoveEntries();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 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. ");
|
||||||
|
|
||||||
|
/* 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();
|
||||||
|
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
};*/
|
||||||
|
//}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,70 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TeamHobby.HobbyProjectGenerator.DataAccessLayer;
|
|
||||||
using TeamHobby.HobbyProjectGenerator.ServiceLayer;
|
|
||||||
|
|
||||||
namespace main
|
|
||||||
{
|
|
||||||
public class GenerateOpFile
|
|
||||||
{
|
|
||||||
public void GenerateOPFile()
|
|
||||||
//public static void Main(string[] args)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Get the current directory.
|
|
||||||
string path = Directory.GetCurrentDirectory();
|
|
||||||
// Open file stream
|
|
||||||
using StreamWriter file = new(path + "\\BulkOps\\Bulk.txt", append: true);
|
|
||||||
// Show location of the file being written
|
|
||||||
Console.WriteLine(path + "\\BulkOps\\Bulk.txt");
|
|
||||||
|
|
||||||
// List choices of operations
|
|
||||||
List<string> ops = new List<string> {"Create Account", "Edit Account",
|
|
||||||
"Delete Account", "Disable Account", "Enable Account"};
|
|
||||||
// Create Account service object
|
|
||||||
AccountService serviceTest = new AccountService();
|
|
||||||
|
|
||||||
// Find database and connect to it
|
|
||||||
string dbType = "sql";
|
|
||||||
RDSFactory dbFactory = new RDSFactory();
|
|
||||||
|
|
||||||
// Testing Data Access Layer
|
|
||||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
|
||||||
"TCPIP=1;" +
|
|
||||||
"SERVER=localhost;" +
|
|
||||||
"DATABASE=hobby;" +
|
|
||||||
"UID=root;" +
|
|
||||||
"PASSWORD=Teamhobby;" +
|
|
||||||
"OPTION=3";
|
|
||||||
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
|
|
||||||
|
|
||||||
// Create a file
|
|
||||||
// Initialize value for random operation
|
|
||||||
Random random = new Random();
|
|
||||||
int index = 0;
|
|
||||||
for (int i = 0; i < 10000; i++)
|
|
||||||
{
|
|
||||||
// Choose random operation
|
|
||||||
index = random.Next(ops.Count);
|
|
||||||
// Create next dummy data
|
|
||||||
UserAccount testAcc = new UserAccount("newUser" + $"{i}", "4567", $"email{i}@aol.com", "regular", DateTime.Now);
|
|
||||||
// Write to file
|
|
||||||
// Write Operation: for now it is only create accounts to avoid errors
|
|
||||||
file.WriteLine($"Operation: {ops[0]}");
|
|
||||||
// Write credentials in the format of: (UserName, Password, Role, IsActive, CreatedBy, CreatedDate, Email)
|
|
||||||
file.WriteLine($"Username: {testAcc.username}\nPassword: {testAcc.password}\nRole: {testAcc.role}\nEmail: {testAcc.email}\n");
|
|
||||||
}
|
|
||||||
file.Close();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Error reading file");
|
|
||||||
Console.WriteLine(e.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
134
Source Code/main/MainMenu.cs
Normal file
134
Source Code/main/MainMenu.cs
Normal file
@ -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;
|
||||||
|
};
|
||||||
|
}*/
|
||||||
|
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
}
|
||||||
50
Source Code/main/SqlDAO.cs
Normal file
50
Source Code/main/SqlDAO.cs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
using Microsoft.Data.SqlClient;
|
||||||
|
using TeamHobby.HobbyProjectGenerator.Models;
|
||||||
|
|
||||||
|
namespace TeamHobby.HobbyProjectGenerator.DAL
|
||||||
|
{
|
||||||
|
public class SqlDAO
|
||||||
|
{
|
||||||
|
public IList<Credentials> 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
|
||||||
|
}*/
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -5,8 +5,6 @@
|
|||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
|
||||||
<Platforms>AnyCPU</Platforms>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -14,8 +12,8 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.DataAccessLayer\TeamHobby.HobbyProjectGenerator.DataAccessLayer.csproj" />
|
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.Archive\TeamHobby.HobbyProjectGenerator.Archive.csproj" />
|
||||||
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator\TeamHobby.HobbyProjectGenerator.ServiceLayer\TeamHobby.HobbyProjectGenerator.ServiceLayer.csproj" />
|
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.DataAccess\TeamHobby.HobbyProjectGenerator.DataAccess.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 314 KiB After Width: | Height: | Size: 314 KiB |
Binary file not shown.
@ -1,5 +1,26 @@
|
|||||||
|
create table users
|
||||||
|
(
|
||||||
|
UserName varchar(50) charset utf8mb3 not null,
|
||||||
|
Password varchar(50) charset utf8mb3 not null,
|
||||||
|
Role varchar(50) charset utf8mb3 not null,
|
||||||
|
IsActive int default 1 not null,
|
||||||
|
CreatedBy varchar(50) charset utf8mb3 not null,
|
||||||
|
CreatedDate datetime not null,
|
||||||
|
constraint userRole_fk foreign key (Role) references roles (Role),
|
||||||
|
constraint user_pk primary key (UserName)
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO hobby.users (UserName, Password, Role, IsActive, CreatedBy, CreatedDate, Email) VALUES
|
||||||
|
('Colin ', 'Waffle', 'Admin', 1, 'Jacob', '2021-12-13 04:27:42', null),
|
||||||
|
('Danny', 'Spartan', 'Admin', 1, 'Jacob', '2021-12-13 04:29:54', null),
|
||||||
|
('Jacob', 'Teamhobby1234', 'Admin', 1, 'SystemCreator', '2021-12-13 03:25:14', null),
|
||||||
|
('Long', 'Joystick', 'regular', 1, 'Jacob', '2021-12-13 04:29:57', null),
|
||||||
|
('Rifat', 'ApproveDar', 'Admin', 1, 'Jacob', '2021-12-13 04:29:55', null);
|
||||||
|
|
||||||
|
|
||||||
create table roles
|
create table roles
|
||||||
(
|
(
|
||||||
|
RoleID int not null,
|
||||||
Role varchar(50) charset utf8mb3 not null,
|
Role varchar(50) charset utf8mb3 not null,
|
||||||
CreatedBy varchar(200) charset utf8mb3 not null,
|
CreatedBy varchar(200) charset utf8mb3 not null,
|
||||||
CreatedDate datetime not null,
|
CreatedDate datetime not null,
|
||||||
@ -7,31 +28,6 @@ create table roles
|
|||||||
primary key (Role)
|
primary key (Role)
|
||||||
);
|
);
|
||||||
|
|
||||||
create table users
|
|
||||||
(
|
|
||||||
UserName varchar(50) charset utf8mb3 not null
|
|
||||||
primary key,
|
|
||||||
Password varchar(50) charset utf8mb3 not null,
|
|
||||||
Role varchar(50) charset utf8mb3 not null,
|
|
||||||
IsActive int default 1 not null,
|
|
||||||
CreatedBy varchar(50) charset utf8mb3 not null,
|
|
||||||
CreatedDate datetime not null,
|
|
||||||
Email varchar(50) null,
|
|
||||||
constraint users_Email_uindex
|
|
||||||
unique (Email),
|
|
||||||
constraint userRole_fk
|
|
||||||
foreign key (Role) references roles (Role)
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
INSERT INTO hobby.users (UserName, Password, Role, IsActive, CreatedBy, CreatedDate, Email) VALUES
|
|
||||||
('Colin ', 'Waffle', 'Admin', 1, 'Jacob', '2021-12-13 04:27:42', null),
|
|
||||||
('Danny', 'Spartan', 'Admin', 1, 'Jacob', '2021-12-13 04:29:54', null),
|
|
||||||
('Jacob', 'Teamhobby1234', 'Admin', 1, 'SystemCreator', '2021-12-13 03:25:14', null),
|
|
||||||
('Long', 'Joystick', 'regular', 1, 'Jacob', '2021-12-13 04:29:57', null),
|
|
||||||
('Rifat', '1234', 'Admin', 1, 'Jacob', '2021-12-13 04:29:55', null);
|
|
||||||
|
|
||||||
|
|
||||||
INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES
|
INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES
|
||||||
('Admin', 'Jacob', '2021-12-13 03:25:14'),
|
('Admin', 'Jacob', '2021-12-13 03:25:14'),
|
||||||
('regular', 'Jacob', '2021-12-13 03:25:14');
|
('regular', 'Colin', '2021-12-13 03:25:14');
|
||||||
|
|||||||
@ -1,54 +1,65 @@
|
|||||||
DROP DATABASE IF EXISTS Hobby;
|
|
||||||
|
|
||||||
create database Hobby;
|
create database Hobby;
|
||||||
|
|
||||||
use hobby;
|
use hobby;
|
||||||
|
|
||||||
create table roles
|
|
||||||
(
|
|
||||||
Role varchar(50) charset utf8mb3 not null,
|
|
||||||
CreatedBy varchar(200) charset utf8mb3 not null,
|
|
||||||
CreatedDate datetime not null,
|
|
||||||
constraint role_pk
|
|
||||||
primary key (Role)
|
|
||||||
);
|
|
||||||
|
|
||||||
create table users
|
create table users
|
||||||
(
|
(
|
||||||
UserName varchar(50) charset utf8mb3 not null
|
UserName varchar(50) charset utf8mb3 not null
|
||||||
primary key,
|
primary key,
|
||||||
Password varchar(50) charset utf8mb3 not null,
|
Password varchar(50) charset utf8mb3 null,
|
||||||
Role varchar(50) charset utf8mb3 not null,
|
RoleID int auto_increment,
|
||||||
IsActive int default 1 not null,
|
IsActive int default 1 null,
|
||||||
CreatedBy varchar(50) charset utf8mb3 not null,
|
CreatedBy varchar(50) charset utf8mb3 null,
|
||||||
CreatedDate datetime not null,
|
CreatedDate datetime null,
|
||||||
Email varchar(50) null,
|
constraint users_UserName_uindex
|
||||||
constraint users_Email_uindex
|
unique (UserName),
|
||||||
unique (Email),
|
constraint users_roles_RoleID_fk
|
||||||
constraint userRole_fk
|
foreign key (RoleID) references roles (RoleID)
|
||||||
foreign key (Role) references roles (Role)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES
|
INSERT INTO hobby.users (UserName, Password, CreatedBy, CreatedDate) VALUES ('Colin ', 'Waffle', 'Jacob', '2021-12-13 04:27:42');
|
||||||
('Admin', 'Jacob', '2021-12-13 03:25:14'),
|
INSERT INTO hobby.users (UserName, Password, CreatedBy, CreatedDate) VALUES ('Danny', 'Spartan', 'Jacob', '2021-12-13 04:29:54');
|
||||||
('regular', 'Jacob', '2021-12-13 03:25:14');
|
INSERT INTO hobby.users (UserName, Password, CreatedBy, CreatedDate) VALUES ('Jacob', 'Teamhobby1234', 'SystemCreator', '2021-12-13 03:25:14');
|
||||||
|
INSERT INTO hobby.users (UserName, Password, CreatedBy, CreatedDate) VALUES ('Long', 'Joystick', 'Jacob', '2021-12-13 04:29:57');
|
||||||
|
INSERT INTO hobby.users (UserName, Password, CreatedBy, CreatedDate) VALUES ('Rifat', 'ApproveDar', 'Jacob', '2021-12-13 04:29:55');
|
||||||
|
|
||||||
|
|
||||||
INSERT INTO hobby.users (UserName, Password, Role, IsActive, CreatedBy, CreatedDate, Email) VALUES
|
create table roles
|
||||||
('Colin ', 'Waffle', 'Admin', 1, 'Jacob', '2021-12-13 04:27:42', null),
|
(
|
||||||
('Danny', 'Spartan', 'Admin', 1, 'Jacob', '2021-12-13 04:29:54', null),
|
RoleID int auto_increment
|
||||||
('Jacob', 'Teamhobby1234', 'Admin', 1, 'SystemCreator', '2021-12-13 03:25:14', null),
|
primary key,
|
||||||
('Long', 'Joystick', 'regular', 1, 'Jacob', '2021-12-13 04:29:57', null),
|
Role varchar(50) charset utf8mb3 null,
|
||||||
('Rifat', '1234', 'Admin', 1, 'Jacob', '2021-12-13 04:29:55', null);
|
CreatedBy varchar(200) charset utf8mb3 null,
|
||||||
|
CreatedDate datetime null
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('Admin', 'SystemCreator', '2021-12-13 03:25:14');
|
||||||
|
INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('regular', 'Colin', '2021-12-13 03:25:14');
|
||||||
|
INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('regular', 'Colin', '2021-12-13 03:25:14');
|
||||||
|
INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('regular', 'Jacob', '2021-12-13 03:37:44');
|
||||||
|
INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('regular', 'Jacob', '2021-12-13 03:37:46');
|
||||||
|
INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('regular', 'Jacob', '2021-12-13 03:37:47');
|
||||||
|
INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('regular', 'Jacob', '2021-12-13 03:37:47');
|
||||||
|
INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('regular', 'Jacob', '2021-12-13 03:37:49');
|
||||||
|
INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('regular', 'Jacob', '2021-12-13 03:37:50');
|
||||||
|
INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('regular', 'Jacob', '2021-12-13 03:37:51');
|
||||||
|
|
||||||
|
|
||||||
|
alter table users
|
||||||
|
add constraint users_roles_RoleID_fk
|
||||||
|
foreign key (RoleID) references roles (RoleID);
|
||||||
|
|
||||||
SET Global innodb_file_per_table=ON;
|
SET Global innodb_file_per_table=ON;
|
||||||
|
-- SET GLOBAL innodb_file_format='Barracuda';
|
||||||
|
|
||||||
SET GLOBAL innodb_default_row_format='dynamic';
|
SET GLOBAL innodb_default_row_format='dynamic';
|
||||||
|
|
||||||
SET GLOBAL innodb_compression_algorithm='zlib';
|
SET GLOBAL innodb_compression_algorithm='zlib';
|
||||||
|
|
||||||
|
-- Check for system settings
|
||||||
|
SHOW VARIABLES LIKE 'innodb_compression_algorithm';
|
||||||
|
SHOW VARIABLES LIKE 'innodb_default_row_format';
|
||||||
|
SHOW VARIABLES LIKE '%innodb%';
|
||||||
|
|
||||||
CREATE TABLE Persons (
|
CREATE TABLE Persons (
|
||||||
PersonID int,
|
PersonID int,
|
||||||
@ -58,7 +69,7 @@ CREATE TABLE Persons (
|
|||||||
City varchar(255)
|
City varchar(255)
|
||||||
);
|
);
|
||||||
|
|
||||||
-- CREATE DATABASE testDB;
|
CREATE DATABASE testDB;
|
||||||
|
|
||||||
-- Hobby DDL
|
-- Hobby DDL
|
||||||
-- Log level table
|
-- Log level table
|
||||||
@ -94,6 +105,23 @@ create table Log
|
|||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
create table Archive
|
||||||
|
(
|
||||||
|
LtimeStamp datetime null,
|
||||||
|
logID int not null,
|
||||||
|
LvName varchar(50) not null,
|
||||||
|
catName varchar(50) not null,
|
||||||
|
userOP varchar(50) not null,
|
||||||
|
logMessage varchar(255) not null,
|
||||||
|
|
||||||
|
constraint Archive_pk primary key (logID)
|
||||||
|
)
|
||||||
|
ENGINE=InnoDB
|
||||||
|
PAGE_COMPRESSED=1
|
||||||
|
PAGE_COMPRESSION_LEVEL=9;
|
||||||
|
|
||||||
|
drop table archive;
|
||||||
|
|
||||||
-- Dummy data for testing purposes
|
-- Dummy data for testing purposes
|
||||||
-- Log categories data
|
-- Log categories data
|
||||||
INSERT into logcategories(catName, catComment) values
|
INSERT into logcategories(catName, catComment) values
|
||||||
@ -116,8 +144,9 @@ INSERT into log(lvname, catname, userop, logmessage) values
|
|||||||
('Info', 'View', 'log out', 'log out successful'),
|
('Info', 'View', 'log out', 'log out successful'),
|
||||||
('Info', 'Business', 'log in', 'log in successfully'),
|
('Info', 'Business', 'log in', 'log in successfully'),
|
||||||
('Info', 'View', 'search for projects', 'result return');
|
('Info', 'View', 'search for projects', 'result return');
|
||||||
show tables;
|
|
||||||
|
select * from logcategories;
|
||||||
|
select * from log;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user