/// <summary>
        /// Get the embedded resource names of a plugin.
        /// </summary>
        /// <param name="plugin">The plugin in which the resources are contained.</param>
        /// <param name="type">The type of the resources. If not provided "Script" will be used.</param>
        /// <returns>A <see cref="IList{T}"/> which contains a list of all the embedded resource names in the overgiven plugin.</returns>
        public static IList <string> GetEmbeddedResources(IBasePlugin plugin, string type = "Script")
        {
            if (plugin == null)
            {
                return(null);
            }

            var pluginNamespace = plugin.GetType().Namespace;

            var embeddedResources = plugin.GetType().Assembly.GetManifestResourceNames().Where(x =>
                                                                                               x.StartsWith(string.Format(CultureInfo.InvariantCulture, "{0}.{1}", pluginNamespace, type), StringComparison.InvariantCulture))
                                    .ToList();

            return(embeddedResources);
        }
Example #2
0
        /// <summary>
        /// Helper object that stores the services available in this plug-in
        /// </summary>
        /// <param name="serviceProvider">IServiceProvider</param>
        /// <param name="events">List of <see href="RegisteredEvents" /> for the plugin</param>
        /// <param name="plugin">Plugin handler</param>
        public BasePluginContext(IServiceProvider serviceProvider, IEnumerable <RegisteredEvent> events, IBasePlugin plugin)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            _provider = serviceProvider;

            // Obtain the organization factory service from the service provider
            _factory = (IOrganizationServiceFactory)_provider.GetService(typeof(IOrganizationServiceFactory));

            // Set Event
            Event = PluginExecutionContext.GetEvent(events);

            PluginTypeName = plugin.GetType().FullName;
        }