From 1272108be55d0fb53170e1273c7f997641fa9c50 Mon Sep 17 00:00:00 2001 From: HenningNormann Date: Tue, 15 Feb 2022 10:49:31 +0100 Subject: [PATCH] Fixed url and parameter separator logic in GetInstanceEvents (#8001) * Fixed url and parameter separator logic in GetInstanceEvents. Implemented ListInstanceEvents in local test. * Removed changes from InstanceEventClient because this file is moved to a separate repo. Co-authored-by: Henning Normann --- .../Implementation/InstanceEventRepository.cs | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/Services/Storage/Implementation/InstanceEventRepository.cs b/src/Services/Storage/Implementation/InstanceEventRepository.cs index 219a12fe..6728bec5 100644 --- a/src/Services/Storage/Implementation/InstanceEventRepository.cs +++ b/src/Services/Storage/Implementation/InstanceEventRepository.cs @@ -3,6 +3,7 @@ using LocalTest.Configuration; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; @@ -43,9 +44,42 @@ public Task InsertInstanceEvent(InstanceEvent instanceEvent) public Task> ListInstanceEvents(string instanceId, string[] eventTypes, DateTime? fromDateTime, DateTime? toDateTime) { - throw new NotImplementedException(); - } + List instanceEvents = new List(); + + string instanceEventPath = GetInstanceEventFolder(); + + if (Directory.Exists(instanceEventPath)) + { + string[] files = Directory.GetFiles(instanceEventPath, "*.json"); + + foreach (var file in files) + { + string content = File.ReadAllText(file); + InstanceEvent instanceEvent = (InstanceEvent)JsonConvert.DeserializeObject(content, typeof(InstanceEvent)); + if (instanceEvent != null && instanceEvent.Id != null && instanceEvent.InstanceId == instanceId) + { + instanceEvents.Add(instanceEvent); + } + } + } + if (fromDateTime != null) + { + instanceEvents.RemoveAll(i => i.Created < fromDateTime); + } + + if (toDateTime != null) + { + instanceEvents.RemoveAll(i => i.Created > toDateTime); + } + + if ((eventTypes?.Length ?? 0) > 0) + { + instanceEvents = instanceEvents.Where(i => eventTypes.Contains(i.EventType)).ToList(); + } + + return Task.FromResult(instanceEvents); + } private string GetInstanceEventPath(string instanceId, Guid instanceEventID) {