コード例 #1
0
        /// <summary>
        /// ScaleOut middleware to add telemetry for scale-out events.
        /// </summary>
        /// <param name="context">Owin context</param>
        /// <returns>Returns task</returns>
        public override async Task Invoke(IOwinContext context)
        {
            if (object.Equals(context.Request.Path, this.callbackPath))
            {
                string body = context.GetRequestBody();

                if (!string.IsNullOrEmpty(body))
                {
                    try
                    {
                        JObject payload = JsonConvert.DeserializeObject(body) as JObject;
                        if (payload != null)
                        {
                            var operation     = payload["operation"] != null ? payload["operation"].Value <string>() : null;
                            var status        = payload["status"] != null ? payload["status"].Value <string>() : null;
                            var contextObject = payload["context"] != null ? payload["context"] as JObject : null;
                            if (operation != null && status != null && contextObject != null)
                            {
                                var timestamp   = contextObject["timestamp"] != null ? contextObject["timestamp"].Value <string>() : null;
                                var details     = contextObject["details"] != null ? contextObject["details"].Value <string>() : null;
                                var resourceId  = contextObject["resourceId"] != null ? contextObject["resourceId"].Value <string>() : null;
                                var oldCapacity = contextObject["oldCapacity"] != null ? contextObject["oldCapacity"].Value <string>() : null;
                                var newCapacity = contextObject["newCapacity"] != null ? contextObject["newCapacity"].Value <string>() : null;

                                // Temp changes till this jarvis event this is not fixed
                                ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("ScaleOut webhook notification. Status: {0}, Operation: {1}, TimeStamp: {2}, Details: {3}, ResourceId: {4}, OldCapacity: {5}, NewCapacity: {6}",
                                                                                                     status, operation, timestamp, details, resourceId, oldCapacity, newCapacity));
                                CmsEventSource.Log.ScaleOutNotification(status, operation, timestamp, details, oldCapacity, newCapacity, resourceId);
                            }
                            else
                            {
                                ADXTrace.Instance.TraceWarning(TraceCategory.Application, string.Format("The payload for scaleout webhook notification is missing essential data to log data. Request.Body: {0}", body));
                            }
                        }
                        else
                        {
                            ADXTrace.Instance.TraceWarning(TraceCategory.Application, string.Format("Something is wrong in the scaleout webhook notification payload. {0}", body));
                        }
                    }
                    catch (Exception ex)
                    {
                        ADXTrace.Instance.TraceWarning(TraceCategory.Application, string.Format("Could not deserialize ScaleOut webhook notification payload. Request.Body: {0} Exception: {1}", body, ex.Message));
                    }
                }
            }
            else
            {
                await Next.Invoke(context);
            }
        }
コード例 #2
0
        public override async Task Invoke(IOwinContext context)
        {
            if (Equals(context.Request.Path, this.Options.CallbackPath))
            {
                var request = new PluginMessageRequest
                {
                    Authorization = context.Request.Headers["Authorization"],
                    ContentType   = context.Request.ContentType,
                    Body          = context.GetRequestBody()
                };

                var message = this.GetPluginMessage(request.Body);

                if (message != null && WebNotificationCryptography.ValidateRequest(request.Authorization))
                {
                    ADXTrace.Instance.TraceInfo(TraceCategory.Application, "Posting message");

                    await this.PostAsync(context, message).WithCurrentCulture();
                }
            }

            await this.Next.Invoke(context);
        }