Esempio n. 1
0
 public RootRunner(IRunListener listener, IAppDomainFactory appDomainFactory, IResourceManager resourceManager, IResultFactory resultFactory)
 {
     _listener = listener;
       _appDomainFactory = appDomainFactory;
       _resourceManager = resourceManager;
       _resultFactory = resultFactory;
 }
Esempio n. 2
0
 public RootRunner(IRunListener listener, IAppDomainFactory appDomainFactory, IResourceManager resourceManager, IResultFactory resultFactory)
 {
     _listener         = listener;
     _appDomainFactory = appDomainFactory;
     _resourceManager  = resourceManager;
     _resultFactory    = resultFactory;
 }
        public static IRazorEngineService Create(IConfigCreator configCreator, IAppDomainFactory appDomainFactory)
        {
            configCreator = configCreator ?? new DefaultConfigCreator();
            var config   = configCreator.CreateConfiguration();
            var isolated = new IsolatedRazorEngineService(configCreator, appDomainFactory);

            return(new DynamicWrapperService(isolated, true, config.AllowMissingPropertiesOnDynamic));
        }
Esempio n. 4
0
 public Module(ILoggerContainer primaryLoggerContainer,
     IDirectoryController directories,
     IAppDomainFactory appDomainFactory,
     ModuleProxyTypeDictionary proxyTypes)
 {
     this.proxyTypes = proxyTypes;
     this.appDomainFactory = appDomainFactory;
     this.primaryLoggerContainer = primaryLoggerContainer;
     this.directories = directories;
 }
Esempio n. 5
0
        /// <summary>
        /// Initialises a new instance of <see cref="IsolatedTemplateService"/>
        /// </summary>
        /// <param name="language">The code language.</param>
        /// <param name="encoding">The encoding.</param>
        /// <param name="appDomainFactory">The application domain factory.</param>
        public IsolatedTemplateService(Language language, Encoding encoding, IAppDomainFactory appDomainFactory)
        {
            _appDomain = CreateAppDomain(appDomainFactory ?? new DefaultAppDomainFactory());

            string assemblyName = TemplateServiceType.Assembly.FullName;
            string typeName     = TemplateServiceType.FullName;

            _proxy = (ITemplateService)_appDomain.CreateInstance(
                assemblyName, typeName, false, BindingFlags.NonPublic | BindingFlags.Instance,
                null, new object[] { language, encoding }, CultureInfo.CurrentCulture, null).Unwrap();
        }
        public static IRazorEngineService Create(IConfigCreator configCreator, IAppDomainFactory appDomainFactory)
        {
            configCreator = configCreator ?? new DefaultConfigCreator();
            var config = configCreator.CreateConfiguration();

            if (config.DisableTempFileLocking)
            {
                throw new InvalidOperationException("DisableTempFileLocking is not supported in the context of Isolation, because it will escape any kind of sandbox. Besides that it's not required because RazorEngine will be able to cleanup the tempfiles in this scenario. Just make sure to call AppDomain.Unload when you are done.");
            }

            var isolated = new IsolatedRazorEngineService(configCreator, appDomainFactory);

            return(new DynamicWrapperService(isolated, true, config.AllowMissingPropertiesOnDynamic));
        }
Esempio n. 7
0
        /// <summary>
        /// Creates an application domain.
        /// </summary>
        /// <param name="factory">The application domain factory.</param>
        /// <returns>An instance of <see cref="AppDomain"/>.</returns>
        private static AppDomain CreateAppDomain(IAppDomainFactory factory)
        {
            var domain = factory.CreateAppDomain();

            if (domain == null)
            {
                throw new InvalidOperationException("The application domain factory did not create an application domain.");
            }

            if (domain == AppDomain.CurrentDomain)
            {
                throw new InvalidOperationException("The application domain factory returned the current application domain which cannot be used for isolation.");
            }

            return(domain);
        }
        internal IsolatedRazorEngineService(IConfigCreator configCreator, IAppDomainFactory appDomainFactory)
        {
            _appDomain = CreateAppDomain(appDomainFactory ?? new DefaultAppDomainFactory());
            var config = configCreator ?? new DefaultConfigCreator();

            ObjectHandle handle =
                Activator.CreateInstanceFrom(
                    _appDomain, typeof(SanboxHelper).Assembly.ManifestModule.FullyQualifiedName,
                    typeof(SanboxHelper).FullName
                );

            using (var helper = (SanboxHelper)handle.Unwrap())
            {
                _proxy = helper.CreateEngine(config);
            }
        }
        internal IsolatedRazorEngineService(IConfigCreator configCreator, IAppDomainFactory appDomainFactory)
        {
            _appDomain = CreateAppDomain(appDomainFactory ?? new DefaultAppDomainFactory());
            var config = configCreator ?? new DefaultConfigCreator();

            ObjectHandle handle =
                Activator.CreateInstanceFrom(
                    _appDomain, typeof(SanboxHelper).Assembly.ManifestModule.FullyQualifiedName,
                    typeof(SanboxHelper).FullName
                    );

            using (var helper = (SanboxHelper)handle.Unwrap())
            {
                _proxy = helper.CreateEngine(config);
            }
        }
        public virtual void before_each()
        {
            autoSubstitute = new AutoSubstitute();

            targetDomain     = autoSubstitute.Resolve <ITargetAppDomain>();
            appDomainFactory = autoSubstitute.Resolve <IAppDomainFactory>();
            appDomainFactory.Create(somePath).Returns(targetDomain);

            proxyable        = autoSubstitute.Resolve <IDummyProxyable>();
            proxyableFactory = autoSubstitute.Resolve <IProxyableFactory <IDummyProxyable> >();
            proxyableFactory.CreateProxy(targetDomain).Returns(proxyable);

            runner = new CrossDomainRunner <IDummyProxyable, float>(appDomainFactory, proxyableFactory);

            proxyable.PassInput(Arg.Any <float>()).Returns(callInfo =>
            {
                float input = callInfo.Arg <float>();
                return(input);
            });
        }
Esempio n. 11
0
 /// <summary>
 /// Initialises a new instance of <see cref="IsolatedTemplateService"/>
 /// </summary>
 /// <param name="appDomainFactory">The application domain factory.</param>
 public IsolatedTemplateService(IAppDomainFactory appDomainFactory)
     : this(Language.CSharp, Encoding.Html, appDomainFactory)
 {
 }
        /// <summary>
        /// Creates an application domain.
        /// </summary>
        /// <param name="factory">The application domain factory.</param>
        /// <returns>An instance of <see cref="AppDomain"/>.</returns>
        private static AppDomain CreateAppDomain(IAppDomainFactory factory)
        {
            var domain = factory.CreateAppDomain();
            if (domain == null)
                throw new InvalidOperationException("The application domain factory did not create an application domain.");

            if (domain == AppDomain.CurrentDomain)
                throw new InvalidOperationException("The application domain factory returned the current application domain which cannot be used for isolation.");

            return domain;
        }
        public static IRazorEngineService Create(IConfigCreator configCreator, IAppDomainFactory appDomainFactory)
        {
            configCreator = configCreator ?? new DefaultConfigCreator();
            var config = configCreator.CreateConfiguration();
            if (config.DisableTempFileLocking)
            {
                throw new InvalidOperationException("DisableTempFileLocking is not supported in the context of Isolation, because it will escape any kind of sandbox. Besides that it's not required because RazorEngine will be able to cleanup the tempfiles in this scenario. Just make sure to call AppDomain.Unload when you are done.");
            }

            var isolated = new IsolatedRazorEngineService(configCreator, appDomainFactory);
            return new DynamicWrapperService(isolated, true, config.AllowMissingPropertiesOnDynamic);
        }
 public static IRazorEngineService Create(IAppDomainFactory appDomainFactory)
 {
     return Create(null, appDomainFactory);
 }
Esempio n. 15
0
        // initial implementation taken from
        // http://thevalerios.net/matt/2008/06/run-anonymous-methods-in-another-appdomain/

        public CrossDomainRunner(IAppDomainFactory appDomainFactory, IProxyableFactory <TProxyable> proxyableFactory)
        {
            this.appDomainFactory = appDomainFactory;
            this.proxyableFactory = proxyableFactory;
        }
 public static IRazorEngineService Create(IConfigCreator configCreator, IAppDomainFactory appDomainFactory)
 {
     configCreator = configCreator ?? new DefaultConfigCreator();
     var config = configCreator.CreateConfiguration();
     var isolated = new IsolatedRazorEngineService(configCreator, appDomainFactory);
     return new DynamicWrapperService(isolated, true, config.AllowMissingPropertiesOnDynamic);
 }
Esempio n. 17
0
 /// <summary>
 /// Initializes a new instance of the class <see cref="ComponentManager"/>.
 /// </summary>
 /// <param name="componentFactory"> Component factory. </param>
 /// <param name="appDomainSetupFactory"> Application domain configuration factory, in which component loads. </param>
 /// <param name="appDomainFactory"> Component application domain factory. </param>
 public ComponentManager(IComponentFactory componentFactory, IAppDomainSetupFactory appDomainSetupFactory, IAppDomainFactory appDomainFactory)
 {
     this.componentFactory      = componentFactory;
     this.appDomainSetupFactory = appDomainSetupFactory;
     this.appDomainFactory      = appDomainFactory;
 }
 public static IRazorEngineService Create(IAppDomainFactory appDomainFactory)
 {
     return(Create(null, appDomainFactory));
 }