Exemplo n.º 1
0
    private string CreateScript(ProxyScriptingModel scriptingModel)
    {
        var apiModel = _modelProvider.CreateApiModel(new ApplicationApiDescriptionModelRequestDto {
            IncludeTypes = false
        });

        if (scriptingModel.IsPartialRequest())
        {
            apiModel = apiModel.CreateSubModel(scriptingModel.Modules, scriptingModel.Controllers, scriptingModel.Actions);
        }

        var generatorType = _options.Generators.GetOrDefault(scriptingModel.GeneratorType);

        if (generatorType == null)
        {
            throw new AbpException($"Could not find a proxy script generator with given name: {scriptingModel.GeneratorType}");
        }

        using (var scope = _serviceProvider.CreateScope())
        {
            return(scope.ServiceProvider
                   .GetRequiredService(generatorType)
                   .As <IProxyScriptGenerator>()
                   .CreateScript(apiModel));
        }
    }
Exemplo n.º 2
0
 private string CreateCacheKey(ProxyScriptingModel model)
 {
     return(_jsonSerializer.Serialize(new {
         model.GeneratorType,
         model.Modules,
         model.Controllers,
         model.Actions,
         model.Properties
     }).ToMd5());
 }
Exemplo n.º 3
0
    public string GetScript(ProxyScriptingModel scriptingModel)
    {
        var cacheKey = CreateCacheKey(scriptingModel);

        if (scriptingModel.UseCache)
        {
            return(_cache.GetOrAdd(cacheKey, () => CreateScript(scriptingModel)));
        }

        var script = CreateScript(scriptingModel);

        _cache.Set(cacheKey, script);
        return(script);
    }
        public ProxyScriptingModel CreateOptions()
        {
            var options = new ProxyScriptingModel(Type, UseCache);

            if (!Modules.IsNullOrEmpty())
            {
                options.Modules = Modules.Split('|').Select(m => m.Trim()).ToArray();
            }

            if (!Controllers.IsNullOrEmpty())
            {
                options.Controllers = Controllers.Split('|').Select(m => m.Trim()).ToArray();
            }

            if (!Actions.IsNullOrEmpty())
            {
                options.Actions = Actions.Split('|').Select(m => m.Trim()).ToArray();
            }

            return(options);
        }