Ejemplo n.º 1
0
        public static ImageSource GetPluginIcon([NotNull] Type plugintype)
        {
            if (plugintype == null)
            {
                throw new ArgumentNullException("plugintype");
            }

            try
            {
                PluginDescriptionAttribute attr = TryGetPluginDescriptionAttribute(plugintype);
                if ((attr != null) && (!attr.IconSrc.IsEmpty()))
                {
                    var uri = new Uri(attr.IconSrc, UriKind.RelativeOrAbsolute);
                    if (!uri.IsAbsoluteUri)
                    {
                        uri = Utils.MakeResourceUri(attr.IconSrc, plugintype.Assembly);
                    }
                    return(Utils.LoadResourceImage(uri));
                }
            }
            catch (Exception ex)
            {
                Core.ReportBackgroundException(ex);
            }

            return(GenericPluginIcon);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Retrieves the plugin description text, or the default text if the description is not specified.
        /// </summary>
        /// <param name="plugintype">The type that implements a plugin.</param>
        /// <returns>A non-empty string with the author name or some stub text.</returns>
        public static FlowDocument GetPluginDesriptionDocument([NotNull] Type plugintype)
        {
            if (plugintype == null)
            {
                throw new ArgumentNullException("plugintype");
            }

            try
            {
                // Descriptor
                PluginDescriptionAttribute attr = TryGetPluginDescriptionAttribute(plugintype);

                // No data?
                if ((attr == null) || (attr.Description.IsEmpty()))
                {
                    return(new FlowDocument(new Paragraph(new Italic(new Run(Stringtable.PluginDescriptionUnavailableText)))
                    {
                        TextAlignment = TextAlignment.Center
                    }));
                }

                // Render
                switch (attr.DescriptionFormat)
                {
                case PluginDescriptionFormat.PlainText:
                    return(RichContentConverter.DocumentFromPlainText(attr.Description));

                case PluginDescriptionFormat.Rtf:
                    return(RichContentConverter.DocumentFromRtf(attr.Description));

                case PluginDescriptionFormat.XamlInline:
                    return(RichContentConverter.DocumentFromInlineXaml(attr.Description));

                case PluginDescriptionFormat.XamlFlowDocumentPackUri:
                    return(RichContentConverter.DocumentFromResource(attr.Description, plugintype.Assembly));

                default:
                    throw new InvalidOperationException(string.Format("The Description Format value {0} is unsupported.", attr.DescriptionFormat));
                }
            }
            catch (Exception ex)
            {
                Core.ReportBackgroundException(ex);
                return(RichContentConverter.DocumentFromException(ex));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Retrieves the plugin user-friendly title text, or the plugin class local name if not specified.
        /// </summary>
        /// <param name="plugintype">The type that implements a plugin.</param>
        /// <returns>A non-empty string with the title.</returns>
        public static string GetPluginTitle([NotNull] Type plugintype)
        {
            if (plugintype == null)
            {
                throw new ArgumentNullException("plugintype");
            }

            // See if we can get a meaningful title from the plugin
            try
            {
                PluginDescriptionAttribute attr = TryGetPluginDescriptionAttribute(plugintype);
                if ((attr != null) && (!attr.Title.IsEmpty()))
                {
                    return(attr.Title);
                }
            }
            catch (Exception ex)
            {
                Core.ReportBackgroundException(ex);
            }

            // Use the local class name (remove the common “Plugin” suffix)
            return(_regexPluginClassLocalName.Replace(plugintype.Name, ""));
        }