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); } }
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); }
private static ScriptRuntimeScope InitScriptRuntimeScope() { //star compile if (Interlocked.Exchange(ref _isCompiling, 1) == 0) { ScriptRuntimeDomain runtimeDomain = null; try { string runtimePath = MathUtils.RuntimePath ?? MathUtils.RuntimeBinPath; AppDomain.CurrentDomain.AppendPrivatePath(ScriptCompiler.ScriptPath); runtimeDomain = new ScriptRuntimeDomain(typeof(ScriptRuntimeDomain).Name, new[] { _settupInfo.RuntimePrivateBinPath, ScriptCompiler.ScriptPath }); foreach (var assemblyName in _settupInfo.ReferencedAssemblyNames) { //排除System的dll if (string.IsNullOrEmpty(assemblyName) || !Path.IsPathRooted(assemblyName)) { continue; } string key = Path.GetFileNameWithoutExtension(assemblyName); runtimeDomain.LoadAssembly(key, assemblyName); } var scope = runtimeDomain.CreateScope(_settupInfo); //ignore error if (scope == null || scope.ModelAssembly == null) { return(scope); } //update befor bool isFirstRun = _runtimeDomain == null; if (!isFirstRun && _settupInfo.ModelChangedBefore != null) { _settupInfo.ModelChangedBefore(_runtimeDomain.Scope.ModelAssembly); } runtimeDomain.MainInstance = runtimeDomain.Scope.Execute(_settupInfo.ScriptMainProgram, _settupInfo.ScriptMainTypeName) as IMainScript; _runtimeDomain = runtimeDomain; EntitySchemaSet._entityAssembly = scope.ModelAssembly; //update after if (!isFirstRun && _settupInfo.ModelChangedAfter != null) { _settupInfo.ModelChangedAfter(scope.ModelAssembly); } else if (scope.ModelAssembly != null) { ProtoBufUtils.LoadProtobufType(scope.ModelAssembly); EntitySchemaSet.LoadAssembly(scope.ModelAssembly); } PrintCompiledMessage(); //replace runtime if (!isFirstRun && runtimeDomain.MainInstance != null) { runtimeDomain.MainInstance.ReStart(); } return(scope); } finally { Interlocked.Exchange(ref _isCompiling, 0); } } else { TraceLog.WriteLine("{1} {0} has not compiled in other thread.", "model", DateTime.Now.ToString("HH:mm:ss")); } return(null); }