/// <summary> /// Set up the SQL connections for the table adapters when creating/opening /// a database. /// </summary> private void CreateConnections() { localDB = new DPDatabaseImportV1(); localTAManager = new DPDatabaseImportV1TableAdapters.TableAdapterManager(); localTAManager.ChatLogTableAdapter = new DPDatabaseImportV1TableAdapters.ChatLogTableAdapter(); // DVS/DirectParse uses SQLCE 3.1, so we can always do an upgrade here. System.Data.SqlServerCe.SqlCeEngine sqlCeEngine = new System.Data.SqlServerCe.SqlCeEngine(databaseConnectionString); // Creates a 0-byte file. We need the name, but don't want the file to exist. tempDatabaseName = Path.GetTempFileName(); File.Delete(tempDatabaseName); string tempConnectionString = string.Format("Data Source={0}", tempDatabaseName); sqlCeEngine.Upgrade(tempConnectionString); Properties.Settings.Default.Properties["DvsParse_SaveConnectionString"].DefaultValue = tempConnectionString; System.Data.SqlServerCe.SqlCeConnection sqlConn = new System.Data.SqlServerCe.SqlCeConnection(tempConnectionString); localTAManager.Connection = sqlConn; localTAManager.ChatLogTableAdapter.Connection = sqlConn; localTAManager.ChatLogTableAdapter.Fill(localDB.ChatLog); }
public void CloseDatabase() { if (localTAManager != null) { localTAManager.Dispose(); localTAManager = null; } if (localDB != null) { localDB.Dispose(); localDB = null; } if (tempDatabaseName != string.Empty) { if (File.Exists(tempDatabaseName)) { File.Delete(tempDatabaseName); } } }
/// <summary> /// Import database files created by DVSParse and DirectParse. /// </summary> private void ImportDirectParseDB() { int rowCount = 0; int totalCount = 0; bool completed = false; string originalChatLine; string breakCodes; string breakCodesChars; uint breakCharVal; char breakChar; List <ChatLine> chatLines = new List <ChatLine>(100); // For DVSD files: // logLine.RawHeader == "bf,00,00,60808080,00000288,000002f1,0034,00,01,00,00,(1E011E01)" // logLine.Text == "The Goblin Tinkerer seems like a decent challenge." // For DPD files: // logLine.RawHeader == "bf,00,00,60808080,00000288,000002f1,0034,00,01,00,00," // logLine.Text == "The Goblin Tinkerer seems like a decent challenge." // Need to combine those two lines back into the original Regex rawHeaderRegex = new Regex(@"^(?<codes>((\w|\d)+,){11})(\((?<breakCodes>(\w|\d)+)\))?$"); Match rawHeaderMatch; try { DirectParseReadingManager readingManager = dbReaderManager as DirectParseReadingManager; if (readingManager == null) { throw new ArgumentNullException(); } DPDatabaseImportV1 readDataSet = readingManager.Database; if (readDataSet != null) { totalCount = readDataSet.ChatLog.Count; // Read the (fixed) record log from the database, reconstruct // the chat line, and send it to the new database. using (new RegionProfiler("Import: Read database and parse")) { foreach (var logLine in readDataSet.ChatLog) { rowCount++; if (IsRunning == false) { break; } rawHeaderMatch = rawHeaderRegex.Match(logLine.RawHeader); if (rawHeaderMatch.Success == true) { originalChatLine = rawHeaderMatch.Groups["codes"].Value; breakCodes = rawHeaderMatch.Groups["breakCodes"].Value; if (breakCodes.Length > 0) { while (breakCodes.Length > 0) { breakCodesChars = breakCodes.Substring(0, 2); if (uint.TryParse(breakCodesChars, NumberStyles.AllowHexSpecifier, null, out breakCharVal)) { breakChar = (char)breakCharVal; originalChatLine += breakChar; } if (breakCodes.Length > 2) { breakCodes = breakCodes.Substring(2); } else { breakCodes = string.Empty; } } } else { // Force insert basic break characters if they weren't saved in the // imported database, so that they get parsed properly by our tokenizer. originalChatLine += (char)0x1e; originalChatLine += (char)0x01; originalChatLine += (char)0x1e; originalChatLine += (char)0x01; } originalChatLine += logLine.Text; chatLines.Add(new ChatLine(originalChatLine, logLine.DateTime)); //if (upgradeTimestamp == true) // chatLines.Add(new ChatLine(originalChatLine, logLine.DateTime.ToUniversalTime())); //else // chatLines.Add(new ChatLine(originalChatLine, logLine.DateTime)); } 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; } } else { throw new InvalidDataException("No database to parse."); } } catch (Exception e) { Logger.Instance.Log(e); } finally { IsRunning = false; OnReaderStatusChanged(new ReaderStatusEventArgs(rowCount, totalCount, completed, (completed != true))); dbReaderManager.CloseDatabase(); } }