feat: first version to introduce database storage (incomplete)
This commit is contained in:
12
Gaseous.sln
12
Gaseous.sln
@@ -9,6 +9,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "gaseous-signature-parser",
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "gaseous-romsignatureobject", "gaseous-romsignatureobject\gaseous-romsignatureobject.csproj", "{9DCD243D-37CE-4562-8411-B5242B687D4F}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "gaseous-signature-ingestor", "gaseous-signature-ingestor\gaseous-signature-ingestor.csproj", "{86DF6E45-2C2B-4C30-AEC1-E7EF8C5CEA7D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "gaseous-tools", "gaseous-tools\gaseous-tools.csproj", "{08FE408A-5EC1-4110-ABD8-D19A1155B8CE}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -35,6 +39,14 @@ Global
|
||||
{9DCD243D-37CE-4562-8411-B5242B687D4F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9DCD243D-37CE-4562-8411-B5242B687D4F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9DCD243D-37CE-4562-8411-B5242B687D4F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{86DF6E45-2C2B-4C30-AEC1-E7EF8C5CEA7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{86DF6E45-2C2B-4C30-AEC1-E7EF8C5CEA7D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{86DF6E45-2C2B-4C30-AEC1-E7EF8C5CEA7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{86DF6E45-2C2B-4C30-AEC1-E7EF8C5CEA7D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{08FE408A-5EC1-4110-ABD8-D19A1155B8CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{08FE408A-5EC1-4110-ABD8-D19A1155B8CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{08FE408A-5EC1-4110-ABD8-D19A1155B8CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{08FE408A-5EC1-4110-ABD8-D19A1155B8CE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
126
gaseous-signature-ingestor/Program.cs
Normal file
126
gaseous-signature-ingestor/Program.cs
Normal file
@@ -0,0 +1,126 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using MySql.Data.MySqlClient;
|
||||
using gaseous_romsignatureobject;
|
||||
using gaseous_signature_parser.parsers;
|
||||
using gaseous_tools;
|
||||
|
||||
string configPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".gaseous-server");
|
||||
|
||||
// process command line
|
||||
string[] commandLineArgs = Environment.GetCommandLineArgs();
|
||||
|
||||
string tosecXML = "";
|
||||
string inArgument = "";
|
||||
foreach (string commandLineArg in commandLineArgs)
|
||||
{
|
||||
if (commandLineArg != commandLineArgs[0])
|
||||
{
|
||||
if (inArgument == "")
|
||||
{
|
||||
switch (commandLineArg.ToLower())
|
||||
{
|
||||
case "-tosecpath":
|
||||
inArgument = commandLineArg.ToLower();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (inArgument)
|
||||
{
|
||||
case "-tosecpath":
|
||||
tosecXML = commandLineArg;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
inArgument = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check if configPath is valid and create it if not
|
||||
if (!Directory.Exists(configPath))
|
||||
{
|
||||
Directory.CreateDirectory(configPath);
|
||||
}
|
||||
|
||||
// connect to database
|
||||
string cs = @"server=localhost;userid=gaseous;password=gaseous;database=gaseous";
|
||||
Database db = new gaseous_tools.Database(Database.databaseType.MySql, cs);
|
||||
|
||||
// process provided files
|
||||
Console.WriteLine("Processing input files:");
|
||||
if (Directory.Exists(tosecXML))
|
||||
{
|
||||
Console.WriteLine("Processing TOSEC data files", ConsoleColor.Green);
|
||||
Console.WriteLine("");
|
||||
Console.WriteLine("");
|
||||
|
||||
tosecXML = Path.GetFullPath(tosecXML);
|
||||
string[] tosecPathContents = Directory.GetFiles(tosecXML);
|
||||
int lineFileNameLength = 0;
|
||||
for (UInt16 i = 0; i < tosecPathContents.Length; ++i)
|
||||
{
|
||||
string tosecXMLFile = tosecPathContents[i];
|
||||
|
||||
string statusOutput = i + " / " + tosecPathContents.Length + " : " + Path.GetFileName(tosecXMLFile);
|
||||
Console.SetCursorPosition(0, Console.CursorTop - 2);
|
||||
Console.WriteLine("\r " + statusOutput.PadRight(lineFileNameLength, ' ') + "\r");
|
||||
lineFileNameLength = statusOutput.Length;
|
||||
|
||||
Console.WriteLine("Parsing file");
|
||||
|
||||
TosecParser tosecParser = new TosecParser();
|
||||
RomSignatureObject tosecObject = tosecParser.Parse(tosecXMLFile);
|
||||
|
||||
// store in database
|
||||
foreach (RomSignatureObject.Game gameObject in tosecObject.Games)
|
||||
{
|
||||
string sql = "";
|
||||
Dictionary<string, object> dbDict = new Dictionary<string, object>();
|
||||
System.Data.DataTable sigDB;
|
||||
|
||||
// store platform
|
||||
if (gameObject.System != null)
|
||||
{
|
||||
sql = "SELECT * FROM signatures_platforms WHERE platform=@platform";
|
||||
dbDict = new Dictionary<string, object>();
|
||||
dbDict.Add("platform", gameObject.System);
|
||||
|
||||
sigDB = db.ExecuteCMD(sql, dbDict);
|
||||
if (sigDB.Rows.Count == 0)
|
||||
{
|
||||
// entry not present, insert it
|
||||
Console.SetCursorPosition(0, Console.CursorTop - 1);
|
||||
Console.WriteLine("Saving platform: " + gameObject.System);
|
||||
|
||||
sql = "INSERT INTO signatures_platforms (platform) VALUES (@platform)";
|
||||
db.ExecuteCMD(sql, dbDict);
|
||||
}
|
||||
}
|
||||
|
||||
// store publisher
|
||||
if (gameObject.Publisher != null)
|
||||
{
|
||||
sql = "SELECT * FROM signatures_publishers WHERE publisher=@publisher";
|
||||
dbDict = new Dictionary<string, object>();
|
||||
dbDict.Add("publisher", gameObject.Publisher);
|
||||
|
||||
sigDB = db.ExecuteCMD(sql, dbDict);
|
||||
if (sigDB.Rows.Count == 0)
|
||||
{
|
||||
// entry not present, insert it
|
||||
Console.SetCursorPosition(0, Console.CursorTop - 1);
|
||||
Console.WriteLine("Saving publisher: " + gameObject.Publisher);
|
||||
|
||||
sql = "INSERT INTO signatures_publishers (publisher) VALUES (@publisher)";
|
||||
db.ExecuteCMD(sql, dbDict);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
19
gaseous-signature-ingestor/gaseous-signature-ingestor.csproj
Normal file
19
gaseous-signature-ingestor/gaseous-signature-ingestor.csproj
Normal file
@@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<RootNamespace>gaseous_signature_ingestor</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\gaseous-romsignatureobject\gaseous-romsignatureobject.csproj" />
|
||||
<ProjectReference Include="..\gaseous-signature-parser\gaseous-signature-parser.csproj" />
|
||||
<ProjectReference Include="..\gaseous-tools\gaseous-tools.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MySql.Data" Version="8.0.32" />
|
||||
</ItemGroup>
|
||||
</Project>
|
111
gaseous-tools/Database.cs
Normal file
111
gaseous-tools/Database.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Diagnostics;
|
||||
using MySql.Data.MySqlClient;
|
||||
|
||||
namespace gaseous_tools
|
||||
{
|
||||
public class Database
|
||||
{
|
||||
public Database()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Database(databaseType Type, string ConnectionString)
|
||||
{
|
||||
_ConnectorType = Type;
|
||||
_ConnectionString = ConnectionString;
|
||||
}
|
||||
|
||||
public enum databaseType
|
||||
{
|
||||
MySql
|
||||
}
|
||||
|
||||
string _ConnectionString = "";
|
||||
|
||||
public string ConnectionString
|
||||
{
|
||||
get
|
||||
{
|
||||
return _ConnectionString;
|
||||
}
|
||||
set
|
||||
{
|
||||
_ConnectionString = value;
|
||||
}
|
||||
}
|
||||
|
||||
databaseType? _ConnectorType = null;
|
||||
|
||||
public databaseType? ConnectorType
|
||||
{
|
||||
get
|
||||
{
|
||||
return _ConnectorType;
|
||||
}
|
||||
set
|
||||
{
|
||||
_ConnectorType = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public DataTable ExecuteCMD(string Command, Dictionary<string, object> Parameters, int Timeout = 30)
|
||||
{
|
||||
switch (_ConnectorType)
|
||||
{
|
||||
case databaseType.MySql:
|
||||
MySQLServerConnector conn = new MySQLServerConnector(_ConnectionString);
|
||||
return (DataTable)conn.ExecCMD(Command, Parameters, Timeout);
|
||||
default:
|
||||
return new DataTable();
|
||||
}
|
||||
}
|
||||
|
||||
private partial class MySQLServerConnector
|
||||
{
|
||||
private string DBConn = "";
|
||||
|
||||
public MySQLServerConnector(string ConnectionString)
|
||||
{
|
||||
DBConn = ConnectionString;
|
||||
}
|
||||
|
||||
public DataTable ExecCMD(string SQL, Dictionary<string, object> Parameters, int Timeout)
|
||||
{
|
||||
DataTable RetTable = new DataTable();
|
||||
|
||||
MySqlConnection conn = new MySqlConnection(DBConn);
|
||||
conn.Open();
|
||||
|
||||
MySqlCommand cmd = new MySqlCommand
|
||||
{
|
||||
Connection = conn,
|
||||
CommandText = SQL,
|
||||
CommandTimeout = Timeout
|
||||
};
|
||||
|
||||
foreach (string Parameter in Parameters.Keys)
|
||||
{
|
||||
cmd.Parameters.AddWithValue(Parameter, Parameters[Parameter]);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
RetTable.Load(cmd.ExecuteReader());
|
||||
} catch (Exception ex) {
|
||||
Trace.WriteLine("Error executing " + SQL);
|
||||
Trace.WriteLine("Full exception: " + ex.ToString());
|
||||
}
|
||||
|
||||
conn.Close();
|
||||
|
||||
return RetTable;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
13
gaseous-tools/gaseous-tools.csproj
Normal file
13
gaseous-tools/gaseous-tools.csproj
Normal file
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<RootNamespace>gaseous_tools</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MySql.Data" Version="8.0.32" />
|
||||
</ItemGroup>
|
||||
</Project>
|
Reference in New Issue
Block a user