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 TransmissionLossCalculatorService(IMasterDatabaseService databaseService, IPluginManagerService pluginService, EnvironmentalCacheService cacheService) : this()
 {
     _databaseService = databaseService;
     _cacheService = cacheService;
 }
        public MainViewModel(IViewAwareStatus viewAwareStatus,
                             IMasterDatabaseService database,
                             IMessageBoxService messageBox,
                             IUIVisualizerService visualizer,
                             IHRCSaveFileService saveFile,
                             IHRCOpenFileService openFile,
                             TransmissionLossCalculatorService transmissionLoss,
                             IPluginManagerService plugins,
                             EnvironmentalCacheService cache)
        {
            try
            {
                Mediator.Instance.Register(this);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("***********\nMainViewModel: Mediator registration failed: " + ex.Message + "\n***********");
                throw;
            }
            Cursor = Cursors.Arrow;

            ESME.Data.AppSettings.ApplicationName = App.Name;
            Globals.AppSettings = ESME.Data.AppSettings.Load(ESME.Data.AppSettings.AppSettingsFile);
            Globals.AppSettings.Save();

            Globals.PluginManagerService = plugins;
            Globals.TransmissionLossCalculatorService = transmissionLoss;
            Globals.MasterDatabaseService = database;
            Globals.VisualizerService = visualizer;
            Globals.SaveFileService = saveFile;
            Globals.OpenFileService = openFile;
            Globals.EnvironmentalCacheService = cache;
            Globals.ViewAwareStatusService = viewAwareStatus;
            Globals.MessageBoxService = messageBox;

            MapViewModel = new MapViewModel(this);

            Globals.TransmissionLossCalculatorService.WorkQueue.PropertyChanged +=
                (s, e) =>
                {
                    if (e.PropertyName == "Count")
                    {
                        TransmissionLossActivity = Globals.TransmissionLossCalculatorService.WorkQueue.Keys.Count > 0
                            ? string.Format("Acoustic Simulator: {0} items", Globals.TransmissionLossCalculatorService.WorkQueue.Keys.Count)
                            : "Acoustic Simulator: idle";
                        // Debug.WriteLine(string.Format("TransmissionLossActivity: {0}", TransmissionLossActivity));
                        var isBusy = Globals.TransmissionLossCalculatorService.WorkQueue.Keys.Count > 0;
                        IsTransmissionLossBusy = isBusy;
                        if (!isBusy && IsSaveSampleDataRequested)
                        {
                            Globals.MasterDatabaseService.SaveChanges();
                            IsSaveSampleDataRequested = false;
                        }

                    }
                };

            if (Designer.IsInDesignMode) return;

            Globals.ViewAwareStatusService.ViewLoaded += ViewLoaded;
            //_appTracker = new ApplicationTracker("UA-44329261-1", "TestWPFApp");
            //_appTracker.StartSession();
            //_appTracker.TrackEvent(ApplicationTrackerCategories.Command, "ApplicationStartup");
        }
        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();
        }