/// <summary> /// Function to load any plugins used to import or export files. /// </summary> /// <returns>A file system provider management interface.</returns> private FileSystemProviders LoadFileSystemPlugIns() { var fileSystemPlugInsDir = new DirectoryInfo(Path.Combine(_plugInLocation.FullName, "Filesystem")); var result = new FileSystemProviders(_commonServices); if (!fileSystemPlugInsDir.Exists) { return(result); } try { _splash.InfoText = Resources.GOREDIT_TEXT_LOADING_FILESYSTEM_PLUGINS; // If the directory does not exist, then we have no plugins to load. if (!fileSystemPlugInsDir.Exists) { fileSystemPlugInsDir.Create(); return(result); } result.LoadProviders(_pluginCache, fileSystemPlugInsDir); return(result); } catch (Exception ex) { Program.Log.LogException(ex); GorgonDialogs.ErrorBox(_splash, Resources.GOREDIT_ERR_LOADING_PLUGINS, Resources.GOREDIT_ERR_ERROR, ex); } return(result); }
/// <summary> /// Initializes a new instance of the <see cref="ViewModelFactory"/> class. /// </summary> /// <param name="settings">The settings for the application.</param> /// <param name="providers">The providers used to open/save files.</param> /// <param name="contentPlugIns">The plugins used for content.</param> /// <param name="toolPlugIns">The plugins used for application tools.</param> /// <param name="projectManager">The application project manager.</param> /// <param name="viewModelInjection">The common services for the application.</param> /// <param name="clipboardService">The application clipboard service.</param> /// <param name="dirLocatorService">The directory locator service.</param> /// <param name="fileScanService">The file scanning service used to scan content files for content plugin associations.</param> /// <param name="folderBrowser">The file system folder browser service.</param> /// <exception cref="ArgumentNullException">Thrown when any parameter is <b>null</b>.</exception> public ViewModelFactory(EditorSettings settings, FileSystemProviders providers, ContentPlugInService contentPlugIns, ToolPlugInService toolPlugIns, ProjectManager projectManager, IViewModelInjection viewModelInjection, ClipboardService clipboardService, DirectoryLocateService dirLocatorService, FileScanService fileScanService, IEditorFileSystemFolderBrowseService folderBrowser) { Settings = settings ?? throw new ArgumentNullException(nameof(settings)); FileSystemProviders = providers ?? throw new ArgumentNullException(nameof(providers)); ContentPlugIns = contentPlugIns ?? throw new ArgumentNullException(nameof(contentPlugIns)); ToolPlugIns = toolPlugIns ?? throw new ArgumentNullException(nameof(toolPlugIns)); _projectManager = projectManager ?? throw new ArgumentNullException(nameof(projectManager)); _viewModelInjection = viewModelInjection ?? throw new ArgumentNullException(nameof(viewModelInjection)); _clipboard = clipboardService ?? throw new ArgumentNullException(nameof(clipboardService)); _dirLocator = dirLocatorService ?? throw new ArgumentNullException(nameof(dirLocatorService)); _fileScanService = fileScanService ?? throw new ArgumentNullException(nameof(fileScanService)); _folderBrowser = folderBrowser ?? throw new ArgumentNullException(nameof(folderBrowser)); }
/// <summary> /// Function to perform the boot strapping operation. /// </summary> /// <returns>The main application window.</returns> public async void BootStrap() { AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; try { // Get our initial context. SynchronizationContext.SetSynchronizationContext(new WindowsFormsSynchronizationContext()); Program.Log.Print("Booting application...", LoggingLevel.All); Cursor.Current = Cursors.WaitCursor; await ShowSplashAsync(); // Initalize the common resources. EditorCommonResources.LoadResources(); _folderBrowser = new FileSystemFolderBrowseService(); _commonServices = new ViewModelInjection(Program.Log, new WaitCursorBusyState(), new MessageBoxService()); _pluginCache = new GorgonMefPlugInCache(Program.Log); _graphicsContext = GraphicsContext.Create(Program.Log); _plugInLocation = new DirectoryInfo(Path.Combine(GorgonApplication.StartupPath.FullName, "PlugIns")); if (!_plugInLocation.Exists) { Program.Log.Print($"[ERROR] Plug in path '{_plugInLocation.FullName}' was not found. No plug ins will be loaded.", LoggingLevel.Simple); GorgonDialogs.ErrorBox(null, Resources.GOREDIT_ERR_LOADING_PLUGINS); } // Get any application settings we might have. _settings = LoadSettings(); // Load our file system import/export plugins. FileSystemProviders fileSystemProviders = LoadFileSystemPlugIns(); // Load our tool plug ins. _toolPlugIns = LoadToolPlugIns(); // Load our content service plugins. _contentPlugIns = LoadContentPlugIns(); // Create the project manager for the application _projectManager = new ProjectManager(fileSystemProviders); _mainForm = new FormMain { Location = new Point(_settings.WindowBounds.Value.X, _settings.WindowBounds.Value.Y), Size = new Size(_settings.WindowBounds.Value.Width, _settings.WindowBounds.Value.Height), WindowState = FormWindowState.Normal }; await HideSplashAsync(); MainForm = _mainForm; var factory = new ViewModelFactory(_settings, fileSystemProviders, _contentPlugIns, _toolPlugIns, _projectManager, _commonServices, new ClipboardService(), new DirectoryLocateService(), new FileScanService(_contentPlugIns), _folderBrowser); FormWindowState windowState; // Ensure the window state values fall into an acceptable range. if (!Enum.IsDefined(typeof(FormWindowState), _settings.WindowState)) { windowState = FormWindowState.Maximized; } else { windowState = (FormWindowState)_settings.WindowState; } _mainForm.GraphicsContext = _graphicsContext; _mainForm.SetDataContext(factory.CreateMainViewModel(_graphicsContext.Graphics.VideoAdapter.Name)); _mainForm.Show(); _mainForm.WindowState = windowState; } finally { Cursor.Current = Cursors.Default; } }