Example #1
0
        /// <summary>
        /// Prepare plugin model
        /// </summary>
        /// <param name="model">Plugin model</param>
        /// <param name="pluginDescriptor">Plugin descriptor</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Plugin model</returns>
        public virtual PluginModel PreparePluginModel(PluginModel model, PluginDescriptor pluginDescriptor, bool excludeProperties = false)
        {
            Action <PluginLocalizedModel, int> localizedModelConfiguration = null;

            if (pluginDescriptor != null)
            {
                //fill in model values from the entity
                model = model ?? pluginDescriptor.ToPluginModel(model);

                model.LogoUrl             = PluginManager.GetLogoUrl(pluginDescriptor);
                model.SelectedUserRoleIds = pluginDescriptor.LimitedToUserRoles;
                if (pluginDescriptor.Installed)
                {
                    PrepareInstalledPluginModel(model, pluginDescriptor.Instance());
                }

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    var plugin = pluginDescriptor.Instance();
                    locale.FriendlyName = _localizationService.GetLocalizedFriendlyName(plugin, languageId, false);
                };
            }

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            //prepare model user roles
            _aclSupportedModelFactory.PrepareModelUserRoles(model);

            return(model);
        }
Example #2
0
        /// <summary>
        /// Prepare plugin model
        /// </summary>
        /// <param name="model">Plugin model</param>
        /// <param name="pluginDescriptor">Plugin descriptor</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>
        /// A task that represents the asynchronous operation
        /// The task result contains the plugin model
        /// </returns>
        public virtual async Task <PluginModel> PreparePluginModelAsync(PluginModel model, PluginDescriptor pluginDescriptor, bool excludeProperties = false)
        {
            Func <PluginLocalizedModel, int, Task> localizedModelConfiguration = null;

            if (pluginDescriptor != null)
            {
                //fill in model values from the entity
                model ??= pluginDescriptor.ToPluginModel(model);

                model.LogoUrl = await _pluginService.GetPluginLogoUrlAsync(pluginDescriptor);

                model.SelectedStoreIds        = pluginDescriptor.LimitedToStores;
                model.SelectedCustomerRoleIds = pluginDescriptor.LimitedToCustomerRoles;
                var plugin = pluginDescriptor.Instance <IPlugin>();
                if (pluginDescriptor.Installed)
                {
                    PrepareInstalledPluginModel(model, plugin);
                }

                //define localized model configuration action
                localizedModelConfiguration = async(locale, languageId) =>
                {
                    locale.FriendlyName = await _localizationService.GetLocalizedFriendlyNameAsync(plugin, languageId, false);
                };
            }

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = await _localizedModelFactory.PrepareLocalizedModelsAsync(localizedModelConfiguration);
            }

            //prepare model customer roles
            await _aclSupportedModelFactory.PrepareModelCustomerRolesAsync(model);

            //prepare available stores
            await _storeMappingSupportedModelFactory.PrepareModelStoresAsync(model);

            return(model);
        }