protected override SafeguardEventListener ReconnectEventListener()
 {
     if (_connection.GetAccessTokenLifetimeRemaining() == 0)
     {
         _connection.RefreshAccessToken();
     }
     return((SafeguardEventListener)_connection.GetEventListener());
 }
        private void HandlePendingApprovalNotification(string eventName, string eventBody)
        {
            if (eventName != "AccessRequestPendingApproval")
            {
                Log.Information("Received {EventName} event, ignoring it", eventName);
                return;
            }

            try
            {
                var approvalEvent   = JsonConvert.DeserializeObject <AccessRequestApprovalPendingEvent>(eventBody);
                var accessRequestId = approvalEvent.RequestId;
                if (string.IsNullOrEmpty(accessRequestId))
                {
                    Log.Warning("Unable to parse access requestId for event {EventBody}", eventBody);
                    return;
                }
                var accessRequestJson =
                    _connection.InvokeMethod(Service.Core, Method.Get, $"AccessRequests/{accessRequestId}");
                var accessRequest = JsonConvert.DeserializeObject <AccessRequest>(accessRequestJson);

                // Only ServiceNow and Remedy are supported in Safeguard. We will be adding a generic ticket system
                // that will allow for arbitrary ticket numbers. Until then, you could overload the comment with
                // the ticket number. TODO: remove this comment when it becomes obselete
                var ticketNumber = accessRequest.TicketNumber;
                if (string.IsNullOrEmpty(ticketNumber))
                {
                    Log.Information("Ignoring access request {AccessRequestId} without ticket number", accessRequestId);
                    return;
                }

                if (_connection.GetAccessTokenLifetimeRemaining() == 0)
                {
                    _connection.RefreshAccessToken();
                }

                switch (_validator.CheckTicket(ticketNumber, accessRequest))
                {
                case ValidationResult.Approve:
                    Log.Information("Approving access request {AccessRequestId} with ticket number {TicketNumber}",
                                    accessRequestId, ticketNumber);
                    _connection.InvokeMethod(Service.Core, Method.Post, $"AccessRequests/{accessRequestId}/Approve");
                    break;

                case ValidationResult.Deny:
                    Log.Information("Denying access request {AccessRequestId} with ticket number {TicketNumber}",
                                    accessRequestId, ticketNumber);
                    _connection.InvokeMethod(Service.Core, Method.Post, $"AccessRequests/{accessRequestId}/Deny");
                    break;

                default:
                    Log.Information("Ignoring access request {AccessRequestId} with ticket number {TicketNumber}",
                                    accessRequestId, ticketNumber);
                    break;
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Exception occured while handling event {EventName}, data={EventBody}", eventName, eventBody);
            }
        }