public void EvaluateCode(string code, IReadOnlyCollection <Type> classes, bool outputScript, bool ignoreConfigHash, bool noOutputConfigAssembly) { string cachedHash = GetCachedConfigHash(); string currentHash = HashString(code); bool discardCache = cachedHash != currentHash || ignoreConfigHash; if (discardCache) { _scriptManager.Create(code, classes, _engine.Namespaces); WriteScript(_scriptManager.Code, outputScript); _scriptManager.Compile(AppDomain.CurrentDomain.GetAssemblies()); SaveCompiledScript(currentHash, noOutputConfigAssembly); } else { byte[] cachedConfig = GetCachedConfig(); _scriptManager.LoadCompiledConfig(cachedConfig); } _engine.DynamicAssemblies.Add(_scriptManager.RawAssembly); _scriptManager.Evaluate(_engine); }
public void EvaluateCode(string code, IReadOnlyCollection <Type> classes, bool outputScript, bool ignoreConfigHash, bool noOutputConfigAssembly) { string cachedHash = GetCachedConfigHash(); string currentHash = HashString(code); byte[] cachedConfig = (cachedHash != currentHash || ignoreConfigHash) ? null : GetCachedConfig(); if (cachedConfig != null) { // Load from cache if the hashes match and we got a cached config file _scriptManager.LoadCompiledConfig(cachedConfig); } else { // Otherwise compile the config and save it as a (new) cached version _scriptManager.Create(code, classes, _engine.Namespaces); WriteScript(_scriptManager.Code, outputScript); _scriptManager.Compile(AppDomain.CurrentDomain.GetAssemblies()); SaveCompiledScript(currentHash, noOutputConfigAssembly); } _engine.DynamicAssemblies.Add(_scriptManager.RawAssembly); _scriptManager.Evaluate(_engine); }