Esempio n. 1
0
        public async Task <IActionResult> AddComment(ActionApiModel model)
        {
            model.Comment.Created = DateTime.Now;
            var count = await _blogService.AddComment(model.BlogId, model.Comment);

            return(Ok(count));
        }
Esempio n. 2
0
        public async Task InvokeAsync(HttpContext context, RequestDelegate next)
        {
            var isAPI = context.Request.Path.Value.Contains("/api/") && !context.Request.Path.Value.Contains("SearchBlog");

            if (isAPI)
            {
                List <string> req = await GetListOfStringsFromStream(context.Request.Body);

                ActionApiModel orgRequest = JsonConvert.DeserializeObject <ActionApiModel>(req.FirstOrDefault());
                orgRequest.User             = new Entities.UserContextEntity();
                orgRequest.User.UserName    = context.User.Claims.Where(c => c.Type == "FullName").Select(c => c.Value).FirstOrDefault();
                orgRequest.User.UserPicPath = context.User.Claims.Where(c => c.Type == "PicPath").Select(c => c.Value).FirstOrDefault();
                orgRequest.User.UserId      = context.User.Claims.Where(c => c.Type == "Id").Select(c => c.Value).FirstOrDefault();
                byte[] byteArray = Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(orgRequest));
                context.Request.Body = new MemoryStream(byteArray);
            }

            await next(context);

            // var response = await FormatResponse(context.Response);

            //TODO: Save log to chosen datastore

            //Copy the contents of the new memory stream (which contains the response) to the original stream, which is then returned to the client.
        }
        private RuleApiModel GetSampleRuleWithCalculation(string calculation, string timePeriod, bool includeActions = false)
        {
            var condition = new ConditionApiModel()
            {
                Field    = "pressure",
                Operator = "GreaterThan",
                Value    = "150"
            };

            var conditions = new List <ConditionApiModel> {
                condition
            };

            RuleApiModel result = new RuleApiModel()
            {
                Name        = calculation + " Test Rule",
                Description = "Test Description",
                GroupId     = DEFAULT_CHILLERS_GROUP_ID,
                Severity    = "Info",
                Enabled     = true,
                Calculation = calculation,
                TimePeriod  = timePeriod,
                Conditions  = conditions
            };

            if (includeActions)
            {
                var parameters = new Dictionary <string, object>
                {
                    { "Notes", "Fake Note" },
                    { "Subject", "Fake Subject" }
                };
                var emails = new JArray {
                    "*****@*****.**"
                };
                parameters.Add("Recipients", emails);
                ActionApiModel action = new ActionApiModel
                {
                    Type       = "Email",
                    Parameters = parameters
                };
                result.Actions = new List <ActionApiModel> {
                    action
                };
            }

            return(result);
        }
Esempio n. 4
0
        public async Task <IActionResult> UpdateContent(ActionApiModel model)
        {
            var count = await _blogService.UpdateBlogContent(model.BlogId, model.Content);

            return(Ok(count));
        }
Esempio n. 5
0
        public async Task <IActionResult> AddRating(ActionApiModel model)
        {
            var count = await _blogService.AddRating(model.BlogId, model.Rating, model.User);

            return(Ok(count));
        }
Esempio n. 6
0
        public async Task <IActionResult> DisLikeBlog(ActionApiModel model)
        {
            var count = await _blogService.DislikeBlog(model.BlogId, model.User);

            return(Ok(count));
        }
        private void CreateRuleWithCalculation(string calculation, string timePeriod, ref string id, bool includeActions)
        {
            var condition = new ConditionApiModel()
            {
                Field    = "temperature",
                Operator = "GreaterThan",
                Value    = "1"
            };

            var conditions = new List <ConditionApiModel> {
                condition
            };

            var newRule = new RuleApiModel()
            {
                Id          = id,
                Name        = calculation + " Faulty Test Rule " + DateTime.UtcNow.ToString("yyyyMMddHHmmss") + "-" + Guid.NewGuid(),
                Description = "Test Description",
                GroupId     = DEFAULT_CHILLERS_GROUP_ID,
                Severity    = "Info",
                Enabled     = true,
                Calculation = calculation,
                TimePeriod  = timePeriod,
                Conditions  = conditions
            };

            if (includeActions)
            {
                var parameters = new Dictionary <string, object>
                {
                    { "Notes", "Fake Note" },
                    { "Subject", "Fake Subject" }
                };
                var emails = new JArray {
                    "*****@*****.**"
                };
                parameters.Add("Recipients", emails);
                ActionApiModel action = new ActionApiModel
                {
                    Type       = "Email",
                    Parameters = parameters
                };
                newRule.Actions = new List <ActionApiModel> {
                    action
                };
            }

            var request = new HttpRequest(Constants.TELEMETRY_ADDRESS + RULES_ENDPOINT_SUFFIX);

            request.AddHeader("Content-Type", "application/json");
            request.SetContent(JsonConvert.SerializeObject(newRule));

            var response     = this.httpClient.PostAsync(request).Result;
            var ruleResponse = JsonConvert.DeserializeObject <RuleApiModel>(response.Content);

            // Update the saved rule ID
            id = ruleResponse.Id;

            // Dispose after tests run
            this.disposeRulesList.Add(ruleResponse.Id);
        }