Esempio n. 1
0
        private static ScriptEnvironmentSetup GetSetupInformation()
        {
#if FULL
            ScriptEnvironmentSetup result;

            // setup provided by app-domain creator:
            result = ScriptEnvironmentSetup.GetAppDomainAssociated(AppDomain.CurrentDomain);
            if (result != null)
            {
                return(result);
            }

            // setup provided in a configuration file:
            // This will load System.Configuration.dll which costs ~350 KB of memory. However, this does not normally
            // need to be loaded in simple scenarios (like running the console hosts). Hence, the working set cost
            // is only paid in hosted scenarios.
            ScriptConfiguration config = System.Configuration.ConfigurationManager.GetSection(ScriptConfiguration.Section) as ScriptConfiguration;
            if (config != null)
            {
                // TODO:
                //return config;
            }
#endif

            // default setup:
            return(new ScriptEnvironmentSetup(true));
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new local <see cref="ScriptDomainManager"/> unless it already exists.
        /// Returns either <c>true</c> and the newly created environment initialized according to the provided setup information
        /// or <c>false</c> and the existing one ignoring the specified setup information.
        /// </summary>
        internal static bool TryCreateLocal(ScriptEnvironmentSetup setup, out ScriptDomainManager manager)
        {
            bool new_created = false;

            if (_singleton == null)
            {
                if (setup == null)
                {
                    setup = GetSetupInformation();
                }

                lock (_singletonLock) {
                    if (_singleton == null)
                    {
                        ScriptDomainManager singleton = new ScriptDomainManager(setup);
                        Utilities.MemoryBarrier();
                        _singleton  = singleton;
                        new_created = true;
                    }
                }
            }

            manager = _singleton;
            return(new_created);
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes environment according to the setup information.
        /// </summary>
        private ScriptDomainManager(ScriptEnvironmentSetup setup)
        {
            Debug.Assert(setup != null);

            // create local environment for the host:
            _environment = new ScriptEnvironment(this);

            // create PAL (default always available):
            _pal = setup.CreatePAL();

            // let setup register providers listed on it:
            setup.RegisterProviders(this);

            // initialize snippets:
            _snippets = new Snippets();

            // create a local host unless a remote one has already been created:
            _host = setup.CreateScriptHost(_environment);
        }