public string GetScript(string name, ProxyScriptType type)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("name is null or empty!", nameof(name));
            }

            var cacheKey = type + "_" + name;

            lock (CachedScripts)
            {
                var cachedScript = CachedScripts.GetOrDefault(cacheKey);
                if (cachedScript == null)
                {
                    var dynamicController = _dynamicApiControllerManager
                                            .GetAll()
                                            .FirstOrDefault(ci => ci.ServiceName == name && ci.IsProxyScriptingEnabled);

                    if (dynamicController == null)
                    {
                        throw new HttpException((int)HttpStatusCode.NotFound, "There is no such a service: " + cacheKey);
                    }

                    var script = CreateProxyGenerator(type, dynamicController, true).Generate();
                    CachedScripts[cacheKey] = cachedScript = new ScriptInfo(script);
                }

                return(cachedScript.Script);
            }
        }
 /// <summary>
 /// Gets javascript proxy for all services.
 /// </summary>
 /// <param name="type">Script type</param>
 public HttpResponseMessage GetAll(ProxyScriptType type = ProxyScriptType.JQuery)
 {
     var script = _scriptProxyManager.GetAllScript(type);
     var response = Request.CreateResponse(System.Net.HttpStatusCode.OK, script, new PlainTextFormatter());
     response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/x-javascript");
     return response;
 }
        public string GetScript(string name, ProxyScriptType type)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("name is null or empty!", "name");
            }

            var cacheKey = type + "_" + name;

            lock (CachedScripts)
            {
                var cachedScript = CachedScripts.GetOrDefault(cacheKey);
                if (cachedScript == null)
                {
                    var dynamicController = DynamicApiControllerManager.GetAll().FirstOrDefault(ci => ci.ServiceName == name);
                    if (dynamicController == null)
                    {
                        throw new HttpException(404, "There is no such a service: " + cacheKey);
                    }

                    var script = CreateProxyGenerator(type, dynamicController, true).Generate();
                    CachedScripts[cacheKey] = cachedScript = new ScriptInfo(script);
                }

                return cachedScript.Script;
            }
        }
        /// <summary>
        /// Gets javascript proxy for all services.
        /// </summary>
        /// <param name="type">Script type</param>
        public HttpResponseMessage GetAll(ProxyScriptType type = ProxyScriptType.JQuery)
        {
            var script   = _scriptProxyManager.GetAllScript(type);
            var response = Request.CreateResponse(System.Net.HttpStatusCode.OK, script, new PlainTextFormatter());

            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/x-javascript");
            return(response);
        }
        /// <summary>
        /// Gets JavaScript proxy for given service name.
        /// </summary>
        /// <param name="name">Name of the service</param>
        /// <param name="type">Script type</param>
        /// <param name="minify">Minify the JavaScript Code</param>
        public HttpResponseMessage Get(string name, ProxyScriptType type = ProxyScriptType.JQuery, bool minify = false)
        {
            var script   = _scriptProxyManager.GetScript(name, type);
            var response = Request.CreateResponse(System.Net.HttpStatusCode.OK,
                                                  minify ? _javaScriptMinifier.Minify(script) : script, new PlainTextFormatter());

            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/x-javascript");
            return(response);
        }
 private static IScriptProxyGenerator CreateProxyGenerator(ProxyScriptType type, DynamicApiControllerInfo controllerInfo, bool amdModule)
 {
     switch (type)
     {
         case ProxyScriptType.JQuery:
             return new JQueryProxyGenerator(controllerInfo, amdModule);
         case ProxyScriptType.Angular:
             return new AngularProxyGenerator(controllerInfo); //TODO: Angular!
         default:
             throw new AbpException("Unknown ProxyScriptType: " + type);
     }
 }
        private static IScriptProxyGenerator CreateProxyGenerator(ProxyScriptType type, DynamicApiControllerInfo controllerInfo, bool amdModule)
        {
            switch (type)
            {
            case ProxyScriptType.JQuery:
                return(new JQueryProxyGenerator(controllerInfo, amdModule));

            case ProxyScriptType.Angular:
                return(new AngularProxyGenerator(controllerInfo));

            default:
                throw new CodeZeroException("Unknown ProxyScriptType: " + type);
            }
        }
        public void GenerateScriptsIfNeeded(ProxyScriptType type)
        {
            lock (CachedScripts)
            {
                if (CachedScripts.Count > 0)
                {
                    return;
                }

                var dynamicControllers = DynamicApiControllerManager.GetAll();
                foreach (var dynamicController in dynamicControllers)
                {
                    var proxyGenerator = CreateProxyGenerator(type, dynamicController, true);
                    var script = proxyGenerator.Generate();
                    var cacheKey = type + "_" + dynamicController.ServiceName;
                    CachedScripts[cacheKey] = new ScriptInfo(script);
                }
            }
        }
示例#9
0
        public void GenerateScriptsIfNeeded(ProxyScriptType type)
        {
            lock (CachedScripts)
            {
                if (CachedScripts.Count > 0)
                {
                    return;
                }

                var dynamicControllers = DynamicApiControllerManager.GetAll();
                foreach (var dynamicController in dynamicControllers)
                {
                    var proxyGenerator = CreateProxyGenerator(type, dynamicController, true);
                    var script         = proxyGenerator.Generate();
                    var cacheKey       = type + "_" + dynamicController.ServiceName;
                    CachedScripts[cacheKey] = new ScriptInfo(script);
                }
            }
        }
        public string GetScript(string name, ProxyScriptType type)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("name is null or empty!", "name");
            }

            GenerateScriptsIfNeeded(type);

            var cacheKey = type + "_" + name;
            lock (CachedScripts)
            {
                if (!CachedScripts.ContainsKey(cacheKey))
                {
                    throw new HttpException(404, "There is no such a service: " + cacheKey);
                }

                return CachedScripts[cacheKey].Script;
            }
        }
示例#11
0
        public string GetScript(string name, ProxyScriptType type)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("name is null or empty!", "name");
            }

            GenerateScriptsIfNeeded(type);

            var cacheKey = type + "_" + name;

            lock (CachedScripts)
            {
                if (!CachedScripts.ContainsKey(cacheKey))
                {
                    throw new HttpException(404, "There is no such a service: " + cacheKey);
                }

                return(CachedScripts[cacheKey].Script);
            }
        }
示例#12
0
        public string GetAllScript(ProxyScriptType type)
        {
            lock (CachedScripts)
            {
                var cacheKey = type + "_all";

                if (!CachedScripts.ContainsKey(cacheKey))
                {
                    var script             = new StringBuilder();
                    var dynamicControllers = _dynamicApiControllerManager.GetAll();

                    foreach (var dynamicController in dynamicControllers)
                    {
                        var proxyGenerator = CreateProxyGenerator(type, dynamicController, false);
                        script.AppendLine(proxyGenerator.Generate());
                        script.AppendLine();
                    }
                    CachedScripts[cacheKey] = new ScriptInfo(script.ToString());
                }
                return(CachedScripts[cacheKey].Script);
            }
        }
        public string GetAllScript(ProxyScriptType type)
        {
            lock (CachedScripts)
            {
                var cacheKey = type + "_all";
                if (!CachedScripts.ContainsKey(cacheKey))
                {
                    var script = new StringBuilder();

                    var dynamicControllers = DynamicApiControllerManager.GetAll();
                    foreach (var dynamicController in dynamicControllers)
                    {
                        var proxyGenerator = CreateProxyGenerator(type, dynamicController, false);
                        script.AppendLine(proxyGenerator.Generate());
                        script.AppendLine();
                    }

                    CachedScripts[cacheKey] = new ScriptInfo(script.ToString());
                }

                return CachedScripts[cacheKey].Script;
            }
        }