using Mogafa.App.Assets; using Mogafa.App.LogEvents; using Mogafa.Common; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; namespace Mogafa.App.Assets.EventIntercepts { public class AssetEventIntercept : MogafaBase, ILogEventIntercept { private readonly IAssetAccessor assetAccessor; private readonly string assetEventParameterName; public AssetEventIntercept(IAssetAccessor assetAccessor, string assetEventParameterName) { this.assetAccessor = assetAccessor; this.assetEventParameterName = assetEventParameterName; } public string Name => "AssetEventIntercept"; public int Order => 10; public async Task>> Execute(string eventName, Dictionary parameters) { var events = new Dictionary>(); if (parameters == null) { parameters = new Dictionary(); } if (string.IsNullOrEmpty(assetEventParameterName)) { events.Add(eventName, parameters); return events; } var assets = await assetAccessor.GetAssets(); if (assets != null && assets.Count > 0) { var assetsJson = JsonConvert.SerializeObject(assets); parameters.Add(assetEventParameterName, assetsJson); } events.Add(eventName, parameters); return events; } } public interface IAssetAccessor { Task> GetAssets(); } }