Esempio n. 1
0
        public ScriptContext()
        {
            Pages = new SharpPages(this);
            PageFormats.Add(new HtmlPageFormat());
            ScriptMethods.Add(new DefaultScripts());
            ScriptMethods.Add(new HtmlScripts());
            Plugins.Add(new DefaultScriptBlocks());
            Plugins.Add(new HtmlScriptBlocks());
            FilterTransformers[ScriptConstants.HtmlEncode] = HtmlPageFormat.HtmlEncodeTransformer;
            FilterTransformers["end"]    = stream => (TypeConstants.EmptyByteArray.InMemoryStream() as Stream).InTask();
            FilterTransformers["buffer"] = stream => stream.InTask();

            Args[nameof(ScriptConfig.MaxQuota)]                = ScriptConfig.MaxQuota;
            Args[nameof(ScriptConfig.DefaultCulture)]          = ScriptConfig.CreateCulture();
            Args[nameof(ScriptConfig.DefaultDateFormat)]       = ScriptConfig.DefaultDateFormat;
            Args[nameof(ScriptConfig.DefaultDateTimeFormat)]   = ScriptConfig.DefaultDateTimeFormat;
            Args[nameof(ScriptConfig.DefaultTimeFormat)]       = ScriptConfig.DefaultTimeFormat;
            Args[nameof(ScriptConfig.DefaultFileCacheExpiry)]  = ScriptConfig.DefaultFileCacheExpiry;
            Args[nameof(ScriptConfig.DefaultUrlCacheExpiry)]   = ScriptConfig.DefaultUrlCacheExpiry;
            Args[nameof(ScriptConfig.DefaultIndent)]           = ScriptConfig.DefaultIndent;
            Args[nameof(ScriptConfig.DefaultNewLine)]          = ScriptConfig.DefaultNewLine;
            Args[nameof(ScriptConfig.DefaultJsConfig)]         = ScriptConfig.DefaultJsConfig;
            Args[nameof(ScriptConfig.DefaultStringComparison)] = ScriptConfig.DefaultStringComparison;
            Args[nameof(ScriptConfig.DefaultTableClassName)]   = ScriptConfig.DefaultTableClassName;
            Args[nameof(ScriptConfig.DefaultErrorClassName)]   = ScriptConfig.DefaultErrorClassName;
        }
Esempio n. 2
0
        public ScriptContext ScanType(Type type)
        {
            if (!type.IsAbstract)
            {
                if (typeof(ScriptMethods).IsAssignableFrom(type))
                {
                    if (ScriptMethods.All(x => x?.GetType() != type))
                    {
                        Container.AddSingleton(type);
                        var filter = (ScriptMethods)Container.Resolve(type);
                        ScriptMethods.Add(filter);
                    }
                }
                else if (typeof(ScriptBlock).IsAssignableFrom(type))
                {
                    if (ScriptBlocks.All(x => x?.GetType() != type))
                    {
                        Container.AddSingleton(type);
                        var block = (ScriptBlock)Container.Resolve(type);
                        ScriptBlocks.Add(block);
                    }
                }
                else if (typeof(SharpCodePage).IsAssignableFrom(type))
                {
                    if (CodePages.Values.All(x => x != type))
                    {
                        Container.AddTransient(type);
                        var pageAttr = type.FirstAttribute <PageAttribute>();
                        if (pageAttr?.VirtualPath != null)
                        {
                            CodePages[pageAttr.VirtualPath] = type;
                        }
                    }
                }
            }

            return(this);
        }