/// <summary> /// Set up the SQL connections for the table adapters when creating/opening /// a database. /// </summary> private void CreateConnections() { localDB = new KPDatabaseReadOnly(); localTAManager = new KPDatabaseReadOnlyTableAdapters.TableAdapterManager(); localTAManager.RecordLogTableAdapter = new KPDatabaseReadOnlyTableAdapters.RecordLogTableAdapter(); localTAManager.VersionTableAdapter = new KPDatabaseReadOnlyTableAdapters.VersionTableAdapter(); localTAManager.CombatantsTableAdapter = new KPDatabaseReadOnlyTableAdapters.CombatantsTableAdapter(); System.Data.SqlServerCe.SqlCeConnection sqlConn = new System.Data.SqlServerCe.SqlCeConnection(databaseConnectionString); localTAManager.Connection = sqlConn; localTAManager.RecordLogTableAdapter.Connection = sqlConn; localTAManager.VersionTableAdapter.Connection = sqlConn; localTAManager.CombatantsTableAdapter.Connection = sqlConn; // If opening an existing database, need to check version info before filling data localTAManager.RecordLogTableAdapter.Fill(localDB.RecordLog); localTAManager.VersionTableAdapter.Fill(localDB.Version); localTAManager.CombatantsTableAdapter.Fill(localDB.Combatants); }
public void CloseDatabase() { if (localTAManager != null) { localTAManager.Dispose(); localTAManager = null; } if (localDB != null) { localDB.Dispose(); localDB = null; } }
/// <summary> /// Import (reparse) KParser database files. /// </summary> private void ImportKParserDB() { int rowCount = 0; int totalCount = 0; bool completed = false; try { KParserReadingManager readingManager = dbReaderManager as KParserReadingManager; if (readingManager == null) { throw new ArgumentNullException(); } KPDatabaseReadOnly readDataSet = readingManager.Database; if (readDataSet != null) { List <ChatLine> chatLines = new List <ChatLine>(100); totalCount = readDataSet.RecordLog.Count; // Read the (fixed) record log from the database, reconstruct // the chat line, and send it to the new database. foreach (var logLine in readDataSet.RecordLog) { rowCount++; if (IsRunning == false) { break; } if (useTimeRange == true) { DateTime logLineTime = logLine.Timestamp; if (upgradeTimestamp == true) { logLineTime = logLine.Timestamp.ToUniversalTime(); } if ((logLineTime >= startOfTimeRange) && (logLineTime <= endOfTimeRange)) { chatLines.Add(new ChatLine(logLine.MessageText, logLineTime)); } } else { if (upgradeTimestamp == true) { chatLines.Add(new ChatLine(logLine.MessageText, logLine.Timestamp.ToUniversalTime())); } else { chatLines.Add(new ChatLine(logLine.MessageText, logLine.Timestamp)); } } OnReaderStatusChanged(new ReaderStatusEventArgs(rowCount, totalCount, completed, false)); if (chatLines.Count > 99) { OnReaderDataChanged(new ReaderDataEventArgs(chatLines)); chatLines = new List <ChatLine>(100); } } if (chatLines.Count > 0) { OnReaderDataChanged(new ReaderDataEventArgs(chatLines)); } completed = IsRunning; List <PlayerInfo> playerInfoList = new List <PlayerInfo>(); foreach (var player in readDataSet.Combatants) { playerInfoList.Add(new PlayerInfo() { Name = player.CombatantName, CombatantType = (EntityType)player.CombatantType, Info = player.PlayerInfo }); } WaywardGamers.KParser.Parsing.MsgManager.Instance.PlayerInfoList = playerInfoList; } else { throw new InvalidDataException("No database to parse."); } } catch (ThreadAbortException e) { Logger.Instance.Log(e); } catch (Exception e) { Logger.Instance.Log(e); } finally { IsRunning = false; OnReaderStatusChanged(new ReaderStatusEventArgs(rowCount, totalCount, completed, (completed == false))); dbReaderManager.CloseDatabase(); } }