public VideoPlayerBuilder() { _videoPlayerBuilderPluginItemStateTracker = new FixedItemStateTracker("VideoPlayerBuilder - MimeType registration"); IPluginManager pluginManager = ServiceRegistration.Get <IPluginManager>(); foreach (PluginItemMetadata itemMetadata in pluginManager.GetAllPluginItemMetadata(VIDEOPLAYERBUILDERMIMETYPES_REGISTRATION_PATH)) { try { VideoPlayerMimeTypeMapping playerMapping = pluginManager.RequestPluginItem <VideoPlayerMimeTypeMapping>( VIDEOPLAYERBUILDERMIMETYPES_REGISTRATION_PATH, itemMetadata.Id, _videoPlayerBuilderPluginItemStateTracker); if (playerMapping == null) { ServiceRegistration.Get <ILogger>().Warn("Could not instantiate VideoPlayerMimeTypeMapping with id '{0}'", itemMetadata.Id); } else { PlayerRegistration.AddMimeTypeMapping(playerMapping.MimeType, playerMapping.PlayerClass); } } catch (PluginInvalidStateException e) { ServiceRegistration.Get <ILogger>().Warn("Cannot add video player MIME type mapping for {0}", e, itemMetadata); } } }
protected void BuildExtensions() { _slimTvExtensionsPluginItemStateTracker = new FixedItemStateTracker("SlimTvHandler - Extension registration"); IPluginManager pluginManager = ServiceRegistration.Get <IPluginManager>(); foreach (PluginItemMetadata itemMetadata in pluginManager.GetAllPluginItemMetadata(SlimTvExtensionBuilder.SLIMTVEXTENSIONPATH)) { try { SlimTvProgramExtension slimTvProgramExtension = pluginManager.RequestPluginItem <SlimTvProgramExtension>( SlimTvExtensionBuilder.SLIMTVEXTENSIONPATH, itemMetadata.Id, _slimTvExtensionsPluginItemStateTracker); if (slimTvProgramExtension == null) { ServiceRegistration.Get <ILogger>().Warn("Could not instantiate SlimTv extension with id '{0}'", itemMetadata.Id); } else { IProgramAction action = Activator.CreateInstance(slimTvProgramExtension.ExtensionClass) as IProgramAction; if (action == null) { throw new PluginInvalidStateException("Could not create IProgramAction instance of class {0}", slimTvProgramExtension.ExtensionClass); } _programExtensions[slimTvProgramExtension.Id] = new TvExtension { Caption = slimTvProgramExtension.Caption, Extension = action }; } } catch (PluginInvalidStateException e) { ServiceRegistration.Get <ILogger>().Warn("Cannot add SlimTv extension with id '{0}'", e, itemMetadata.Id); } } }
private void InitProviders(string providerPath) { lock (_syncObj) { if (_providersInititialized) { return; } _providersInititialized = true; _listProviders = new ContentListProviderDictionary(); _listProviders.ProviderRequested += OnProviderRequested; _providerPluginItemStateTracker = new FixedItemStateTracker($"Content Lists - Provider registration for path {providerPath}"); IPluginManager pluginManager = ServiceRegistration.Get <IPluginManager>(); foreach (PluginItemMetadata itemMetadata in pluginManager.GetAllPluginItemMetadata(providerPath)) { try { ContentListProviderRegistration providerRegistration = pluginManager.RequestPluginItem <ContentListProviderRegistration>(providerPath, itemMetadata.Id, _providerPluginItemStateTracker); if (providerRegistration == null) { ServiceRegistration.Get <ILogger>().Warn("Could not instantiate Content List provider with id '{0}'", itemMetadata.Id); } else { IContentListProvider provider = Activator.CreateInstance(providerRegistration.ProviderClass) as IContentListProvider; if (provider == null) { throw new PluginInvalidStateException("Could not create IContentListProvider instance of class {0}", providerRegistration.ProviderClass); } if (_listProviders.ContainsKey(providerRegistration.Key)) { //The default providers cannot replace existing providers if (provider.GetType().Assembly != System.Reflection.Assembly.GetExecutingAssembly()) { //Replace the provider _listProviders[providerRegistration.Key] = provider; ServiceRegistration.Get <ILogger>().Info("Successfully replaced Content List '{1}' with provider '{0}' (Id '{2}')", itemMetadata.Attributes["ClassName"], itemMetadata.Attributes["Key"], itemMetadata.Id); } } else { _listProviders.Add(providerRegistration.Key, provider); ServiceRegistration.Get <ILogger>().Info("Successfully activated Content List '{1}' with provider '{0}' (Id '{2}')", itemMetadata.Attributes["ClassName"], itemMetadata.Attributes["Key"], itemMetadata.Id); } } } catch (PluginInvalidStateException e) { ServiceRegistration.Get <ILogger>().Warn("Cannot add IContentListProvider extension with id '{0}'", e, itemMetadata.Id); } } } }
/// <summary> /// Reads filter settings for <see cref="BaseNavigationInitializer"/> derived classes from plugin.xml. /// </summary> protected void BuildFilters() { if (_tracker != null) { return; } _tracker = new FixedItemStateTracker("BaseNavigationInitializer - Media navigation filter registration"); IPluginManager pluginManager = ServiceRegistration.Get <IPluginManager>(); foreach (PluginItemMetadata itemMetadata in pluginManager.GetAllPluginItemMetadata(MediaNavigationFilterBuilder.MEDIA_FILTERS_PATH)) { try { MediaNavigationFilter navigationFilter = pluginManager.RequestPluginItem <MediaNavigationFilter>( MediaNavigationFilterBuilder.MEDIA_FILTERS_PATH, itemMetadata.Id, _tracker); if (navigationFilter == null) { ServiceRegistration.Get <ILogger>().Warn("Could not instantiate Media navigation filter with id '{0}'", itemMetadata.Id); } else { string extensionClass = navigationFilter.ClassName; if (extensionClass == null) { throw new PluginInvalidStateException("Could not find class type for Media navigation filter {0}", navigationFilter.ClassName); } if (extensionClass != GetType().Name) { continue; } _filters.Add(navigationFilter.Filter); } } catch (PluginInvalidStateException e) { ServiceRegistration.Get <ILogger>().Warn("Cannot add Media navigation filter with id '{0}'", e, itemMetadata.Id); } } if (_filters.Count == 0) { _filter = null; return; } _filter = _filters.Count == 1 ? // Single filter _filters[0] : // Or a "AND" combined filter new BooleanCombinationFilter(BooleanOperator.And, _filters); }
protected void LoadChildren() { if (_childrenLoaded) { return; } ILogger logger = ServiceRegistration.Get <ILogger>(); IPluginManager pluginManager = ServiceRegistration.Get <IPluginManager>(); string itemLocation = Constants.PLUGINTREE_BASELOCATION + Location; // We'll use a FixedItemStateTracker in the hope that the configuration will be disposed // after usage. The alternative would be to use a plugin item state tracker which is able to // remove a config element usage. But this would mean to also expose a listener registration // to the outside. I think this is not worth the labor. _childPluginItemStateTracker = new FixedItemStateTracker(string.Format("ConfigurationManager: ConfigurationNode '{0}'", itemLocation)); ICollection <PluginItemMetadata> items = pluginManager.GetAllPluginItemMetadata(itemLocation); IDictionary <string, object> childSet = new Dictionary <string, object>(); foreach (PluginItemMetadata itemMetadata in items) { try { ConfigBaseMetadata metadata = pluginManager.RequestPluginItem <ConfigBaseMetadata>(itemMetadata.RegistrationLocation, itemMetadata.Id, _childPluginItemStateTracker); ConfigBase childObj = Instantiate(metadata, itemMetadata.PluginRuntime); if (childObj == null) { continue; } AddChildNode(childObj); childSet.Add(metadata.Id, null); } catch (PluginInvalidStateException e) { logger.Warn("Cannot add configuration node for {0}", e, itemMetadata); } } ICollection <string> childLocations = pluginManager.GetAvailableChildLocations(itemLocation); foreach (string childLocation in childLocations) { string childId = RegistryHelper.GetLastPathSegment(childLocation); if (childSet.ContainsKey(childId)) { continue; } logger.Warn("Configuration: Configuration section '{0}' was found in the tree but not explicitly registered as section (config items in this section are registered by those plugins: {1})", childLocation, StringUtils.Join(", ", FindPluginRegistrations(childLocation))); ConfigSectionMetadata dummyMetadata = new ConfigSectionMetadata(childLocation, Constants.INVALID_SECTION_TEXT, null, null); ConfigSection dummySection = new ConfigSection(); dummySection.SetMetadata(dummyMetadata); AddChildNode(dummySection); } _childrenLoaded = true; }
public static void LoadServicesFromPlugins() { IPluginManager pluginManager = Get <IPluginManager>(); pluginManager.AddItemRegistrationChangeListener(PLUGIN_TREE_SERVICES_LOCATION, _servicesRegistrationChangeListener); ILogger logger = Get <ILogger>(); logger.Info("ServiceRegistration: Loading services from plugin manager at location '{0}'", PLUGIN_TREE_SERVICES_LOCATION); ICollection <PluginItemMetadata> items = pluginManager.GetAllPluginItemMetadata(PLUGIN_TREE_SERVICES_LOCATION); Instance.AddServiceItems(items); }
protected void LoadPlayerBuilders() { lock (_syncObj) { IPluginManager pluginManager = ServiceRegistration.Get <IPluginManager>(); pluginManager.AddItemRegistrationChangeListener(PLAYERBUILDERS_REGISTRATION_PATH, _playerBuilderRegistrationChangeListener); foreach (PluginItemMetadata itemMetadata in pluginManager.GetAllPluginItemMetadata(PLAYERBUILDERS_REGISTRATION_PATH)) { LoadPlayerBuilder(itemMetadata.Id); } } }
protected static void InitRegisteredViewModes() { lock (_syncObj) { if (_pluginItemStateTracker == null) { _pluginItemStateTracker = new FixedItemStateTracker("WorkflowStates - ViewModes registration"); } // Key: Skin name, Key 2: WorkflowStateId, Value: LayoutTypes var viewModes = new Dictionary <string, Dictionary <Guid, List <LayoutType> > >(StringComparer.InvariantCultureIgnoreCase); IPluginManager pluginManager = ServiceRegistration.Get <IPluginManager>(); foreach (PluginItemMetadata itemMetadata in pluginManager.GetAllPluginItemMetadata(WorkflowStateViewModesBuilder.WF_VIEWMODES_PROVIDER_PATH)) { try { WorkflowStateViewModesRegistration providerRegistration = pluginManager.RequestPluginItem <WorkflowStateViewModesRegistration>( WorkflowStateViewModesBuilder.WF_VIEWMODES_PROVIDER_PATH, itemMetadata.Id, _pluginItemStateTracker); if (providerRegistration == null) { ServiceRegistration.Get <ILogger>().Warn("Could not instantiate WorkflowState ViewModes registration with id '{0}'", itemMetadata.Id); } else { if (!viewModes.ContainsKey(providerRegistration.Skin)) { viewModes.Add(providerRegistration.Skin, new Dictionary <Guid, List <LayoutType> >()); } var skinDict = viewModes[providerRegistration.Skin]; if (skinDict.ContainsKey(providerRegistration.StateId)) { ServiceRegistration.Get <ILogger>().Warn("Could not add ViewModes for WorkflowState '{0}'. The ID is already in defined.", providerRegistration.StateId); continue; } skinDict[providerRegistration.StateId] = providerRegistration.ViewModes.Split(',').Select(v => (LayoutType)Enum.Parse(typeof(LayoutType), v)).ToList(); ServiceRegistration.Get <ILogger>().Info("Successfully added ViewModes for Skin '{0}' for WorkflowState ID '{1}', Modes: {2}", providerRegistration.Skin, providerRegistration.StateId, providerRegistration.ViewModes); } } catch (PluginInvalidStateException e) { ServiceRegistration.Get <ILogger>().Warn("Cannot add Skin Settings registration with id '{0}'", e, itemMetadata.Id); } } _viewModes = viewModes; } }
/// <summary> /// Loads all <see cref="HomeEditorRegistration"/>s and gets a collection of supported skins. /// </summary> /// <returns>A collection of supported skin names.</returns> protected HashSet <string> GetSupportedSkins() { HashSet <string> registrations = new HashSet <string>(); IPluginManager pluginManager = ServiceRegistration.Get <IPluginManager>(); foreach (PluginItemMetadata itemMetadata in pluginManager.GetAllPluginItemMetadata(HomeEditorRegistrationBuilder.HOME_EDITOR_PROVIDER_PATH)) { HomeEditorRegistration registration = GetSkinRegistration(itemMetadata, pluginManager); if (registration != null) { registrations.Add(registration.SkinName); } } return(registrations); }
/// <summary> /// Helper method to create a meaningful log message. See usage. /// </summary> /// <param name="location">Parent location to search all child locations where plugins registering /// items to.</param> /// <returns>List of plugin names registering items under the specified /// <paramref name="location"/>.</returns> private static ICollection <string> FindPluginRegistrations(string location) { IPluginManager pluginManager = ServiceRegistration.Get <IPluginManager>(); ICollection <PluginItemMetadata> itemRegistrations = pluginManager.GetAllPluginItemMetadata(location); List <string> result = new List <string>(); foreach (PluginItemMetadata itemRegistration in itemRegistrations) { result.Add(itemRegistration.PluginRuntime.Metadata.Name); } foreach (string childLocation in pluginManager.GetAvailableChildLocations(location)) { result.AddRange(FindPluginRegistrations(childLocation)); } return(result); }
protected void InitRegisteredSettings() { lock (_syncObj) { if (_pluginItemStateTracker == null) { _pluginItemStateTracker = new FixedItemStateTracker("Skin Settings - Type registration"); } var types = new Dictionary <Type, string>(); var names = new Dictionary <string, SettingsLoader>(); IPluginManager pluginManager = ServiceRegistration.Get <IPluginManager>(); foreach (PluginItemMetadata itemMetadata in pluginManager.GetAllPluginItemMetadata(SkinSettingsBuilder.SKIN_SETTINGS_PROVIDER_PATH)) { try { SkinSettingsRegistration providerRegistration = pluginManager.RequestPluginItem <SkinSettingsRegistration>( SkinSettingsBuilder.SKIN_SETTINGS_PROVIDER_PATH, itemMetadata.Id, _pluginItemStateTracker); if (providerRegistration == null) { ServiceRegistration.Get <ILogger>().Warn("Could not instantiate Skin Settings registration with id '{0}'", itemMetadata.Id); } else { if (names.ContainsKey(providerRegistration.Name)) { ServiceRegistration.Get <ILogger>().Warn("Could not add Skin Settings type '{0}' with name '{1}' (Id '{2}'). The name is already in use.", itemMetadata.Attributes["ClassName"], providerRegistration.Name, itemMetadata.Id); continue; } types[providerRegistration.ProviderClass] = providerRegistration.Name; names[providerRegistration.Name] = new SettingsLoader(providerRegistration.ProviderClass); ServiceRegistration.Get <ILogger>().Info("Successfully added Skin Settings type '{0}' with name '{1}' (Id '{2}')", itemMetadata.Attributes["ClassName"], providerRegistration.Name, itemMetadata.Id); } } catch (PluginInvalidStateException e) { ServiceRegistration.Get <ILogger>().Warn("Cannot add Skin Settings registration with id '{0}'", e, itemMetadata.Id); } } _registeredTypes = types; _registeredNames = names; } FireChange(); }
public void InitProviders() { lock (_syncObj) { if (_providerList != null) { return; } var providerList = new List <SortedGenreConverter>(); _genreProviderPluginItemStateTracker = new FixedItemStateTracker("GenreConverter Service - Provider registration"); IPluginManager pluginManager = ServiceRegistration.Get <IPluginManager>(); foreach (PluginItemMetadata itemMetadata in pluginManager.GetAllPluginItemMetadata(GenreProviderBuilder.GENRE_PROVIDER_PATH)) { try { GenreProviderRegistration genreProviderRegistration = pluginManager.RequestPluginItem <GenreProviderRegistration>(GenreProviderBuilder.GENRE_PROVIDER_PATH, itemMetadata.Id, _genreProviderPluginItemStateTracker); if (genreProviderRegistration == null || genreProviderRegistration.ProviderClass == null) { ServiceRegistration.Get <ILogger>().Warn("Could not instantiate IGenreProvider with id '{0}'", itemMetadata.Id); } else { IGenreProvider provider = Activator.CreateInstance(genreProviderRegistration.ProviderClass) as IGenreProvider; if (provider == null) { throw new PluginInvalidStateException("Could not create IGenreProvider instance of class {0}", genreProviderRegistration.ProviderClass); } providerList.Add(new SortedGenreConverter { Priority = genreProviderRegistration.Priority, Provider = provider }); } } catch (PluginInvalidStateException e) { ServiceRegistration.Get <ILogger>().Warn("Cannot add IGenreProvider with id '{0}'", e, itemMetadata.Id); } } providerList.Sort((p1, p2) => p1.Priority.CompareTo(p2.Priority)); _providerList = providerList; } }
protected void BuildExtensions() { if (_mediaActionPluginItemStateTracker != null) { return; } _mediaActionPluginItemStateTracker = new FixedItemStateTracker("MediaItemsActionModel - Extension registration"); IPluginManager pluginManager = ServiceRegistration.Get <IPluginManager>(); foreach (PluginItemMetadata itemMetadata in pluginManager.GetAllPluginItemMetadata(MediaItemActionBuilder.MEDIA_EXTENSION_PATH)) { try { MediaItemActionExtension mediaExtension = pluginManager.RequestPluginItem <MediaItemActionExtension>( MediaItemActionBuilder.MEDIA_EXTENSION_PATH, itemMetadata.Id, _mediaActionPluginItemStateTracker); if (mediaExtension == null) { ServiceRegistration.Get <ILogger>().Warn("Could not instantiate Media extension with id '{0}'", itemMetadata.Id); } else { Type extensionClass = mediaExtension.ExtensionClass; if (extensionClass == null) { throw new PluginInvalidStateException("Could not find class type for extension {0}", mediaExtension.Caption); } IMediaItemAction action = Activator.CreateInstance(extensionClass) as IMediaItemAction; if (action == null) { throw new PluginInvalidStateException("Could not create IMediaItemAction instance of class {0}", extensionClass); } mediaExtension.Action = action; _actions.Add(mediaExtension); } } catch (PluginInvalidStateException e) { ServiceRegistration.Get <ILogger>().Warn("Cannot add Media extension with id '{0}'", e, itemMetadata.Id); } } }
private void InitNavigationFilters() { if (_tracker != null) { return; } _tracker = new FixedItemStateTracker("MediaListProvider - Media navigation filter registration"); _navigationFilters = new Dictionary <string, IList <IFilter> >(); IPluginManager pluginManager = ServiceRegistration.Get <IPluginManager>(); foreach (PluginItemMetadata itemMetadata in pluginManager.GetAllPluginItemMetadata(MediaNavigationFilterBuilder.MEDIA_FILTERS_PATH)) { try { MediaNavigationFilter navigationFilter = pluginManager.RequestPluginItem <MediaNavigationFilter>( MediaNavigationFilterBuilder.MEDIA_FILTERS_PATH, itemMetadata.Id, _tracker); if (navigationFilter == null) { ServiceRegistration.Get <ILogger>().Warn("MediaListProvider: Could not instantiate Media navigation filter with id '{0}'", itemMetadata.Id); } else { string extensionClass = navigationFilter.ClassName; if (extensionClass == null) { throw new PluginInvalidStateException("MediaListProvider: Could not find class type for Media navigation filter {0}", navigationFilter.ClassName); } IList <IFilter> filters; if (!_navigationFilters.TryGetValue(extensionClass, out filters)) { _navigationFilters[extensionClass] = filters = new List <IFilter>(); } filters.Add(navigationFilter.Filter); } } catch (PluginInvalidStateException e) { ServiceRegistration.Get <ILogger>().Warn("MediaListProvider: Cannot add Media navigation filter with id '{0}'", e, itemMetadata.Id); } } }
public void InitProviders() { lock (_syncObj) { if (_providerList != null) { return; } var providerList = new List <IThumbnailProvider>(); _thumbnailProviderPluginItemStateTracker = new FixedItemStateTracker("ThumbnailGenerator Service - Provider registration"); IPluginManager pluginManager = ServiceRegistration.Get <IPluginManager>(); foreach (PluginItemMetadata itemMetadata in pluginManager.GetAllPluginItemMetadata(ThumbnailProviderBuilder.THUMBNAIL_PROVIDER_PATH)) { try { ThumbnailProviderRegistration thumbnailProviderRegistration = pluginManager.RequestPluginItem <ThumbnailProviderRegistration>(ThumbnailProviderBuilder.THUMBNAIL_PROVIDER_PATH, itemMetadata.Id, _thumbnailProviderPluginItemStateTracker); if (thumbnailProviderRegistration == null) { ServiceRegistration.Get <ILogger>().Warn("Could not instantiate IThumbnailProvider with id '{0}'", itemMetadata.Id); } else { IThumbnailProvider provider = Activator.CreateInstance(thumbnailProviderRegistration.ProviderClass) as IThumbnailProvider; if (provider == null) { throw new PluginInvalidStateException("Could not create IThumbnailProvider instance of class {0}", thumbnailProviderRegistration.ProviderClass); } providerList.Add(provider); } } catch (PluginInvalidStateException e) { ServiceRegistration.Get <ILogger>().Warn("Cannot add IThumbnailProvider with id '{0}'", e, itemMetadata.Id); } } // TODO: implement sorting based on ThumbnailProviderRegistration //providerList.Sort((p1, p2) => p1.Priority.CompareTo(p2.Priority)); _providerList = providerList; } }
public void InitProviders() { lock (_syncObj) { if (_providerList != null) { return; } _providerList = new List <IFanartImageSourceProvider>(); _providerPluginItemStateTracker = new FixedItemStateTracker("Fanart Service - Provider registration"); IPluginManager pluginManager = ServiceRegistration.Get <IPluginManager>(); foreach (PluginItemMetadata itemMetadata in pluginManager.GetAllPluginItemMetadata(FanartImageSourceProviderBuilder.FANART_IMAGE_SOURCE_PROVIDER_PATH)) { try { FanartImageSourceProviderRegistration providerRegistration = pluginManager.RequestPluginItem <FanartImageSourceProviderRegistration>(FanartImageSourceProviderBuilder.FANART_IMAGE_SOURCE_PROVIDER_PATH, itemMetadata.Id, _providerPluginItemStateTracker); if (providerRegistration == null) { ServiceRegistration.Get <ILogger>().Warn("Could not instantiate Fanart Image Source provider with id '{0}'", itemMetadata.Id); } else { IFanartImageSourceProvider provider = Activator.CreateInstance(providerRegistration.ProviderClass) as IFanartImageSourceProvider; if (provider == null) { throw new PluginInvalidStateException("Could not create IFanartImageSourceProvider instance of class {0}", providerRegistration.ProviderClass); } _providerList.Add(provider); ServiceRegistration.Get <ILogger>().Info("Successfully activated Fanart Image Source provider '{0}' (Id '{1}')", itemMetadata.Attributes["ClassName"], itemMetadata.Id); } } catch (PluginInvalidStateException e) { ServiceRegistration.Get <ILogger>().Warn("Cannot add IFanartImageSourceProvider extension with id '{0}'", e, itemMetadata.Id); } } } }