Esempio n. 1
0
        public void Init()
        {
            viewEngineManagerMock = mockRepository.DynamicMock <IViewEngineManager>();

            service = new EmailTemplateService(viewEngineManagerMock);

            engineContext     = new StubEngineContext(null, null, null, null);
            controller        = new DummyController();
            controllerContext = new ControllerContext();
        }
		public void Init()
		{
			viewEngineManagerMock = mockRepository.DynamicMock<IViewEngineManager>();

			service = new EmailTemplateService(viewEngineManagerMock);

			engineContext = new StubEngineContext(null, null, null, null);
			controller = new DummyController();
			controllerContext = new ControllerContext();
		}
Esempio n. 3
0
 private static void RenderToFile(IViewEngineManager brail, string name, string file, Dictionary <string, object> arguments)
 {
     using (var writer = new StreamWriter(File.Create(file))) {
         brail.Process(
             Inflector.Capitalize(name) + "/Print",
             "Print",
             writer,
             arguments);
     }
 }
		/// <summary>
		/// Invoked by the framework in order to give a chance to
		/// obtain other services
		/// </summary>
		/// <param name="serviceProvider">The service proviver</param>
		public void Service(IMonoRailServices serviceProvider)
		{
			var loggerFactory = serviceProvider.GetService<ILoggerFactory>();

			if (loggerFactory != null)
			{
				logger = loggerFactory.Create(typeof(EmailTemplateService));
			}

			viewEngineManager = serviceProvider.ViewEngineManager;
		}
Esempio n. 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JSCodeGenerator"/> class.
 /// </summary>
 /// <param name="serverUtility">The server utility.</param>
 /// <param name="viewEngineManager">The view engine manager.</param>
 /// <param name="engineContext">The engine context.</param>
 /// <param name="controller">The controller.</param>
 /// <param name="context">The context.</param>
 /// <param name="urlBuilder">The URL builder.</param>
 public JSCodeGenerator(IServerUtility serverUtility, IViewEngineManager viewEngineManager,
                        IEngineContext engineContext, IController controller, IControllerContext context,
                        IUrlBuilder urlBuilder)
 {
     this.ServerUtility     = serverUtility;
     this.viewEngineManager = viewEngineManager;
     this.engineContext     = engineContext;
     this.controller        = controller;
     this.context           = context;
     this.UrlBuilder        = urlBuilder;
 }
		/// <summary>
		/// Initializes a new instance of the <see cref="JSCodeGenerator"/> class.
		/// </summary>
		/// <param name="serverUtility">The server utility.</param>
		/// <param name="viewEngineManager">The view engine manager.</param>
		/// <param name="engineContext">The engine context.</param>
		/// <param name="controller">The controller.</param>
		/// <param name="context">The context.</param>
		/// <param name="urlBuilder">The URL builder.</param>
		public JSCodeGenerator(IServerUtility serverUtility, IViewEngineManager viewEngineManager,
		                       IEngineContext engineContext, IController controller, IControllerContext context,
		                       IUrlBuilder urlBuilder)
		{
			this.serverUtility = serverUtility;
			this.viewEngineManager = viewEngineManager;
			this.engineContext = engineContext;
			this.controller = controller;
			this.context = context;
			this.urlBuilder = urlBuilder;
		}
        /// <summary>
        /// Invoked by the framework in order to give a chance to
        /// obtain other services
        /// </summary>
        /// <param name="serviceProvider">The service proviver</param>
        public void Service(IMonoRailServices serviceProvider)
        {
            var loggerFactory = serviceProvider.GetService <ILoggerFactory>();

            if (loggerFactory != null)
            {
                logger = loggerFactory.Create(typeof(EmailTemplateService));
            }

            viewEngineManager = serviceProvider.ViewEngineManager;
        }
Esempio n. 8
0
        private static void Print(IViewEngineManager brail, string printer, string name, IEnumerable documents)
        {
            var plural = Inflector.Pluralize(name);

            if (String.IsNullOrEmpty(plural))
            {
                plural = name;
            }
            var singular = Inflector.Singularize(name);

            if (String.IsNullOrEmpty(singular))
            {
                singular = name;
            }

            using (new SessionScope(FlushAction.Never)) {
                foreach (var document in documents)
                {
                    var file = Path.Combine(Path.GetTempPath(), Path.ChangeExtension(Path.GetRandomFileName(), ".html"));
                    try {
                        var arguments = new Dictionary <string, object> {
                            { singular, document },
                            { "doc", document },
                            //тк chrome.printer не печатает у него media будет screen а не print
                            //что бы стили продолжели работать нужно их исправить
                            { "print", true }
                        };
                        RenderToFile(brail, plural, file, arguments);
                        ChromePrinter(printer, file);
                    }
                    finally {
                        File.Delete(file);
                    }
                }
            }
        }
Esempio n. 9
0
		/// <summary>
		/// Sets the engine context. Also initialize all required services by querying
		/// <see cref="IEngineContext.Services"/>
		/// </summary>
		/// <param name="engineContext">The engine context.</param>
		public virtual void SetEngineContext(IEngineContext engineContext)
		{
			this.engineContext = engineContext;

			helperFactory = engineContext.Services.HelperFactory; // should not be null
			serviceInitializer = engineContext.Services.ServiceInitializer; // should not be null
			filterFactory = engineContext.Services.FilterFactory; // should not be null
			viewEngineManager = engineContext.Services.ViewEngineManager; // should not be null
			actionSelector = engineContext.Services.ActionSelector; // should not be null
			scaffoldSupport = engineContext.Services.ScaffoldingSupport; // might be null
			dynamicActionProviderFactory = engineContext.Services.DynamicActionProviderFactory; // should not be null
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="EmailTemplateService"/> class.
		/// </summary>
		/// <param name="viewEngineManager">The view engine manager.</param>
		public EmailTemplateService(IViewEngineManager viewEngineManager)
		{
			this.viewEngineManager = viewEngineManager;
		}
Esempio n. 11
0
		/// <summary>
		/// Extracts the services the controller uses from the context -- which ultimately 
		/// is a service provider.
		/// </summary>
		/// <param name="context">The context/service provider.</param>
		public void InitializeFieldsFromServiceProvider(IRailsEngineContext context)
		{
			serviceProvider = context;

			viewEngineManager = (IViewEngineManager) serviceProvider.GetService(typeof(IViewEngineManager));

			IControllerDescriptorProvider controllerDescriptorBuilder = (IControllerDescriptorProvider)
				serviceProvider.GetService( typeof(IControllerDescriptorProvider) );

			metaDescriptor = controllerDescriptorBuilder.BuildDescriptor(this);

			ILoggerFactory loggerFactory = (ILoggerFactory) context.GetService(typeof(ILoggerFactory));
			
			if (loggerFactory != null)
			{
				logger = loggerFactory.Create(GetType().Name);
			}
			
			this.context = context;

			Initialize();
		}
		/// <summary>
		/// Invoked by the framework in order to give a chance to
		/// obtain other services
		/// </summary>
		/// <param name="provider">The service proviver</param>
		public void Service(IServiceProvider provider)
		{
			viewEngineManager = (IViewEngineManager) provider.GetService(typeof(IViewEngineManager));
			filterFactory = (IFilterFactory) provider.GetService(typeof(IFilterFactory));
			resourceFactory = (IResourceFactory) provider.GetService(typeof(IResourceFactory));
			scaffoldSupport = (IScaffoldingSupport) provider.GetService(typeof(IScaffoldingSupport));
			transformFilterFactory = (ITransformFilterFactory)provider.GetService(typeof(ITransformFilterFactory));
			
			ILoggerFactory loggerFactory = (ILoggerFactory) provider.GetService(typeof(ILoggerFactory));

			if (loggerFactory != null)
			{
				logger = loggerFactory.Create(typeof(ControllerLifecycleExecutor));
			}
		}
        /// <summary>
        /// Initializes a new instance of the <see cref="StubMonoRailServices"/> class.
        /// </summary>
        /// <param name="urlBuilder">The URL builder.</param>
        /// <param name="filterFactory">The filter factory.</param>
        /// <param name="viewEngineManager">The view engine manager.</param>
        /// <param name="actionSelector">The action selector.</param>
        /// <param name="dynamicActionProviderFactory">The dynamic action provider factory.</param>
        public StubMonoRailServices(IUrlBuilder urlBuilder, IFilterFactory filterFactory, IViewEngineManager viewEngineManager,
                                    IActionSelector actionSelector, IDynamicActionProviderFactory dynamicActionProviderFactory)
        {
            this.UrlBuilder                   = urlBuilder;
            this.FilterFactory                = filterFactory;
            this.ViewEngineManager            = viewEngineManager;
            this.ActionSelector               = actionSelector;
            this.DynamicActionProviderFactory = dynamicActionProviderFactory;
            controllerTree         = new DefaultControllerTree();
            ControllerFactory      = new DefaultControllerFactory(controllerTree);
            StaticResourceRegistry = new DefaultStaticResourceRegistry();

            ControllerContextFactory = new DefaultControllerContextFactory();

            ControllerDescriptorProvider = new DefaultControllerDescriptorProvider(
                new DefaultHelperDescriptorProvider(),
                new DefaultFilterDescriptorProvider(),
                new DefaultLayoutDescriptorProvider(),
                new DefaultRescueDescriptorProvider(),
                new DefaultResourceDescriptorProvider(),
                new DefaultTransformFilterDescriptorProvider(),
                new DefaultReturnBinderDescriptorProvider(),
                new DefaultDynamicActionProviderDescriptorProvider());

            ResourceFactory    = new DefaultResourceFactory();
            ScaffoldingSupport = new StubScaffoldingSupport();
            CacheProvider      = new StubCacheProvider();
            HelperFactory      = new DefaultHelperFactory();
            ServiceInitializer = new DefaultServiceInitializer();

            ExtensionManager = new ExtensionManager(this);

            ValidatorRegistry = new CachedValidationRegistry();

            JSONSerializer = new NewtonsoftJSONSerializer();

            DictionaryAdapterFactory = new DictionaryAdapterFactory();

            ScriptBuilder = new DefaultScriptBuilder();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="EmailTemplateService"/> class.
 /// </summary>
 /// <param name="viewEngineManager">The view engine manager.</param>
 public EmailTemplateService(IViewEngineManager viewEngineManager)
 {
     this.viewEngineManager = viewEngineManager;
 }