Exemplo n.º 1
0
        /// <summary>
        /// 获取API代理脚本
        /// </summary>
        /// <param name="options">API代理生成选项</param>
        /// <returns></returns>
        public string GetScript(ApiProxyGenerationOptions options)
        {
            if (options.UseCache)
            {
                return(_cache.GetOrAdd(CreateCacheKey(options), (key) => CreateScript(options)));
            }

            return(_cache[CreateCacheKey(options)] = CreateScript(options));
        }
        public string GetScript(ApiProxyGenerationOptions options)
        {
            if (options.UseCache)
            {
                return _cache.GetOrAdd(CreateCacheKey(options), (key) => CreateScript(options));
            }

            return _cache[CreateCacheKey(options)] = CreateScript(options);
        }
        private string CreateScript(ApiProxyGenerationOptions options)
        {
            var model = _modelProvider.CreateModel();

            if (options.IsPartialRequest())
            {
                model = model.CreateSubModel(options.Modules, options.Controllers, options.Actions);
            }

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

            using (var generator = _iocResolver.ResolveAsDisposable<IProxyScriptGenerator>(generatorType))
            {
                return generator.Object.CreateScript(model);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 生成脚本
        /// </summary>
        /// <param name="options">API代理生成选项</param>
        /// <returns></returns>
        private string CreateScript(ApiProxyGenerationOptions options)
        {
            var model = _modelProvider.CreateModel();

            if (options.IsPartialRequest())
            {
                model = model.CreateSubModel(options.Modules, options.Controllers, options.Actions);
            }

            var generatorType = _configuration.Generators.GetOrDefault(options.GeneratorType);

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

            using (var generator = _iocResolver.ResolveAsDisposable <IProxyScriptGenerator>(generatorType))
            {
                return(generator.Object.CreateScript(model));
            }
        }
        public ApiProxyGenerationOptions CreateOptions()
        {
            var options = new ApiProxyGenerationOptions(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;
        }
Exemplo n.º 6
0
 /// <summary>
 /// 创建缓存Key
 /// </summary>
 /// <param name="options">API代理生成选项</param>
 /// <returns></returns>
 private static string CreateCacheKey(ApiProxyGenerationOptions options)
 {
     return(options.ToJsonString().ToMd5());
 }
 private static string CreateCacheKey(ApiProxyGenerationOptions options)
 {
     return options.ToJsonString().ToMd5();
 }