예제 #1
0
        public static RenderRespnose RenderImage(RenderContext Context, RenderOption option, string relativeurl)
        {
            RenderRespnose response = new RenderRespnose();

            response.ContentType = "image";

            string extension = Kooboo.Lib.Helper.UrlHelper.FileExtension(relativeurl);

            if (!string.IsNullOrWhiteSpace(extension))
            {
                if (!string.IsNullOrEmpty(extension) && extension.StartsWith("."))
                {
                    extension = extension.Substring(1);
                }
                response.ContentType = response.ContentType + "/" + extension;

                if (extension.ToLower() == "svg")
                {
                    response.ContentType = response.ContentType + "+xml";
                }
            }

            var provider = GetSourceProvider(Context, option);

            if (provider != null)
            {
                response.BinaryBytes = provider.GetBinary(Context, relativeurl);
            }
            return(response);
        }
예제 #2
0
        public static RenderRespnose RenderHtml(RenderContext Context, RenderOption option, string relativeurl)
        {
            var sourceprovider = GetSourceProvider(Context, option);

            RenderRespnose response = new RenderRespnose();

            response.ContentType = "text/html";
            string minetype = IOHelper.MimeType(relativeurl);

            if (!string.IsNullOrEmpty(minetype))
            {
                response.ContentType = minetype;
            }

            if (Context == null || sourceprovider == null)
            {
                return(response);
            }
            string htmlbody = sourceprovider.GetString(Context, relativeurl);

            if (string.IsNullOrEmpty(htmlbody))
            {
                return(response);
            }

            var hashid = Lib.Security.Hash.ComputeHashGuid(htmlbody);

            var EvaluatorOption = new EvaluatorOption();

            EvaluatorOption.EnableImageBrowserCache = true;
            EvaluatorOption.EnableJsCssBrowserCache = true;

            EvaluatorOption.Evaluators = Kooboo.Render.Components.EvaluatorContainer.ListWithServerComponent;

            var RenderPlan = RenderPlanCache.GetOrAddRenderPlan(hashid, () => RenderEvaluator.Evaluate(htmlbody, EvaluatorOption));

            // set the culture...
            string culture = Context.Culture;

            if (!string.IsNullOrEmpty(culture))
            {
                Context.DataContext.Push("culture", culture);
            }

            string result = Kooboo.Sites.Render.RenderHelper.Render(RenderPlan, Context);

            string finalreseult = null;

            if (!string.IsNullOrEmpty(finalreseult))
            {
                response.Body = finalreseult;
            }
            else
            {
                response.Body = result;
            }

            return(response);
        }
예제 #3
0
        public static RenderRespnose RenderHtml(RenderContext Context, RenderOption option, string relativeurl)
        {
            var sourceprovider = GetSourceProvider(Context, option);

            RenderRespnose response = new RenderRespnose();

            response.ContentType = "text/html";
            string minetype = IOHelper.MimeType(relativeurl);

            if (!string.IsNullOrEmpty(minetype))
            {
                response.ContentType = minetype;
            }

            if (Context == null || sourceprovider == null)
            {
                return(response);
            }
            string htmlbody = sourceprovider.GetString(Context, relativeurl);

            if (string.IsNullOrEmpty(htmlbody))
            {
                return(response);
            }

            var hashid = Lib.Security.Hash.ComputeHashGuid(htmlbody);

            var RenderPlan = RenderPlanCache.GetOrAddRenderPlan(hashid, () => RenderEvaluator.Evaluate(htmlbody, new EvaluatorOption()));

            string result = Kooboo.Sites.Render.RenderHelper.Render(RenderPlan, Context);

            string finalreseult = null;

            if (!string.IsNullOrEmpty(finalreseult))
            {
                response.Body = finalreseult;
            }
            else
            {
                response.Body = result;
            }

            return(response);
        }
예제 #4
0
        public static RenderRespnose Render(RenderContext Context, RenderOption option, string relativeurl)
        {
            var sourceprovider = GetSourceProvider(Context, option);

            var            FileType = RenderHelper.GetFileType(relativeurl);
            RenderRespnose response = new RenderRespnose();

            switch (FileType)
            {
            case UrlFileType.Image:

                response = RenderImage(Context, option, relativeurl);

                break;

            case UrlFileType.JavaScript:

                if (sourceprovider is CommandDiskSourceProvider)
                {
                    response = ServerSide.ServerEngine.RenderJs(sourceprovider as CommandDiskSourceProvider, option, Context, relativeurl);
                }
                else
                {
                    response.ContentType = "application/javascript";
                    response.BinaryBytes = sourceprovider.GetBinary(Context, relativeurl);
                }

                break;

            case UrlFileType.Style:

                response.ContentType = "text/css";
                response.BinaryBytes = sourceprovider.GetBinary(Context, relativeurl);

                break;

            case UrlFileType.File:

                string contenttype = IOHelper.MimeType(relativeurl);
                if (string.IsNullOrEmpty(contenttype))
                {
                    contenttype = "application/octet-stream";
                }
                response.ContentType = contenttype;

                if (contenttype.ToLower().Contains("zip"))
                {
                    var stream = sourceprovider.GetStream(Context, relativeurl);

                    if (stream != null)
                    {
                        response.Stream = stream;
                    }
                    else
                    {
                        response.BinaryBytes = sourceprovider.GetBinary(Context, relativeurl);
                    }
                }
                else
                {
                    response.BinaryBytes = sourceprovider.GetBinary(Context, relativeurl);

                    if (contenttype.ToLower().Contains("font"))
                    {
                        Context.Response.Headers["Expires"] = DateTime.UtcNow.AddYears(1).ToString("r");
                    }
                }

                break;

            case UrlFileType.Html:

                return(RenderHtml(Context, option, relativeurl));

            default:
                break;
            }

            var version = Context.Request.Get("version");

            if (!string.IsNullOrEmpty(version))
            {
                if (Lib.Helper.CharHelper.isAsciiDigit(version))
                {
                    Context.Response.Headers["Expires"] = DateTime.UtcNow.AddYears(1).ToString("r");
                }
            }
            return(response);
        }
예제 #5
0
        public static RenderRespnose Render(RenderContext Context, RenderOption option, string relativeurl)
        {
            var sourceprovider = GetSourceProvider(Context, option);

            var            FileType = RenderHelper.GetFileType(relativeurl);
            RenderRespnose response = new RenderRespnose();

            switch (FileType)
            {
            case UrlFileType.Image:

                return(RenderImage(Context, option, relativeurl));

            case UrlFileType.JavaScript:

                if (sourceprovider is CommandDiskSourceProvider)
                {
                    return(ServerSide.ServerEngine.RenderJs(sourceprovider as CommandDiskSourceProvider, option, Context, relativeurl));
                }
                else
                {
                    response.ContentType = "application/javascript";
                    response.BinaryBytes = sourceprovider.GetBinary(Context, relativeurl);
                }

                break;

            case UrlFileType.Style:

                response.ContentType = "text/css";
                response.BinaryBytes = sourceprovider.GetBinary(Context, relativeurl);

                break;

            case UrlFileType.File:

                string contenttype = IOHelper.MimeType(relativeurl);
                if (string.IsNullOrEmpty(contenttype))
                {
                    contenttype = "application/octet-stream";
                }
                response.ContentType = contenttype;

                if (contenttype.ToLower().Contains("zip"))
                {
                    var stream = sourceprovider.GetStream(Context, relativeurl);

                    if (stream != null)
                    {
                        response.Stream = stream;
                    }
                    else
                    {
                        response.BinaryBytes = sourceprovider.GetBinary(Context, relativeurl);
                    }
                }
                else
                {
                    response.BinaryBytes = sourceprovider.GetBinary(Context, relativeurl);
                }

                break;

            case UrlFileType.Html:

                return(RenderHtml(Context, option, relativeurl));

            default:
                break;
            }

            return(response);
        }