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"); }
public void CreateScenario(string locationName, string scenarioName, double north, double south, double east, double west) { Console.WriteLine("Creating database service..."); var database = new MasterDatabaseService { MasterDatabaseDirectory = _databaseDirectory }; Console.WriteLine("Loading plugins..."); var plugins = new PluginManagerService { PluginDirectory = PluginDirectory }; var cache = new EnvironmentalCacheService(plugins, database); Console.WriteLine(string.Format("Looking for test location '{0}'...", locationName)); var location = database.FindLocation(locationName); if (location != null) { Console.WriteLine(string.Format("Test location '{0}' already exists. Deleting the existing location.", locationName)); database.DeleteLocation(location); } Console.WriteLine(string.Format("Creating test location '{0}'...", locationName)); var geoRect = new GeoRect(north, south, east, west); location = new Location { Name = locationName, Comments = null, GeoRect = geoRect }; location.LayerSettings.IsChecked = true; database.Add(location); foreach (var month in NAVOConfiguration.AllMonths) { // SoundSpeed dataset for each month Console.WriteLine(string.Format("Importing soundspeed for {0}", month)); cache.ImportDatasetTest(database.LoadOrCreateEnvironmentalDataSet(location, 15, month, plugins[PluginType.EnvironmentalDataSource, PluginSubtype.SoundSpeed].PluginIdentifier)); // Wind dataset for each month Console.WriteLine(string.Format("Importing wind for {0}", month)); cache.ImportDatasetTest(database.LoadOrCreateEnvironmentalDataSet(location, 60, month, plugins[PluginType.EnvironmentalDataSource, PluginSubtype.Wind].PluginIdentifier)); } // Sediment dataset Console.WriteLine("Importing 5min sediment"); cache.ImportDatasetTest(database.LoadOrCreateEnvironmentalDataSet(location, 5f, TimePeriod.Invalid, plugins[PluginType.EnvironmentalDataSource, PluginSubtype.Sediment].PluginIdentifier)); Console.WriteLine("Importing 0.1min sediment"); cache.ImportDatasetTest(database.LoadOrCreateEnvironmentalDataSet(location, 0.1f, TimePeriod.Invalid, plugins[PluginType.EnvironmentalDataSource, PluginSubtype.Sediment].PluginIdentifier)); // Bathymetry dataset at 2min resolution Console.WriteLine("Importing 2min bathymetry"); cache.ImportDatasetTest(database.LoadOrCreateEnvironmentalDataSet(location, 2f, TimePeriod.Invalid, plugins[PluginType.EnvironmentalDataSource, PluginSubtype.Bathymetry].PluginIdentifier)); // Bathymetry dataset at 1min resolution Console.WriteLine("Importing 1min bathymetry"); cache.ImportDatasetTest(database.LoadOrCreateEnvironmentalDataSet(location, 1f, TimePeriod.Invalid, plugins[PluginType.EnvironmentalDataSource, PluginSubtype.Bathymetry].PluginIdentifier)); // Bathymetry dataset at 0.5min resolution Console.WriteLine("Importing 0.5min bathymetry"); cache.ImportDatasetTest(database.LoadOrCreateEnvironmentalDataSet(location, 0.5f, TimePeriod.Invalid, plugins[PluginType.EnvironmentalDataSource, PluginSubtype.Bathymetry].PluginIdentifier)); Scenario scenario; database.Add(scenario = new Scenario { Location = location, Name = scenarioName, Comments = string.Format("Some comments for {0}", scenarioName), StartTime = new DbTimeSpan(new TimeSpan(0, 12, 0, 0)), Duration = new DbTimeSpan(new TimeSpan(0, 1, 0, 0)), TimePeriod = TimePeriod.April, }); location.Scenarios.Add(scenario); Platform platform; database.Add(platform = new Platform { Description = "Platform description", PlatformName = "PlatformName", PlatformType = "PlatformType", RepeatCount = 0, Scenario = scenario, Course = 45, Depth = 0, Geo = geoRect.Center, Speed = 0, IsRandom = false, TrackType = TrackType.Stationary, Perimeter = null, }); Source source; database.Add(source = new Source { Platform = platform, SourceName = "SourceName", SourceType = "SourceType", }); database.Add(new Mode { ActiveTime = 500, DepressionElevationAngle = 0, Depth = 5, HighFrequency = 3000, HorizontalBeamWidth = 360, LowFrequency = 3000, MaxPropagationRadius = 25000, ModeName = "ModeName", ModeType = "ModeType", //PSMModeGuid = PulseInterval = new TimeSpan(0, 0, 0, 30), PulseLength = new TimeSpan(0, 0, 0, 0, 500), RelativeBeamAngle = 0, Source = source, SourceLevel = 200, VerticalBeamWidth = 180, }); database.SetEnvironmentalData(scenario, (from data in location.EnvironmentalDataSets where data.SourcePlugin.PluginSubtype == PluginSubtype.Wind && ((TimePeriod)scenario.TimePeriod == (TimePeriod)data.TimePeriod) select data).FirstOrDefault()); database.SetEnvironmentalData(scenario, (from data in location.EnvironmentalDataSets where data.SourcePlugin.PluginSubtype == PluginSubtype.SoundSpeed && ((TimePeriod)scenario.TimePeriod == (TimePeriod)data.TimePeriod) select data).FirstOrDefault()); database.SetEnvironmentalData(scenario, (from data in location.EnvironmentalDataSets where data.SourcePlugin.PluginSubtype == PluginSubtype.Sediment orderby data.Resolution select data).FirstOrDefault()); database.SetEnvironmentalData(scenario, (from data in location.EnvironmentalDataSets where data.SourcePlugin.PluginSubtype == PluginSubtype.Bathymetry orderby data.Resolution select data).FirstOrDefault()); database.SaveChanges(); }