Exemplo n.º 1
0
        public static async Task <IActionResult> UpdateFunction(
            [HttpTrigger(AuthorizationLevel.Function, "put", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("UpdateRuleFunction: Starting");
            try
            {
                string        storageAccount = Common.Helpers.Common.GetStorageKey(req);
                string        source         = Common.Helpers.Common.GetQueryString(req, "name");
                int           id             = Common.Helpers.Common.GetIntFromWebQuery(req, "id");
                string        requestBody    = await new StreamReader(req.Body).ReadToEndAsync();
                RuleFunctions ruleFunction   = JsonConvert.DeserializeObject <RuleFunctions>(requestBody);
                if (ruleFunction == null)
                {
                    log.LogError("UpdateRuleFunction: error missing function");
                    return(new BadRequestObjectResult("Error missing function"));
                }
                RuleManagement rules = new RuleManagement(storageAccount);
                await rules.UpdateFunction(source, id, ruleFunction);
            }
            catch (Exception ex)
            {
                log.LogError($"UpdateRuleFunction: Error updating functions: {ex}");
                return(new BadRequestObjectResult($"Error updating function: {ex}"));
            }

            return(new OkObjectResult("OK"));
        }
Exemplo n.º 2
0
        public static async Task <IActionResult> DeletePrediction(
            [HttpTrigger(AuthorizationLevel.Function, "delete", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("DeletePredictionSet: Starting");
            try
            {
                string name = req.Query["name"];
                if (string.IsNullOrEmpty(name))
                {
                    log.LogError("DeletePredictionSet: error, prediction set name is missing");
                    return(new BadRequestObjectResult("Error missing prediction set name"));
                }
                string         storageAccount = Common.Helpers.Common.GetStorageKey(req);
                RuleManagement rules          = new RuleManagement(storageAccount);
                await rules.DeletePrediction(name);
            }
            catch (Exception ex)
            {
                log.LogError($"DeletePredictionSet: {ex}");
                return(new BadRequestObjectResult($"Error deleting rule: {ex}"));
            }

            log.LogInformation("DeletePredictionSet: Complete");
            return(new OkObjectResult("OK"));
        }
Exemplo n.º 3
0
        public static async Task <IActionResult> GetPredictions(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("GetPredictionSets: Starting");
            string responseMessage = "";

            try
            {
                var    headers        = req.Headers;
                string storageAccount = headers.FirstOrDefault(x => x.Key == "azurestorageconnection").Value;
                if (string.IsNullOrEmpty(storageAccount))
                {
                    log.LogError("GetPredictionSets: error, missing azure storage account");
                    return(new BadRequestObjectResult("Missing azure storage account in http header"));
                }
                RuleManagement rules = new RuleManagement(storageAccount);
                responseMessage = await rules.GetPredictions();
            }
            catch (Exception ex)
            {
                log.LogError($"GetPredictionSets: Error getting rules: {ex}");
                return(new BadRequestObjectResult($"Error getting rules: {ex}"));
            }

            return(new OkObjectResult(responseMessage));
        }
Exemplo n.º 4
0
        public async Task <ActionResult <RuleInfo> > GetRuleInfo(string source)
        {
            GetStorageAccount();
            RuleManagement rules           = new RuleManagement(connectionString);
            string         responseMessage = await rules.GetRuleInfo();

            RuleInfo ruleInfo = JsonConvert.DeserializeObject <RuleInfo>(responseMessage);

            return(ruleInfo);
        }
Exemplo n.º 5
0
 public async Task <ActionResult <string> > UpdateRule(string source, int id, RuleModel rule)
 {
     try
     {
         GetStorageAccount();
         RuleManagement rules = new RuleManagement(connectionString);
         await rules.UpdateRule(source, id, rule);
     }
     catch (Exception ex)
     {
         return(BadRequest());
     }
     return(Ok($"OK"));
 }
Exemplo n.º 6
0
 public async Task <ActionResult <string> > SaveRuleToFile(string RuleName, PredictionSet predictionSet)
 {
     try
     {
         GetStorageAccount();
         RuleManagement rules = new RuleManagement(connectionString);
         await rules.SavePredictionSet(RuleName, predictionSet);
     }
     catch (Exception ex)
     {
         return(BadRequest());
     }
     return(Ok($"OK"));
 }
Exemplo n.º 7
0
 public async Task <ActionResult> Delete(string source, int id)
 {
     try
     {
         GetStorageAccount();
         RuleManagement rm = new RuleManagement(connectionString);
         await rm.DeleteFunction(source, id);
     }
     catch (Exception)
     {
         return(BadRequest());
     }
     return(NoContent());
 }
Exemplo n.º 8
0
        public static async Task <IActionResult> UpdateRule(
            [HttpTrigger(AuthorizationLevel.Function, "put", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("UpdateDataRule: Starting");

            try
            {
                string name = req.Query["name"];
                if (string.IsNullOrEmpty(name))
                {
                    log.LogError("UpdateDataRule: error, source name is missing");
                    return(new BadRequestObjectResult("Error missing source name"));
                }

                string strId = req.Query["id"];
                int?   tmpId = strId.GetIntFromString();
                if (tmpId == null)
                {
                    log.LogError("UpdateDataRule: error, rule id name is missing");
                    return(new BadRequestObjectResult("Error missing rule id"));
                }
                int id = tmpId.GetValueOrDefault();

                string    requestBody = await new StreamReader(req.Body).ReadToEndAsync();
                RuleModel rule        = JsonConvert.DeserializeObject <RuleModel>(requestBody);
                if (rule == null)
                {
                    log.LogError("UpdateDataRule: error missing rule data");
                    return(new BadRequestObjectResult("Error missing rule data"));
                }
                var    headers        = req.Headers;
                string storageAccount = headers.FirstOrDefault(x => x.Key == "azurestorageconnection").Value;
                if (string.IsNullOrEmpty(storageAccount))
                {
                    log.LogError("SavePredictionSet: error, missing azure storage account");
                    return(new BadRequestObjectResult("Missing azure storage account in http header"));
                }
                RuleManagement rules = new RuleManagement(storageAccount);
                await rules.UpdateRule(name, id, rule);
            }
            catch (Exception ex)
            {
                log.LogError($"UpdateDataRule: Error updating rule: {ex}");
                return(new BadRequestObjectResult($"Error updating rule: {ex}"));
            }

            return(new OkObjectResult("OK"));
        }
Exemplo n.º 9
0
        public async Task <ActionResult> DeleteTable(string RuleName)
        {
            try
            {
                GetStorageAccount();
                RuleManagement rules = new RuleManagement(connectionString);
                await rules.DeletePrediction(RuleName);
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }

            return(NoContent());
        }
Exemplo n.º 10
0
        public async Task <ActionResult <string> > GetPrediction(string ruleName)
        {
            try
            {
                GetStorageAccount();
                RuleManagement rules  = new RuleManagement(connectionString);
                string         result = await rules.GetPrediction(ruleName);

                return(result);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.ToString()));
            }
        }
Exemplo n.º 11
0
        public async Task <ActionResult <string> > GetRule(string source, int id)
        {
            string result = "";

            try
            {
                GetStorageAccount();
                RuleManagement rules = new RuleManagement(connectionString);
                result = await rules.GetRule(source, id);
            }
            catch (Exception)
            {
                return(BadRequest());
            }
            return(result);
        }
Exemplo n.º 12
0
        public async Task <ActionResult <List <PredictionSet> > > GetPredictions()
        {
            try
            {
                List <PredictionSet> predictionSets = new List <PredictionSet>();
                GetStorageAccount();
                RuleManagement rules           = new RuleManagement(connectionString);
                string         responseMessage = await rules.GetPredictions();

                predictionSets = JsonConvert.DeserializeObject <List <PredictionSet> >(responseMessage);
                return(predictionSets);
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
Exemplo n.º 13
0
 public async Task <ActionResult <string> > UpdateFunction(string source, int id, RuleFunctions function)
 {
     if (function == null)
     {
         return(BadRequest());
     }
     try
     {
         GetStorageAccount();
         RuleManagement rm = new RuleManagement(connectionString);
         await rm.UpdateFunction(source, id, function);
     }
     catch (Exception)
     {
         return(BadRequest());
     }
     return(Ok($"OK"));
 }
Exemplo n.º 14
0
        public static async Task <IActionResult> GetRule(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("GetDataRule: Starting");
            string responseMessage = "";

            try
            {
                string name = req.Query["name"];
                if (string.IsNullOrEmpty(name))
                {
                    log.LogError("GetDataRule: error, source name is missing");
                    return(new BadRequestObjectResult("Error missing source name"));
                }

                string strId = req.Query["id"];
                int?   tmpId = strId.GetIntFromString();
                if (tmpId == null)
                {
                    log.LogError("GetDataRule: error, rule id name is missing");
                    return(new BadRequestObjectResult("Error missing rule id"));
                }
                int id = tmpId.GetValueOrDefault();

                var    headers        = req.Headers;
                string storageAccount = headers.FirstOrDefault(x => x.Key == "azurestorageconnection").Value;
                if (string.IsNullOrEmpty(storageAccount))
                {
                    log.LogError("GetDataRules: error, missing azure storage account");
                    return(new BadRequestObjectResult("Missing azure storage account in http header"));
                }
                RuleManagement rules = new RuleManagement(storageAccount);
                responseMessage = await rules.GetRule(name, id);
            }
            catch (Exception ex)
            {
                log.LogError($"GetDataRule: Error getting rules: {ex}");
                return(new BadRequestObjectResult($"Error getting rules: {ex}"));
            }

            return(new OkObjectResult(responseMessage));
        }
Exemplo n.º 15
0
        public static async Task <IActionResult> DeleteFunction(
            [HttpTrigger(AuthorizationLevel.Function, "delete", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("DeleteRuleFunction: Starting");
            try
            {
                string         storageAccount = Common.Helpers.Common.GetStorageKey(req);
                string         source         = Common.Helpers.Common.GetQueryString(req, "name");
                int            id             = Common.Helpers.Common.GetIntFromWebQuery(req, "id");
                RuleManagement rules          = new RuleManagement(storageAccount);
                await rules.DeleteFunction(source, id);
            }
            catch (Exception ex)
            {
                log.LogError($"DeleteRuleFunction: Error deleting functions: {ex}");
                return(new BadRequestObjectResult($"Error deleting function: {ex}"));
            }

            return(new OkObjectResult("OK"));
        }
Exemplo n.º 16
0
        public static async Task <IActionResult> SavePrediction(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("SavePredictionSet: Starting");

            try
            {
                string name = req.Query["name"];
                if (string.IsNullOrEmpty(name))
                {
                    log.LogError("SaveDaSavePredictionSettaRule: error, prediction set name is missing");
                    return(new BadRequestObjectResult("Error missing prediction set name"));
                }
                string        requestBody = await new StreamReader(req.Body).ReadToEndAsync();
                PredictionSet set         = JsonConvert.DeserializeObject <PredictionSet>(requestBody);
                if (set == null || set.RuleSet == null)
                {
                    log.LogError("SavePredictionSet: error missing prediction set");
                    return(new BadRequestObjectResult("Error missing prediction set"));
                }
                var    headers        = req.Headers;
                string storageAccount = headers.FirstOrDefault(x => x.Key == "azurestorageconnection").Value;
                if (string.IsNullOrEmpty(storageAccount))
                {
                    log.LogError("SavePredictionSet: error, missing azure storage account");
                    return(new BadRequestObjectResult("Missing azure storage account in http header"));
                }
                RuleManagement rules = new RuleManagement(storageAccount);
                await rules.SavePredictionSet(name, set);
            }
            catch (Exception ex)
            {
                log.LogError($"SavePredictionSet: Error saving prediction set: {ex}");
                return(new BadRequestObjectResult($"Error saving prediction set: {ex}"));
            }

            return(new OkObjectResult("OK"));
        }
Exemplo n.º 17
0
        public static async Task <IActionResult> GetFunctions(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("GetRuleFunctions: Starting");
            string responseMessage = "";

            try
            {
                string         storageAccount = Common.Helpers.Common.GetStorageKey(req);
                string         source         = Common.Helpers.Common.GetQueryString(req, "name");
                RuleManagement rules          = new RuleManagement(storageAccount);
                responseMessage = await rules.GetFunctions(source);
            }
            catch (Exception ex)
            {
                log.LogError($"GetRuleFunctions: Error getting functions: {ex}");
                return(new BadRequestObjectResult($"Error getting functions: {ex}"));
            }

            return(new OkObjectResult(responseMessage));
        }
Exemplo n.º 18
0
        public static async Task <IActionResult> DeleteRule(
            [HttpTrigger(AuthorizationLevel.Function, "delete", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("DeleteDataRule: Starting");
            try
            {
                string name = req.Query["name"];
                if (string.IsNullOrEmpty(name))
                {
                    log.LogError("DeleteDataRule: error, source name is missing");
                    return(new BadRequestObjectResult("Error missing source name"));
                }

                string strId = req.Query["id"];
                int?   tmpId = strId.GetIntFromString();
                if (tmpId == null)
                {
                    log.LogError("DeleteDataRule: error, rule id name is missing");
                    return(new BadRequestObjectResult("Error missing rule id"));
                }
                int id = tmpId.GetValueOrDefault();

                string         storageAccount = Common.Helpers.Common.GetStorageKey(req);
                RuleManagement rules          = new RuleManagement(storageAccount);
                await rules.DeleteRule(name, id);
            }
            catch (Exception ex)
            {
                log.LogError($"DeleteDataRule: {ex}");
                return(new BadRequestObjectResult($"Error deleting rule: {ex}"));
            }

            log.LogInformation("DeleteDataRule: Complete");
            return(new OkObjectResult("OK"));
        }