예제 #1
0
    public void InitProviders()
    {
      lock (_syncObj)
      {
        if (_providerList != null)
          return;
        _providerList = new List<IFanArtProvider>();

        _fanartProviderPluginItemStateTracker = new FixedItemStateTracker("Fanart Service - Provider registration");

        IPluginManager pluginManager = ServiceRegistration.Get<IPluginManager>();
        foreach (PluginItemMetadata itemMetadata in pluginManager.GetAllPluginItemMetadata(FanartProviderBuilder.FANART_PROVIDER_PATH))
        {
          try
          {
            FanartProviderRegistration fanartProviderRegistration = pluginManager.RequestPluginItem<FanartProviderRegistration>(FanartProviderBuilder.FANART_PROVIDER_PATH, itemMetadata.Id, _fanartProviderPluginItemStateTracker);
            if (fanartProviderRegistration == null)
              ServiceRegistration.Get<ILogger>().Warn("Could not instantiate Fanart provider with id '{0}'", itemMetadata.Id);
            else
            {
              IFanArtProvider provider = Activator.CreateInstance(fanartProviderRegistration.ProviderClass) as IFanArtProvider;
              if (provider == null)
                throw new PluginInvalidStateException("Could not create IFanArtProvider instance of class {0}", fanartProviderRegistration.ProviderClass);
              _providerList.Add(provider);
            }
          }
          catch (PluginInvalidStateException e)
          {
            ServiceRegistration.Get<ILogger>().Warn("Cannot add IFanArtProvider extension with id '{0}'", e, itemMetadata.Id);
          }
        }
      }
    }
예제 #2
0
        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);
                }
            }
        }
예제 #3
0
        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);
                }
            }
        }
 public WorkflowContributorAction(Guid actionId, string name, IEnumerable <Guid> sourceStateIds, IResourceString displayTitle,
                                  Guid contributorModelId) : base(actionId, name, sourceStateIds, displayTitle)
 {
     _modelItemStateTracker = new DefaultItemStateTracker("WorkflowContributorAction: Usage of workflow action contributor model")
     {
         Stopped = registration => Unbind()
     };
     _contributorModelId = contributorModelId;
 }
 public WorkflowContributorAction(Guid actionId, string name, IEnumerable<Guid> sourceStateIds, IResourceString displayTitle,
     Guid contributorModelId) : base(actionId, name, sourceStateIds, displayTitle)
 {
   _modelItemStateTracker = new DefaultItemStateTracker("WorkflowContributorAction: Usage of workflow action contributor model")
     {
         Stopped = registration => Unbind()
     };
   _contributorModelId = contributorModelId;
 }
        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);
                    }
                }
            }
        }
예제 #7
0
        public PlayerManager()
        {
            _slots = new List <PlayerSlotController>();

            // Albert, 2010-12-06: It's too difficult to revoke a player builder. We cannot guarantee that no player of that
            // player builder is currently in use by other threads, so we simply don't allow to revoke them by using a FixedItemStateTracker.
            _playerBuilderPluginItemStateTracker     = new FixedItemStateTracker("PlayerManager: PlayerBuilder usage");
            _playerBuilderRegistrationChangeListener = new PlayerBuilderRegistrationChangeListener(this);
            LoadSettings();
            SubscribeToMessages();
        }
예제 #8
0
        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;
        }
예제 #9
0
        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;
            }
        }
예제 #10
0
        public StringManagerBase()
        {
            _languagePluginStateTracker = new DefaultItemStateTracker("Localization system: Language resources")
            {
                // We don't care about strings which are currently in use; we don't have an overview which strings are still needed. So we don't
                // provide an implementation of RequestEnd.

                Stopped = RemoveLanguageResource
            };
            _languageResourcesRegistrationChangeListener = new DefaultItemRegistrationChangeListener("Localization system: Language resources")
            {
                ItemsWereAdded = (location, items) => AddLanguageResources(items)
                                 // Item removals are handled by the SkinResourcesPluginItemStateTracker
            };
        }
예제 #11
0
    public StringManagerBase()
    {
      _languagePluginStateTracker = new DefaultItemStateTracker("Localization system: Language resources")
        {
            // We don't care about strings which are currently in use; we don't have an overview which strings are still needed. So we don't
            // provide an implementation of RequestEnd.

            Stopped = RemoveLanguageResource
        };
      _languageResourcesRegistrationChangeListener = new DefaultItemRegistrationChangeListener("Localization system: Language resources")
        {
            ItemsWereAdded = (location, items) => AddLanguageResources(items)
            // Item removals are handled by the SkinResourcesPluginItemStateTracker
        };
    }
        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();
        }
예제 #13
0
        public SkinManager()
        {
            _skinResourcesPluginItemStateTracker = new DefaultItemStateTracker("SkinManager: Usage of skin resources")
            {
                Stopped = itemRegistration => SkinResourcesWereChanged()
            };
            _skinResourcesRegistrationChangeListener = new DefaultItemRegistrationChangeListener("SkinManager: Usage of skin resources")
            {
                ItemsWereAdded = (location, items) => SkinResourcesWereChanged()
                                 // Item removals are handled by the plugin item state tracker
            };
            _backgroundManagerData = new BackgroundManagerData(this);
            IPluginManager pluginManager = ServiceRegistration.Get <IPluginManager>();

            pluginManager.AddItemRegistrationChangeListener(
                SKIN_RESOURCES_REGISTRATION_PATH, _skinResourcesRegistrationChangeListener);
            ReloadSkins();
        }
        protected void Init(bool reloadCurrentSkins)
        {
            //Get the currently loaded skins
            if (reloadCurrentSkins || _currentSkins == null)
            {
                _currentSkins = GetCurrentSkins();
            }

            //Only load the plugin items once
            if (_pluginItemStateTracker != null)
            {
                return;
            }

            //Get all registered plugin items
            _pluginItemStateTracker = new FixedItemStateTracker("Home Editor - skin registration");
            _supportedSkins         = GetSupportedSkins();
        }
        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);
                }
            }
        }
예제 #16
0
        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;
            }
        }
        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;
            }
        }
예제 #18
0
        /// <summary>
        /// Disposes the child nodes and release their registration at the plugin manager.
        /// After this method was called, the node is in the same state like it was before it was
        /// lazy loaded - and will switch back to a fully initialized state automatically when it is used again.
        /// </summary>
        public void DisposeChildren()
        {
            if (!_childrenLoaded)
            {
                return;
            }
            IPluginManager pluginManager = ServiceRegistration.Get <IPluginManager>();
            string         itemLocation  = Constants.PLUGINTREE_BASELOCATION + Location;

            foreach (ConfigurationNode node in _childNodes)
            {
                node.DisposeChildren();
                node.DisposeConfigObj();
                // To fulfill the classes invariant, we need to do the dispose work for our children - like
                // we built up our children in method LoadChildren()
                pluginManager.RevokePluginItem(itemLocation, node.Id, _childPluginItemStateTracker);
                _childPluginItemStateTracker = null;
            }
            _childNodes.Clear();
            _childrenLoaded = false;
        }
예제 #19
0
        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);
                    }
                }
            }
        }
예제 #20
0
    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;
      }
    }
예제 #21
0
 public void RevokeAllPluginItems(string location, IPluginItemStateTracker stateTracker)
 {
     throw new NotImplementedException();
 }
예제 #22
0
    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);
        }
      }
    }
예제 #23
0
 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, null);
     ConfigSection dummySection = new ConfigSection();
     dummySection.SetMetadata(dummyMetadata);
     AddChildNode(dummySection);
   }
   _childrenLoaded = true;
 }
예제 #24
0
 /// <summary>
 /// Disposes the child nodes and release their registration at the plugin manager.
 /// After this method was called, the node is in the same state like it was before it was
 /// lazy loaded - and will switch back to a fully initialized state automatically when it is used again.
 /// </summary>
 public void DisposeChildren()
 {
   if (!_childrenLoaded)
     return;
   IPluginManager pluginManager = ServiceRegistration.Get<IPluginManager>();
   string itemLocation = Constants.PLUGINTREE_BASELOCATION + Location;
   foreach (ConfigurationNode node in _childNodes)
   {
     node.DisposeChildren();
     node.DisposeConfigObj();
     // To fulfill the classes invariant, we need to do the dispose work for our children - like
     // we built up our children in method LoadChildren()
     pluginManager.RevokePluginItem(itemLocation, node.Id, _childPluginItemStateTracker);
     _childPluginItemStateTracker = null;
   }
   _childNodes.Clear();
   _childrenLoaded = false;
 }
예제 #25
0
 public SkinManager()
 {
   _skinResourcesPluginItemStateTracker = new DefaultItemStateTracker("SkinManager: Usage of skin resources")
     {
         Stopped = itemRegistration => SkinResourcesWereChanged()
     };
   _skinResourcesRegistrationChangeListener = new DefaultItemRegistrationChangeListener("SkinManager: Usage of skin resources")
     {
         ItemsWereAdded = (location, items) => SkinResourcesWereChanged()
         // Item removals are handled by the plugin item state tracker
     };
   _backgroundManagerData = new BackgroundManagerData(this);
   IPluginManager pluginManager = ServiceRegistration.Get<IPluginManager>();
   pluginManager.AddItemRegistrationChangeListener(
       SKIN_RESOURCES_REGISTRATION_PATH, _skinResourcesRegistrationChangeListener);
   ReloadSkins();
 }
예제 #26
0
 public T RequestPluginItem <T>(string location, string id, IPluginItemStateTracker stateTracker) where T : class
 {
     throw new NotImplementedException();
 }
예제 #27
0
 public ICollection <T> RequestAllPluginItems <T>(string location, IPluginItemStateTracker stateTracker) where T : class
 {
     return(new List <T>());
 }
예제 #28
0
 public object RequestPluginItem(string location, string id, Type type, IPluginItemStateTracker stateTracker)
 {
     throw new NotImplementedException();
 }
예제 #29
0
 public ICollection RequestAllPluginItems(string location, Type type, IPluginItemStateTracker stateTracker)
 {
     throw new NotImplementedException();
 }
예제 #30
0
    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);
        }
      }
    }
예제 #31
0
    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
          {
            Type extensionClass = slimTvProgramExtension.ExtensionClass;
            if (extensionClass == null)
              throw new PluginInvalidStateException("Could not find class type for extension {0}", slimTvProgramExtension.Caption);
            IProgramAction action = Activator.CreateInstance(extensionClass) as IProgramAction;
            if (action == null)
              throw new PluginInvalidStateException("Could not create IProgramAction instance of class {0}", 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);
        }
      }
    }
예제 #32
0
    public PlayerManager()
    {
      _slots = new PlayerSlotController[] {
          new PlayerSlotController(this, PlayerManagerConsts.PRIMARY_SLOT),
          new PlayerSlotController(this, PlayerManagerConsts.SECONDARY_SLOT)
      };

      // Albert, 2010-12-06: It's too difficult to revoke a player builder. We cannot guarantee that no player of that
      // player builder is currently in use by other threads, so we simply don't allow to revoke them by using a FixedItemStateTracker.
      _playerBuilderPluginItemStateTracker = new FixedItemStateTracker("PlayerManager: PlayerBuilder usage");
      _playerBuilderRegistrationChangeListener = new PlayerBuilderRegistrationChangeListener(this);
      LoadSettings();
      SubscribeToMessages();
    }
예제 #33
0
    public WorkflowManager()
    {
      _modelItemStateTracker = new DefaultItemStateTracker("WorkflowManager: Model usage")
        {
            // We could store the end-requested model in an array of "suspended models" in the WF manager,
            // method WFM.GetOrLoadModel would then fail to load any of the suspended models
            EndRequested = itemRegistration => !IsModelContainedInNavigationStack(new Guid(itemRegistration.Metadata.Id)),

            Stopped = itemRegistration => NavigatePopModel(new Guid(itemRegistration.Metadata.Id))

            // If we'd maintain a collection of "suspended models" (like said in comment in method RequestEnd),
            // we would need to cancel the suspension of the continued model in the Continued delegate.
        };
      _wfStateItemStateTracker = new DefaultItemStateTracker("WorkflowManager: Workflow state usage")
        {
            Stopped = itemRegistration => ReloadWorkflowStates()
        };
      _workflowPluginItemsChangeListener = new DefaultItemRegistrationChangeListener("WorkflowManager: Workflow state usage")
        {
            ItemsWereAdded = (location, items) => ReloadWorkflowStates(),

            ItemsWereRemoved = (location, items) => ReloadWorkflowStates()
        };
    }