Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public ScriptDomainContext InitDomainContext()
        {
            var type = typeof(ScriptDomainContext);

            _context = (ScriptDomainContext)_currDomain.CreateInstanceFromAndUnwrap(type.Assembly.GetName().CodeBase, type.FullName);
            return(_context);
        }
Esempio n. 2
0
        private void InitDomain(string name, AppDomainSetup setup)
        {
#if STATIC
#else
            _currDomain = AppDomain.CreateDomain(name, null, setup);
            var type = typeof(ScriptDomainContext);
            _context = (ScriptDomainContext)_currDomain.CreateInstanceFromAndUnwrap(type.Assembly.GetName().CodeBase, type.FullName);
#endif
        }
Esempio n. 3
0
 /// <summary>
 ///
 /// </summary>
 public void Dispose()
 {
     Unload();
     _currDomain = null;
     _scope.Dispose();
     _scope   = null;
     _context = null;
     GC.SuppressFinalize(this);
 }
        private static ScriptRuntimeScope InitScriptRuntimeScope()
        {
            //star compile
            Interlocked.Exchange(ref _isCompiling, 1);
            try
            {
                string runtimePath = MathUtils.RuntimePath ?? MathUtils.RuntimeBinPath;
                AppDomain.CurrentDomain.AppendPrivatePath(ScriptCompiler.ScriptPath);
                bool isFirstRun = _runtimeDomain == null;
                if (!isFirstRun && _settupInfo.ModelChangedBefore != null)
                {
                    _settupInfo.ModelChangedBefore(_runtimeDomain.Scope.ModelAssembly);
                }

                // Declan 2017-4-19 防止重复new,加入判断
                if (_runtimeDomain == null)
                {
                    _runtimeDomain = new ScriptRuntimeDomain(typeof(ScriptRuntimeDomain).Name, new[] { _settupInfo.RuntimePrivateBinPath, ScriptCompiler.ScriptPath });
                }

                ScriptDomainContext domainContext = _runtimeDomain.InitDomainContext();

                foreach (var assemblyName in _settupInfo.ReferencedAssemblyNames)
                {
                    //排除System的dll
                    if (string.IsNullOrEmpty(assemblyName) ||
                        !Path.IsPathRooted(assemblyName))
                    {
                        continue;
                    }
                    string key = Path.GetFileNameWithoutExtension(assemblyName);
                    domainContext.LoadAssembly(key, assemblyName);
                }

                var scope = _runtimeDomain.CreateScope(_settupInfo);
                if (scope == null)
                {
                    return(scope);
                }
                PrintCompiledMessage();
                if (!isFirstRun && _settupInfo.ModelChangedAfter != null)
                {
                    _settupInfo.ModelChangedAfter(scope.ModelAssembly);
                }
                else if (scope.ModelAssembly != null)
                {
                    ProtoBufUtils.LoadProtobufType(scope.ModelAssembly);
                    EntitySchemaSet.LoadAssembly(scope.ModelAssembly);
                }
                return(scope);
            }
            finally
            {
                Interlocked.Exchange(ref _isCompiling, 0);
            }
        }
Esempio n. 5
0
        private void InitDomain(string name, AppDomainSetup setup)
        {
#if STATIC

#else
            _currDomain = AppDomain.CreateDomain(name, null, setup);
            var type = typeof(ScriptDomainContext);
            _context = (ScriptDomainContext)_currDomain.CreateInstanceFromAndUnwrap(type.Assembly.GetName().CodeBase, type.FullName);
#endif
        }
Esempio n. 6
0
        private static ScriptRuntimeScope InitScriptRuntimeScope()
        {
            string runtimePath = MathUtils.RuntimePath ?? MathUtils.RuntimeBinPath;

            AppDomain.CurrentDomain.AppendPrivatePath(ScriptCompiler.ScriptPath);
            bool isFirstRun = _runtimeDomain == null;

            if (!isFirstRun && _settupInfo.ModelChangedBefore != null)
            {
                _settupInfo.ModelChangedBefore(_runtimeDomain.Scope.ModelAssembly);
            }

            _runtimeDomain = new ScriptRuntimeDomain(typeof(ScriptRuntimeDomain).Name, new[] { _settupInfo.RuntimePath, ScriptCompiler.ScriptPath });

            ScriptDomainContext domainContext = _runtimeDomain.InitDomainContext();

            foreach (var assemblyName in _settupInfo.ReferencedAssemblyNames)
            {
                //排除System的dll
                if (string.IsNullOrEmpty(assemblyName) ||
                    assemblyName.IndexOf(":") == -1)
                {
                    continue;
                }
                string key = Path.GetFileNameWithoutExtension(assemblyName);
                domainContext.LoadAssembly(key, assemblyName);
            }

            var scope = _runtimeDomain.CreateScope(_settupInfo);

            PrintCompiledMessage();
            if (!isFirstRun && _settupInfo.ModelChangedAfter != null)
            {
                _settupInfo.ModelChangedAfter(scope.ModelAssembly);
            }
            else
            {
                ProtoBufUtils.LoadProtobufType(scope.ModelAssembly);
                EntitySchemaSet.LoadAssembly(scope.ModelAssembly);
            }
            return(scope);
        }
Esempio n. 7
0
 /// <summary>
 /// 
 /// </summary>
 public void Dispose()
 {
     Unload();
     _currDomain = null;
     _scope.Dispose();
     _scope = null;
     _context = null;
     GC.SuppressFinalize(this);
 }
Esempio n. 8
0
 /// <summary>
 /// 
 /// </summary>
 /// <returns></returns>
 public ScriptDomainContext InitDomainContext()
 {
     var type = typeof(ScriptDomainContext);
     _context = (ScriptDomainContext)_currDomain.CreateInstanceFromAndUnwrap(type.Assembly.GetName().CodeBase, type.FullName);
     return _context;
 }