Skip to content

Commit

Permalink
Fixed url and parameter separator logic in GetInstanceEvents (#8001)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
HenningNormann and Henning Normann authored Feb 15, 2022
1 parent ff9cc6f commit 1272108
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions src/Services/Storage/Implementation/InstanceEventRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -43,9 +44,42 @@ public Task<InstanceEvent> InsertInstanceEvent(InstanceEvent instanceEvent)

public Task<List<InstanceEvent>> ListInstanceEvents(string instanceId, string[] eventTypes, DateTime? fromDateTime, DateTime? toDateTime)
{
throw new NotImplementedException();
}
List<InstanceEvent> instanceEvents = new List<InstanceEvent>();

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)
{
Expand Down

0 comments on commit 1272108

Please sign in to comment.