259 lines
7.2 KiB
C#
259 lines
7.2 KiB
C#
using System;
|
|
using SzCore;
|
|
using SzCore.DataObjects;
|
|
using SzCore.Defaults;
|
|
|
|
namespace SzCli;
|
|
|
|
public class Program
|
|
{
|
|
private static readonly DefaultLocalFileManager _fileManager = new();
|
|
private static readonly Logger _logger = new(_fileManager);
|
|
|
|
public static void Main(string[] args)
|
|
{
|
|
SZ.Init(_fileManager, _logger);
|
|
|
|
bool shouldClose = false;
|
|
|
|
while (!shouldClose)
|
|
{
|
|
Console.WriteLine(" -- SZ CLI MAIN MENU -- ");
|
|
Console.WriteLine("0: Exit");
|
|
Console.WriteLine("1: Create Template");
|
|
Console.WriteLine("2: Create Dataset");
|
|
Console.WriteLine("3: Evaluate Dataset");
|
|
Console.WriteLine("4: Delete Template");
|
|
Console.WriteLine("5: Delete Dataset");
|
|
// Console.WriteLine("6: Fetch Template");
|
|
// Console.WriteLine("7: Fetch Dataset");
|
|
|
|
Console.Write("> ");
|
|
var userInput = Console.ReadLine();
|
|
if (!int.TryParse(userInput, out var result))
|
|
{
|
|
Console.WriteLine($"Input was not a number, please try again.\n\n");
|
|
continue;
|
|
}
|
|
|
|
switch (result)
|
|
{
|
|
case 0:
|
|
shouldClose = true;
|
|
break;
|
|
case 1:
|
|
CreateTemplate();
|
|
break;
|
|
case 2:
|
|
CreateDataset();
|
|
break;
|
|
case 3:
|
|
EvaluateDataset();
|
|
break;
|
|
case 4:
|
|
DeleteTemplate();
|
|
break;
|
|
case 5:
|
|
DeleteDataset();
|
|
break;
|
|
default:
|
|
Console.WriteLine("Invalid input, please try again");
|
|
break;
|
|
}
|
|
}
|
|
|
|
Console.WriteLine("\n\n");
|
|
}
|
|
|
|
private static void DeleteDataset()
|
|
{
|
|
Console.Write("Dataset ID: ");
|
|
var userInput = Console.ReadLine();
|
|
if (string.IsNullOrEmpty(userInput))
|
|
{
|
|
Console.WriteLine("Id was null");
|
|
return;
|
|
}
|
|
SZ.SzDataHandler.DeleteDataset(userInput);
|
|
}
|
|
|
|
private static void DeleteTemplate()
|
|
{
|
|
Console.Write("Template ID: ");
|
|
var userInput = Console.ReadLine();
|
|
if (string.IsNullOrEmpty(userInput))
|
|
{
|
|
Console.WriteLine("Id was null");
|
|
return;
|
|
}
|
|
SZ.SzDataHandler.DeleteTemplate(userInput);
|
|
}
|
|
|
|
private static void EvaluateDataset()
|
|
{
|
|
Console.Write("Dataset ID: ");
|
|
var userInput = Console.ReadLine();
|
|
if (string.IsNullOrEmpty(userInput))
|
|
{
|
|
Console.WriteLine("Id was null");
|
|
return;
|
|
}
|
|
var dataset = SZ.SzDataHandler.LoadDataset(userInput);
|
|
if (dataset is null)
|
|
{
|
|
Console.WriteLine($"Dataset with ID {userInput} could not be loaded");
|
|
return;
|
|
}
|
|
|
|
var evalResult = SZ.SzEvaluator.EvaluateDataset(dataset);
|
|
}
|
|
|
|
private static void CreateDataset()
|
|
{
|
|
Console.Write("Enter a name for the dataset: ");
|
|
var nameInput = Console.ReadLine();
|
|
if (string.IsNullOrEmpty(nameInput))
|
|
{
|
|
Console.WriteLine("Dataset name can't be blank");
|
|
return;
|
|
}
|
|
|
|
var id = nameInput.ToLower().Replace(" ", "-").Trim();
|
|
|
|
Console.Write("Enter template ID: ");
|
|
var templateIdInput = Console.ReadLine();
|
|
if (string.IsNullOrEmpty(templateIdInput))
|
|
{
|
|
Console.WriteLine("Template ID can't be blank");
|
|
return;
|
|
}
|
|
|
|
var template = SZ.SzDataHandler.LoadTemplate<SzDataObjectTemplate>(templateIdInput);
|
|
if (template is null)
|
|
{
|
|
Console.WriteLine($"Could not load template with ID {templateIdInput}");
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
private static void CreateTemplate()
|
|
{
|
|
Console.Write("Enter a name for the template: ");
|
|
var nameInput = Console.ReadLine();
|
|
if (string.IsNullOrEmpty(nameInput))
|
|
{
|
|
Console.WriteLine("Template name can't be blank");
|
|
return;
|
|
}
|
|
|
|
var id = nameInput.ToLower().Replace(" ", "-").Trim();
|
|
|
|
Console.Write("Enter a data type for the template: ");
|
|
var dataTypeInput = Console.ReadLine();
|
|
if (string.IsNullOrEmpty(dataTypeInput))
|
|
{
|
|
Console.WriteLine("Template Data Type can't be blank");
|
|
return;
|
|
}
|
|
|
|
Console.Write("Enter a description for the template: ");
|
|
var descInput = Console.ReadLine();
|
|
|
|
var fields = CreateTemplateFields();
|
|
|
|
var newTemplate = new SzDataObjectTemplate()
|
|
{
|
|
Name = nameInput,
|
|
Id = id,
|
|
DataObjectType = dataTypeInput,
|
|
Description = descInput ?? "",
|
|
};
|
|
|
|
foreach (var f in fields)
|
|
{
|
|
newTemplate.TemplateFields.Add(f.Id, f);
|
|
}
|
|
|
|
SZ.SzDataHandler.SaveTemplate(newTemplate);
|
|
|
|
}
|
|
|
|
private static List<SzTemplateField> CreateTemplateFields()
|
|
{
|
|
bool done = false;
|
|
int i = 0;
|
|
List<SzTemplateField> list = [];
|
|
while (!done)
|
|
{
|
|
i++;
|
|
Console.Write($"Field {i} ID: ");
|
|
var idInput = Console.ReadLine();
|
|
if (string.IsNullOrEmpty(idInput))
|
|
{
|
|
Console.WriteLine("Field id can't be blank");
|
|
i--;
|
|
continue;
|
|
}
|
|
|
|
if (list.Any(f => f.Id == idInput))
|
|
{
|
|
Console.WriteLine($"Field id '{idInput}' must be unique");
|
|
i--;
|
|
continue;
|
|
}
|
|
|
|
Console.WriteLine($"Field {idInput} type: ");
|
|
int enumIter = 0;
|
|
foreach (var enumType in Enum.GetValues<SzFieldType>())
|
|
{
|
|
Console.WriteLine($"- {enumType}");
|
|
enumIter++;
|
|
}
|
|
Console.Write("> ");
|
|
var typeInput = Console.ReadLine();
|
|
if (!Enum.TryParse<SzFieldType>(typeInput, out var typeEnumResult))
|
|
{
|
|
Console.WriteLine("Field type input was invalid");
|
|
i--;
|
|
continue;
|
|
}
|
|
|
|
// Console.Write("Is the field a list?: ");
|
|
// var isListInput = Console.ReadLine();
|
|
// if (!bool.TryParse(isListInput, out var isListResult))
|
|
// {
|
|
// Console.WriteLine("Field isList input was invalid");
|
|
// i--;
|
|
// continue;
|
|
// }
|
|
|
|
Console.Write("Add another field? ");
|
|
var contInput = Console.ReadLine();
|
|
switch (contInput)
|
|
{
|
|
case "n":
|
|
case "N":
|
|
default:
|
|
done = true;
|
|
break;
|
|
case "y":
|
|
case "Y":
|
|
break;
|
|
}
|
|
|
|
var newField = new SzTemplateField(){
|
|
Id = idInput,
|
|
FieldType = typeEnumResult
|
|
};
|
|
|
|
list.Add(newField);
|
|
}
|
|
|
|
return list;
|
|
}
|
|
}
|