Exemplo n.º 1
0
        internal void LoadAssembly(string key, string assemblyName)
        {
#if STATIC
            Assembly.LoadFrom(assemblyName);
#else
            _context.LoadAssembly(key, assemblyName);
#endif
        }
        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);
            }
        }
Exemplo n.º 3
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);
        }