35 lines
1.0 KiB
Plaintext
35 lines
1.0 KiB
Plaintext
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using MDP.SID.Scripting.Grpc;
|
|
using MDP.SID.Scripting.Shared.Http;
|
|
using MDP.SID.Shared.Public.Events;
|
|
using MDP.SID.Shared.Public.Readers;
|
|
using Event = MDP.SID.Scripting.Grpc.Event;
|
|
|
|
private string _lastGrantedEvent = "";
|
|
private string _lastGrantedImagePath = "";
|
|
|
|
private async void EventReceived(Event received)
|
|
{
|
|
Guid typeUid = Guid.Parse(received.TypeUid);
|
|
if (typeUid == EventTypes.AccessGranted)
|
|
{
|
|
_lastGrantedEvent = $"{received.LocalizedTypeName} {received.FirstName} {received.LastName} {received.Time.ToDateTimeOffset()}";
|
|
_lastGrantedImagePath = $"/users/{received.UserId}/{received.UserId}.Jpeg";
|
|
}
|
|
}
|
|
|
|
Http.MapGet("/doors", async _ => {
|
|
return new { Name = _lastGrantedEvent, Path = _lastGrantedImagePath };
|
|
});
|
|
|
|
Context.OnEventReceived += EventReceived;
|
|
|
|
// run script till it receives stop signal
|
|
CancellationToken.WaitHandle.WaitOne();
|
|
|
|
|
|
Context.LogInformation("Script done"); |