示例#1
0
        public LessHandler(IFileWrapper fileWrapper)
        {
            this.fileWrapper = fileWrapper;
            var config = new DotlessConfiguration
            {
                CacheEnabled = false,
                Logger       = typeof(LessLogger),
                Web          = HttpContext.Current != null,
            };

            if (HttpContext.Current == null)
            {
                engine = new EngineFactory(config).GetEngine();
            }
            else
            {
                var dotLessAssembly = Assembly.GetAssembly(typeof(ContainerFactory));
                var factoryType     = dotLessAssembly.GetType("dotless.Core.AspNetContainerFactory");
                var fac             = (ContainerFactory)(factoryType.InvokeMember("", BindingFlags.CreateInstance, null, null, null));
                var locator         = factoryType.InvokeMember("GetContainer", BindingFlags.InvokeMethod, null, fac, new object[] { config });
                engine =
                    (ILessEngine)
                    (dotLessAssembly.GetType("Microsoft.Practices.ServiceLocation.IServiceLocator").InvokeMember(
                         "GetInstance", BindingFlags.InvokeMethod, null, locator, new object[] { typeof(ILessEngine) }));
            }
        }
示例#2
0
 protected virtual void OverrideServices(FluentRegistration pandora, DotlessConfiguration configuration)
 {
     if (configuration.Logger != null)
     {
         pandora.Service <ILogger>().Implementor(configuration.Logger);
     }
 }
        public void BaseSetup()
        {
            HttpContext = new Mock<HttpContextBase>();
            HttpRequest = new Mock<HttpRequestBase>();
            HttpResponse = new Mock<HttpResponseBase>();
            HttpSession = new Mock<HttpSessionStateBase>();
            HttpServer = new Mock<HttpServerUtilityBase>();
            HttpCache = new Mock<HttpCachePolicyBase>();
            Http = new Mock<IHttp>();
            Clock = new Mock<IClock>();
            ConfigManager = new Mock<IConfigurationManager>();

            QueryString = new NameValueCollection();
            Form = new NameValueCollection();
            Headers = new NameValueCollection();
            Config = DotlessConfiguration.GetDefaultWeb();

            Http.SetupGet(h => h.Context).Returns(HttpContext.Object);

            ConfigManager.Setup(c => c.GetSection<DotlessConfiguration>(It.IsRegex("^dotless$"))).Returns(Config);
            DotlessConfiguration.ConfigurationManager = ConfigManager.Object;

            Now = DateTime.Now;
            Clock.Setup(c => c.GetUtcNow()).Returns(Now);

            HttpContext.SetupGet(c => c.Request).Returns(HttpRequest.Object);
            HttpContext.SetupGet(c => c.Response).Returns(HttpResponse.Object);
            HttpContext.SetupGet(c => c.Server).Returns(HttpServer.Object);
            HttpContext.SetupGet(c => c.Session).Returns(HttpSession.Object);
            HttpResponse.SetupGet(r => r.Cache).Returns(HttpCache.Object);
            HttpResponse.SetupGet(r => r.Filter).Returns(new MemoryStream(new byte[1000], true));
            HttpRequest.SetupGet(r => r.QueryString).Returns(QueryString);
            HttpRequest.SetupGet(r => r.Form).Returns(Form);
            HttpRequest.SetupGet(r => r.Headers).Returns(Headers);
        }
        private void RegisterWebServices(FluentRegistration pandora, DotlessConfiguration configuration)
        {
            pandora.Service<IHttp>().Implementor<Http>().Lifestyle.Transient();
            pandora.Service<HandlerImpl>().Implementor<HandlerImpl>().Lifestyle.Transient();

            if (!configuration.DisableParameters)
            {
                pandora.Service<IParameterSource>().Implementor<QueryStringParameterSource>().Lifestyle.Transient();
            }

            var responseService = configuration.CacheEnabled ?
                pandora.Service<IResponse>().Implementor<CachedCssResponse>() :
                pandora.Service<IResponse>().Implementor<CssResponse>();
            pandora.Service<IClock>().Implementor<Clock>();

            responseService.Parameters("isCompressionHandledByResponse").Set("default-is-compression-handled-by-response").Lifestyle.Transient();
            pandora.Service<bool>("default-is-compression-handled-by-response").Instance(configuration.HandleWebCompression);

            if (configuration.CacheEnabled)
            {
                responseService.Parameters("httpExpiryInMinutes").Set("http-expiry-in-minutes").Lifestyle.Transient();
                pandora.Service<int>("http-expiry-in-minutes").Instance(configuration.HttpExpiryInMinutes);
            }

            pandora.Service<ICache>().Implementor<HttpCache>().Lifestyle.Transient();
            pandora.Service<ILogger>().Implementor<AspResponseLogger>().Parameters("level").Set("error-level").Lifestyle.Transient();

            if (configuration.MapPathsToWeb)
                pandora.Service<IPathResolver>().Implementor<AspServerPathResolver>().Lifestyle.Transient();
            else
                pandora.Service<IPathResolver>().Implementor<AspRelativePathResolver>().Lifestyle.Transient();
        }
示例#5
0
        /// <inheritdoc />
        public IEnumerable <IDocument> Execute(IReadOnlyList <IDocument> inputs, IExecutionContext context)
        {
            DotlessConfiguration config = DotlessConfiguration.GetDefault();

            config.Logger = typeof(LessLogger);
            EngineFactory    engineFactory    = new EngineFactory(config);
            FileSystemReader fileSystemReader = new FileSystemReader(context.FileSystem);

            return(inputs.AsParallel().Select(context, input =>
            {
                Trace.Verbose("Processing Less for {0}", input.SourceString());
                ILessEngine engine = engineFactory.GetEngine();

                // TODO: Get rid of RefelectionMagic and this ugly hack as soon as dotless gets better external DI support
                engine.AsDynamic().Underlying.Cache = new LessCache(context.ExecutionCache);
                engine.AsDynamic().Underlying.Underlying.Parser.Importer.FileReader = fileSystemReader;

                FilePath path = input.FilePath(Keys.RelativeFilePath);
                string fileName = null;
                if (path != null)
                {
                    engine.CurrentDirectory = path.Directory.FullPath;
                    fileName = path.FileName.FullPath;
                }
                else
                {
                    engine.CurrentDirectory = string.Empty;
                    fileName = Path.GetRandomFileName();
                }
                string content = engine.TransformToCss(input.Content, fileName);
                return context.GetDocument(input, content);
            }));
        }
示例#6
0
        public void BaseSetup()
        {
            HttpContext   = new Mock <HttpContextBase>();
            HttpRequest   = new Mock <HttpRequestBase>();
            HttpResponse  = new Mock <HttpResponseBase>();
            HttpSession   = new Mock <HttpSessionStateBase>();
            HttpServer    = new Mock <HttpServerUtilityBase>();
            HttpCache     = new Mock <HttpCachePolicyBase>();
            Http          = new Mock <IHttp>();
            Clock         = new Mock <IClock>();
            ConfigManager = new Mock <IConfigurationManager>();

            QueryString = new NameValueCollection();
            Form        = new NameValueCollection();
            Headers     = new NameValueCollection();
            Config      = DotlessConfiguration.GetDefaultWeb();

            Http.SetupGet(h => h.Context).Returns(HttpContext.Object);

            ConfigManager.Setup(c => c.GetSection <DotlessConfiguration>(It.IsRegex("^dotless$"))).Returns(Config);
            WebConfigConfigurationLoader.ConfigurationManager = ConfigManager.Object;

            Now = DateTime.Now;
            Clock.Setup(c => c.GetUtcNow()).Returns(Now);

            HttpContext.SetupGet(c => c.Request).Returns(HttpRequest.Object);
            HttpContext.SetupGet(c => c.Response).Returns(HttpResponse.Object);
            HttpContext.SetupGet(c => c.Server).Returns(HttpServer.Object);
            HttpContext.SetupGet(c => c.Session).Returns(HttpSession.Object);
            HttpResponse.SetupGet(r => r.Cache).Returns(HttpCache.Object);
            HttpResponse.SetupGet(r => r.Filter).Returns(new MemoryStream(new byte[1000], true));
            HttpRequest.SetupGet(r => r.QueryString).Returns(QueryString);
            HttpRequest.SetupGet(r => r.Form).Returns(Form);
            HttpRequest.SetupGet(r => r.Headers).Returns(Headers);
        }
        public void HandlerImplInstanceIsTransient()
        {
            var config = new DotlessConfiguration {
                Web = true
            };

            var serviceLocator = new ContainerFactory().GetContainer(config);

            var handler1 = serviceLocator.GetInstance <HandlerImpl>();
            var handler2 = serviceLocator.GetInstance <HandlerImpl>();

            Assert.That(handler1, Is.Not.SameAs(handler2));

            var http1 = handler1.Http;
            var http2 = handler2.Http;

            Assert.That(http1, Is.Not.SameAs(http2));

            var response1 = handler1.Response;
            var response2 = handler2.Response;

            Assert.That(response1, Is.Not.SameAs(response2));

            var engine1 = handler1.Engine;
            var engine2 = handler2.Engine;

            Assert.That(engine1, Is.Not.SameAs(engine2));
        }
示例#8
0
        protected virtual void RegisterCoreServices(FluentRegistration pandora, DotlessConfiguration configuration)
        {
            pandora.Service<LogLevel>("error-level").Instance(configuration.LogLevel);
            pandora.Service<IStylizer>().Implementor<PlainStylizer>();

            var importer = pandora.Service<IImporter>().Implementor<Importer>();

            importer.Parameters("inlineCssFiles").Set("default-inline-css-files").Lifestyle.Transient();
            importer.Parameters("disableUrlRewriting").Set("default-disable-url-rewriting").Lifestyle.Transient();
            importer.Parameters("importAllFilesAsLess").Set("default-import-all-files-as-less").Lifestyle.Transient();

            pandora.Service<bool>("default-disable-url-rewriting").Instance(configuration.DisableUrlRewriting);
            pandora.Service<bool>("default-inline-css-files").Instance(configuration.InlineCssFiles);
            pandora.Service<bool>("default-import-all-files-as-less").Instance(configuration.ImportAllFilesAsLess);

            pandora.Service<Parser.Parser>().Implementor<Parser.Parser>().Parameters("optimization").Set("default-optimization").Lifestyle.Transient();
            pandora.Service<int>("default-optimization").Instance(configuration.Optimization);

            pandora.Service<ILessEngine>().Implementor<ParameterDecorator>().Lifestyle.Transient();

            if (configuration.CacheEnabled)
                pandora.Service<ILessEngine>().Implementor<CacheDecorator>().Lifestyle.Transient();

            pandora.Service<ILessEngine>().Implementor<LessEngine>().Parameters("compress").Set("minify-output").Lifestyle.Transient();
            pandora.Service<bool>("minify-output").Instance(configuration.MinifyOutput);

            pandora.Service<ILessEngine>().Implementor<LessEngine>().Parameters("plugins").Set("default-plugins").Lifestyle.Transient();
            pandora.Service<IEnumerable<IPluginConfigurator>>("default-plugins").Instance(configuration.Plugins);

            pandora.Service<IFileReader>().Implementor(configuration.LessSource);
        }
示例#9
0
        public bool WriteToStream(BaseCompositeFileProcessingProvider provider, StreamWriter sw, FileInfo fi, ClientDependencyType type, string origUrl, HttpContextBase http)
        {
            try
            {
                //if it is a file based dependency then read it
                var fileContents = File.ReadAllText(fi.FullName, Encoding.UTF8); //read as utf 8

                //for our custom file reader to work we just need to put the origUrl into the httpcontext items so
                //we can retreive it in the reader to then figure out the 'real' requested path.
                http.Items["Cdf_LessWriter_origUrl"] = origUrl;
                //get the default less config
                var config = DotlessConfiguration.GetDefaultWeb();
                //set the file reader to our custom file reader
                config.LessSource = typeof(CdfFileReader);
                //disable cache for this engine since we are already caching our own, plus enabling this will cause errors because
                // the import paths aren't resolved properly.
                config.CacheEnabled = false;
                //get the engine based on the custom config with our custom file reader
                var lessEngine = LessWeb.GetEngine(config);

                var output = lessEngine.TransformToCss(fileContents, origUrl);

                DefaultFileWriter.WriteContentToStream(provider, sw, output, type, http, origUrl);

                return(true);
            }
            catch (Exception ex)
            {
                ClientDependencySettings.Instance.Logger.Error(string.Format("Could not write file {0} contents to stream. EXCEPTION: {1}", fi.FullName, ex.Message), ex);
                return(false);
            }
        }
示例#10
0
        private void RegisterWebServices(IServiceCollection services, DotlessConfiguration configuration)
        {
            services.AddTransient <IClock, Clock>();
            services.AddTransient <IHttp, Http>();
            services.AddTransient <HandlerImpl>();

            if (configuration.CacheEnabled)
            {
                services.AddTransient <IResponse, CachedCssResponse>();
            }
            else
            {
                services.AddTransient <IResponse, CssResponse>();
            }


            services.AddTransient <ICache, HttpCache>();
            services.AddTransient <ILogger, AspResponseLogger>();

            if (configuration.MapPathsToWeb)
            {
                services.AddTransient <IPathResolver, AspServerPathResolver>();
            }
            else
            {
                services.AddTransient <IPathResolver, AspRelativePathResolver>();
            }
        }
示例#11
0
 protected virtual void OverrideServices(IServiceCollection services, DotlessConfiguration configuration)
 {
     if (configuration.Logger != null)
     {
         services.AddSingleton(typeof(ILogger), configuration.Logger);
     }
 }
示例#12
0
        private void RegisterWebServices(FluentRegistration pandora, DotlessConfiguration configuration)
        {
            pandora.Service <IHttp>().Implementor <Http>().Lifestyle.Transient();
            pandora.Service <HandlerImpl>().Implementor <HandlerImpl>().Lifestyle.Transient();

            if (!configuration.DisableParameters)
            {
                pandora.Service <IParameterSource>().Implementor <QueryStringParameterSource>().Lifestyle.Transient();
            }

            var responseService = configuration.CacheEnabled ?
                                  pandora.Service <IResponse>().Implementor <CachedCssResponse>() :
                                  pandora.Service <IResponse>().Implementor <CssResponse>();

            responseService.Parameters("isCompressionHandledByResponse").Set("default-is-compression-handled-by-response").Lifestyle.Transient();
            pandora.Service <bool>("default-is-compression-handled-by-response").Instance(configuration.HandleWebCompression);

            pandora.Service <ICache>().Implementor <HttpCache>().Lifestyle.Transient();
            pandora.Service <ILogger>().Implementor <AspResponseLogger>().Parameters("level").Set("error-level").Lifestyle.Transient();

            if (configuration.MapPathsToWeb)
            {
                pandora.Service <IPathResolver>().Implementor <AspServerPathResolver>().Lifestyle.Transient();
            }
            else
            {
                pandora.Service <IPathResolver>().Implementor <AspRelativePathResolver>().Lifestyle.Transient();
            }
        }
示例#13
0
        private void RegisterCoreServices(FluentRegistration pandora, DotlessConfiguration configuration)
        {
            pandora.Service<LogLevel>("error-level")
                .Instance(configuration.LogLevel);

            pandora.Service<int>("default-optimization")
                .Instance(configuration.Optimization);

            pandora.Service<bool>("minify-output")
                .Instance(configuration.MinifyOutput);

            pandora.Service<IStylizer>()
                .Implementor<PlainStylizer>();

            pandora.Service<Parser.Parser>()
                .Implementor<Parser.Parser>()
                    .Parameters("optimization").Set("default-optimization")
                .Lifestyle.Transient();

            pandora.Service<ILessEngine>()
                .Implementor<ParameterDecorator>().Lifestyle.Transient();

            if (configuration.CacheEnabled)
                pandora.Service<ILessEngine>()
                    .Implementor<CacheDecorator>().Lifestyle.Transient();

            pandora.Service<ILessEngine>()
                .Implementor<LessEngine>()
                    .Parameters("compress").Set("minify-output")
                .Lifestyle.Transient();

            pandora.Service<IFileReader>()
                .Implementor(configuration.LessSource);
        }
示例#14
0
        private void RegisterCoreServices(ICoreServiceRegistrar serviceLocator, DotlessConfiguration configuration)
        {
            serviceLocator.Register <LoggerConfig>();

            serviceLocator.Register <IStylizer, PlainStylizer>();
            serviceLocator.RegisterInstance(configuration);
            serviceLocator.Register <ImporterConfig>();
            serviceLocator.Register <IImporter, Importer>();
            serviceLocator.Register <Parser.ParserConfig>();
            serviceLocator.Register <Parser.Parser>();

            if (!configuration.DisableParameters)
            {
                serviceLocator.Register <ILessEngine, ParameterDecorator>();
            }

            if (configuration.CacheEnabled)
            {
                serviceLocator.Register <ILessEngine, CacheDecorator>();
            }

            serviceLocator.Register <LessEngineConfig>();
            serviceLocator.Register <ILessEngine, LessEngine>();
            serviceLocator.Register <IFileReader>(configuration.LessSource);
        }
示例#15
0
 protected override void RegisterParameterSource(IServiceCollection services, DotlessConfiguration configuration)
 {
     if (!configuration.DisableParameters)
     {
         services.AddTransient <IParameterSource, QueryStringParameterSource>();
     }
 }
示例#16
0
        /// <summary>
        /// Used to create the Container for the HttpHandler. Not used by Console Compiler and T4CSS
        /// </summary>
        /// <param name="configuration">Configuration for the HttpHandler</param>
        /// <returns></returns>
        private PandoraContainer CreateContainer(DotlessConfiguration configuration)
        {
            var container = new PandoraContainer();
            container.Register(p =>
                                   {
                                       p.Service<ILessSource>()
                                           .Implementor(configuration.LessSource);
                                       p.Service<ICache>()
                                           .Implementor<CssCache>();
                                       p.Service<IRequest>()
                                           .Implementor<Request>();

                                       if (!configuration.CacheEnabled)
                                       {
                                           p.Service<IResponse>()
                                               .Implementor<CssResponse>();
                                       }
                                       else
                                       {
                                           p.Service<IResponse>()
                                               .Implementor<CachedCssResponse>();
                                           p.Service<ILessEngine>()
                                               .Implementor<AspCacheDecorator>();
                                       }
                                   });

            return RegisterCoreServices(container, configuration);
        }
示例#17
0
 private void OverrideServices(ICoreServiceRegistrar serviceLocator, DotlessConfiguration configuration)
 {
     if (configuration.Logger != null)
     {
         serviceLocator.Register <ILogger>(configuration.Logger);
     }
 }
示例#18
0
        private void RegisterWebServices(FluentRegistration pandora, DotlessConfiguration configuration)
        {
            pandora.Service <IClock>().Implementor <Clock>().Lifestyle.Transient();
            pandora.Service <IHttp>().Implementor <Http>().Lifestyle.Transient();
            pandora.Service <HandlerImpl>().Implementor <HandlerImpl>().Lifestyle.Transient();

            var responseService = configuration.CacheEnabled ?
                                  pandora.Service <IResponse>().Implementor <CachedCssResponse>() :
                                  pandora.Service <IResponse>().Implementor <CssResponse>();

            responseService.Parameters("isCompressionHandledByResponse").Set("default-is-compression-handled-by-response").Lifestyle.Transient();
            pandora.Service <bool>("default-is-compression-handled-by-response").Instance(configuration.HandleWebCompression);

            if (configuration.CacheEnabled)
            {
                responseService.Parameters("httpExpiryInMinutes").Set("http-expiry-in-minutes").Lifestyle.Transient();
                pandora.Service <int>("http-expiry-in-minutes").Instance(configuration.HttpExpiryInMinutes);
            }

            pandora.Service <ICache>().Implementor <HttpCache>().Lifestyle.Transient();
            pandora.Service <ILogger>().Implementor <AspResponseLogger>().Parameters("level").Set("error-level").Lifestyle.Transient();

            if (configuration.MapPathsToWeb)
            {
                pandora.Service <IPathResolver>().Implementor <AspServerPathResolver>().Lifestyle.Transient();
            }
            else
            {
                pandora.Service <IPathResolver>().Implementor <AspRelativePathResolver>().Lifestyle.Transient();
            }
        }
示例#19
0
        private void RegisterCoreServices(FluentRegistration pandora, DotlessConfiguration configuration)
        {
            pandora.Service <LogLevel>("error-level").Instance(configuration.LogLevel);
            pandora.Service <IStylizer>().Implementor <PlainStylizer>();

            pandora.Service <IImporter>().Implementor <Importer>().Parameters("disableUrlRewriting").Set("default-disable-url-rewriting").Lifestyle.Transient();
            pandora.Service <bool>("default-disable-url-rewriting").Instance(configuration.DisableUrlRewriting);

            pandora.Service <Parser.Parser>().Implementor <Parser.Parser>().Parameters("optimization").Set("default-optimization").Lifestyle.Transient();
            pandora.Service <int>("default-optimization").Instance(configuration.Optimization);

            pandora.Service <ILessEngine>().Implementor <ParameterDecorator>().Lifestyle.Transient();

            if (configuration.CacheEnabled)
            {
                pandora.Service <ILessEngine>().Implementor <CacheDecorator>().Lifestyle.Transient();
            }

            pandora.Service <ILessEngine>().Implementor <LessEngine>().Parameters("compress").Set("minify-output").Lifestyle.Transient();
            pandora.Service <bool>("minify-output").Instance(configuration.MinifyOutput);

            pandora.Service <ILessEngine>().Implementor <LessEngine>().Parameters("plugins").Set("default-plugins").Lifestyle.Transient();
            pandora.Service <IEnumerable <IPluginConfigurator> >("default-plugins").Instance(configuration.Plugins);

            pandora.Service <IFileReader>().Implementor(configuration.LessSource);
        }
        public static void Configure()
        {
            DotlessConfiguration config = new DotlessConfiguration();

            config.Plugins.Add(new GenericPluginConfigurator <UserProfilePlugin>());
            config.Plugins.Add(new GenericPluginConfigurator <UserFontPlugin>());
        }
示例#21
0
        public IEnumerable <IDocument> Execute(IReadOnlyList <IDocument> inputs, IExecutionContext context)
        {
            DotlessConfiguration config = DotlessConfiguration.GetDefault();

            config.Logger = typeof(LessLogger);
            EngineFactory engineFactory = new EngineFactory(config);

            return(inputs.AsParallel().Select(x =>
            {
                context.Trace.Verbose("Processing Less for {0}", x.Source);
                ILessEngine engine = engineFactory.GetEngine();

                // TODO: Get rid of RefelectionMagic and this ugly hack as soon as dotless gets better external DI support
                engine.AsDynamic().Underlying.Cache = new LessCache(context.ExecutionCache);

                string path = x.Get <string>(Keys.SourceFilePath, null);
                string fileName = null;
                if (path != null)
                {
                    engine.CurrentDirectory = Path.GetDirectoryName(path);
                    fileName = Path.GetFileName(path);
                }
                else
                {
                    engine.CurrentDirectory = context.InputFolder;
                    fileName = Path.GetRandomFileName();
                }
                string content = engine.TransformToCss(x.Content, fileName);
                return x.Clone(content);
            }));
        }
示例#22
0
        private void RegisterWebServices(FluentRegistration pandora, DotlessConfiguration configuration)
        {
            pandora.Service <IHttp>()
            .Implementor <Http>().Lifestyle.Transient();

            pandora.Service <LessHandlerImpl>()
            .Implementor <LessHandlerImpl>().Lifestyle.Transient();

            pandora.Service <IParameterSource>()
            .Implementor <QueryStringParameterSource>().Lifestyle.Transient();

            if (configuration.CacheEnabled)
            {
                pandora.Service <IResponse>()
                .Implementor <CachedCssResponse>().Lifestyle.Transient();
            }
            else
            {
                pandora.Service <IResponse>()
                .Implementor <CssResponse>().Lifestyle.Transient();
            }

            pandora.Service <ICache>()
            .Implementor <HttpCache>().Lifestyle.Transient();

            pandora.Service <ILogger>()
            .Implementor <AspResponseLogger>().Parameters("level").Set("error-level").Lifestyle.Transient();

            pandora.Service <IPathResolver>()
            .Implementor <AspServerPathResolver>().Lifestyle.Transient();
        }
示例#23
0
 public ImporterConfig(DotlessConfiguration config)
 {
     DisableUrlRewriting  = config.DisableUrlRewriting;
     RootPath             = config.RootPath;
     InlineCssFiles       = config.InlineCssFiles;
     ImportAllFilesAsLess = config.ImportAllFilesAsLess;
 }
 protected override void RegisterParameterSource(FluentRegistration pandora, DotlessConfiguration configuration)
 {
     if (!configuration.DisableParameters)
     {
         pandora.Service <IParameterSource>().Implementor <QueryStringParameterSource>().Lifestyle.Transient();
     }
 }
示例#25
0
        protected override void RegisterServices(FluentRegistration pandora, DotlessConfiguration configuration)
        {
            base.RegisterServices(pandora, configuration);

            RegisterParameterSource(pandora, configuration);

            RegisterWebServices(pandora, configuration);
        }
示例#26
0
        public IServiceLocator GetContainer(DotlessConfiguration configuration)
        {
            Container = new PandoraContainer();

            Container.Register(pandora => RegisterServices(pandora, configuration));

            return new CommonServiceLocatorAdapter(Container);
        }
示例#27
0
        private void RegisterServices(FluentRegistration pandora, DotlessConfiguration configuration)
        {
            OverrideServices(pandora, configuration);

            RegisterLocalServices(pandora);

            RegisterCoreServices(pandora, configuration);
        }
        public void IfMinifyOptionSetEngineIsLessEngine()
        {
            var config = new DotlessConfiguration { MinifyOutput = true, CacheEnabled = false };

            var engine = GetEngine(config);

            Assert.That(engine, Is.TypeOf<LessEngine>());
        }
示例#29
0
            public void Process(BundleContext context, BundleResponse response)
            {
                var config = new DotlessConfiguration();

                // config.Plugins.Add(new BuildNumberPluginConfigurator());
                response.Content     = Less.Parse(response.Content, config);
                response.ContentType = "text/css";
            }
示例#30
0
 public static ILessEngine GetEngine(DotlessConfiguration config)
 {
     if (config == null)
     {
         config = new WebConfigConfigurationLoader().GetConfiguration();
     }
     return(new EngineFactory(config).GetEngine(new AspNetContainerFactory()));
 }
示例#31
0
        public void Process(BundleContext context, BundleResponse response)
        {
            DotlessConfiguration config = new DotlessConfiguration();

            config.LessSource    = typeof(VirtualFileReader);
            response.Content     = dotless.Core.Less.Parse(response.Content, config);
            response.ContentType = "text/css";
        }
示例#32
0
        public void RegisterServices(ICoreServiceRegistrar serviceLocator, DotlessConfiguration configuration)
        {
            OverrideServices(serviceLocator, configuration);

            RegisterLocalServices(serviceLocator);

            RegisterCoreServices(serviceLocator, configuration);
        }
        protected override void RegisterServices(FluentRegistration pandora, DotlessConfiguration configuration)
        {
            base.RegisterServices(pandora, configuration);

            RegisterParameterSource(pandora, configuration);

            RegisterWebServices(pandora, configuration);
        }
示例#34
0
        public ServiceCollection GetServices(DotlessConfiguration configuration)
        {
            var services = new ServiceCollection();

            RegisterServices(services, configuration);

            return(services);
        }
示例#35
0
        protected override void RegisterServices(IServiceCollection services, DotlessConfiguration configuration)
        {
            base.RegisterServices(services, configuration);

            RegisterParameterSource(services, configuration);

            RegisterWebServices(services, configuration);
        }
示例#36
0
 public static string Parse(string less, DotlessConfiguration config)
 {
     if (config.Web)
     {
         throw new Exception("Please use dotless.Core.LessWeb.Parse for web applications. This makes sure all web features are available.");
     }
     return new EngineFactory(config).GetEngine().TransformToCss(less, null);
 }
示例#37
0
        private void RegisterServices(FluentRegistration pandora, DotlessConfiguration configuration)
        {
            OverrideServices(pandora, configuration);

            RegisterLocalServices(pandora);

            RegisterCoreServices(pandora, configuration);
        }
示例#38
0
 public static string Parse(string less, DotlessConfiguration config)
 {
     if (config.Web)
     {
         throw new Exception("Please use dotless.Core.LessWeb.Parse for web applications. This makes sure all web features are available.");
     }
     return(new EngineFactory(config).GetEngine().TransformToCss(less, null));
 }
示例#39
0
        public System.IServiceProvider GetContainer(DotlessConfiguration configuration)
        {
            var builder = new ServiceCollection();

            RegisterServices(builder, configuration);

            return(builder.BuildServiceProvider());
        }
示例#40
0
        public IServiceLocator GetContainer(DotlessConfiguration configuration)
        {
            Container = new PandoraContainer();

            Container.Register(pandora => RegisterServices(pandora, configuration));

            return(new CommonServiceLocatorAdapter(Container));
        }
示例#41
0
        protected virtual void RegisterServices(FluentRegistration pandora, DotlessConfiguration configuration)
        {
            OverrideServices(pandora, configuration);

            if (!configuration.Web)
                RegisterLocalServices(pandora);

            RegisterCoreServices(pandora, configuration);
        }
        public void IfCacheOptionSetCacheIsInMemoryCache()
        {
            var config = new DotlessConfiguration { Web = false, CacheEnabled = true };

            var serviceLocator = new ContainerFactory().GetContainer(config);

            var cache = serviceLocator.GetInstance<ICache>();

            Assert.That(cache, Is.TypeOf<InMemoryCache>());
        }
示例#43
0
        public void CanOverrideOptimization()
        {
            var config = new DotlessConfiguration { Optimization = 7 };

            var serviceLocator = new ContainerFactory().GetContainer(config);

            var parser = serviceLocator.GetInstance<Parser>();

            Assert.That(parser.Tokenizer.Optimization, Is.EqualTo(7));
        }
示例#44
0
        public void CanPassCustomLogger()
        {
            var config = new DotlessConfiguration { Logger = typeof(DummyLogger) };

            var serviceLocator = new ContainerFactory().GetContainer(config);

            var logger = serviceLocator.GetInstance<ILogger>();

            Assert.That(logger, Is.TypeOf<DummyLogger>());
        }
示例#45
0
        public void CanPassCustomLessSource()
        {
            var config = new DotlessConfiguration { LessSource = typeof(DummyFileReader) };

            var serviceLocator = new ContainerFactory().GetContainer(config);

            var source = serviceLocator.GetInstance<IFileReader>();

            Assert.That(source, Is.TypeOf<DummyFileReader>());
        }
示例#46
0
        public CompilerConfiguration(DotlessConfiguration config)
        {
            LessSource = config.LessSource;
            LogLevel = config.LogLevel;
            MinifyOutput = config.MinifyOutput;
            Optimization = config.Optimization;

            CacheEnabled = false;
            Web = false;
        }
示例#47
0
        public void CanOverrideLogLevel()
        {
            var config = new DotlessConfiguration { LogLevel = LogLevel.Info };

            var serviceLocator = new ContainerFactory().GetContainer(config);

            var logger = serviceLocator.GetInstance<ILogger>();

            Assert.That(logger, Is.TypeOf<ConsoleLogger>());

            var consoleLogger = (ConsoleLogger)logger;

            Assert.That(consoleLogger.Level, Is.EqualTo(LogLevel.Info));
        }
示例#48
0
 private PandoraContainer RegisterCoreServices(PandoraContainer container, DotlessConfiguration configuration)
 {
     container.Register(p =>
                            {
                                if (configuration.MinifyOutput)
                                {
                                    p.Service<ILessEngine>()
                                        .Implementor<MinifierDecorator>();
                                }
                                p.Service<ILessEngine>()
                                    .Implementor<ExtensibleEngine>();
                                p.Service<ILessSource>()
                                    .Implementor<FileSource>();
                            });
     return container;
 }
示例#49
0
        public void CachedCssResponseInstanceIsTransient()
        {
            var config = new DotlessConfiguration { Web = true };

            var serviceLocator = new ContainerFactory().GetContainer(config);

            var response1 = serviceLocator.GetInstance<IResponse>();
            var response2 = serviceLocator.GetInstance<IResponse>();

            Assert.That(response1, Is.Not.SameAs(response2));

            var http1 = (response1 as CachedCssResponse).Http;
            var http2 = (response2 as CachedCssResponse).Http;

            Assert.That(http1, Is.Not.SameAs(http2));
        }
示例#50
0
        private void RegisterWebServices(FluentRegistration pandora, DotlessConfiguration configuration)
        {
            pandora.Service<IHttp>().Implementor<Http>().Lifestyle.Transient();
            pandora.Service<HandlerImpl>().Implementor<HandlerImpl>().Lifestyle.Transient();
            pandora.Service<IParameterSource>().Implementor<QueryStringParameterSource>().Lifestyle.Transient();

            if (configuration.CacheEnabled)
                pandora.Service<IResponse>().Implementor<CachedCssResponse>().Lifestyle.Transient();
            else
                pandora.Service<IResponse>().Implementor<CssResponse>().Lifestyle.Transient();

            pandora.Service<ICache>().Implementor<HttpCache>().Lifestyle.Transient();
            pandora.Service<ILogger>().Implementor<AspResponseLogger>().Parameters("level").Set("error-level").Lifestyle.Transient();

            if (configuration.MapPathsToWeb)
                pandora.Service<IPathResolver>().Implementor<AspServerPathResolver>().Lifestyle.Transient();
            else
                pandora.Service<IPathResolver>().Implementor<AspRelativePathResolver>().Lifestyle.Transient();
        }
示例#51
0
        public void IfWebCacheAndMinifyOptionsSetEngineIsCacheDecoratorThenLessEngine()
        {
            var config = new DotlessConfiguration { Web = true, CacheEnabled = true, MinifyOutput = true };

            var engine = GetEngine(config);

            Assert.That(engine, Is.TypeOf<CacheDecorator>());

            var aspEngine = (CacheDecorator)engine;
            Assert.That(aspEngine.Underlying, Is.TypeOf<LessEngine>());
        }
示例#52
0
 public IServiceLocator GetCoreContainer(DotlessConfiguration configuration)
 {
     return new CommonServiceLocatorAdapter(RegisterCoreServices(new PandoraContainer(), configuration));
 }
示例#53
0
 protected virtual void OverrideServices(FluentRegistration pandora, DotlessConfiguration configuration)
 {
     if (configuration.Logger != null)
         pandora.Service<ILogger>().Implementor(configuration.Logger);
 }
示例#54
0
        public void HandlerImplInstanceIsTransient()
        {
            var config = new DotlessConfiguration { Web = true };

            var serviceLocator = new ContainerFactory().GetContainer(config);

            var handler1 = serviceLocator.GetInstance<HandlerImpl>();
            var handler2 = serviceLocator.GetInstance<HandlerImpl>();

            Assert.That(handler1, Is.Not.SameAs(handler2));

            var http1 = handler1.Http;
            var http2 = handler2.Http;

            Assert.That(http1, Is.Not.SameAs(http2));

            var response1 = handler1.Response;
            var response2 = handler2.Response;

            Assert.That(response1, Is.Not.SameAs(response2));

            var engine1 = handler1.Engine;
            var engine2 = handler2.Engine;

            Assert.That(engine1, Is.Not.SameAs(engine2));
        }
示例#55
0
        public void HttpInstanceIsTransient()
        {
            var config = new DotlessConfiguration { Web = true };

            var serviceLocator = new ContainerFactory().GetContainer(config);

            var http1 = serviceLocator.GetInstance<IHttp>();
            var http2 = serviceLocator.GetInstance<IHttp>();

            Assert.That(http1, Is.Not.SameAs(http2));
        }
示例#56
0
 public static string Parse(string less, DotlessConfiguration config)
 {
     return new EngineFactory(config).GetEngine().TransformToCss(less, null);
 }
示例#57
0
        public void IfWebOptionSetButCachedIsFalseEngineIsLessEngine()
        {
            var config = new DotlessConfiguration { Web = true, CacheEnabled = false };

            var engine = GetEngine(config);

            Assert.That(engine, Is.TypeOf<LessEngine>());
        }
示例#58
0
 public LessCssHttpHandler()
 {
     Config = new WebConfigConfigurationLoader().GetConfiguration();
     mHandlerImpl = new ContainerFactory().GetLessContainer(Config)
         .GetInstance<LessHandlerImpl>();
 }
示例#59
0
 public EngineFactory(DotlessConfiguration configuration)
 {
     Configuration = configuration;
 }
示例#60
0
 private ILessEngine GetEngine(DotlessConfiguration config)
 {
     return ((ParameterDecorator)new EngineFactory(config).GetEngine()).Underlying;
 }