Beispiel #1
0
        private StationsLevelReportViewModel GetStationsReportViewModel(CommandLineViewModel commandLine)
        {
            try
            {
                var reportView = new StationsLevelReportViewModel
                {
                    ReportType = string.IsNullOrEmpty(commandLine.Parameter) ?
                                 _config.GetDefaultParameter() : commandLine.Parameter.ToLower()
                };

                var stations = _monitor.GetStationReferencesAndNamesForRiver(commandLine.RiverName).Result;

                if (stations != null && stations.Any())
                {
                    reportView.RiverBasedStationNames = string.Join(", ", stations.Values);

                    var stationReferences = stations.Keys.ToList();

                    foreach (var stationRef in stationReferences)
                    {
                        reportView.StationBasedRiverLevels.Add(
                            _monitor.GetRiverWaterLevelDataAtStation(stationRef, commandLine).Result);
                    }
                }

                return(reportView);
            }
            catch (Exception ex)
            {
                _logger.LogException(ex, _config.GetDefaultLoggingPath());
                return(null);
            }
        }
Beispiel #2
0
        private void InitializeTab()
        {
            try
            {
                mControl = new TmxEditor.TmxEditorControl();
            }
            catch (System.NotSupportedException exc)
            {
                GlueCommands.PrintError("Could not find a graphics device that supports XNA hi-def. Attempting to load Tiled plugin without the control tab");
            }

            if (mControl != null)
            {
                mControl.AnyTileMapChange += HandleUserChangeTmx;
                mControl.LoadEntities     += OnLoadEntities;


                EntityCreationManager.Self.AddEntityCreationView(mControl);


                var commandLineArgumentsView = new TileGraphicsPlugin.Views.CommandLineArgumentsView();
                mCommandLineViewModel = new CommandLineViewModel();
                mCommandLineViewModel.CommandLineChanged += HandleCommandLinePropertyChanged;
                commandLineArgumentsView.DataContext      = mCommandLineViewModel;
                mControl.AddTab("Command Line", commandLineArgumentsView);

                mTilesetXnaRightClickController = new TilesetXnaRightClickController();
                mTilesetXnaRightClickController.Initialize(mControl.TilesetXnaContextMenu);
                mControl.TilesetDisplayRightClick += (o, s) => mTilesetXnaRightClickController.RefreshMenuItems();
            }
        }
Beispiel #3
0
        private string BuildApiStationReadingsUrl(string stationReference, CommandLineViewModel commandObj)
        {
            try
            {
                var urlBuilder = new StringBuilder();

                urlBuilder.Append(string.Format(_config.GetApiStationReadingsUrl(), stationReference));

                var supportedRange = _config.GetDateRange();
                var endDate        = DateTime.Today;
                var startDate      = endDate.AddDays((commandObj.Days > supportedRange) ? (-(double)supportedRange) : (-(double)commandObj.Days));

                urlBuilder.Append("&startdate=");
                urlBuilder.Append(startDate.ToString(_config.GetDateFormat()));

                urlBuilder.Append("&enddate=");
                urlBuilder.Append(endDate.ToString(_config.GetDateFormat()));

                urlBuilder.Append(!string.IsNullOrEmpty(commandObj.Parameter) ? ("&parameter=" + commandObj.Parameter) : "");

                var limitFilter =
                    ((commandObj.Limit <= 0) || (commandObj.Limit > _config.GetMaxReadLimit())) ?
                    ("&_limit=" + _config.GetDefaultReadLimit()) :
                    ("&_limit=" + commandObj.Limit);

                urlBuilder.Append(limitFilter);

                return(urlBuilder.ToString());
            }
            catch (Exception ex)
            {
                _logger.LogException(ex, _config.GetDefaultLoggingPath());
                return(null);
            }
        }
Beispiel #4
0
        static int Main(string[] args)
        {
            Application application = new Application();

            // Show about info
            application.ShowAboutView();

            ViewModels.MainViewModel mainViewModel = new ViewModels.MainViewModel(application);

            try
            {
                // Read command line args
                CommandLineViewModel _commandLine = new CommandLineViewModel(args);

                if (!_commandLine.IsGenerateMode)
                {
                    throw new InvalidOperationException("Use the \"-generate\" mode at command line.");
                }

                if (!string.IsNullOrEmpty(_commandLine.ProjectPath))
                {
                    // Open the project
                    System.Console.WriteLine(string.Format(FilePackager.Console.Properties.Resources.OpeningProject, _commandLine.ProjectPath));

                    mainViewModel.OpenProject(_commandLine.ProjectPath);
                }
                else
                {
                    // Setup a temporary project from command line
                    Project          project          = new Project();
                    ProjectViewModel projectViewModel = new ProjectViewModel(project);
                    mainViewModel.Project = projectViewModel;

                    _commandLine.SetupProject(projectViewModel);
                }

                // Generate packages
                mainViewModel.Project.BuildAllPackages();
            }
            catch (Exception exception)
            {
                System.Console.Error.WriteLine(exception.Message);
                return(1);
            }

            if (application.MaxSeverityFound == FilePackager.Packaging.Severity.Error)
            {
                return(1);
            }

            return(0);
        }
Beispiel #5
0
        private string JoinFilters(CommandLineViewModel commandObj)
        {
            var joinedFilters = new StringBuilder();

            joinedFilters.Append("-");

            joinedFilters.Append(string.IsNullOrEmpty(commandObj.Parameter) ?
                                 _config.GetDefaultParameter() : commandObj.Parameter.ToLower());

            joinedFilters.Append("-");
            joinedFilters.Append(commandObj.Limit);
            joinedFilters.Append("-");
            joinedFilters.Append(commandObj.Days);

            return(joinedFilters.ToString());
        }
Beispiel #6
0
        public void Init()
        {
            _mockConfig          = new Mock <IConfigurationServices>();
            _mockLogger          = new Mock <ILogging>();
            _mockCache           = new Mock <ICacheWrapper>();
            _mockExternalService = new Mock <IExternalServiceWrapper>();

            _monitor = new FloodMonitoringServices(
                _mockLogger.Object, _mockConfig.Object, _mockCache.Object, _mockExternalService.Object);

            _commandObj = new CommandLineViewModel
            {
                RiverName = "Testttt",
                Parameter = "ew",
                Limit     = 1300,
                Days      = 3
            };
        }
        private void InitializeTab()
        {
            mControl = new TmxEditor.TmxEditorControl();
            mControl.AnyTileMapChange += HandleUserChangeTmx;
            mControl.LoadEntities     += OnLoadEntities;
            var commandLineArgumentsView = new TileGraphicsPlugin.Views.CommandLineArgumentsView();

            mCommandLineViewModel = new CommandLineViewModel();

            mCommandLineViewModel.CommandLineChanged += HandleCommandLinePropertyChanged;

            commandLineArgumentsView.DataContext = mCommandLineViewModel;
            mControl.AddTab("Command Line", commandLineArgumentsView);


            mTilesetXnaRightClickController = new TilesetXnaRightClickController();
            mTilesetXnaRightClickController.Initialize(mControl.TilesetXnaContextMenu);
            mControl.TilesetDisplayRightClick += (o, s) => mTilesetXnaRightClickController.RefreshMenuItems();
        }
Beispiel #8
0
        private CommandLineViewModel ParseArguments(List <string> argsList)
        {
            try
            {
                var commandObj = new CommandLineViewModel
                {
                    RiverName = argsList[0].Trim(new char[] { '"', ' ', '/', '\\', '?' })
                };

                if (argsList.Count > 1)
                {
                    for (int i = 1; i < argsList.Count; i++)
                    {
                        var arg = argsList[i].Split(':');

                        switch (arg[0].ToLower().Trim())
                        {
                        case "days":
                            commandObj.Days = Convert.ToInt32(arg[1]);
                            break;

                        case "parameter":
                            commandObj.Parameter = arg[1].ToLower();
                            break;

                        case "limit":
                            commandObj.Limit = Convert.ToInt32(arg[1]);
                            break;
                        }
                    }
                }

                return(commandObj);
            }
            catch (Exception ex)
            {
                _logger.LogException(ex, _config.GetDefaultLoggingPath());
                return(null);
            }
        }
Beispiel #9
0
        public async Task <StationBasedRiverMeasureViewModel> GetRiverWaterLevelDataAtStation(string stationReference, CommandLineViewModel commandObj)
        {
            try
            {
                var cacheKey          = stationReference.ToLower() + JoinFilters(commandObj);
                var processedCacheKey = cacheKey + "-processed";
                var riverMeasureView  = new StationBasedRiverMeasureViewModel();

                riverMeasureView = (StationBasedRiverMeasureViewModel)_memoryCache.Get(processedCacheKey);

                if (riverMeasureView != null)
                {
                    return(riverMeasureView);
                }
                else
                {
                    var readingsFromCache = (StationReadings)_memoryCache.Get(cacheKey);

                    if (readingsFromCache != null)
                    {
                        riverMeasureView = ProcessReadings(readingsFromCache);

                        // Add processed data to cache memory
                        _memoryCache.AddOrGetExisting(processedCacheKey, riverMeasureView);

                        return(riverMeasureView);
                    }
                    else
                    {
                        var responseData = await _externalService.GetAsync(BuildApiStationReadingsUrl(stationReference, commandObj));

                        var readings = JsonConvert.DeserializeObject <StationReadings>(responseData);

                        if (readings != null)
                        {
                            if (readings.Readings != null && readings.Readings.Any())
                            {
                                // Add readings data to cache memory
                                _memoryCache.AddOrGetExisting(cacheKey, readings);

                                riverMeasureView = ProcessReadings(readings);

                                // Add processed data to cache memory
                                _memoryCache.AddOrGetExisting(processedCacheKey, riverMeasureView);

                                return(riverMeasureView);
                            }
                        }
                    }
                }

                return(riverMeasureView);
            }
            catch (Exception ex)
            {
                _logger.LogException(ex, _config.GetDefaultLoggingPath());
                return(null);
            }
        }
Beispiel #10
0
        private void OnStartup(object sender, StartupEventArgs e)
        {
            try
            {
                // Create the ViewModel
                ViewModels.MainViewModel mainViewModel = new ViewModels.MainViewModel(this);

                _commandLine = new CommandLineViewModel(e.Args);

                if (_commandLine.IsGenerateMode)
                {
                    if (!string.IsNullOrEmpty(_commandLine.ProjectPath))
                    {
                        mainViewModel.OpenProject(_commandLine.ProjectPath);
                    }
                    else
                    {
                        // Setup a temporary project from command line
                        Project          project          = new Project();
                        ProjectViewModel projectViewModel = new ProjectViewModel(project);
                        mainViewModel.Project = projectViewModel;

                        _commandLine.SetupProject(projectViewModel);
                    }

                    _splashScreen.Close(new TimeSpan(0));

                    // Generate packages
                    mainViewModel.Project.BuildAllPackages();

                    // The app won't terminate if no UI was shown
                    if (!_commandLine.ShowProgressUi)
                    {
                        Shutdown();
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(_commandLine.ProjectPath))
                    {
                        mainViewModel.OpenProject(_commandLine.ProjectPath);
                    }
                    else
                    {
                        mainViewModel.NewProject();
                    }

                    mainViewModel.PropertyChanged += MainViewModel_PropertyChanged;

                    // Create the view, and set the ViewModel as the DataContext
                    Views.MainView mainView = new Views.MainView();
                    mainView.DataContext = mainViewModel;

                    _splashScreen.Close(new TimeSpan(0));

                    mainView.Show();
                }
            }
            catch (Exception exception)
            {
                _splashScreen.Close(new TimeSpan(0));

                ShowMessage(exception.Message, Severity.Error);
                Shutdown();
            }
        }