public void Register(string name, IDynamicScript script) { if (name == null) { throw new ArgumentNullException(nameof(name)); } registeredScripts[name] = script ?? throw new ArgumentNullException(nameof(script)); }
public static void Register(string name, IDynamicScript script) { var item = new Item(name, script); item.NonCached = script.NonCached; var reg = Hashtable.Synchronized(registeredScripts); reg[name] = item; }
public string PeekScriptHash(string name, IDynamicScript script) { if (name == null) { throw new ArgumentNullException(nameof(name)); } var cacheKey = "DynamicScript:" + name; if (script is ICacheSuffix ics) { cacheKey = cacheKey + ":" + ics.CacheSuffix; } var groupKey = script.GroupKey; ScriptContent scriptContent; if (groupKey == null) { scriptContent = cache.Memory.Get <ScriptContent>(cacheKey, TimeSpan.Zero, null); } else { scriptContent = cache.GetLocalStoreOnly <ScriptContent>(cacheKey, TimeSpan.Zero, groupKey, null); } if (scriptContent != null && scriptLastChange.TryGetValue(name, out DateTime lastChange) && lastChange >= scriptContent.Time) { if (groupKey == null) { cache.Memory.Remove(cacheKey); } else { cache.Remove(cacheKey); } scriptContent = null; } var hash = scriptContent?.Hash; if (hash == null) { hash = DateTime.UtcNow.Ticks.ToString(CultureInfo.InvariantCulture); if (script is ICacheSuffix ics2) { hash = "-" + ics2.CacheSuffix.GetHashCode(StringComparison.Ordinal).ToString(CultureInfo.InvariantCulture); } } return(hash); }
private IScriptContent EnsureScriptContent(string name, IDynamicScript script) { if (name == null) { throw new ArgumentNullException(nameof(name)); } var cacheKey = "DynamicScript:" + name; if (script is ICacheSuffix ics) { cacheKey = cacheKey + ":" + ics.CacheSuffix; } ScriptContent factory() { var content = utf8Encoding.GetBytes(script.GetScript()); return(new ScriptContent(content, DateTime.UtcNow, content.Length > 4096)); } var groupKey = script.GroupKey; ScriptContent getOrCreate() { if (groupKey == null) { return(cache.Memory.Get(cacheKey, script.Expiration, factory)); } else { return(cache.GetLocalStoreOnly(cacheKey, script.Expiration, groupKey, factory)); } }; var scriptContent = getOrCreate(); if (scriptLastChange.TryGetValue(name, out DateTime lastChange) && lastChange >= scriptContent.Time) { if (groupKey == null) { cache.Memory.Remove(cacheKey); } else { cache.Remove(cacheKey); } return(getOrCreate()); } return(scriptContent); }
public Item(string name, IDynamicScript generator) { Name = name; Generator = generator; content = new Script { Time = DateTime.UtcNow, Hash = null, UncompressedBytes = null, CompressedBytes = null }; generator.ScriptChanged += ScriptChanged; }
public Item(string name, IDynamicScript generator) { Name = name; Generator = generator; content = new Script { Time = DateTime.UtcNow, Hash = DateTime.Now.Ticks.ToString(), UncompressedBytes = null, CompressedBytes = null }; generator.ScriptChanged += ScriptChanged; }
public Item(string name, IDynamicScript generator) { Name = name; Generator = generator; content = new Script { Time = DateTime.UtcNow, Hash = DateTime.Now.Ticks.ToString(), UncompressedBytes = null, CompressedBytes = null }; NonCached = false; generator.ScriptChanged += ScriptChanged; }
public IDynamicScript CreateDynamicScript(DynamicScript script) { IDynamicScript dynamicScript = null; switch (script.RunTime.Language) { case DynamicScriptLanguageEnum.CSharp: dynamicScript = new CSharpScriptEngine(script.ApplicationName) .LoadNameSpaces(script.CompileTime.ScriptReferenceNamespace) .LoadAssembly(script.CompileTime.ScriptReferenceAssemblies) .LoadAssembly(script.CompileTime.ScriptReferenceAssemblyNames) .InitMetadataReference() .BuildDynamicScript(script.CompileTime); break; } return(dynamicScript); }
public static void Register(string name, IDynamicScript script) { var item = new Item(name, script); registeredScripts[name] = item; }