예제 #1
0
 public void WriteDataTableCallsigns(DataTableCallsigns dt)
 {
     if (dt != null)
     {
         db.ClearTable(dt.TableName);
         db.InsertOrReplaceTable(dt);
     }
 }
예제 #2
0
 public ScoutBaseDatabase()
 {
     try
     {
         // create dictionaries
         versioninfo = new VersionInfo();
         callsigns   = new CallsignDictionary();
         horizons    = new HorizonDictionary();
         // check if database path exists --> create if not
         if (!Directory.Exists(DefaultDatabaseDirectory()))
         {
             Directory.CreateDirectory(DefaultDatabaseDirectory());
         }
         // check if database is already on disk
         DBPath = Path.Combine(DefaultDatabaseDirectory(), "ScoutBase.db3");
         if (!File.Exists(DBPath))
         {
             // create one on disk
             System.Data.SQLite.SQLiteDatabase dbn = new System.Data.SQLite.SQLiteDatabase(DBPath);
             dbn.Open();
             dbn.CreateTable(new DataTableVersionInfo());
             dbn.CreateTable(new DataTableCallsigns());
             dbn.CreateTable(new DataTableHorizons());
             dbn.CreateTable(new DataTableGLOBE());
             dbn.CreateTable(new DataTableSRTM3());
             dbn.CreateTable(new DataTableSRTM1());
             if (String.IsNullOrEmpty(versioninfo.Version))
             {
                 // no version info
                 // initally create one and store in database
                 versioninfo.Version     = System.Reflection.Assembly.GetAssembly(typeof(ScoutBaseDatabase)).GetName().Version.ToString();
                 versioninfo.LastUpdated = DateTime.UtcNow;
                 dbn.InsertOrReplaceTable(versioninfo.WriteToTable());
             }
             dbn.Close();
         }
         if (Properties.Settings.Default.Database_InMemory)
         {
             db = System.Data.SQLite.SQLiteDatabase.CreateInMemoryDB(DBPath);
         }
         else
         {
             db = new System.Data.SQLite.SQLiteDatabase(DBPath);
             db.Open();
         }
         // check version
         if (String.Compare(System.Reflection.Assembly.GetAssembly(typeof(ScoutBaseDatabase)).GetName().Version.ToString(), versioninfo.Version) > 0)
         {
             // do any upgrade stuff here if necessary
         }
         // read data tables and initialize dictionaries
         ReadDataTables();
     }
     catch (Exception ex)
     {
         Console.WriteLine("Error initilalizing database: " + ex.Message);
         throw new TypeInitializationException(this.GetType().Name, ex);
     }
 }