コード例 #1
0
        private LicensingData PrepareLicenseLabelModel(LicenseLabelModel model, PluginDescriptor pluginDescriptor, string url = null)
        {
            if (IsLicensable(pluginDescriptor))
            {
                // We always show license button to serve ability to delete a key.
                model.IsLicensable = true;
                model.LicenseUrl   = Url.Action("LicensePlugin", new { systemName = pluginDescriptor.SystemName });

                var cachedLicense = LicenseChecker.GetLicense(pluginDescriptor.SystemName, url);
                if (cachedLicense == null)
                {
                    // Licensed plugin has not been used yet -> Check state.
                    model.LicenseState = LicenseChecker.CheckState(pluginDescriptor.SystemName, url);

                    // And try to get license data again.
                    cachedLicense = LicenseChecker.GetLicense(pluginDescriptor.SystemName, url);
                }

                if (cachedLicense != null)
                {
                    // Licensed plugin has been used.
                    model.LicenseState           = cachedLicense.State;
                    model.TruncatedLicenseKey    = cachedLicense.TruncatedLicenseKey;
                    model.RemainingDemoUsageDays = cachedLicense.RemainingDemoDays;
                }
                else
                {
                    // It's confusing to display a license state when there is no license data yet.
                    model.HideLabel = true;
                }

                return(cachedLicense);
            }

            return(null);
        }
コード例 #2
0
        protected PluginModel PreparePluginModel(PluginDescriptor pluginDescriptor, bool forList = true)
        {
            var model = pluginDescriptor.ToModel();

            model.Group = T("Admin.Plugins.KnownGroup." + pluginDescriptor.Group);

            if (forList)
            {
                model.FriendlyName = pluginDescriptor.GetLocalizedValue(_services.Localization, "FriendlyName");
                model.Description  = pluginDescriptor.GetLocalizedValue(_services.Localization, "Description");
            }

            //locales
            AddLocales(_languageService, model.Locales, (locale, languageId) =>
            {
                locale.FriendlyName = pluginDescriptor.GetLocalizedValue(_services.Localization, "FriendlyName", languageId, false);
                locale.Description  = pluginDescriptor.GetLocalizedValue(_services.Localization, "Description", languageId, false);
            });

            // Stores
            model.SelectedStoreIds = _services.Settings.GetSettingByKey <string>(pluginDescriptor.GetSettingKey("LimitedToStores")).ToIntArray();

            // Icon
            model.IconUrl = _pluginMediator.GetIconUrl(pluginDescriptor);

            if (pluginDescriptor.Installed)
            {
                // specify configuration URL only when a plugin is already installed
                if (pluginDescriptor.IsConfigurable)
                {
                    model.ConfigurationUrl = Url.Action("ConfigurePlugin", new { systemName = pluginDescriptor.SystemName });

                    if (!forList)
                    {
                        var configurable = pluginDescriptor.Instance() as IConfigurable;

                        string actionName;
                        string controllerName;
                        RouteValueDictionary routeValues;
                        configurable.GetConfigurationRoute(out actionName, out controllerName, out routeValues);

                        if (actionName.HasValue() && controllerName.HasValue())
                        {
                            model.ConfigurationRoute = new RouteInfo(actionName, controllerName, routeValues);
                        }
                    }
                }

                // License data
                if (LicenseChecker.IsLicensablePlugin(pluginDescriptor))
                {
                    // We always show license button to serve ability to delete a key.
                    model.LicenseModel.IsLicensable = true;
                    model.LicenseModel.LicenseUrl   = Url.Action("LicensePlugin", new { systemName = pluginDescriptor.SystemName });

                    var license = LicenseChecker.GetLicense(pluginDescriptor.SystemName);
                    if (license == null)
                    {
                        // Licensed plugin has not been used yet -> Check state.
                        var unused = LicenseChecker.CheckState(pluginDescriptor.SystemName);

                        // And try to get license data again.
                        license = LicenseChecker.GetLicense(pluginDescriptor.SystemName);
                    }

                    if (license != null)
                    {
                        // Licensed plugin has been used.
                        model.LicenseModel.LicenseState           = license.State;
                        model.LicenseModel.TruncatedLicenseKey    = license.TruncatedLicenseKey;
                        model.LicenseModel.RemainingDemoUsageDays = license.RemainingDemoDays;
                    }
                    else
                    {
                        // It's confusing to display a license state when there is no license data yet.
                        model.LicenseModel.HideLabel = true;
                    }
                }
            }

            return(model);
        }