Exemple #1
0
        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;
        }
Exemple #2
0
        // 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);
            }
        }
Exemple #3
0
 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);
     }
 }
Exemple #4
0
        // 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);
        }