Example #1
0
        public void UpdateFromDataTables(bool clear = true)
        {
            // update from tables from database into dictionaries
            // create empty dictionaries if not already created
            if (callsigns == null)
            {
                callsigns = new CallsignDictionary();
            }
            if (horizons == null)
            {
                horizons = new HorizonDictionary();
            }
            // clear dictionaries
            if (clear)
            {
                callsigns.Clear();
                horizons.Clear();
            }
            // fill dictionaries
            DataTable dt;

            dt = db.Select("SELECT * FROM " + new DataTableCallsigns().TableName);
            callsigns.FromTable(dt);
            dt = db.Select("SELECT * FROM " + new DataTableHorizons().TableName);
            horizons.FromTable(dt);
        }
Example #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);
     }
 }
Example #3
0
 public JSONArrayCallsigns(CallsignDictionary callsigns)
 {
     version    = callsigns.Version;
     full_count = callsigns.Calls.Count;
     calls      = new List <List <string> >(full_count);
     foreach (CallsignDesignator call in callsigns.Calls.Values)
     {
         List <string> l = new List <string>();
         l.Add(call.Call);
         l.Add(call.Lat.ToString("F8", CultureInfo.InvariantCulture));
         l.Add(call.Lon.ToString("F8", CultureInfo.InvariantCulture));
         l.Add(call.Source.ToString());
         l.Add(call.LastUpdated.ToString("u"));
         calls.Add(l);
     }
 }
Example #4
0
        public void ReadDataTables()
        {
            // initialize and load tables from database into directories
            DataTable dt;

            dt = db.Select("SELECT * FROM '" + new DataTableCallsigns().TableName + "'");
            if ((dt != null) && (dt.Rows.Count > 0))
            {
                callsigns = new CallsignDictionary(dt);
            }
            else
            {
                callsigns = new CallsignDictionary();
            }
            dt = db.Select("SELECT * FROM " + new DataTableHorizons().TableName);
            if ((dt != null) && (dt.Rows.Count > 0))
            {
                horizons = new HorizonDictionary(dt);
            }
            else
            {
                horizons = new HorizonDictionary();
            }
        }