示例#1
0
        private async Task <SavedSearchesModel> InitializeModel()
        {
            _store = new Mock <IConfigStore>();
            _relay = new Mock <IMessageRelay>();

            var config = new SavedSearchesConfigFile
            {
                new SavedSearchConfig {
                    Alias = "Test", Tags = { "Test1", "Test2" }
                }
            };

            _store.Setup(s => s.LoadAsyncOrDefault <SavedSearchesConfigFile>()).ReturnsAsync(config);

            var model = new SavedSearchesModel(_store.Object, _relay.Object);
            await model.InitializeAsync();

            return(model);
        }
示例#2
0
        private async void Start()
        {
            var aggregator = new MessageAggregator();

            _relay = aggregator;
            IConfigStore       configStore  = new AppDataConfigStore();
            IPreviewImageStore previewStore = new AppDataPreviewImageStore();

            _library = new Library(configStore, _previewBuilder, previewStore, _relay);
            var factory = new ImportFolderFactory(_library);

            // Main View
            var progressModel    = new ProgressModel();
            var applicationModel = new ApplicationModel(_relay);
            var searchViewModel  = new SearchModel(_library, _relay);
            var itemsViewModel   = new ItemsModel(_library, _relay);

            // Main Menu
            var importFoldersViewModel = new ImportFoldersModel(configStore, factory, _relay);
            var savedSearchesViewModel = new SavedSearchesModel(configStore, _relay);
            var collectionsViewModel   = new CollectionsModel(configStore, _relay);

            // Detail Menu
            var detailMenuModel = new DetailMenuModel(_library, _relay);

            // Dialogs
            var addSavedSearchViewModel  = new AddSavedSearchModel(_relay);
            var addImportFolderViewModel = new AddImportFolderModel(_relay);
            var applicationSettingsModel = new ApplicationSettingsModel(configStore);
            var userFeedbackModel        = new UserFeedbackModel();
            var exitingModel             = new ExitingModel(_library, OnShutdownComplete);
            var editScreenModel          = new EditScreenModel(_library);

            BindViewModels();
            BindSettings();

            // Wire up misc items
            _disposables.Add(importFoldersViewModel);
            _editScreen.MainView = _mainGroup;

            // Also restores app settings for import etc.
            await applicationSettingsModel.InitializeAsync();

            await _library.InitializeAsync();

            InitializeViewModelsAsync();

            aggregator.Subscribe(
                // Main View
                progressModel,
                searchViewModel,
                itemsViewModel,

                // Main Menu
                importFoldersViewModel,
                savedSearchesViewModel,
                collectionsViewModel,

                // DetailMenu
                detailMenuModel,

                // Dialogs
                addSavedSearchViewModel,
                addImportFolderViewModel,
                applicationSettingsModel,
                userFeedbackModel,
                exitingModel,
                editScreenModel);

            void BindViewModels()
            {
                // Main View
                _progressView.BindTo(progressModel);
                _applicationView.BindTo(applicationModel);
                _searchView.BindTo(searchViewModel);
                _libraryView.BindTo(itemsViewModel);

                // Main Menu
                _importFoldersView.BindTo(importFoldersViewModel);
                _savedSearchesView.BindTo(savedSearchesViewModel);
                _collectionsView.BindTo(collectionsViewModel);

                // Detail Menu
                _detailMenu.BindTo(detailMenuModel);

                // Dialogs
                _addImportFolderDialog.BindTo(addImportFolderViewModel);
                _addSavedSearchDialog.BindTo(addSavedSearchViewModel);
                _applicationSettingsDialog.BindTo(applicationSettingsModel);
                _userFeedbackDialog.BindTo(userFeedbackModel);
                _exitingDialog.BindTo(exitingModel);
                _editScreen.BindTo(editScreenModel);
            }

            void BindSettings()
            {
                var rt = applicationSettingsModel.RuntimeSettings;

                rt.ImportParallelism.ValueChanged += factor => _library.Parallelism = factor;
                rt.LogLevel.ValueChanged          += logLevel => UnityLogger.LogLevel = logLevel;

                rt.UiScalePercent.ValueChanged += factor =>
                {
                    foreach (var canvas in FindObjectsOfType <Canvas>())
                    {
                        canvas.scaleFactor = applicationSettingsModel.UiScalePercent / 125f;
                    }
                };

                rt.ScrollSensitivity.ValueChanged += sensitivity =>
                {
                    foreach (var area in FindObjectsOfType <ScrollRect>())
                    {
                        area.scrollSensitivity = sensitivity;
                    }
                };

                rt.PreviewResolution.ValueChanged  += res => _previewBuilder.PreviewResolution.Value = Mathf.RoundToInt(Mathf.Pow(2f, res));
                rt.PreviewJpegQuality.ValueChanged += quality => _previewBuilder.Quality = quality;
            }

            async void InitializeViewModelsAsync()
            {
                await savedSearchesViewModel.InitializeAsync();

                await importFoldersViewModel.InitializeAsync();

                await collectionsViewModel.InitializeAsync();
            }
        }