public async Task EmitIncidentAsync(IcmIncident incident) { var cert = await _keyVault.GetCertificateAsync(_connectorCertificateName); var incidentToSend = GetIncidentToSend(incident); using var client = ConnectorClientFactory.CreateClient(_uri, cert); try { var result = client.AddOrUpdateIncident2(_connectorId, incidentToSend, RoutingOptions.None); if (result.Status != IncidentAddUpdateStatus.AddedNew) { throw new Exception($"Result status does not indicate success: {result.Status}."); } } catch (Exception e) { Console.WriteLine("Failed to submit incident to IcM:\n" + e.ToString()); throw; } }
public async Task EmitIncidentAsync(IcmIncident incident) { if (incident.CacheTimeToLive is not null) { if (_cachedIcms.Contains(incident.Title)) { // Update TTL and return. _cachedIcms.Add(incident.Title, incident.CacheTimeToLive.Value); return; } else { // Add to cached incidents. _cachedIcms.Add(incident.Title, incident.CacheTimeToLive.Value); } } var cert = await _keyVault.GetCertificateAsync(_connectorCertificateName); var incidentToSend = GetIncidentToSend(incident); using var client = ConnectorClientFactory.CreateClient(_uri, cert); try { var result = client.AddOrUpdateIncident2(_connectorId, incidentToSend, RoutingOptions.None); if (result.Status != IncidentAddUpdateStatus.AddedNew && // Discarded means that we're updating hit count or it was suppressed because it's too soon // since we updated hit count last and the incident is still active. result.Status != IncidentAddUpdateStatus.Discarded) { throw new Exception($"Result status does not indicate success: {result.Status}."); } } catch (Exception e) { Console.WriteLine("Failed to submit incident to IcM:\n" + e.ToString()); throw; } }