Exemple #1
0
        private IActionResult ResponseWithServiceExceptionReport(string?code, string message, string version)
        {
            var xmlDoc = new ServiceExceptionReport(code, message, version).ToXml();

            Response.ContentType = MediaTypeNames.Text.Xml + ";charset=UTF-8";
            Response.StatusCode  = (int)HttpStatusCode.OK;
            return(File(xmlDoc.ToUTF8ByteArray(), Response.ContentType));
        }
        public async Task <IActionResult> GetExceptions()
        {
            if (string.IsNullOrWhiteSpace(_appInsightsConfiguration?.AppId))
            {
                ModelState.AddModelError(ErrorResponses.MisconfiguredApplicationInsightsId, string.Empty);
            }
            if (string.IsNullOrWhiteSpace(_appInsightsConfiguration?.TenantId))
            {
                ModelState.AddModelError(ErrorResponses.MisconfiguredApplicationInsightsTenant, string.Empty);
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            using (var appInsightsClient = await Jibberwock.Shared.Telemetry.ApplicationInsightsDataClientFactory.CreateDataClientAsync(_appInsightsConfiguration.AppId, _appInsightsConfiguration.TenantId))
            {
                var aiExceptionList = await appInsightsClient.GetExceptionEventsAsync(_appInsightsConfiguration.ExceptionTimeRange, cancellationToken : HttpContext.RequestAborted);

                var serviceExceptions = (from aiEx in aiExceptionList.Value
                                         select new ServiceException()
                {
                    Id = aiEx.Id,
                    Operation = aiEx?.Operation?.Name,
                    Timestamp = new DateTimeOffset(aiEx.Timestamp.Value, TimeSpan.Zero),
                    Type = aiEx?.Exception?.Type,
                    Message = string.IsNullOrWhiteSpace(aiEx?.Exception?.InnermostMessage)
                                                ? aiEx?.Exception?.OuterMessage
                                                : aiEx?.Exception?.InnermostMessage,
                    RoleName = aiEx.Cloud.RoleName,
                    UserId = aiEx.User.Id,
                    SessionId = aiEx.Session.Id,
                    Source = aiEx.Ai.SdkVersion.Split(':').FirstOrDefault()?.Trim()
                }).OrderBy(e => e.Timestamp).ToArray();
                var serviceReport = new ServiceExceptionReport()
                {
                    StartDate  = DateTimeOffset.UtcNow - _appInsightsConfiguration.ExceptionTimeRange,
                    EndDate    = DateTimeOffset.UtcNow,
                    Exceptions = serviceExceptions
                };

                return(Ok(serviceReport));
            }
        }
Exemple #3
0
        /// <summary>
        /// Populate the HttpResponse with a ServiceExceptionReport
        /// </summary>
        /// <param name="response"></param>
        /// <param name="code"></param>
        /// <param name="message"></param>
        private void SetResponseToServiceException(HttpResponse response, WmsExceptionCode code, string message)
        {
            ServiceExceptionReport serviceExceptionReport = new ServiceExceptionReport();

            serviceExceptionReport.ServiceExceptionList.Add(new ServiceException(code, message));
            response.Clear();
            response.ContentType = "text/xml";

            // Namespaces
            XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();

            namespaces.Add(Declarations.WmsPrefix, Declarations.WmsNameSpace);
            namespaces.Add(Declarations.OgcPrefix, Declarations.OgcNameSpace);
            namespaces.Add(Declarations.XlinkPrefix, Declarations.XlinkNameSpace);

            // Serialize
            XmlSerializer serializer = new XmlSerializer(typeof(ServiceExceptionReport));

            serializer.Serialize(response.OutputStream, serviceExceptionReport, namespaces);
        }