public override bool CanRefreshData() { using (var db = new SqlCEContext()) { // See if there's actually data in the DB var commodityCount = from comm in db.Commodities select comm; if (commodityCount.Count() == 0) return true; // Check the last update on a volatile table var latestCommodity = from comm in db.Commodities where comm.Updated < DbFunctions.AddDays(DateTime.Now, -1) select comm; if (latestCommodity.Count() > 0) return true; } return false; }
// Abstract LoggableDataProvider Implementations public override void Save() { try { using(var db = new SqlCEContext()) { if (commodities != null) db.Commodities.AddRange(commodities); if (modules != null) db.Modules.AddRange(modules); if (stations != null) db.Stations.AddRange(stations); if (systems != null) db.Systems.AddRange(systems); db.SaveChanges(); } } catch (Exception e) { logger.Error(e, "Unable to save to the database"); logger.Debug(e); } }
public override void DeleteDatabase() { try { using (var db = new SqlCEContext()) { db.DeleteDatabase(); } } catch (Exception e) { logger.Error(e, "Unable to clear the database"); logger.Debug(e); } }
// METHODS public override void Load() { logger.Trace("Using compression: {0}", UseCompression); if (CanRefreshData()) { CalculateDownloadSize(); DownloadFiles(); } else { using (var db = new SqlCEContext()) { commodities = db.Commodities.ToList(); modules = db.Modules.ToList(); stations = db.Stations.ToList(); systems = db.Systems.ToList(); } } // Signal completion if (DataLoadCompleted != null) DataLoadCompleted(this, EventArgs.Empty); }