Esempio n. 1
0
        /// <summary>
        /// Initialise the app domain.
        /// </summary>
        /// <param name="path">The path to the assemblies.</param>
        /// <param name="configurationFile">The configuration file name.</param>
        protected virtual void Initialise(string path, string configurationFile = null)
        {
            // Setting the AppDomainSetup. It is very important to set the ApplicationBase to a folder
            // other than the one in which the sandboxer resides.
            AppDomainSetup adSetup = new AppDomainSetup();

            adSetup.ApplicationBase = Path.GetFullPath(path);

            // Get the configuration file.
            if (!String.IsNullOrEmpty(configurationFile))
            {
                adSetup.ConfigurationFile = configurationFile;
            }

            // Create the application loader.
            AppDomianLoader loader = new AppDomianLoader()
                                     .DomainFriendlyName(DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo).GetHashCode().ToString("x"))
                                     .AppDomainSetup(adSetup);

            // Create the app domain.
            _appDomain = loader.CreateAppDomain();

            // Load the domain.
            _instance = AppDomianLoader.Load <T>(_appDomain);
        }
Esempio n. 2
0
        /// <summary>
        /// Initialise the app domain.
        /// </summary>
        /// <param name="path">The path to the assemblies.</param>
        /// <param name="configurationFile">The configuration file name.</param>
        protected override void Initialise(string path, string configurationFile = null)
        {
            // Setting the AppDomainSetup. It is very important to set the ApplicationBase to a folder
            // other than the one in which the sandboxer resides.
            AppDomainSetup adSetup = new AppDomainSetup();

            adSetup.ApplicationBase = Path.GetFullPath(path);

            // Get the configuration file.
            if (!String.IsNullOrEmpty(configurationFile))
            {
                adSetup.ConfigurationFile = configurationFile;
            }

            // Setting the permissions for the AppDomain. We give the permission to execute and to
            // read/discover the location where the untrusted code is loaded.
            PermissionSet permSet = new PermissionSet(PermissionState.None);

            permSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));

            // We want the sandboxer assembly's strong name, so that we can add it to the full trust list.
            //StrongName fullTrustAssembly = typeof(AppDomianMarshal).Assembly.Evidence.GetHostEvidence<StrongName>();

            // Create the application loader.
            AppDomianLoader loader = new AppDomianLoader()
                                     .DomainFriendlyName("SandboxModule")
                                     .AppDomainSetup(adSetup)
                                     .PermissionSet(permSet);

            // Create the app domain.
            base.AppDomain = loader.CreateAppDomain();

            // Load the domain.
            base.Instance = AppDomianLoader.Load <AppDomianMarshal>(base.AppDomain);
        }