public MazakBackend(IConfiguration configuration, FMSSettings st) { var cfg = configuration.GetSection("Mazak"); string localDbPath = cfg.GetValue <string>("Database Path"); MazakType = DetectMazakType(cfg, localDbPath); // database settings string sqlConnectString = cfg.GetValue <string>("SQL ConnectionString"); string dbConnStr; if (MazakType == MazakDbType.MazakSmooth) { 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 { var b = new System.Data.SqlClient.SqlConnectionStringBuilder(); b.UserID = "mazakpmc"; b.Password = "******"; b.DataSource = "(local)"; dbConnStr = b.ConnectionString; } } else { dbConnStr = localDbPath; if (string.IsNullOrEmpty(dbConnStr)) { dbConnStr = "c:\\Mazak\\NFMS\\DB"; } } // log csv string logPath = cfg.GetValue <string>("Log CSV Path"); if (logPath == null || logPath == "") { logPath = "c:\\Mazak\\FMS\\Log"; } if (MazakType != MazakDbType.MazakVersionE && !System.IO.Directory.Exists(logPath)) { Log.Error("Log CSV Directory {path} does not exist. Set the directory in the config.ini file.", logPath); } else if (MazakType != MazakDbType.MazakVersionE) { Log.Information("Loading log CSV files from {logcsv}", logPath); } // general config string useStarting = cfg.GetValue <string>("Use Starting Offset For Due Date"); string useStarting2 = cfg.GetValue <string>("Use Starting Offset"); if (string.IsNullOrEmpty(useStarting)) { if (string.IsNullOrEmpty(useStarting2)) { UseStartingOffsetForDueDate = true; } else { UseStartingOffsetForDueDate = Convert.ToBoolean(useStarting2); } } else { UseStartingOffsetForDueDate = Convert.ToBoolean(useStarting); } //Perhaps this should be a new setting, but if you don't check for pallets used once //then you don't care if all faces on a pallet are full so might as well use priority //which causes pallet positions to go empty. CheckPalletsUsedOnce = !UseStartingOffsetForDueDate; ProgramDirectory = cfg.GetValue <string>("Program Directory"); if (string.IsNullOrEmpty(ProgramDirectory)) { ProgramDirectory = "C:\\NCProgs"; } // serial settings string serialPerMaterial = cfg.GetValue <string>("Assign Serial Per Material"); if (!string.IsNullOrEmpty(serialPerMaterial)) { bool result; if (bool.TryParse(serialPerMaterial, out result)) { if (!result) { st.SerialType = SerialType.AssignOneSerialPerCycle; } } } Log.Debug( "Configured UseStartingOffsetForDueDate = {useStarting}", UseStartingOffsetForDueDate); jobLog = new BlackMaple.MachineFramework.JobLogDB(st); jobLog.Open( System.IO.Path.Combine(st.DataDirectory, "log.db"), System.IO.Path.Combine(st.DataDirectory, "insp.db"), startingSerial: st.StartingSerial ); jobDB = new BlackMaple.MachineFramework.JobDB(); var jobInspName = System.IO.Path.Combine(st.DataDirectory, "jobinspection.db"); if (System.IO.File.Exists(jobInspName)) { jobDB.Open(jobInspName); } else { jobDB.Open(System.IO.Path.Combine(st.DataDirectory, "mazakjobs.db")); } _writeDB = new OpenDatabaseKitTransactionDB(dbConnStr, MazakType); if (MazakType == MazakDbType.MazakVersionE) { loadOper = new LoadOperationsFromFile(cfg, enableWatcher: true); } else if (MazakType == MazakDbType.MazakWeb) { loadOper = new LoadOperationsFromFile(cfg, enableWatcher: false); // web instead watches the log csv files } else { loadOper = null; // smooth db doesn't use the load operations file } var openReadDb = new OpenDatabaseKitReadDB(dbConnStr, MazakType, loadOper); if (MazakType == MazakDbType.MazakSmooth) { _readDB = new SmoothReadOnlyDB(dbConnStr, openReadDb); } else { _readDB = openReadDb; } queues = new MazakQueues(jobLog, jobDB, _writeDB); var sendToExternal = new SendMaterialToExternalQueue(); hold = new HoldPattern(_writeDB, _readDB, jobDB, true); var writeJobs = new WriteJobs(_writeDB, _readDB, hold, jobDB, jobLog, st, CheckPalletsUsedOnce, UseStartingOffsetForDueDate, ProgramDirectory); var decr = new DecrementPlanQty(jobDB, _writeDB, _readDB); if (MazakType == MazakDbType.MazakWeb || MazakType == MazakDbType.MazakSmooth) { logDataLoader = new LogDataWeb(logPath, jobLog, jobDB, writeJobs, sendToExternal, _readDB, queues, st); } else { #if USE_OLEDB logDataLoader = new LogDataVerE(jobLog, jobDB, sendToExternal, writeJobs, _readDB, queues, st); #else throw new Exception("Mazak Web and VerE are not supported on .NET core"); #endif } routing = new RoutingInfo(_writeDB, writeJobs, _readDB, logDataLoader, jobDB, jobLog, writeJobs, queues, decr, CheckPalletsUsedOnce, st); logDataLoader.NewEntries += OnNewLogEntries; if (loadOper != null) { loadOper.LoadActions += OnLoadActions; } }
public SmoothReadOnlyDB(string connectionStr, OpenDatabaseKitReadDB readDb) { _connStr = connectionStr + ";Database=PMC_Basic"; _readConnStr = connectionStr + ";Database=FCREADDAT01"; _openReadDB = readDb; }