Skip to content

Commit

Permalink
mazak: rework config settings
Browse files Browse the repository at this point in the history
  • Loading branch information
wuzzeb committed Sep 6, 2024
1 parent 605d192 commit f1e9991
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 118 deletions.
1 change: 1 addition & 0 deletions server/machines/mazak-proxy/MazakConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class MazakConfig
{
public MazakDbType DBType { get; init; }
public string SQLConnectionString { get; init; }
public string OleDbDatabasePath { get; init; }
public string LogCSVPath { get; init; }
public string LoadCSVPath { get; init; }
}
95 changes: 40 additions & 55 deletions server/machines/mazak/MazakConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ namespace MazakMachineInterface
public record MazakConfig
{
public required MazakDbType DBType { get; init; }
public required string SQLConnectionString { get; init; }
public required string LogCSVPath { get; init; }
public required string ProgramDirectory { get; init; }
public string? SQLConnectionString { get; init; }
public string? OleDbDatabasePath { get; init; }
public string? LogCSVPath { get; init; }
public string? ProgramDirectory { get; init; }
public string? LoadCSVPath { get; init; }
public bool UseStartingOffsetForDueDate { get; init; } = true;
public bool WaitForAllCastings { get; init; } = false;
Expand All @@ -67,44 +68,34 @@ public record MazakConfig
public static MazakConfig Load(IConfiguration configuration)
{
var cfg = configuration.GetSection("Mazak");
var localDbPath = cfg.GetValue<string>("Database Path");
var sqlConnectString = cfg.GetValue<string>("SQL ConnectionString");
var localDbPath = cfg.GetValue<string>("Database Path") ?? "c:\\Mazak\\NFMS\\DB";
var dbtype = DetectMazakType(cfg, localDbPath);

// database settings
string dbConnStr;
if (dbtype == MazakDbType.MazakSmooth)
var sqlConnectString = cfg.GetValue<string>("SQL ConnectionString");
if (!string.IsNullOrEmpty(sqlConnectString))
{
if (!string.IsNullOrEmpty(sqlConnectString))
{
dbConnStr = sqlConnectString;
}
else if (!string.IsNullOrEmpty(localDbPath))
{
// old installers put sql server computer name in localDbPath
dbConnStr = "Server=" + localDbPath + "\\pmcsqlserver;" + "User ID=mazakpmc;Password=Fms-978";
}
else
dbConnStr = sqlConnectString;
}
else if (dbtype == MazakDbType.MazakSmooth)
{
var b = new System.Data.SqlClient.SqlConnectionStringBuilder
{
var b = new System.Data.SqlClient.SqlConnectionStringBuilder
{
UserID = "mazakpmc",
Password = "Fms-978",
DataSource = "(local)",
};
dbConnStr = b.ConnectionString;
}
UserID = "mazakpmc",
Password = "Fms-978",
DataSource = "(local)",
};
dbConnStr = b.ConnectionString;
}
else
{
dbConnStr = localDbPath ?? "c:\\Mazak\\NFMS\\DB";
dbConnStr =
"Provider=Microsoft.ACE.OLEDB.12.0;Password=\"\";" + "User ID=Admin;" + "Mode=Share Deny None;";
}

// log csv
var logPath = cfg.GetValue<string>("Log CSV Path");
if (logPath == null || logPath == "")
logPath = "c:\\Mazak\\FMS\\Log";

var logPath = cfg.GetValue<string>("Log CSV Path") ?? "c:\\Mazak\\FMS\\Log";
if (dbtype != MazakDbType.MazakVersionE && !System.IO.Directory.Exists(logPath))
{
Serilog.Log.Error(
Expand All @@ -116,30 +107,21 @@ public static MazakConfig Load(IConfiguration configuration)
string? loadPath = null;
if (dbtype == MazakDbType.MazakVersionE || dbtype == MazakDbType.MazakWeb)
{
loadPath = cfg.GetValue<string>("Load CSV Path");
if (string.IsNullOrEmpty(loadPath))
{
loadPath = "c:\\mazak\\FMS\\LDS\\";
}

loadPath = cfg.GetValue<string>("Load CSV Path") ?? "c:\\mazak\\FMS\\LDS";
if (!System.IO.Directory.Exists(loadPath))
{
loadPath = "c:\\mazak\\LDS\\";

if (!System.IO.Directory.Exists(loadPath))
{
Serilog.Log.Error(
"Unable to determine the path to the mazak load CSV files. Please add/update a setting"
+ " called 'Load CSV Path' in config file"
);
}
Serilog.Log.Error(
"Load CSV Directory {path} does not exist. Set the directory in the config.ini file.",
loadPath
);
}
}

return new MazakConfig
{
DBType = dbtype,
SQLConnectionString = dbConnStr,
OleDbDatabasePath = localDbPath,
LogCSVPath = logPath,
LoadCSVPath = loadPath,
ProgramDirectory = cfg.GetValue<string?>("Program Directory") ?? "C:\\NCProgs",
Expand All @@ -150,29 +132,32 @@ public static MazakConfig Load(IConfiguration configuration)
};
}

private static MazakDbType DetectMazakType(IConfigurationSection cfg, string? localDbPath)
private static MazakDbType DetectMazakType(IConfigurationSection cfg, string localDbPath)
{
var verE = cfg.GetValue<bool>("VersionE");
var webver = cfg.GetValue<bool>("Web Version");
var smoothVer = cfg.GetValue<bool>("Smooth Version");

string testPath = System.IO.Path.Combine(localDbPath, "FCREADDAT01.mdb");

if (verE || webver)
{
if (!System.IO.File.Exists(testPath))
{
Serilog.Log.Error(
"Mazak Version E or Web Version selected, but database file {path} does not exist.",
testPath
);
}
}

if (verE)
return MazakDbType.MazakVersionE;
else if (webver)
return MazakDbType.MazakWeb;
else if (smoothVer)
return MazakDbType.MazakSmooth;

string testPath;
if (string.IsNullOrEmpty(localDbPath))
{
testPath = "C:\\Mazak\\NFMS\\DB\\FCREADDAT01.mdb";
}
else
{
testPath = System.IO.Path.Combine(localDbPath, "FCREADDAT01.mdb");
}

if (System.IO.File.Exists(testPath))
{
//TODO: open database to check column existance for web vs E.
Expand Down
4 changes: 3 additions & 1 deletion server/machines/mazak/db/DataAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -760,13 +760,15 @@ public interface ICurrentLoadActions

public interface IMazakDB
{
MazakDbType MazakType { get; }
MazakAllData LoadAllData();
MazakAllDataAndLogs LoadAllDataAndLogs(string maxLogID);
IEnumerable<MazakProgramRow> LoadPrograms();
IEnumerable<ToolPocketRow> LoadTools();
void DeleteLogs(string lastSeenForeignId);

void Save(MazakWriteData data);

event Action OnNewEvent;
}

[DataContract]
Expand Down
Loading

0 comments on commit f1e9991

Please sign in to comment.