| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using com.sun.net.ssl.@internal.ssl;
- using Comal.Classes;
- using Comal.Stores;
- using InABox.Core;
- using InABox.Database;
- using InABox.Scripting;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Microsoft.CodeAnalysis.VisualBasic.Syntax;
- namespace PRSStores;
- public class BillApprovalSetStore : BaseStore<BillApprovalSet>
- {
- private static Dictionary<Guid, ScriptDocument?> _scripts = new();
- protected override void BeforeSave(BillApprovalSet entity)
- {
- base.BeforeSave(entity);
- if(entity.HasOriginalValue(x => x.ApprovalSetUpdateScript))
- {
- UpdateApprovalSetScript(entity.ID, entity.ApprovalSetUpdateScript);
- }
- }
- private static ScriptDocument? UpdateApprovalSetScript(Guid approvalSetID, string script)
- {
- ScriptDocument? document = null;
- if (!script.IsNullOrWhiteSpace())
- {
- document = new ScriptDocument(script);
- if (!document.Compile())
- {
- InABox.Core.Logger.Send(LogType.Error, "", $"Bill Approval Script failed to compile: {document.Result}");
- document = null;
- }
- }
- lock(_scripts)
- {
- _scripts[approvalSetID] = document;
- }
- return document;
- }
- public static ScriptDocument? GetUpdateApprovalsScript(Guid approvalSetID)
- {
- lock (_scripts)
- {
- if (_scripts.TryGetValue(approvalSetID, out var script)) return script;
- }
- var set = DbFactory.NewProvider(Logger.Main).Query<BillApprovalSet>(
- Filter<BillApprovalSet>.Where(x => x.ID).IsEqualTo(approvalSetID),
- Columns.None<BillApprovalSet>().Add(x => x.ApprovalSetUpdateScript))
- .ToObjects<BillApprovalSet>().FirstOrDefault();
- if(set is not null)
- {
- return UpdateApprovalSetScript(approvalSetID, set.ApprovalSetUpdateScript);
- }
- else
- {
- return null;
- }
- }
- }
|