using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Data; using System.Data.Common; using System.Reflection; using System.Text; using Microsoft.Win32; using Microsoft.Samples.Debugging.CorSymbolStore; using System.Diagnostics.SymbolStore; using System.Configuration; using System.Threading; using System.Data.SQLite; using Dapper; using SQLinq; using SQLinq.Dapper; using DapperExtensions; using DapperExtensions.Mapper; using DapperExtensions.Sql; namespace Cosmos.Debug.Common { public class DebugInfo : IDisposable { // Please beware this field, it may cause issues if used incorrectly. public static DebugInfo CurrentInstance { get; private set; } public class Field_Map { public string TypeName { get; set; } public List FieldNames = new List(); } protected SQLiteConnection mConnection; protected string mDbName; // Dont use DbConnectionStringBuilder class, it doesnt work with LocalDB properly. //protected mDataSouce = @".\SQLEXPRESS"; protected string mConnStr; public void DeleteDB(string aDbName, string aPathname) { File.Delete(aDbName); } public DebugInfo(string aPathname, bool aCreate = false) { CurrentInstance = this; if (aCreate) { File.Delete(aPathname); } aCreate = !File.Exists(aPathname); // Manually register the data provider. Do not remove this otherwise the data provider doesn't register properly. mConnStr = String.Format("data source={0};journal mode=Memory;synchronous=Off;foreign keys=True;BinaryGuid=false", aPathname); // Use the SQLiteConnectionFactory as the default database connection // Do not open mConnection before mEntities.CreateDatabase mConnection = new SQLiteConnection(mConnStr); DapperExtensions.DapperExtensions.DefaultMapper = typeof(PluralizedAutoClassMapper<>); DapperExtensions.DapperExtensions.SqlDialect = new SqliteDialect(); if (aCreate) { // DatabaseExists checks if the DBName exists, not physical files. if (aCreate) { mConnection.Open(); var xSQL = new SQL(mConnection); xSQL.CreateDB(); // Be careful with indexes, they slow down inserts. So on tables that we have a // lot of inserts, but limited look ups, dont add them. // xSQL.MakeIndex("Labels", "Address", false); xSQL.MakeIndex("Labels", "Name", true); xSQL.MakeIndex("Methods", "DocumentID", false); } } if (mConnection.State == ConnectionState.Closed) { mConnection.Open(); } } public IDbConnection Connection { get { return mConnection; } } // The GUIDs etc are populated by the MSBuild task, so they wont be loaded when the debugger runs. // Because of this, we also allow manual loading. public void LoadLookups() { foreach (var xDoc in Connection.Query(new SQLinq().ToSQL().ToQuery())) { DocumentGUIDs.Add(xDoc.Pathname.ToLower(), xDoc.ID); } } public UInt32 AddressOfLabel(string aLabel) { var xRow = Connection.Query