public static async Task CallWebhookAsync(Uri uri, ActionEnum action, ResourceStatusEnum status)
        {
            if (uri == null)
            {
                LoggerService.Warn("No URI for webhook call", LoggerService.Webhook);
                return;
            }

            RestClient  client  = new RestClient();
            RestRequest request = CreateRequest(uri, action, status);

            IRestResponse response = await client.ExecuteAsync(request);

            bool isSuccessful = Is2xxResponse(response.StatusCode);

            if (!isSuccessful)
            {
                throw new WebhookResponseException
                      {
                          DeveloperMessage = "A call to the provided webhook returned a response other than 200 - 299",
                          Message          = "Unable to make a call out to the provided webhook"
                      };
            }
            else
            {
                string message = string.Format("Called webhook for action {0}, and status {1}", action, status);
                LoggerService.Info(message, LoggerService.Webhook);
            }
        }
示例#2
0
        private NotificationContentModel GenerateNotificationText(ResourceStatusEnum status)
        {
            switch (status)
            {
            case ResourceStatusEnum.Running:
                return(new NotificationContentModel
                {
                    Message = ResourceLoader.GetString("StatusRunning"),
                    Title = ResourceLoader.GetString("ServicesOn")
                });

            case ResourceStatusEnum.Stopped:
                return(new NotificationContentModel
                {
                    Message = ResourceLoader.GetString("StatusStopped"),
                    Title = ResourceLoader.GetString("ServicesOff")
                });

            default:
                return(new NotificationContentModel
                {
                    Message = ResourceLoader.GetString("StatusError"),
                    Title = ResourceLoader.GetString("ServicesError")
                });
            }
        }
        public static RestRequest CreateRequest(Uri uri, ActionEnum action, ResourceStatusEnum status)
        {
            WebhookOutputModel model = new WebhookOutputModel
            {
                Action = action,
                Status = status
            };

            uri = AddActionAndStatusToUri(uri, model);
            RestRequest request = new RestRequest(uri, Method.POST);
            string      payload = JsonConvert.SerializeObject(model);

            request.AddParameter("application/json", payload, ParameterType.RequestBody);
            request.RequestFormat = DataFormat.Json;

            return(request);
        }
示例#4
0
        private string MapStatus(ResourceStatusEnum status)
        {
            switch (status)
            {
            case ResourceStatusEnum.Running:
                return(ResourceLoader.GetString("StatusRunning"));

            case ResourceStatusEnum.Starting:
                return(ResourceLoader.GetString("StatusStarting"));

            case ResourceStatusEnum.Stopped:
                return(ResourceLoader.GetString("StatusStopped"));

            case ResourceStatusEnum.Stopping:
                return(ResourceLoader.GetString("StatusStopping"));

            default:
                return(ResourceLoader.GetString("StatusError"));
            }
        }
示例#5
0
        private static string GetRequestStatus(int statusId)
        {
            ResourceStatusEnum status = (ResourceStatusEnum)statusId;

            return(status.ToString());
        }