public static Location LoadOrCreate(string locationName, string overlayFile, string databaseDirectory, string pluginDirectory, out IMasterDatabaseService databaseService, out EnvironmentalCacheService cacheService, out PluginManagerService pluginService) { Console.WriteLine("Creating database service..."); databaseService = new MasterDatabaseService {MasterDatabaseDirectory = databaseDirectory}; Console.WriteLine("Loading plugins..."); pluginService = new PluginManagerService {PluginDirectory = pluginDirectory}; cacheService = new EnvironmentalCacheService(pluginService, databaseService); Console.WriteLine(string.Format("Looking for test location '{0}'...", locationName)); var location = databaseService.FindLocation(locationName); if (location != null) { Console.WriteLine(string.Format("Test location '{0}' already exists. Deleting the existing location.", locationName)); databaseService.DeleteLocation(location); } Console.WriteLine(string.Format("Creating test location '{0}'...", locationName)); location = databaseService.ImportLocationFromOverlayFile(overlayFile, locationName); foreach (var month in NAVOConfiguration.AllMonths) { // SoundSpeed dataset for each month Console.WriteLine(string.Format("Importing soundspeed for {0}", month)); cacheService.ImportDatasetTest(databaseService.LoadOrCreateEnvironmentalDataSet(location, 15, month, pluginService[PluginType.EnvironmentalDataSource, PluginSubtype.SoundSpeed].PluginIdentifier)); // Wind dataset for each month Console.WriteLine(string.Format("Importing wind for {0}", month)); cacheService.ImportDatasetTest(databaseService.LoadOrCreateEnvironmentalDataSet(location, 60, month, pluginService[PluginType.EnvironmentalDataSource, PluginSubtype.Wind].PluginIdentifier)); } // Sediment dataset Console.WriteLine("Importing sediment"); cacheService.ImportDatasetTest(databaseService.LoadOrCreateEnvironmentalDataSet(location, 5f, TimePeriod.Invalid, pluginService[PluginType.EnvironmentalDataSource, PluginSubtype.Sediment].PluginIdentifier)); // Bathymetry dataset at 2min resolution Console.WriteLine("Importing 2min bathymetry"); cacheService.ImportDatasetTest(databaseService.LoadOrCreateEnvironmentalDataSet(location, 2f, TimePeriod.Invalid, pluginService[PluginType.EnvironmentalDataSource, PluginSubtype.Bathymetry].PluginIdentifier)); // Bathymetry dataset at 1min resolution Console.WriteLine("Importing 1min bathymetry"); cacheService.ImportDatasetTest(databaseService.LoadOrCreateEnvironmentalDataSet(location, 1f, TimePeriod.Invalid, pluginService[PluginType.EnvironmentalDataSource, PluginSubtype.Bathymetry].PluginIdentifier)); // Bathymetry dataset at 0.5min resolution Console.WriteLine("Importing 0.5min bathymetry"); cacheService.ImportDatasetTest(databaseService.LoadOrCreateEnvironmentalDataSet(location, 0.5f, TimePeriod.Invalid, pluginService[PluginType.EnvironmentalDataSource, PluginSubtype.Bathymetry].PluginIdentifier)); return location; }
public void CreateNewSimulation() { Console.WriteLine("Creating database service..."); var database = new MasterDatabaseService { MasterDatabaseDirectory = _databaseDirectory }; Console.WriteLine("Loading plugins..."); var plugins = new PluginManagerService { PluginDirectory = PluginDirectory }; Console.WriteLine("Looking for test location 'Jacksonville'..."); var location = database.FindLocation("Jacksonville"); if (location == null) { Console.WriteLine("Creating test location 'Jacksonville'..."); location = database.ImportLocationFromOverlayFile(@"C:\Users\Dave Anderson\Desktop\NAEMO demos\BU Test Sample\Sim Areas\Jacksonville\Areas\Jax_Ops_Area.ovr", "Jacksonville"); foreach (var month in NAVOConfiguration.AllMonths) { // SoundSpeed dataset for each month database.LoadOrCreateEnvironmentalDataSet(location, 15, month, plugins[PluginType.EnvironmentalDataSource, PluginSubtype.SoundSpeed].PluginIdentifier); // Wind dataset for each month database.LoadOrCreateEnvironmentalDataSet(location, 60, month, plugins[PluginType.EnvironmentalDataSource, PluginSubtype.Wind].PluginIdentifier); } // Sediment dataset database.LoadOrCreateEnvironmentalDataSet(location, 5f, TimePeriod.Invalid, plugins[PluginType.EnvironmentalDataSource, PluginSubtype.Sediment].PluginIdentifier); // Bathymetry dataset at 2min resolution database.LoadOrCreateEnvironmentalDataSet(location, 2f, TimePeriod.Invalid, plugins[PluginType.EnvironmentalDataSource, PluginSubtype.Bathymetry].PluginIdentifier); // Bathymetry dataset at 1min resolution database.LoadOrCreateEnvironmentalDataSet(location, 1f, TimePeriod.Invalid, plugins[PluginType.EnvironmentalDataSource, PluginSubtype.Bathymetry].PluginIdentifier); // Bathymetry dataset at 0.5min resolution database.LoadOrCreateEnvironmentalDataSet(location, 0.5f, TimePeriod.Invalid, plugins[PluginType.EnvironmentalDataSource, PluginSubtype.Bathymetry].PluginIdentifier); } Console.WriteLine("Looking for test scenario 'BU Test Sample'..."); var scenario = database.FindScenario("BU Test Sample"); if (scenario == null) { Console.WriteLine("Importing test scenario 'BU Test Sample'..."); scenario = Scenario.FromNemoFile(database, location, @"C:\Users\Dave Anderson\Desktop\NAEMO demos\BU Test Sample\Jacksonville\BU Test Sample.nemo", @"C:\Users\Dave Anderson\Desktop\NAEMO demos\BU Test Sample\Sim Areas"); database.SetEnvironmentalData(scenario, (from data in location.EnvironmentalDataSets where data.SourcePlugin.PluginSubtype == PluginSubtype.Wind select data).FirstOrDefault()); var sourceFile = Path.Combine(database.MasterDatabaseDirectory, location.StorageDirectory, scenario.Wind.FileName); var destFile = Path.Combine(_databaseDirectory, scenario.Wind.FileName); if (File.Exists(sourceFile)) File.Copy(sourceFile, destFile); database.SetEnvironmentalData(scenario, (from data in location.EnvironmentalDataSets where data.SourcePlugin.PluginSubtype == PluginSubtype.SoundSpeed select data).FirstOrDefault()); sourceFile = Path.Combine(database.MasterDatabaseDirectory, location.StorageDirectory, scenario.SoundSpeed.FileName); destFile = Path.Combine(_databaseDirectory, scenario.SoundSpeed.FileName); if (File.Exists(sourceFile)) File.Copy(sourceFile, destFile); database.SetEnvironmentalData(scenario, (from data in location.EnvironmentalDataSets where data.SourcePlugin.PluginSubtype == PluginSubtype.Sediment select data).FirstOrDefault()); sourceFile = Path.Combine(database.MasterDatabaseDirectory, location.StorageDirectory, scenario.Sediment.FileName); destFile = Path.Combine(_databaseDirectory, scenario.Sediment.FileName); if (File.Exists(sourceFile)) File.Copy(sourceFile, destFile); database.SetEnvironmentalData(scenario, (from data in location.EnvironmentalDataSets where data.SourcePlugin.PluginSubtype == PluginSubtype.Bathymetry select data).FirstOrDefault()); sourceFile = Path.Combine(database.MasterDatabaseDirectory, location.StorageDirectory, scenario.Bathymetry.FileName); destFile = Path.Combine(_databaseDirectory, scenario.Bathymetry.FileName); if (File.Exists(sourceFile)) File.Copy(sourceFile, destFile); } Console.WriteLine("Deleting existing simulation directory..."); if (Directory.Exists(_simulationDirectory)) Directory.Delete(_simulationDirectory, true); for (var i = 0; i < 10; i++) if (Directory.Exists(_simulationDirectory)) Thread.Sleep(100); else break; Assert.IsFalse(Directory.Exists(_simulationDirectory)); Console.WriteLine("Creating simulation..."); var simulation = Simulation.Create(scenario, _simulationDirectory); Console.WriteLine("Starting simulation..."); simulation.Start(1000, new TimeSpan(0, 0, 0, 1)); Console.WriteLine("Test complete"); }