コード例 #1
0
        public async Task UpdateFunction(string sourceName, int id, RuleFunctions function)
        {
            ConnectParameters connector = await Common.GetConnectParameters(azureConnectionString, sourceName);

            if (connector.SourceType != "DataBase")
            {
                Exception error = new Exception($"RuleManagement: data source must be a Database type");
                throw error;
            }
            string query = $" where Id = {id}";
            List <RuleFunctions> oldFunction = SelectFunctionByQuery(query, connector.ConnectionString);

            if (oldFunction.Count == 0)
            {
                Exception error = new Exception($"RuleManagement: could not find function");
                throw error;
            }
            else
            {
                string json = JsonConvert.SerializeObject(function, Formatting.Indented);
                using (IDbConnection cnn = new SqlConnection(connector.ConnectionString))
                {
                    var p = new DynamicParameters();
                    p.Add("@json", json);
                    string sql             = "dbo.spUpdateFunctions";
                    int    recordsAffected = cnn.Execute(sql, p, commandType: CommandType.StoredProcedure);
                }
            }
        }
コード例 #2
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"));
        }
コード例 #3
0
        public async Task <string> GetFunction(string sourceName, int id)
        {
            string            result    = "";
            ConnectParameters connector = await Common.GetConnectParameters(azureConnectionString, sourceName);

            RuleFunctions function = await _functionData.GetFunctionFromSP(id, connector.ConnectionString);

            result = JsonConvert.SerializeObject(function, Formatting.Indented);
            return(result);
        }
コード例 #4
0
        private void InsertFunction(RuleFunctions function, string connectionString)
        {
            string json = JsonConvert.SerializeObject(function, Formatting.Indented);

            using (IDbConnection cnn = new SqlConnection(connectionString))
            {
                var p = new DynamicParameters();
                p.Add("@json", json);
                string sql             = "dbo.spInsertFunctions";
                int    recordsAffected = cnn.Execute(sql, p, commandType: CommandType.StoredProcedure);
            }
        }
コード例 #5
0
        private RuleFunctions SelectFunctionByName(string functionName, string connectionString)
        {
            RuleFunctions function = new RuleFunctions();

            using (IDbConnection cnn = new SqlConnection(connectionString))
            {
                string sql       = functionSql + $" where FunctionName = '{functionName}'";
                var    functions = cnn.Query <RuleFunctions>(sql);
                function = functions.FirstOrDefault();
            }
            return(function);
        }
コード例 #6
0
ファイル: Rules.cs プロジェクト: vandresen/DatabaseManager
        public async Task UpdateFunction(RuleFunctions function, string source, int id)
        {
            if (string.IsNullOrEmpty(baseUrl))
            {
                url = $"api/functions/{source}/{id}";
            }
            else
            {
                url = baseUrl.BuildFunctionUrl("UpdateRuleFunction", $"name={source}&id={id}", apiKey);
            }
            var response = await httpService.Put(url, function);

            if (!response.Success)
            {
                throw new ApplicationException(await response.GetBody());
            }
        }
コード例 #7
0
 public async Task <ActionResult <string> > SaveFunction(string source, RuleFunctions function)
 {
     if (function == null)
     {
         return(BadRequest());
     }
     try
     {
         GetStorageAccount();
         RuleManagement rm = new RuleManagement(connectionString);
         await rm.SaveFunction(source, function);
     }
     catch (Exception)
     {
         return(BadRequest());
     }
     return(Ok($"OK"));
 }
コード例 #8
0
        public async Task <RuleModel> GetRuleAndFunction(string sourceName, int id)
        {
            ConnectParameters connector = await Common.GetConnectParameters(azureConnectionString, sourceName);

            RuleModel rule = await _ruleData.GetRuleFromSP(id, connector.ConnectionString);

            IEnumerable <RuleFunctions> functions = await _functionData.GetFunctionsFromSP(connector.ConnectionString);

            RuleFunctions function = functions.FirstOrDefault(x => x.FunctionName == rule.RuleFunction);

            if (function != null)
            {
                if (!string.IsNullOrEmpty(function.FunctionKey))
                {
                    rule.RuleFunction = function.FunctionUrl + "?code=" + function.FunctionKey;
                }
            }
            return(rule);
        }
コード例 #9
0
        public async Task SaveRulesToDatabase(string ruleString, ConnectParameters connector)
        {
            List <RuleFunctions> ruleFunctions = new List <RuleFunctions>();
            string query = "";
            IEnumerable <RuleFunctions> functions = await _functionData.GetFunctionsFromSP(connector.ConnectionString);

            List <RuleModel> rules = JsonConvert.DeserializeObject <List <RuleModel> >(ruleString);

            foreach (var rule in rules)
            {
                string functionType = "";
                if (rule.RuleType == "Validity")
                {
                    functionType = "V";
                }
                if (rule.RuleType == "Predictions")
                {
                    functionType = "P";
                }
                RuleFunctions ruleFunction   = BuildFunctionData(rule.RuleFunction, functionType);
                RuleFunctions functionIsInDB = functions.FirstOrDefault(s => s.FunctionName == ruleFunction.FunctionName);
                if (functionIsInDB == null)
                {
                    RuleFunctions result = ruleFunctions.FirstOrDefault(s => s.FunctionName == ruleFunction.FunctionName);
                    if (result == null)
                    {
                        ruleFunctions.Add(ruleFunction);
                    }
                }
                rule.RuleFunction = ruleFunction.FunctionName;
            }
            await _ruleData.InsertRules(rules, connector.ConnectionString);

            foreach (var function in ruleFunctions)
            {
                InsertFunction(function, connector.ConnectionString);
            }
        }
コード例 #10
0
        private RuleFunctions BuildFunctionData(string ruleFunction, string functionType)
        {
            RuleFunctions rf = new RuleFunctions();
            int           startFunctionName = ruleFunction.IndexOf(@"/api/");

            if (startFunctionName == -1)
            {
                startFunctionName = 0;
            }
            else
            {
                startFunctionName = startFunctionName + 5;
            }

            int    endFunctionName = ruleFunction.IndexOf(@"?");
            string functionKey     = "";

            if (endFunctionName == -1)
            {
                endFunctionName = ruleFunction.Length;
            }
            else
            {
                functionKey = ruleFunction.Substring((endFunctionName + 6));
            }

            int    functionNameLength = endFunctionName - startFunctionName;
            string functionname       = ruleFunction.Substring(startFunctionName, functionNameLength);
            string functionUrl        = ruleFunction.Substring(0, endFunctionName);

            rf.FunctionName = functionname;
            rf.FunctionUrl  = functionUrl;
            rf.FunctionKey  = functionKey;
            rf.FunctionType = functionType;
            return(rf);
        }
コード例 #11
0
        public async Task SaveFunction(string sourceName, RuleFunctions function)
        {
            ConnectParameters connector = await Common.GetConnectParameters(azureConnectionString, sourceName);

            InsertFunction(function, connector.ConnectionString);
        }
コード例 #12
0
 public BasicResolutionChecks_FunctionCall(RuleFunctions ruleFunctions, Being parentBeing)
 {
     this.ruleFunctions = ruleFunctions;
     this.parentBeing   = parentBeing;
 }