public void Ctor_Defaults_Set()
        {
            // Arrange/Act
            var helper = new RecentFilesHelper(new RecentFilesInMemorySerializer(), new MockFileSystem());

            // Assert
            Assert.Empty(helper.RecentFiles);
            Assert.Equal(10, helper.MaximumItemCount);
        }
        public void Ctor_Defaults_ShouldCallDeserialize()
        {
            // Arrange
            var mockedSerializer = new Mock <IRecentFilesSerializer>();

            mockedSerializer.Setup(_ => _.Deserialize()).Returns(() => new List <RecentFile>());

            // Arrange/Act
            var helper = new RecentFilesHelper(mockedSerializer.Object, new MockFileSystem());

            // Assert
            mockedSerializer.Verify(_ => _.Deserialize(), Times.Once);
        }
Esempio n. 3
0
        private async void Application_Startup(object sender, StartupEventArgs e)
        {
            // retrieve file argument if given
            if (e.Args.Length > 0)
            {
                if (!e.Args[0].Equals(Constants.Argument_Ask_For_Admin, StringComparison.OrdinalIgnoreCase))
                {
                    FilenameArgument = e.Args[0];
                }
            }

            using var mutexAnnoDesigner = new Mutex(true, MutexHelper.MUTEX_ANNO_DESIGNER, out var createdNewMutex);
            //Are there other processes still running?
            if (!createdNewMutex)
            {
                try
                {
                    var       currentTry = 0;
                    const int maxTrys    = 10;
                    while (!createdNewMutex && currentTry < maxTrys)
                    {
                        logger.Trace($"Waiting for other processes to finish. Try {currentTry} of {maxTrys}");

                        createdNewMutex = mutexAnnoDesigner.WaitOne(TimeSpan.FromSeconds(1), true);
                        currentTry++;
                    }

                    if (!createdNewMutex)
                    {
                        _messageBoxService.ShowMessage(Localization.Localization.Instance.GetLocalization("AnotherInstanceIsAlreadyRunning"));
                        Environment.Exit(-1);
                    }
                }
                catch (AbandonedMutexException)
                {
                    //mutex was killed
                    createdNewMutex = true;
                }
            }

            try
            {
                //check if file is not corrupt
                _appSettings.Reload();

                if (_appSettings.SettingsUpgradeNeeded)
                {
                    _appSettings.Upgrade();
                    _appSettings.SettingsUpgradeNeeded = false;
                    _appSettings.Save();
                }
            }
            catch (ConfigurationErrorsException ex)
            {
                logger.Error(ex, "Error upgrading settings.");

                _messageBoxService.ShowError(_localizationHelper.GetLocalization("ErrorUpgradingSettings"));

                var fileName = "";
                if (!string.IsNullOrEmpty(ex.Filename))
                {
                    fileName = ex.Filename;
                }
                else
                {
                    if (ex.InnerException is ConfigurationErrorsException innerException && !string.IsNullOrEmpty(innerException.Filename))
                    {
                        fileName = innerException.Filename;
                    }
                }

                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }

                _appSettings.Reload();
            }

            //var updateWindow = new UpdateWindow();
            await _updateHelper.ReplaceUpdatedPresetsFilesAsync();

            var recentFilesSerializer = new RecentFilesAppSettingsSerializer(_appSettings);

            IRecentFilesHelper recentFilesHelper = new RecentFilesHelper(recentFilesSerializer, _fileSystem);
            var mainVM = new MainViewModel(_commons, _appSettings, recentFilesHelper, _messageBoxService, _updateHelper, _localizationHelper, _fileSystem);

            //TODO MainWindow.ctor calls AnnoCanvas.ctor loads presets -> change logic when to load data
            MainWindow             = new MainWindow(_appSettings);
            MainWindow.DataContext = mainVM;

            //If language is not recognized, bring up the language selection screen
            if (!_commons.LanguageCodeMap.ContainsKey(_appSettings.SelectedLanguage))
            {
                var w = new Welcome();
                w.DataContext = mainVM.WelcomeViewModel;
                w.ShowDialog();
            }
            else
            {
                _commons.CurrentLanguage = _appSettings.SelectedLanguage;
            }

            MainWindow.ShowDialog();
        }