/// <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);
        }
Exemplo n.º 2
0
        private static string GenerateProxy(IHubManager hubManager, IJavaScriptMinifier javaScriptMinifier, bool includeDocComments)
        {
            string script = _templateFromResource.Value;

            var hubs  = new StringBuilder();
            var first = true;

            foreach (var descriptor in hubManager.GetHubs().OrderBy(h => h.Name))
            {
                if (!first)
                {
                    hubs.AppendLine(";");
                    hubs.AppendLine();
                    hubs.Append("    ");
                }
                GenerateType(hubManager, hubs, descriptor, includeDocComments);
                first = false;
            }

            if (hubs.Length > 0)
            {
                hubs.Append(";");
            }

            script = script.Replace("/*hubs*/", hubs.ToString());

            return(javaScriptMinifier.Minify(script));
        }
Exemplo n.º 3
0
        public string GenerateProxy(string serviceUrl, bool includeDocComments)
        {
            string script;

            if (_scriptCache.TryGetValue(serviceUrl, out script))
            {
                return(script);
            }

            var template = _template.Value;

            script = template.Replace("{serviceUrl}", serviceUrl);

            var hubs  = new StringBuilder();
            var first = true;

            foreach (var descriptor in _manager.GetHubs().OrderBy(h => h.Name))
            {
                if (!first)
                {
                    hubs.AppendLine(";");
                    hubs.AppendLine();
                    hubs.Append("    ");
                }
                GenerateType(hubs, descriptor, includeDocComments);
                first = false;
            }

            if (hubs.Length > 0)
            {
                hubs.Append(";");
            }
            script = script.Replace("/*hubs*/", hubs.ToString());

            if (!IsDebuggingEnabled)
            {
                script = _javaScriptMinifier.Minify(script);
            }

            _scriptCache.TryAdd(serviceUrl, script);

            return(script);
        }
        public async Task <ActionResult> GetScripts(string culture = "", bool minify = false)
        {
            if (!culture.IsNullOrEmpty())
            {
                CultureInfo.CurrentCulture   = CultureInfo.GetCultureInfo(culture);
                CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo(culture);
            }

            var sb = new StringBuilder();

            sb.AppendLine(_multiTenancyScriptManager.GetScript());
            sb.AppendLine();

            sb.AppendLine(_sessionScriptManager.GetScript());
            sb.AppendLine();

            sb.AppendLine(_localizationScriptManager.GetScript());
            sb.AppendLine();

            sb.AppendLine(await _featuresScriptManager.GetScriptAsync());
            sb.AppendLine();

            sb.AppendLine(await _authorizationScriptManager.GetScriptAsync());
            sb.AppendLine();

            sb.AppendLine(await _navigationScriptManager.GetScriptAsync());
            sb.AppendLine();

            sb.AppendLine(await _settingScriptManager.GetScriptAsync());
            sb.AppendLine();

            sb.AppendLine(await _timingScriptManager.GetScriptAsync());
            sb.AppendLine();

            sb.AppendLine(_customConfigScriptManager.GetScript());
            sb.AppendLine();

            sb.AppendLine(GetTriggerScript());

            return(Content(minify ? _javaScriptMinifier.Minify(sb.ToString()) : sb.ToString(),
                           "application/x-javascript", Encoding.UTF8));
        }
Exemplo n.º 5
0
        public string GenerateProxy(HttpContextBase context, string serviceUrl)
        {
            string script;

            if (_scriptCache.TryGetValue(serviceUrl, out script))
            {
                return(script);
            }

            var template = _template.Value;

            script = template.Replace("{serviceUrl}", serviceUrl);

            var hubs  = new StringBuilder();
            var first = true;

            foreach (var type in _hubLocator.GetHubs())
            {
                if (!first)
                {
                    hubs.AppendLine(",");
                    hubs.Append("        ");
                }
                GenerateType(serviceUrl, hubs, type);
                first = false;
            }

            script = script.Replace("/*hubs*/", hubs.ToString());

            if (!context.IsDebuggingEnabled)
            {
                script = _javascriptMinifier.Minify(script);
            }

            _scriptCache.TryAdd(serviceUrl, script);

            return(script);
        }
Exemplo n.º 6
0
        public ContentResult GetAll(ApiProxyGenerationModel model)
        {
            var script = _proxyScriptManager.GetScript(model.CreateOptions());

            return(Content(model.Minify ? _javaScriptMinifier.Minify(script) : script, "application/x-javascript"));
        }