Example #1
0
        public static RenderRespnose RenderImage(RenderContext Context, SpaRenderOption 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);
        }
Example #2
0
        public static string GetRelativeUrl(string RawRelativeUrl, SpaRenderOption option)
        {
            string RelativeUrl = RemoveQuestionMark(RawRelativeUrl);

            if (!string.IsNullOrEmpty(option.Prefix))
            {
                if (RelativeUrl.ToLower().StartsWith(option.Prefix))
                {
                    RelativeUrl = RelativeUrl.Substring(option.Prefix.Length);
                }
            }
            return(RelativeUrl);
        }
Example #3
0
        public bool ShouldTryHandle(Kooboo.Data.Context.RenderContext context, SpaRenderOption Options)
        {
            if (string.IsNullOrEmpty(Options.Prefix))
            {
                return(true);
            }
            string RelativeUrl = context.Request.RawRelativeUrl;

            if (RelativeUrl.ToLower().StartsWith(Options.Prefix.ToLower()))
            {
                return(true);
            }
            return(false);
        }
Example #4
0
        public static RenderRespnose Render(RenderContext Context, SpaRenderOption 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:

                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;

                response.BinaryBytes = sourceprovider.GetBinary(Context, relativeurl);

                break;

            case UrlFileType.Html:

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

            default:
                break;
            }

            return(response);
        }
Example #5
0
        public static RenderRespnose RenderHtml(RenderContext Context, SpaRenderOption 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.IgnoreEvaluators = EnumEvaluator.Form | EnumEvaluator.LayoutCommand;
            EvaluatorOption.Evaluators       = Kooboo.Render.Components.EvaluatorContainer.ListWithServerComponent;

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

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

            string finalreseult = null;

            if (!string.IsNullOrEmpty(finalreseult))
            {
                response.Body = finalreseult;
            }
            else
            {
                response.Body = result;
            }
            return(response);
        }
        private static byte[] GetBinary(RenderContext context, SpaRenderOption option, string RelativeUrl, string FullFileName)
        {
            byte[] result = null;
#if DEBUG
            {
                result = System.IO.File.ReadAllBytes(FullFileName);
            }
#endif
            if (result == null)
            {
                Guid key = Kooboo.Lib.Security.Hash.ComputeGuidIgnoreCase(RelativeUrl);
                result = Kooboo.Data.Cache.RenderCache.GetBinary(key);
                if (result == null)
                {
                    result = System.IO.File.ReadAllBytes(FullFileName);
                    Kooboo.Data.Cache.RenderCache.SetBinary(key, result);
                }
            }
            return(result);
        }
        private static string GetText(RenderContext context, SpaRenderOption option, string RelativeUrl, string FullFileName)
        {
            Guid   key  = Lib.Security.Hash.ComputeGuidIgnoreCase(FullFileName);
            string text = null;

#if DEBUG
            {
                text = System.IO.File.ReadAllText(FullFileName);
                key  = Lib.Security.Hash.ComputeGuidIgnoreCase(text);
            }
#endif

            if (option.EnableMultilingual)
            {
                string htmlbody = Kooboo.Data.Cache.MultiLingualRender.GetHtml(context, key);
                if (htmlbody == null)
                {
                    if (text == null)
                    {
                        text = File.ReadAllText(FullFileName);
                    }
                    htmlbody = Kooboo.Data.Cache.MultiLingualRender.SetGetHtml(context, key, text);
                }
                return(htmlbody);
            }
            else
            {
                if (text == null)
                {
                    text = Kooboo.Data.Cache.RenderCache.GetHtml(key);
                    if (text == null)
                    {
                        text = File.ReadAllText(FullFileName);
                    }
                    Kooboo.Data.Cache.RenderCache.SetHtml(key, text);
                }
                return(text);
            }
        }
Example #8
0
 public SpaMiddleWare(SpaRenderOption options)
 {
     this.options = options;
 }
Example #9
0
 private static Sites.Render.Commands.ICommandSourceProvider GetSourceProvider(RenderContext context, SpaRenderOption option)
 {
     Sites.Render.Commands.ICommandSourceProvider sourceprovider;
     if (!context.HasItem <Sites.Render.Commands.ICommandSourceProvider>("commandsource"))
     {
         sourceprovider = new CommandDiskSourceProvider(option);
         context.SetItem <Sites.Render.Commands.ICommandSourceProvider>(sourceprovider, "commandsource");
     }
     else
     {
         sourceprovider = context.GetItem <Sites.Render.Commands.ICommandSourceProvider>("commandsource");
     }
     return(sourceprovider);
 }
Example #10
0
        public static string GetRelativeUrl(Uri AbsoluteUri, SpaRenderOption option)
        {
            string RawRelativeUrl = Kooboo.Lib.Helper.UrlHelper.RelativePath(AbsoluteUri);

            return(GetRelativeUrl(RawRelativeUrl, option));
        }
Example #11
0
 public CommandDiskSourceProvider(SpaRenderOption option)
 {
     this.option = option;
 }