using InABox.Core; using InABox.Core.Postable; using InABox.Scripting; using System; using System.Collections.Generic; using System.Formats.Asn1; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; namespace InABox.Poster.Timberline { public class TimberlinePosterEngine : PosterEngine, TSettings> where TPostable : Entity, IPostable, IRemotable, IPersistent, new() where TSettings : TimberlinePosterSettings, new() { private ScriptDocument? _script; private bool _hasCheckedScript; protected override ITimberlinePoster CreatePoster() { var poster = base.CreatePoster(); poster.Script = GetScriptDocument(); return poster; } private ScriptDocument? GetScriptDocument() { if (_hasCheckedScript) { return _script; } var settings = GetSettings(); if (settings.ScriptEnabled && !string.IsNullOrWhiteSpace(settings.Script)) { var document = new ScriptDocument(settings.Script); if (!document.Compile()) { throw new Exception("Script failed to compile!"); } _script = document; } else { _script = null; } _hasCheckedScript = true; return _script; } public override bool BeforePost(IDataModel model) { return Poster.BeforePost(model); } protected override IPostResult DoProcess(IDataModel model) { return Poster.Process(model); } public override void AfterPost(IDataModel model, IPostResult result) { Poster.AfterPost(model, result); } } }