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);
        }
Ejemplo n.º 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);
                        }
                    }
                }

                if (LicenseChecker.IsLicensablePlugin(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 license = LicenseChecker.GetLicense(pluginDescriptor.SystemName);

                    if (license != null)                        // license\plugin has been used
                    {
                        model.LicenseState           = license.State;
                        model.TruncatedLicenseKey    = license.TruncatedLicenseKey;
                        model.RemainingDemoUsageDays = license.RemainingDemoDays;
                    }
                }
            }
            return(model);
        }
Ejemplo n.º 3
0
        public ActionResult LicensePlugin(string systemName, string licenseKey)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePlugins))
            {
                return(AccessDeniedPartialView());
            }

            var descriptor = _pluginFinder.GetPluginDescriptorBySystemName(systemName);

            if (descriptor == null || !descriptor.Installed)
            {
                return(Content(T("Admin.Common.ResourceNotFound")));
            }

            bool singleLicenseForAllStores = false;
            bool isLicensable = LicenseChecker.IsLicensablePlugin(descriptor, out singleLicenseForAllStores);

            if (!isLicensable)
            {
                return(Content(T("Admin.Common.ResourceNotFound")));
            }

            var stores = _services.StoreService.GetAllStores();
            var model  = new LicensePluginModel
            {
                SystemName = systemName,
                Licenses   = new List <LicensePluginModel.LicenseModel>()
            };

            // validate store url
            foreach (var store in stores)
            {
                if (!_services.StoreService.IsStoreDataValid(store))
                {
                    model.InvalidDataStoreId = store.Id;
                    return(View(model));
                }
            }

            if (singleLicenseForAllStores)
            {
                var licenseModel = new LicensePluginModel.LicenseModel();
                var license      = LicenseChecker.GetLicense(systemName, "");

                if (license != null)
                {
                    licenseModel.LicenseKey = license.TruncatedLicenseKey;
                }

                model.Licenses.Add(licenseModel);
            }
            else
            {
                foreach (var store in stores)
                {
                    var licenseModel = new LicensePluginModel.LicenseModel
                    {
                        StoreId   = store.Id,
                        StoreName = store.Name,
                        StoreUrl  = store.Url
                    };

                    var license = LicenseChecker.GetLicense(systemName, store.Url);

                    if (license != null)
                    {
                        licenseModel.LicenseKey = license.TruncatedLicenseKey;
                    }

                    model.Licenses.Add(licenseModel);
                }
            }

            return(View(model));
        }