initial script for dummy bulk data

This commit is contained in:
Im_Alpha 2021-12-14 22:24:10 -08:00
parent de8dd8a583
commit 9bba0ebcc1
8 changed files with 268 additions and 6 deletions

View 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));
}
}
}
}

View File

@ -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");

View File

@ -98,5 +98,13 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
return false;
}
}
public bool BulkOperation()
{
// List choices of operations
List<string> ops = new List<string> {"Create Account", "Edit Account",
"Delete Account", "Disable Account", "Enable Account"};
return true;
}
}
}

View File

@ -11,6 +11,13 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
{
public class SystemAccountManager
{
public bool BulkOperation()
{
// List choices of operations
List<string> ops = new List<string> {"Create Account", "Edit Account",
"Delete Account", "Disable Account", "Enable Account"};
return true;
}
public string IsInputValid(string checkUN, string checkPWD)
{
// Create bool variables to check if username and password are valid
@ -304,11 +311,51 @@ 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()}";
// Read file
FileInfo fileInfo = new FileInfo(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
bulkOP.BulkOperation();
break;
}
}
break;
// View logs
case 7:
break;
// View archive
case 7:
case 8:
break;
default:
Console.WriteLine("Invalid input.\nPlease enter a valid option.\n");

View File

@ -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;

View File

@ -1,4 +1,4 @@
using System;
/*using System;
using System.Data.Odbc;
using TeamHobby.HobbyProjectGenerator.Archive;
using TeamHobby.HobbyProjectGenerator.DataAccess;
@ -147,3 +147,4 @@ namespace TeamHobby.HobbyProjectGenerator.Main
*/

View File

@ -0,0 +1,90 @@
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()
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"};
// Create Account service object
AccountService serviceTest = new AccountService();
// List to hold file operation and credentials
List<string[]> fileList = new List<string[]>();
// 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))
{
// Declare empty list each time operation is found
string[] temp = new string[] { };
// Loop until empty line is found
while (true)
{
string currLine = fileRead.ReadLine();
// Check if line is not empty
if(currLine != null && currLine.Contains(":"))
{
currLine = currLine.Split(':')[1].Trim();
if (ops.Contains(currLine))
{
break;
}
else
{
temp.Append(currLine);
}
}
}
fileList.Add(temp);
}
}
}
Console.WriteLine(fileList[2]);
/* for (int i = 0; i < fileList.Count; i++)
{
for(int j = 0; j < fileList[i].Length; j++)
{
Console.WriteLine(fileList[i][j]);
}
}*/
fileRead.Close();
}
catch (Exception e)
{
Console.WriteLine("Error reading file");
Console.WriteLine(e.Message);
}
}
}
}

View 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);
}
}
}
}