Mass refactoring and reworking of DevConsole.
- Implemented exception for attempting to close the MongoDB connection as it's an officially unsupported feature.
This commit is contained in:
+112
-102
@@ -14,150 +14,160 @@ namespace DevConsole
|
|||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
ConnectToGsmDb();
|
||||||
|
ConnectToFlcDb();
|
||||||
|
Console.WriteLine("");
|
||||||
while (true) { CommandsMenu(); }
|
while (true) { CommandsMenu(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void CommandsMenu()
|
private static void CommandsMenu()
|
||||||
{
|
{
|
||||||
Console.WriteLine("Please select an option below:\n");
|
Console.WriteLine("Please select an option below:\n");
|
||||||
Console.WriteLine("A. GSMParser Database connection");
|
Console.WriteLine("A. Manage DB Connections --->");
|
||||||
Console.WriteLine("B. Query game by ID");
|
Console.WriteLine("B. GSM Actions --->");
|
||||||
Console.WriteLine("C. Query directory by ID");
|
Console.WriteLine("C. FLC Actions --->");
|
||||||
Console.WriteLine("D. Query game by NAME");
|
|
||||||
Console.WriteLine("E. FireLance Database connection");
|
|
||||||
Console.WriteLine("F. FireLance Import Predefined SaveData Entry");
|
|
||||||
Console.WriteLine("X. Exit application\n");
|
Console.WriteLine("X. Exit application\n");
|
||||||
Console.Write(":");
|
Console.Write(":");
|
||||||
|
|
||||||
var userInput = Console.ReadKey();
|
var userInput = Console.ReadLine();
|
||||||
Console.Write("\n\n");
|
Console.Write("\n\n");
|
||||||
|
|
||||||
switch (userInput.Key)
|
switch (userInput.ToUpper())
|
||||||
{
|
{
|
||||||
case ConsoleKey.A:
|
case "A":
|
||||||
OptionA();
|
CmdDbMgr();
|
||||||
break;
|
break;
|
||||||
case ConsoleKey.B:
|
case "B":
|
||||||
OptionB();
|
CmdGsmActions();
|
||||||
break;
|
break;
|
||||||
case ConsoleKey.C:
|
case "C":
|
||||||
OptionC();
|
CmdFlcActions();
|
||||||
break;
|
break;
|
||||||
case ConsoleKey.D:
|
case "G":
|
||||||
OptionD();
|
|
||||||
break;
|
|
||||||
case ConsoleKey.E:
|
|
||||||
OptionE();
|
|
||||||
break;
|
|
||||||
case ConsoleKey.F:
|
|
||||||
OptionF();
|
|
||||||
break;
|
|
||||||
case ConsoleKey.X:
|
|
||||||
Environment.Exit(0);
|
Environment.Exit(0);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
Console.WriteLine("Invalid selection, please enter a listed command.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void ConnectToGsmDb()
|
||||||
|
{
|
||||||
|
gsmRO.OpenConnection(@"C:\Users\Dunestorm\Projects\FireLance\GSMParser\games.db", 0);
|
||||||
|
Console.WriteLine($"GSMParser Connection State: {gsmRO.IsConnectionOpen()}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ConnectToFlcDb()
|
||||||
|
{
|
||||||
|
fireLanceCRUD.OpenConnection("sr3", 27017);
|
||||||
|
Console.WriteLine($"FireLance Connection State: {fireLanceCRUD.IsConnectionOpen()}");
|
||||||
|
}
|
||||||
|
|
||||||
#region Command Options
|
#region Command Options
|
||||||
private static void OptionA()
|
private static void CmdDbMgr()
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("[GsmDb]------------");
|
||||||
Console.WriteLine("A. Open DB");
|
Console.WriteLine("A. Open DB");
|
||||||
Console.WriteLine("B. Close DB");
|
Console.WriteLine("B. Close DB");
|
||||||
|
Console.WriteLine("[FlcDb]------------");
|
||||||
|
Console.WriteLine("C. Open DB");
|
||||||
|
Console.WriteLine("D. Close DB (Unsupported)");
|
||||||
|
Console.WriteLine("X. <--- Go back\n");
|
||||||
Console.Write(":");
|
Console.Write(":");
|
||||||
|
|
||||||
var userInput = Console.ReadKey();
|
var userInput = Console.ReadLine();
|
||||||
Console.Write("\n\n");
|
Console.Write("\n\n");
|
||||||
|
|
||||||
switch (userInput.Key)
|
switch (userInput.ToUpper())
|
||||||
{
|
{
|
||||||
case ConsoleKey.A:
|
case "A":
|
||||||
Console.WriteLine("Connect to database");
|
ConnectToGsmDb();
|
||||||
gsmRO.OpenConnection(@"C:\Users\Dunestorm\Projects\FireLance\GSMParser\games.db", 0);
|
|
||||||
break;
|
break;
|
||||||
case ConsoleKey.B:
|
case "B":
|
||||||
gsmRO.CloseCurrentConnection();
|
gsmRO.CloseCurrentConnection();
|
||||||
break;
|
break;
|
||||||
}
|
case "C":
|
||||||
|
ConnectToFlcDb();
|
||||||
Console.WriteLine($"GSMParser Connection State: {gsmRO.IsConnectionOpen()}\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void OptionB()
|
|
||||||
{
|
|
||||||
Console.WriteLine("Enter a game ID:");
|
|
||||||
string r = Console.ReadLine();
|
|
||||||
Console.Write("\n");
|
|
||||||
|
|
||||||
PrintGameEntries(gsmRO.LoadRecords<GameEntryModel>( GsmDbStruct.Columns.GameName,
|
|
||||||
GsmDbStruct.Tables.GameEntry,
|
|
||||||
GsmDbStruct.Columns.ID,
|
|
||||||
r,
|
|
||||||
true));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void OptionC()
|
|
||||||
{
|
|
||||||
Console.WriteLine("Enter a game ID:");
|
|
||||||
string r = Console.ReadLine();
|
|
||||||
Console.Write("\n");
|
|
||||||
|
|
||||||
PrintDirectories(gsmRO.LoadRecords<DirectoriesModel>( "*",
|
|
||||||
GsmDbStruct.Tables.Directories,
|
|
||||||
GsmDbStruct.Columns.GameID,
|
|
||||||
r,
|
|
||||||
true));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void OptionD()
|
|
||||||
{
|
|
||||||
Console.WriteLine("Enter game title to search:");
|
|
||||||
string r = Console.ReadLine();
|
|
||||||
Console.Write("\n");
|
|
||||||
|
|
||||||
PrintGameEntries(gsmRO.LoadRecords<GameEntryModel>( GsmDbStruct.Columns.GameName,
|
|
||||||
GsmDbStruct.Tables.GameEntry,
|
|
||||||
GsmDbStruct.Columns.GameName,
|
|
||||||
r,
|
|
||||||
false));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void OptionE()
|
|
||||||
{
|
|
||||||
Console.WriteLine("A. Open DB");
|
|
||||||
Console.WriteLine("B. Close DB");
|
|
||||||
Console.Write(":");
|
|
||||||
|
|
||||||
var userInput = Console.ReadKey();
|
|
||||||
Console.Write("\n\n");
|
|
||||||
|
|
||||||
switch (userInput.Key)
|
|
||||||
{
|
|
||||||
case ConsoleKey.A:
|
|
||||||
Console.WriteLine("Connect to database");
|
|
||||||
fireLanceCRUD.OpenConnection("sr3", 27017);
|
|
||||||
break;
|
break;
|
||||||
case ConsoleKey.B:
|
case "D":
|
||||||
fireLanceCRUD.CloseCurrentConnection();
|
fireLanceCRUD.CloseCurrentConnection();
|
||||||
break;
|
break;
|
||||||
|
case "X":
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine($"FireLance Connection State: {fireLanceCRUD.IsConnectionOpen()}\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void OptionF()
|
private static void CmdGsmActions()
|
||||||
{
|
{
|
||||||
//Guid guid = Guid.NewGuid();
|
Console.WriteLine("A. Query game by ID");
|
||||||
List<DirectoriesModel> dm = gsmRO.LoadRecords< DirectoriesModel>("*",
|
Console.WriteLine("B. Query directory by ID");
|
||||||
GsmDbStruct.Tables.Directories,
|
Console.WriteLine("C. Query game by NAME");
|
||||||
GsmDbStruct.Columns.GameID,
|
Console.WriteLine("X. <--- Go back\n");
|
||||||
"600",
|
Console.Write(":");
|
||||||
true);
|
|
||||||
foreach (var entry in dm)
|
var userInput = Console.ReadLine();
|
||||||
|
Console.Write("\n\n");
|
||||||
|
|
||||||
|
switch (userInput.ToUpper())
|
||||||
{
|
{
|
||||||
//entry.Path = guid.ToString();
|
case "A":
|
||||||
fireLanceCRUD.InsertRecord("SaveData", entry);
|
Console.WriteLine("Enter a game ID:");
|
||||||
|
|
||||||
|
PrintGameEntries(gsmRO.LoadRecords<GameEntryModel>( GsmDbStruct.Columns.GameName,
|
||||||
|
GsmDbStruct.Tables.GameEntry,
|
||||||
|
GsmDbStruct.Columns.ID,
|
||||||
|
Console.ReadLine(),
|
||||||
|
true));
|
||||||
|
break;
|
||||||
|
case "B":
|
||||||
|
Console.WriteLine("Enter a game ID:");
|
||||||
|
|
||||||
|
PrintDirectories(gsmRO.LoadRecords<DirectoriesModel>( "*",
|
||||||
|
GsmDbStruct.Tables.Directories,
|
||||||
|
GsmDbStruct.Columns.GameID,
|
||||||
|
Console.ReadLine(),
|
||||||
|
true));
|
||||||
|
break;
|
||||||
|
case "C":
|
||||||
|
Console.WriteLine("Enter game title to search:");
|
||||||
|
|
||||||
|
PrintGameEntries(gsmRO.LoadRecords<GameEntryModel>( GsmDbStruct.Columns.GameName,
|
||||||
|
GsmDbStruct.Tables.GameEntry,
|
||||||
|
GsmDbStruct.Columns.GameName,
|
||||||
|
Console.ReadLine(),
|
||||||
|
false));
|
||||||
|
break;
|
||||||
|
case "X":
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void CmdFlcActions()
|
||||||
|
{
|
||||||
|
Console.WriteLine("A. FireLance Import Predefined SaveData Entry");
|
||||||
|
Console.WriteLine("X. <--- Go back\n");
|
||||||
|
Console.Write(":");
|
||||||
|
|
||||||
|
var userInput = Console.ReadLine();
|
||||||
|
Console.Write("\n\n");
|
||||||
|
|
||||||
|
switch (userInput.ToUpper())
|
||||||
|
{
|
||||||
|
case "A":
|
||||||
|
List<DirectoriesModel> dm = gsmRO.LoadRecords<DirectoriesModel>("*",
|
||||||
|
GsmDbStruct.Tables.Directories,
|
||||||
|
GsmDbStruct.Columns.GameID,
|
||||||
|
"600",
|
||||||
|
true);
|
||||||
|
foreach (var entry in dm)
|
||||||
|
{
|
||||||
|
//entry.Path = guid.ToString();
|
||||||
|
fireLanceCRUD.InsertRecord("SaveData", entry);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "X":
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
+16
-15
@@ -1,6 +1,7 @@
|
|||||||
using FireLance.Interfaces;
|
using FireLance.Interfaces;
|
||||||
using MongoDB.Bson;
|
using MongoDB.Bson;
|
||||||
using MongoDB.Driver;
|
using MongoDB.Driver;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace FireLance
|
namespace FireLance
|
||||||
{
|
{
|
||||||
@@ -8,21 +9,6 @@ namespace FireLance
|
|||||||
{
|
{
|
||||||
internal IMongoDatabase db;
|
internal IMongoDatabase db;
|
||||||
|
|
||||||
public void CloseCurrentConnection()
|
|
||||||
{
|
|
||||||
OpenConnection(string.Empty, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsConnectionOpen()
|
|
||||||
{
|
|
||||||
int connectionCnt = 0;
|
|
||||||
|
|
||||||
try { connectionCnt = db.Client.ListDatabases().ToList().Count; }
|
|
||||||
catch {}
|
|
||||||
|
|
||||||
return (connectionCnt > 0) ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OpenConnection(string dbLocation, int port)
|
public void OpenConnection(string dbLocation, int port)
|
||||||
{
|
{
|
||||||
var client = new MongoClient($"mongodb://{dbLocation}:{port}");
|
var client = new MongoClient($"mongodb://{dbLocation}:{port}");
|
||||||
@@ -30,5 +16,20 @@ namespace FireLance
|
|||||||
|
|
||||||
db = client.GetDatabase(dbLocation, settings);
|
db = client.GetDatabase(dbLocation, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void CloseCurrentConnection()
|
||||||
|
{
|
||||||
|
throw new NotSupportedException("MongoDB does not support closing connections.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsConnectionOpen()
|
||||||
|
{
|
||||||
|
int connectionCnt = 0;
|
||||||
|
|
||||||
|
try { connectionCnt = db.Client.ListDatabases().ToList().Count; }
|
||||||
|
catch { }
|
||||||
|
|
||||||
|
return (connectionCnt > 0) ? true : false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user