internal JsonPluginEndPoint(PluginFeature pluginFeature, string name, PluginsModule pluginsModule, Func <T, object?> responseRequestHandler) : base(pluginFeature, name, pluginsModule)
 {
     _responseRequestHandler = responseRequestHandler;
     ThrowOnFail             = true;
     Accepts = MimeType.Json;
     Returns = MimeType.Json;
 }
Exemple #2
0
        internal PluginEndPoint(PluginFeature pluginFeature, string name, PluginsModule pluginsModule)
        {
            _pluginsModule = pluginsModule;
            PluginFeature  = pluginFeature;
            Name           = name;

            PluginFeature.Disabled += OnDisabled;
        }
        /// <summary>
        /// Return TRUE if this is a Visualization element
        /// </summary>
        static bool FilterVisFeatures(PluginFeature feature)
        {
            if (!(feature is ElementFactory))
            {
                return(false);
            }
            var factory = (ElementFactory)feature;

            return(factory.GetMetadata(Gst.Constants.ELEMENT_METADATA_KLASS).Contains("Visualization"));
        }
        /// <summary>
        /// Return TRUE if this is a effectv element
        /// </summary>
        static bool FilterEffectFeatures(PluginFeature feature)
        {
            if (!(feature is ElementFactory))
            {
                return(false);
            }
            var factory = (ElementFactory)feature;
            var klass   = factory.GetMetadata(Gst.Constants.ELEMENT_METADATA_KLASS);

            return(klass.Contains("Filter/Effect/Video") && factory.PluginName == "effectv");
        }
Exemple #5
0
        private static bool FilterVisFeatures(PluginFeature feature)
        {
            if (!(feature is ElementFactory))
            {
                return(false);
            }

            var factory = (ElementFactory)feature;

            return((factory.GetMetadata(Gst.Constants.ELEMENT_METADATA_KLASS).ToLower().Contains("codec/decoder")) || (factory.GetMetadata(Gst.Constants.ELEMENT_METADATA_KLASS).ToLower().Contains("sink/video")));
        }
Exemple #6
0
        public void AddModule <T>(PluginFeature feature) where T : IWebModule
        {
            if (feature == null)
            {
                throw new ArgumentNullException(nameof(feature));
            }
            if (_modules.Any(r => r.WebModuleType == typeof(T)))
            {
                return;
            }

            _modules.Add(new WebModuleRegistration(feature, typeof(T)));
            StartWebServer();
        }
Exemple #7
0
        public JsonPluginEndPoint <T> AddJsonEndPoint <T>(PluginFeature feature, string endPointName, Action <T> requestHandler)
        {
            if (feature == null)
            {
                throw new ArgumentNullException(nameof(feature));
            }
            if (endPointName == null)
            {
                throw new ArgumentNullException(nameof(endPointName));
            }
            if (requestHandler == null)
            {
                throw new ArgumentNullException(nameof(requestHandler));
            }
            JsonPluginEndPoint <T> endPoint = new(feature, endPointName, PluginsModule, requestHandler);

            PluginsModule.AddPluginEndPoint(endPoint);
            return(endPoint);
        }
Exemple #8
0
        public RawPluginEndPoint AddRawEndPoint(PluginFeature feature, string endPointName, Func <IHttpContext, Task> requestHandler)
        {
            if (feature == null)
            {
                throw new ArgumentNullException(nameof(feature));
            }
            if (endPointName == null)
            {
                throw new ArgumentNullException(nameof(endPointName));
            }
            if (requestHandler == null)
            {
                throw new ArgumentNullException(nameof(requestHandler));
            }
            RawPluginEndPoint endPoint = new(feature, endPointName, PluginsModule, requestHandler);

            PluginsModule.AddPluginEndPoint(endPoint);
            return(endPoint);
        }
Exemple #9
0
        public StringPluginEndPoint AddResponsiveStringEndPoint(PluginFeature feature, string endPointName, Func <string, string?> requestHandler)
        {
            if (feature == null)
            {
                throw new ArgumentNullException(nameof(feature));
            }
            if (endPointName == null)
            {
                throw new ArgumentNullException(nameof(endPointName));
            }
            if (requestHandler == null)
            {
                throw new ArgumentNullException(nameof(requestHandler));
            }
            StringPluginEndPoint endPoint = new(feature, endPointName, PluginsModule, requestHandler);

            PluginsModule.AddPluginEndPoint(endPoint);
            return(endPoint);
        }
Exemple #10
0
        public void DisablePluginFeature(PluginFeature pluginFeature, bool saveState)
        {
            try
            {
                _logger.Verbose("Disabling plugin feature {feature} - {plugin}", pluginFeature, pluginFeature.Plugin);
                pluginFeature.SetEnabled(false);
            }
            finally
            {
                if (saveState)
                {
                    pluginFeature.Entity.IsEnabled = false;
                    SavePlugin(pluginFeature.Plugin);
                }

                if (!pluginFeature.IsEnabled)
                {
                    _logger.Verbose("Successfully disabled plugin feature {feature} - {plugin}", pluginFeature, pluginFeature.Plugin);
                    OnPluginFeatureDisabled(new PluginFeatureEventArgs(pluginFeature));
                }
            }
        }
Exemple #11
0
        private void SetPrimaryDecoder(string decoderName)
        {
            var registry   = Gst.Registry.Get();
            var pluginList = registry.FeatureFilter(FilterVisFeatures, false);

            // First we find the current primary decoders
            var primaryPlugins = pluginList.Where(plugin => plugin.Rank == (uint)Rank.Primary);

            // And then downrank them
            foreach (var plugin in primaryPlugins)
            {
                --plugin.Rank;
            }

            // Then we set our plugin to the primary rank
            PluginFeature d3d11Plugin = pluginList.FirstOrDefault(plugin => plugin.Name == decoderName);

            if (d3d11Plugin != null)
            {
                d3d11Plugin.Rank = (uint)Rank.Primary;
            }
        }
        public DataModelPropertiesViewModel?GetPluginDataModelVisualization(PluginFeature pluginFeature, bool includeMainDataModel)
        {
            if (includeMainDataModel)
            {
                DataModelPropertiesViewModel mainDataModel = GetMainDataModelVisualization();

                // If the main data model already includes the plugin data model we're done
                if (mainDataModel.Children.Any(c => c.DataModel?.Feature == pluginFeature))
                {
                    return(mainDataModel);
                }
                // Otherwise get just the plugin data model and add it
                DataModelPropertiesViewModel?pluginDataModel = GetPluginDataModelVisualization(pluginFeature, false);
                if (pluginDataModel != null)
                {
                    mainDataModel.Children.Add(pluginDataModel);
                }

                return(mainDataModel);
            }

            DataModel?dataModel = _dataModelService.GetPluginDataModel(pluginFeature);

            if (dataModel == null)
            {
                return(null);
            }

            DataModelPropertiesViewModel viewModel = new(null, null, null);

            viewModel.Children.Add(new DataModelPropertiesViewModel(dataModel, viewModel, new DataModelPath(dataModel)));

            // Update to populate children
            viewModel.Update(this, null);
            viewModel.UpdateRequested += (sender, args) => viewModel.Update(this, null);
            return(viewModel);
        }
Exemple #13
0
 public WebApiControllerRegistration(PluginFeature feature) : base(feature, typeof(T))
 {
     Factory = () => feature.Plugin.Kernel !.Get <T>();
 }
Exemple #14
0
 /// <inheritdoc />
 internal RawPluginEndPoint(PluginFeature pluginFeature, string name, PluginsModule pluginsModule, Func <IHttpContext, Task> requestHandler) : base(pluginFeature, name, pluginsModule)
 {
     RequestHandler = requestHandler;
 }
 internal StringPluginEndPoint(PluginFeature pluginFeature, string name, PluginsModule pluginsModule, Func <string, string?> requestHandler) : base(pluginFeature, name, pluginsModule)
 {
     _responseRequestHandler = requestHandler;
     Accepts = MimeType.PlainText;
     Returns = MimeType.PlainText;
 }
Exemple #16
0
 public void AddController <T>(PluginFeature feature) where T : WebApiController
 {
     _controllers.Add(new WebApiControllerRegistration <T>(feature));
     StartWebServer();
 }
Exemple #17
0
 public WebModuleRegistration(PluginFeature feature, Type webModuleType)
 {
     Feature       = feature;
     WebModuleType = webModuleType;
 }
 internal JsonPluginEndPoint(PluginFeature pluginFeature, string name, PluginsModule pluginsModule, Action <T> requestHandler) : base(pluginFeature, name, pluginsModule)
 {
     _requestHandler = requestHandler;
     ThrowOnFail     = true;
     Accepts         = MimeType.Json;
 }
 internal StringPluginEndPoint(PluginFeature pluginFeature, string name, PluginsModule pluginsModule, Action <string> requestHandler) : base(pluginFeature, name, pluginsModule)
 {
     _requestHandler = requestHandler;
     Accepts         = MimeType.PlainText;
 }
Exemple #20
0
 public DataModel?GetPluginDataModel(PluginFeature pluginFeature)
 {
     return(DataModelStore.Get(pluginFeature.Id)?.DataModel);
 }
Exemple #21
0
        public void EnablePluginFeature(PluginFeature pluginFeature, bool saveState, bool isAutoEnable)
        {
            _logger.Verbose("Enabling plugin feature {feature} - {plugin}", pluginFeature, pluginFeature.Plugin);

            OnPluginFeatureEnabling(new PluginFeatureEventArgs(pluginFeature));

            if (pluginFeature.Plugin.Info.RequiresAdmin && !_isElevated)
            {
                if (!saveState)
                {
                    throw new ArtemisCoreException("Cannot enable a feature that requires elevation without saving it's state.");
                }

                pluginFeature.Entity.IsEnabled        = true;
                pluginFeature.Plugin.Entity.IsEnabled = true;
                SavePlugin(pluginFeature.Plugin);

                _logger.Information("Restarting because a newly enabled feature requires elevation");
                Utilities.Restart(true, TimeSpan.FromMilliseconds(500));
                return;
            }

            try
            {
                pluginFeature.SetEnabled(true, isAutoEnable);
                if (saveState)
                {
                    pluginFeature.Entity.IsEnabled = true;
                }
            }
            catch (Exception e)
            {
                _logger.Warning(
                    new ArtemisPluginException(pluginFeature.Plugin, $"Exception during SetEnabled(true) on {pluginFeature}", e),
                    "Failed to enable plugin"
                    );
                throw;
            }
            finally
            {
                // On an auto-enable, ensure PluginInfo.Enabled is true even if enable failed, that way a failure on auto-enable does
                // not affect the user's settings
                if (saveState)
                {
                    if (isAutoEnable)
                    {
                        pluginFeature.Entity.IsEnabled = true;
                    }

                    SavePlugin(pluginFeature.Plugin);
                }

                if (pluginFeature.IsEnabled)
                {
                    _logger.Verbose("Successfully enabled plugin feature {feature} - {plugin}", pluginFeature, pluginFeature.Plugin);
                    OnPluginFeatureEnabled(new PluginFeatureEventArgs(pluginFeature));
                }
                else
                {
                    OnPluginFeatureEnableFailed(new PluginFeatureEventArgs(pluginFeature));
                }
            }
        }
Exemple #22
0
        public void EnablePlugin(Plugin plugin, bool saveState, bool ignorePluginLock)
        {
            if (plugin.Assembly == null)
            {
                throw new ArtemisPluginException(plugin, "Cannot enable a plugin that hasn't successfully been loaded");
            }

            if (plugin.Info.RequiresAdmin && plugin.HasEnabledFeatures() && !_isElevated)
            {
                if (!saveState)
                {
                    throw new ArtemisCoreException("Cannot enable a plugin that requires elevation without saving it's state.");
                }

                plugin.Entity.IsEnabled = true;
                SavePlugin(plugin);

                _logger.Information("Restarting because a newly enabled plugin requires elevation");
                Utilities.Restart(true, TimeSpan.FromMilliseconds(500));
                return;
            }

            // Create the Ninject child kernel and load the module
            plugin.Kernel = new ChildKernel(_kernel, new PluginModule(plugin));
            OnPluginEnabling(new PluginEventArgs(plugin));

            plugin.SetEnabled(true);

            // Create instances of each feature
            // Construction should be simple and not contain any logic so failure at this point means the entire plugin fails
            foreach (PluginFeatureInfo featureInfo in plugin.Features)
            {
                try
                {
                    plugin.Kernel.Bind(featureInfo.FeatureType).ToSelf().InSingletonScope();

                    // Include Plugin as a parameter for the PluginSettingsProvider
                    IParameter[]  parameters = { new Parameter("Plugin", plugin, false) };
                    PluginFeature instance   = (PluginFeature)plugin.Kernel.Get(featureInfo.FeatureType, parameters);

                    // Get the PluginFeature attribute which contains extra info on the feature
                    featureInfo.Instance = instance;
                    instance.Info        = featureInfo;
                    instance.Plugin      = plugin;

                    // Load the enabled state and if not found, default to true
                    instance.Entity = plugin.Entity.Features.FirstOrDefault(i => i.Type == featureInfo.FeatureType.FullName) ??
                                      new PluginFeatureEntity {
                        IsEnabled = plugin.Info.AutoEnableFeatures, Type = featureInfo.FeatureType.FullName !
                    };
                }
                catch (Exception e)
                {
                    _logger.Warning(new ArtemisPluginException(plugin, "Failed to instantiate feature", e), "Failed to instantiate feature", plugin);
                }
            }

            // Activate features after they are all loaded
            foreach (PluginFeatureInfo pluginFeature in plugin.Features.Where(f => f.Instance != null && (f.Instance.Entity.IsEnabled || f.AlwaysEnabled)))
            {
                try
                {
                    EnablePluginFeature(pluginFeature.Instance !, false, !ignorePluginLock);
                }
                catch (Exception)
                {
                    // ignored, logged in EnablePluginFeature
                }
            }

            if (saveState)
            {
                plugin.Entity.IsEnabled = plugin.IsEnabled;
                SavePlugin(plugin);
            }

            OnPluginEnabled(new PluginEventArgs(plugin));
        }