コード例 #1
0
 private bool IsDatabaseComplete()
 {
     // checks if elevation database is complete
     try
     {
         // get all locs needed for covered area
         // try to read cached catalogue first
         ElevationCatalogue cat = ElevationData.Database.ElevationCatalogueCreateCheckBoundsAndLastModified(null, StartOptions.Model, StartOptions.MinLat, StartOptions.MinLon, StartOptions.MaxLat, StartOptions.MaxLon);
         // process tiles
         foreach (KeyValuePair <string, DateTime> availabletile in cat.Files)
         {
             // check if tile is in database and return false if tile is not found
             if (!ElevationData.Database.ElevationTileExists(availabletile.Key.Substring(0, 6).ToUpper(), StartOptions.Model))
             {
                 return(false);
             }
             if (this.CancellationPending)
             {
                 break;
             }
         }
     }
     catch (Exception ex)
     {
         this.ReportProgress(-1, ex.ToString());
         return(false);
     }
     return(true);
 }
コード例 #2
0
        public static ElevationCatalogue FromJSONFileCheckBoundsAndLastModified(string filename, double minlat, double minlon, double maxlat, double maxlon)
        {
            // read cache from json file
            ElevationCatalogue cat = FromJSONFile(filename);

            // return null on error
            if (cat == null)
            {
                return(null);
            }
            // check last write time from json file --> must be equal to LastModification timestamp of catalogue
            if (File.GetLastWriteTimeUtc(filename) != cat.LastModified)
            {
                return(null);
            }
            // check if bounds are equal
            if ((cat.MinLat != minlat) || (cat.MinLon != minlon) || (cat.MaxLat != maxlat) || (cat.MaxLon != maxlon))
            {
                return(null);
            }
            // success --> return cached catalogue
            return(cat);
        }
コード例 #3
0
        private int UpdateDatabase()
        {
            // updates elevation database
            int errors  = 0;
            int bulkmax = 400;

            try
            {
                // get all locs needed for covered area
                // try to read cached catalogue first
                ElevationCatalogue cat = ElevationData.Database.ElevationCatalogueCreateCheckBoundsAndLastModified(null, StartOptions.Model, StartOptions.MinLat, StartOptions.MinLon, StartOptions.MaxLat, StartOptions.MaxLon);
                // process tiles
                List <ElevationTileDesignator> tiles = new List <ElevationTileDesignator>();
                foreach (KeyValuePair <string, DateTime> availabletile in cat.Files)
                {
                    // collect tiles for bulk insert
                    ElevationTileDesignator t;
                    bool b = UpdateElevationTileFromURL(availabletile.Key, availabletile.Value, StartOptions.Model, out t);
                    if (b)
                    {
                        if (t != null)
                        {
                            tiles.Add(t);
                        }
                    }
                    else
                    {
                        errors++;
                    }
                    if (tiles.Count >= bulkmax)
                    {
                        errors -= ElevationData.Database.ElevationTileBulkInsert(tiles, StartOptions.Model);
                        tiles.Clear();
                    }
                    if (this.CancellationPending)
                    {
                        break;
                    }
                    // sleep or not whether database is complete
                    if ((ElevationData.Database.GetDBStatus(StartOptions.Model) & DATABASESTATUS.COMPLETE) > 0)
                    {
                        Thread.Sleep(Properties.Settings.Default.Database_BackgroundUpdate_ThreadWait);
                    }
                    else
                    {
                        Thread.Sleep(10);
                    }
                }
                // update rest of tiles
                if (tiles.Count > 0)
                {
                    errors -= ElevationData.Database.ElevationTileBulkInsert(tiles, StartOptions.Model);
                }
                // cleanup all *.loc files
                foreach (string f in Directory.EnumerateFiles(ElevationData.Database.DefaultDatabaseDirectory(StartOptions.Model), "*.loc"))
                {
                    try
                    {
                        File.Delete(f);
                    }
                    catch (Exception ex)
                    {
                        this.ReportProgress(-1, ex.ToString() + ": " + f);
                        errors++;
                    }
                }
            }
            catch (Exception ex)
            {
                this.ReportProgress(-1, ex.ToString());
                // report at least one error
                if (errors == 0)
                {
                    errors = 1;
                }
                return(-errors);
            }
            return(-errors);
        }