using InABox.Core; using InABox.Poster.Shared; using InABox.Scripting; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace InABox.Poster.Custom; public class CustomPosterEngine : BasePosterEngine, CustomPosterSettings> where TPostable : Entity, IPostable, IRemotable, IPersistent, new() { public override bool BeforePost(IDataModel model) { if (GetScriptDocument() is ScriptDocument script) { return script.Execute(methodname: "BeforePost", parameters: new object[] { model }); } return false; } protected override IPostResult DoProcess(IDataModel model) { if (GetScriptDocument() is ScriptDocument script) { if(!script.Execute(methodname: "Process", parameters: new object[] { model })) { throw new Exception("Post Failed."); } var resultsObject = script.GetValue("Results"); return (resultsObject as IPostResult) ?? throw new Exception($"Script 'Results' property expected to be IPostResult<{typeof(TPostable)}>, got {resultsObject}"); } else { throw new Exception("Post Failed."); } } public override void AfterPost(IDataModel model, IPostResult result) { if (GetScriptDocument() is ScriptDocument script) { script.Execute(methodname: "AfterPost", parameters: new object[] { model }); } } }