Merge branch 'Jacobs-Branch'
This commit is contained in:
commit
a709675c99
41
Source Code/FileExtract.cs
Normal file
41
Source Code/FileExtract.cs
Normal file
@ -0,0 +1,41 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,6 +6,9 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess
|
||||
{
|
||||
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
|
||||
int menu = 0;
|
||||
Console.WriteLine("-------------------------------------\n");
|
||||
@ -23,6 +26,8 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess
|
||||
menu += 1;
|
||||
Console.WriteLine(menu + ") Enable an account.\n");
|
||||
menu += 1;
|
||||
Console.WriteLine(menu + $") Bulk operation from file within the directory.\n{path}\\BulkOps\n");
|
||||
menu += 1;
|
||||
Console.WriteLine(menu + ") View log path.\n");
|
||||
menu += 1;
|
||||
Console.WriteLine(menu + ") View archive path.\n");
|
||||
|
||||
@ -15,6 +15,18 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
|
||||
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," +
|
||||
@ -22,7 +34,7 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
|
||||
|
||||
bool insertNewUser = dbSource.WriteData(sqlUser);
|
||||
return insertNewUser;
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -34,13 +46,24 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
|
||||
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)
|
||||
{
|
||||
@ -98,5 +121,181 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public bool BulkOperation(string signedUser, IDataSource<string> dbSource)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Get the current directory.
|
||||
string path = Directory.GetCurrentDirectory();
|
||||
// Open file reader stream
|
||||
using StreamReader fileRead = new(path + "\\BulkOps\\Bulk.txt"); // path + "\\BulkOps\\{input}"
|
||||
// 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"};
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -239,7 +239,6 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
|
||||
case 2:
|
||||
// State what account is being edited
|
||||
string userName = newCredentials.GetUserName();
|
||||
string userRole = newCredentials.GetRole();
|
||||
|
||||
// Notify the user of what can be edited
|
||||
Console.WriteLine($"\n****The following information will be used to update {userName}");
|
||||
@ -304,11 +303,55 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
|
||||
return "User does not exist";
|
||||
}
|
||||
break;
|
||||
// View logs
|
||||
// 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}\\BulkOps\\{Console.ReadLine()}";
|
||||
|
||||
// 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, dbSource);
|
||||
if (bulkReq is true)
|
||||
{
|
||||
Console.WriteLine("\nBulk operation complete");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Bulk operation failed";
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
// View logs
|
||||
case 7:
|
||||
break;
|
||||
// View archive
|
||||
case 7:
|
||||
case 8:
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine("Invalid input.\nPlease enter a valid option.\n");
|
||||
|
||||
@ -47,7 +47,25 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
|
||||
}
|
||||
public string GetRole()
|
||||
{
|
||||
Console.WriteLine("Please enter the role of the user:");
|
||||
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();
|
||||
}
|
||||
}
|
||||
@ -65,26 +83,62 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
|
||||
{
|
||||
_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;
|
||||
_Role = role;
|
||||
_Email = Email;
|
||||
_Time = newTime;
|
||||
}
|
||||
public UserAccount()
|
||||
{
|
||||
_Role = "regular";
|
||||
_Time= DateTime.Now;
|
||||
_Email = "NULL";
|
||||
_Time = DateTime.Now;
|
||||
}
|
||||
|
||||
public string username { get { return _userName; } }
|
||||
|
||||
@ -31,7 +31,7 @@ namespace TeamHobby.UserManagement.xTests
|
||||
"SERVER=localhost;" +
|
||||
"DATABASE=hobby;" +
|
||||
"UID=root;" +
|
||||
"PASSWORD=hobby;" +
|
||||
"PASSWORD=Teamhobby;" +
|
||||
"OPTION=3";
|
||||
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
|
||||
|
||||
@ -72,7 +72,7 @@ namespace TeamHobby.UserManagement.xTests
|
||||
"SERVER=localhost;" +
|
||||
"DATABASE=hobby;" +
|
||||
"UID=root;" +
|
||||
"PASSWORD=hobby;" +
|
||||
"PASSWORD=Teamhobby;" +
|
||||
"OPTION=3";
|
||||
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
|
||||
|
||||
@ -81,7 +81,7 @@ namespace TeamHobby.UserManagement.xTests
|
||||
for (int i = 0; i < 10000; i++)
|
||||
{
|
||||
var TestAcc = new UserAccount("newUser" + $"{i}", "4567", $"email{i}@a.com", "regular", sTime);
|
||||
serviceTest.CreateUserRecord(TestAcc, "Rifat", datasource);
|
||||
serviceTest.DeleteUserRecord(TestAcc, "Rifat", datasource);
|
||||
}
|
||||
|
||||
DateTime eTime = DateTime.Now;
|
||||
|
||||
@ -46,8 +46,6 @@ namespace TeamHobby.HobbyProjectGenerator.Main
|
||||
// Get time of login attempt
|
||||
DateTime TimeStamp = DateTime.UtcNow;
|
||||
|
||||
|
||||
|
||||
// String for checking query return type
|
||||
string dbType = "sql";
|
||||
// Creating the Factory class
|
||||
@ -98,49 +96,6 @@ namespace TeamHobby.HobbyProjectGenerator.Main
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//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. ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
163
Source Code/main/ExtractBulkOp.cs
Normal file
163
Source Code/main/ExtractBulkOp.cs
Normal file
@ -0,0 +1,163 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Data.Odbc;
|
||||
using TeamHobby.HobbyProjectGenerator.DataAccess;
|
||||
using TeamHobby.HobbyProjectGenerator.UserManagement;
|
||||
|
||||
namespace main
|
||||
{
|
||||
public class ExtractBulkOp
|
||||
{
|
||||
public void ExtractBulkOP(string signedUser, IDataSource<string> dbSource)
|
||||
//public static void Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Get the current directory.
|
||||
string path = Directory.GetCurrentDirectory();
|
||||
// Open file reader stream
|
||||
using StreamReader fileRead = new(path + "\\BulkOps\\Bulk.txt"); // path + "\\BulkOps\\{input}"
|
||||
// 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"};
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (operation)
|
||||
{
|
||||
case "Create Account":
|
||||
//Console.WriteLine(operation);
|
||||
if (String.IsNullOrEmpty(Role))
|
||||
{
|
||||
Role = null;
|
||||
// Create UserAccount object
|
||||
UserAccount user = new UserAccount(UN, PWD, Email, DateTime.UtcNow);
|
||||
// Create Account service object
|
||||
AccountService serviceTest = new AccountService();
|
||||
Console.WriteLine($"VALUES ('{user.username}', " +
|
||||
$"'{user.password}','{user.role}', 1," +
|
||||
$"'Jacob', NOW(),'{user.email}');");
|
||||
//Console.WriteLine(serviceTest.CreateUserRecord(user, 'Jacob', dbSource));
|
||||
}
|
||||
else if (String.IsNullOrEmpty(Email))
|
||||
{
|
||||
Email = null;
|
||||
// Create UserAccount object
|
||||
UserAccount user = new UserAccount(UN, PWD, Role);
|
||||
// Create Account service object
|
||||
AccountService serviceTest = new AccountService();
|
||||
Console.WriteLine($"VALUES ('{user.username}', " +
|
||||
$"'{user.password}','{user.role}', 1," +
|
||||
$"'Jacob', NOW(),'{user.email}');");
|
||||
//serviceTest.CreateUserRecord(user, signedUser, dbSource);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Console.WriteLine(UN);
|
||||
// Create UserAccount object
|
||||
UserAccount user = new UserAccount(UN, PWD, DateTime.UtcNow);
|
||||
// Create Account service object
|
||||
AccountService serviceTest = new AccountService();
|
||||
if (user.email == null)
|
||||
{
|
||||
Console.WriteLine("wokring correctly");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"VALUES ('{user.username}', " +
|
||||
$"'{user.password}','{user.role}', 1," +
|
||||
$"'Jacob', NOW(),'{user.email}');");
|
||||
//serviceTest.CreateUserRecord(user, signedUser, dbSource);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "Edit Account":
|
||||
//Console.WriteLine(operation);
|
||||
//Console.WriteLine(operation);
|
||||
|
||||
break;
|
||||
case "Delete Account":
|
||||
//Console.WriteLine(operation);
|
||||
//Console.WriteLine(operation);
|
||||
|
||||
break;
|
||||
case "Disable Account":
|
||||
//Console.WriteLine(operation);
|
||||
//Console.WriteLine(operation);
|
||||
|
||||
break;
|
||||
case "Enable Account":
|
||||
//Console.WriteLine(operation);
|
||||
//Console.WriteLine(operation);
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
fileRead.Close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("Error reading file");
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
70
Source Code/main/GenerateOpFile.cs
Normal file
70
Source Code/main/GenerateOpFile.cs
Normal file
@ -0,0 +1,70 @@
|
||||
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
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user