Exemple #1
0
        public ICorePlugin Activate(long pluginId)
        {
            var plugin = _pluginRepository.GetById(pluginId);

            if (plugin == null)
            {
                throw new ArgumentException(nameof(pluginId));
            }

            var currentLicense = _licenseProvider.GetCurrent();

            var pluginLicenseComponent = currentLicense.Get <PluginLicenceComponent>();

            var pluginTypeName = plugin.TypeFullName;

            if (!pluginLicenseComponent.CanUse(pluginTypeName))
            {
                throw new PluginActivationDeniedByLicenseException(currentLicense.Id, pluginTypeName);
            }

            var pluginInstance = _pluginContainerManager.Resolve(pluginTypeName);

            _log.Debug(Resources.Resources.PluginActivator_Activate_PluginActivated.FormatWith(pluginId, pluginTypeName));

            return(pluginInstance);
        }
        /// <summary>
        ///   Executes the specified data query.
        /// </summary>
        /// <param name="dataQuery">The data query.</param>
        /// <returns>The result of execution.</returns>
        public LicenceInfoDto Execute(GetLicenceInfoQuery dataQuery)
        {
            var currentLicence = _licenceProvider.GetCurrent();

            return(new LicenceInfoDto
            {
                Description = currentLicence.Description,
                Id = currentLicence.Id
            });
        }
Exemple #3
0
        /// <summary>
        ///   Executes the specified data query.
        /// </summary>
        /// <param name="dataQuery">The data query.</param>
        /// <returns>The result of execution.</returns>
        public string Execute([NotNull] GetCapabilityByKeyQuery dataQuery)
        {
            if (dataQuery == null)
            {
                throw new ArgumentNullException(nameof(dataQuery));
            }

            var currentLicence = _licenceProvider.GetCurrent();

            var userInterfaceLicenceComponent = currentLicence.Get <UserInterfaceLicenceComponent>();

            return(userInterfaceLicenceComponent.Get(dataQuery.CapabilityKey));
        }
Exemple #4
0
        public void Initialize([NotNull] IPlugin plugin)
        {
            if (plugin == null)
            {
                throw new ArgumentNullException(nameof(plugin));
            }

            var assemblyName = plugin.GetType().Assembly.GetName().Name;
            var typeFullName = plugin.GetType().FullName;
            var pluginTypes  = GetPluginTypes(plugin);

            var currentLicense = _licenseProvider.GetCurrent();

            var pluginLicenseComponent = currentLicense.Get <PluginLicenceComponent>();

            if (!pluginLicenseComponent.CanUse(typeFullName))
            {
                _log.Warning(
                    $"Plugin type registration denied by licence. Licence Id='{currentLicense.Id}', Plugin type='{typeFullName}'");

                return;
            }

            if (pluginTypes.Length == 0)
            {
                _log.Warning(
                    Resources.Resources.PluginProvider_Initialize_PluginNotImplementsInterfaces.FormatWith(
                        typeFullName,
                        assemblyName));

                return;
            }

            foreach (var pluginType in pluginTypes)
            {
                var pluginDb = _pluginRepository.GetByType(typeFullName, assemblyName, pluginType);

                if (pluginDb != null)
                {
                    _log.Info(
                        Resources.Resources.PluginProvider_Initialize_PluginAlreadyRegistered.FormatWith(
                            typeFullName,
                            assemblyName,
                            pluginType));
                }
                else
                {
                    pluginDb = new Plugins
                    {
                        AssemblyName = assemblyName,
                        DisplayName  = plugin.Title,
                        TypeFullName = typeFullName,
                        Type         = (int)pluginType
                    };

                    _pluginRepository.Insert(pluginDb);

                    _pluginRepository.Save();

                    LogInitializedPlugin(pluginDb);
                }

                _pluginSettingProvider.Initialize(plugin, pluginType);

                _pluginContainerManager.Register(plugin, typeFullName);
            }
        }