public static void Dump(IMasterDatabaseService locationService, bool dumpLogs = false)
 {
     foreach (var location in locationService.Context.Locations)
     {
         DumpLocation(location);
         if (dumpLogs) foreach (var logEntry in location.Logs) DumpLogEntry(logEntry);
         if (location.EnvironmentalDataSets != null)
             foreach (var dataSet in location.EnvironmentalDataSets)
                 DumpEnvironmentalDataSet(dataSet);
     }
 }
 public MainViewModel(IHRCSaveFileService saveFileService, IViewAwareStatus viewAwareStatus, IMasterDatabaseService database)
 {
     ESME.Globals.SaveFileService = saveFileService;
     ESME.Globals.ViewAwareStatusService = viewAwareStatus;
     ESME.Globals.MasterDatabaseService = database;
     if (!Designer.IsInDesignMode)
     {
         viewAwareStatus.ViewLoaded += () =>
                                           {
                                               TransmissionLossViewModel.RadialViewModel = new RadialViewModel { RadialView = ((Window)viewAwareStatus.View).FindChildren<RadialView>().First() };
                                               TransmissionLossViewModel.SaveFileService = saveFileService;
                                               TransmissionLossViewModel.RadialViewModel.WaitToRenderText = "No Scenario Selected";
                                           };
         viewAwareStatus.ViewActivated += () => ESME.Globals.MasterDatabaseService.Refresh();
     }
 }
        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 static Scenario LoadOrCreate(IMasterDatabaseService databaseService, Location location, string simAreaFolder, string scenarioFile)
        {
            var scenarioName = Path.GetFileNameWithoutExtension(scenarioFile);
            Console.WriteLine(string.Format("Looking for test scenario '{0}'...", scenarioName));
            var scenario = databaseService.FindScenario(scenarioName);
            if (scenario != null) return scenario;
            Console.WriteLine(string.Format("Importing test scenario '{0}'...", scenarioName));
            scenario = Scenario.FromNemoFile(databaseService, location, scenarioFile, simAreaFolder);

            databaseService.SetEnvironmentalData(scenario, (from data in location.EnvironmentalDataSets
                                                            where data.SourcePlugin.PluginSubtype == PluginSubtype.Wind && ((TimePeriod)scenario.TimePeriod == (TimePeriod)data.TimePeriod)
                                                            select data).FirstOrDefault());

            databaseService.SetEnvironmentalData(scenario, (from data in location.EnvironmentalDataSets
                                                            where data.SourcePlugin.PluginSubtype == PluginSubtype.SoundSpeed && ((TimePeriod)scenario.TimePeriod == (TimePeriod)data.TimePeriod)
                                                            select data).FirstOrDefault());

            databaseService.SetEnvironmentalData(scenario, (from data in location.EnvironmentalDataSets
                                                            where data.SourcePlugin.PluginSubtype == PluginSubtype.Sediment
                                                            select data).FirstOrDefault());

            databaseService.SetEnvironmentalData(scenario, (from data in location.EnvironmentalDataSets
                                                            where data.SourcePlugin.PluginSubtype == PluginSubtype.Bathymetry
                                                            select data).FirstOrDefault());
            return scenario;
        }
        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");
        }