Example #1
0
        /// <summary>Function to inject dependencies for the view model.</summary>
        /// <param name="injectionParameters">The parameters to inject.</param>
        /// <remarks>
        /// Applications should call this when setting up the view model for complex operations and/or dependency injection. The constructor should only be used for simple set up and initialization of objects.
        /// </remarks>
        protected override void OnInitialize(ImportPlugInSettingsParameters injectionParameters)
        {
            _messageDisplay  = injectionParameters.MessageDisplay ?? throw new ArgumentMissingException(nameof(injectionParameters.MessageDisplay), nameof(injectionParameters));
            _settings        = injectionParameters.Settings ?? throw new ArgumentMissingException(nameof(injectionParameters.Settings), nameof(injectionParameters));
            _plugInService   = injectionParameters.ContentPlugInService ?? throw new ArgumentMissingException(nameof(injectionParameters.ContentPlugInService), nameof(injectionParameters));
            _codecs          = injectionParameters.Codecs ?? throw new ArgumentMissingException(nameof(injectionParameters.Codecs), nameof(injectionParameters));
            _openCodecDialog = injectionParameters.OpenCodecDialog ?? throw new ArgumentMissingException(nameof(injectionParameters.OpenCodecDialog), nameof(injectionParameters));
            _busyService     = injectionParameters.BusyService ?? throw new ArgumentMissingException(nameof(injectionParameters.BusyService), nameof(injectionParameters));

            foreach (GorgonSpriteCodecPlugIn plugin in _codecs.CodecPlugIns)
            {
                foreach (GorgonSpriteCodecDescription desc in plugin.Codecs)
                {
                    IGorgonSpriteCodec codec = _codecs.Codecs.FirstOrDefault(item => string.Equals(item.GetType().FullName, desc.Name, StringComparison.OrdinalIgnoreCase));

                    if (codec == null)
                    {
                        continue;
                    }

                    CodecPlugInPaths.Add(new CodecSetting(codec.CodecDescription, plugin, desc));
                }
            }
        }
Example #2
0
        /// <summary>
        /// Function to load in a plug in assembly.
        /// </summary>
        private void DoLoadPlugInAssembly()
        {
            try
            {
                string lastCodecPath = _settings.LastCodecPlugInPath.FormatDirectory(Path.DirectorySeparatorChar);

                if ((string.IsNullOrWhiteSpace(lastCodecPath)) || (!Directory.Exists(lastCodecPath)))
                {
                    lastCodecPath = AppDomain.CurrentDomain.BaseDirectory;
                }

                _openCodecDialog.DialogTitle      = Resources.GORSPR_CAPTION_SELECT_CODEC_DLL;
                _openCodecDialog.FileFilter       = Resources.GORSPR_FILTER_SELECT_CODEC;
                _openCodecDialog.InitialDirectory = new DirectoryInfo(lastCodecPath);

                string path = _openCodecDialog.GetFilename();

                if ((string.IsNullOrWhiteSpace(path)) || (!File.Exists(path)))
                {
                    return;
                }

                _busyService.SetBusy();
                IReadOnlyList <GorgonSpriteCodecPlugIn> codecs = _codecs.AddCodecPlugIn(path, out IReadOnlyList <string> errors);

                if (errors.Count > 0)
                {
                    _messageDisplay.ShowError(Resources.GORSPR_ERR_CODEC_LOAD_ERRORS_PRESENT, details: string.Join("\n\n", errors.Select((item, index) => $"Error #{index + 1}\n--------------\n{item}")));

                    if (codecs.Count == 0)
                    {
                        return;
                    }
                }

                foreach (GorgonSpriteCodecPlugIn plugin in codecs)
                {
                    foreach (GorgonSpriteCodecDescription desc in plugin.Codecs)
                    {
                        IGorgonSpriteCodec codec = _codecs.Codecs.FirstOrDefault(item => string.Equals(item.GetType().FullName, desc.Name, StringComparison.OrdinalIgnoreCase));

                        if (codec == null)
                        {
                            continue;
                        }

                        CodecPlugInPaths.Add(new CodecSetting(codec.CodecDescription, plugin, desc));
                    }
                }

                _settings.LastCodecPlugInPath = Path.GetDirectoryName(path).FormatDirectory(Path.DirectorySeparatorChar);

                // Store the settings now.
                DoWriteSettings();
            }
            catch (Exception ex)
            {
                _messageDisplay.ShowError(ex, Resources.GORSPR_ERR_CANNOT_LOAD_CODEC);
            }
            finally
            {
                _busyService.SetIdle();
            }
        }