Esempio n. 1
0
        public void GivenRiskeerGuiWithStorageSql_WhenRunWithMigratedFile_MigratedProjectSet(string sourceFilePath)
        {
            string targetFilePath = Path.Combine(workingDirectory, nameof(GivenRiskeerGuiWithStorageSql_WhenRunWithMigratedFile_MigratedProjectSet));

            MigrateFile(sourceFilePath, targetFilePath);

            // Given
            var projectStore  = new StorageSqLite();
            var mocks         = new MockRepository();
            var inquiryHelper = mocks.StrictMock <IInquiryHelper>();

            mocks.ReplayAll();

            var projectMigrator = new ProjectMigrator(inquiryHelper);
            var guiCoreSettings = new GuiCoreSettings
            {
                ApplicationIcon = SystemIcons.Application
            };

            using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, new RiskeerProjectFactory(() => null), guiCoreSettings))
            {
                // When
                gui.Run(targetFilePath);

                // Then
                Assert.AreEqual(targetFilePath, gui.ProjectFilePath);
                Assert.NotNull(gui.Project);
                string expectedProjectName = Path.GetFileNameWithoutExtension(targetFilePath);
                Assert.AreEqual(expectedProjectName, gui.Project.Name);
                Assert.AreEqual("description", gui.Project.Description);
                Assert.IsInstanceOf <RiskeerProject>(gui.Project);
            }

            mocks.VerifyAll();
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GuiCore"/> class.
        /// </summary>
        /// <param name="mainWindow">The main window.</param>
        /// <param name="projectStore">The project store.</param>
        /// <param name="projectMigrator">The project migrator.</param>
        /// <param name="projectFactory">The project factory.</param>
        /// <param name="fixedSettings">The fixed settings.</param>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        public GuiCore(IMainWindow mainWindow, IStoreProject projectStore, IMigrateProject projectMigrator, IProjectFactory projectFactory, GuiCoreSettings fixedSettings)
        {
            if (mainWindow == null)
            {
                throw new ArgumentNullException(nameof(mainWindow));
            }

            if (projectStore == null)
            {
                throw new ArgumentNullException(nameof(projectStore));
            }

            if (projectMigrator == null)
            {
                throw new ArgumentNullException(nameof(projectMigrator));
            }

            if (projectFactory == null)
            {
                throw new ArgumentNullException(nameof(projectFactory));
            }

            if (fixedSettings == null)
            {
                throw new ArgumentNullException(nameof(fixedSettings));
            }

            ProjectStore  = projectStore;
            FixedSettings = fixedSettings;
            MainWindow    = mainWindow;

            Plugins = new List <PluginBase>();

            viewCommandHandler = new ViewCommandHandler(this, this, this);

            StorageCommands = new StorageCommandHandler(projectStore, projectMigrator, projectFactory,
                                                        this, dialogBasedInquiryHelper, this);

            importCommandHandler = new GuiImportHandler(MainWindow, Plugins.SelectMany(p => p.GetImportInfos())
                                                        .Concat(MapImportInfoFactory.Create()),
                                                        dialogBasedInquiryHelper);
            exportCommandHandler = new GuiExportHandler(MainWindow, Plugins.SelectMany(p => p.GetExportInfos()));
            updateCommandHandler = new GuiUpdateHandler(MainWindow, Plugins.SelectMany(p => p.GetUpdateInfos()), dialogBasedInquiryHelper);

            WindowsApplication.EnableVisualStyles();
            ViewPropertyEditor.ViewCommands = ViewCommands;

            ProjectOpened       += ApplicationProjectOpened;
            BeforeProjectOpened += ApplicationBeforeProjectOpened;
            projectObserver      = new Observer(UpdateProjectData);

            applicationTitle = string.Format(CultureInfo.CurrentCulture, "{0} {1}",
                                             FixedSettings.ApplicationName,
                                             SettingsHelper.Instance.ApplicationVersion);

            SetTitle();
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a new instance of <see cref="SupportViewModel"/>.
        /// </summary>
        /// <param name="settings">The application settings.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="settings"/> is <c>null</c>.</exception>
        public SupportViewModel(GuiCoreSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            this.settings = settings;
        }
Esempio n. 4
0
        private void OnStartup(object sender, StartupEventArgs e)
        {
            ParseArguments(e.Args);

            DeleteOldLogFiles();

            Resources.Add(SystemParameters.MenuPopupAnimationKey, PopupAnimation.None);

            var settings = new GuiCoreSettings
            {
                ApplicationName          = "Riskeer",
                ApplicationIcon          = ApplicationResources.Riskeer,
                SupportHeader            = ApplicationResources.SupportHeader,
                SupportText              = ApplicationResources.SupportText,
                SupportWebsiteAddressUrl = "https://iplo.nl/contact/",
                SupportPhoneNumber       = "088-7970790",
                ManualFilePath           = "Gebruikershandleiding Riskeer 22.1.1.pdf",
                MadeByBitmapImage        = new BitmapImage(new Uri($"{PackUriHelper.UriSchemePack}://application:,,,/Resources/MadeBy.png"))
            };

            var mainWindow      = new MainWindow();
            var projectMigrator = new ProjectMigrator(new DialogBasedInquiryHelper(mainWindow));
            var assessmentSectionFromFileHandler = new AssessmentSectionFromFileHandler(mainWindow);
            var projectFactory = new RiskeerProjectFactory(() => assessmentSectionFromFileHandler.GetAssessmentSectionFromFile());

            gui = new GuiCore(mainWindow, new StorageSqLite(), projectMigrator, projectFactory, settings)
            {
                Plugins =
                {
                    new RiskeerPlugin(),
                    new ClosingStructuresPlugin(),
                    new StabilityPointStructuresPlugin(),
                    new WaveImpactAsphaltCoverPlugin(),
                    new GrassCoverErosionInwardsPlugin(),
                    new GrassCoverErosionOutwardsPlugin(),
                    new PipingPlugin(),
                    new HeightStructuresPlugin(),
                    new StabilityStoneCoverPlugin(),
                    new DuneErosionPlugin(),
                    new MacroStabilityInwardsPlugin()
                }
            };

            RunRiskeer();
        }
Esempio n. 5
0
        /// <summary>
        /// Creates a new instance of <see cref="BackstageViewModel"/>.
        /// </summary>
        /// <param name="settings">The application settings.</param>
        /// <param name="version">The application version.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="settings"/> is <c>null</c>.</exception>
        public BackstageViewModel(GuiCoreSettings settings, string version)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            this.settings = settings;

            InfoViewModel    = new InfoViewModel();
            AboutViewModel   = new AboutViewModel(settings, version);
            SupportViewModel = new SupportViewModel(settings);

            OpenUserManualCommand       = new RelayCommand(OnOpenUserManual, CanOpenUserManual);
            SetSelectedViewModelCommand = new RelayCommand(OnSetCurrentViewModel);

            SelectedViewModel = InfoViewModel;
        }
Esempio n. 6
0
        /// <summary>
        /// Creates a new instance of <see cref="AboutViewModel"/>.
        /// </summary>
        /// <param name="settings">The application settings.</param>
        /// <param name="version">The application version.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="settings"/> is <c>null</c>.</exception>
        public AboutViewModel(GuiCoreSettings settings, string version)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            this.settings = settings;

            Version = version;

            WindowsEdition = (string)GetManagementObjectProperty("Win32_OperatingSystem", "Caption")
                             ?? Resources.AboutViewModel_Unknown_value;
            WindowsBuild = (string)GetManagementObjectProperty("Win32_OperatingSystem", "BuildNumber")
                           ?? Resources.AboutViewModel_Unknown_value;
            Processor = (string)GetManagementObjectProperty("Win32_Processor", "Name")
                        ?? Resources.AboutViewModel_Unknown_value;
        }
Esempio n. 7
0
        public void GivenViewModelWithSettingsWithOrWithoutUserManualPathSet_WhenCanExecuteOpenUserManualCommand_ThenExpectedValue(
            bool userManualPresent)
        {
            // Given
            string path = Uri.UnescapeDataString(new UriBuilder(Assembly.GetExecutingAssembly().CodeBase).Path);

            var settings = new GuiCoreSettings
            {
                ManualFilePath = userManualPresent ? path : null
            };

            var viewModel = new BackstageViewModel(settings, "1.0");

            // When
            bool canExecute = viewModel.OpenUserManualCommand.CanExecute(null);

            // Then
            Assert.AreEqual(userManualPresent, canExecute);
        }
Esempio n. 8
0
        public void Constructor_ExpectedValues()
        {
            // Setup
            var settings = new GuiCoreSettings
            {
                SupportHeader            = "Support",
                SupportText              = "Some text",
                SupportWebsiteAddressUrl = "www.test.nl",
                SupportPhoneNumber       = "012-3456789"
            };

            // Call
            var viewModel = new SupportViewModel(settings);

            // Assert
            Assert.IsInstanceOf <IBackstagePageViewModel>(viewModel);
            Assert.AreEqual(settings.SupportHeader, viewModel.SupportHeader);
            Assert.AreEqual(settings.SupportText, viewModel.SupportText);
            Assert.AreEqual(settings.SupportWebsiteAddressUrl, viewModel.SupportWebsiteAddressUrl);
            Assert.AreEqual(settings.SupportPhoneNumber, viewModel.SupportPhoneNumber);
        }
Esempio n. 9
0
        public void Constructor_ExpectedValues()
        {
            // Setup
            var settings = new GuiCoreSettings
            {
                ApplicationName   = "Test application",
                MadeByBitmapImage = new BitmapImage()
            };

            const string version = "1.0";

            // Call
            var viewModel = new AboutViewModel(settings, version);

            // Assert
            Assert.IsInstanceOf <IBackstagePageViewModel>(viewModel);
            Assert.AreEqual(settings.ApplicationName, viewModel.ApplicationName);
            Assert.AreEqual(version, viewModel.Version);

            ManagementObject processorManagementObject =
                new ManagementObjectSearcher("select * from Win32_Processor")
                .Get()
                .Cast <ManagementObject>()
                .First();

            ManagementObject operatingSystemManagementObject =
                new ManagementObjectSearcher("select * from Win32_OperatingSystem")
                .Get()
                .Cast <ManagementObject>()
                .First();

            var installedRam = $"{Math.Round(GetInstalledRam(), 2).ToString(CultureInfo.InvariantCulture)} GB";

            Assert.AreEqual(operatingSystemManagementObject["Caption"], viewModel.WindowsEdition);
            Assert.AreEqual(operatingSystemManagementObject["BuildNumber"], viewModel.WindowsBuild);
            Assert.AreEqual(processorManagementObject["Name"], viewModel.Processor);
            Assert.AreEqual(installedRam, AboutViewModel.InstalledRam);
            Assert.AreEqual(GetResolution(), AboutViewModel.Resolution);
            Assert.AreSame(settings.MadeByBitmapImage, viewModel.MadeByBitmapImage);
        }
Esempio n. 10
0
        public void GivenRiskeerGui_WhenRunWithUnmigratedFileAndInquireContinuation_MigratedProjectSet(string sourceFilePath)
        {
            // Given
            string targetFilePath = Path.Combine(workingDirectory, nameof(GivenRiskeerGui_WhenRunWithUnmigratedFileAndInquireContinuation_MigratedProjectSet));

            var projectStore  = new StorageSqLite();
            var mocks         = new MockRepository();
            var inquiryHelper = mocks.Stub <IInquiryHelper>();

            inquiryHelper.Expect(helper => helper.InquireContinuation(null))
            .IgnoreArguments()
            .Return(true);
            inquiryHelper.Expect(helper => helper.GetTargetFileLocation(null, null))
            .IgnoreArguments()
            .Return(targetFilePath);
            mocks.ReplayAll();

            var projectMigrator = new ProjectMigrator(inquiryHelper);
            var guiCoreSettings = new GuiCoreSettings
            {
                ApplicationIcon = SystemIcons.Application
            };

            using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, new RiskeerProjectFactory(() => null), guiCoreSettings))
            {
                // When
                gui.Run(sourceFilePath);

                // Then
                Assert.AreEqual(targetFilePath, gui.ProjectFilePath);
                string expectedProjectName = Path.GetFileNameWithoutExtension(targetFilePath);
                Assert.AreEqual(expectedProjectName, gui.Project.Name);
                Assert.AreEqual("description", gui.Project.Description);
                Assert.IsInstanceOf <RiskeerProject>(gui.Project);
            }

            mocks.VerifyAll();
        }
Esempio n. 11
0
        public void Constructor_ExpectedValues()
        {
            // Setup
            var settings = new GuiCoreSettings
            {
                ApplicationName = "Test application",
                SupportHeader   = "Support",
                SupportText     = "Some text"
            };
            const string version = "1.0";

            // Call
            var viewModel = new BackstageViewModel(settings, version);

            // Assert
            Assert.IsInstanceOf <INotifyPropertyChanged>(viewModel);

            Assert.IsNotNull(viewModel.InfoViewModel);
            Assert.IsNull(viewModel.InfoViewModel.ProjectName);

            Assert.IsNotNull(viewModel.AboutViewModel);
            Assert.AreEqual(settings.ApplicationName, viewModel.AboutViewModel.ApplicationName);
            Assert.AreEqual(version, viewModel.AboutViewModel.Version);

            Assert.IsNotNull(viewModel.SupportViewModel);
            Assert.AreEqual(settings.SupportHeader, viewModel.SupportViewModel.SupportHeader);
            Assert.AreEqual(settings.SupportText, viewModel.SupportViewModel.SupportText);

            Assert.IsNotNull(viewModel.OpenUserManualCommand);
            Assert.IsNotNull(viewModel.SetSelectedViewModelCommand);

            Assert.AreSame(viewModel.InfoViewModel, viewModel.SelectedViewModel);
            Assert.IsTrue(viewModel.InfoSelected);
            Assert.IsFalse(viewModel.AboutSelected);
            Assert.IsFalse(viewModel.SupportSelected);
        }