public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, [Table("FunctionExecutions", Connection = "StorageConnectionString")] CloudTable table, ExecutionContext executionContext, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); // query table storage for all entries (you might want to restrict the query to the last day etc) TableQuery <FunctionExecution> query = new TableQuery <FunctionExecution>(); TableQuerySegment <FunctionExecution> data = await table.ExecuteQuerySegmentedAsync(query, null); // get the last function execution by ordering by Timestamp FunctionExecution lastFunctionExecution = data.OrderByDescending(r => r.Timestamp).FirstOrDefault(); DateTimeOffset?begin = lastFunctionExecution?.Timestamp; DateTime end = DateTime.UtcNow; // call off to ThirdPartyClient // log successful execution to table storage TableOperation insertOperation = TableOperation.Insert(new FunctionExecution { PartitionKey = executionContext.InvocationId.ToString(), // using the InvocationId of the function so you can relate executions if needed RowKey = Guid.NewGuid().ToString(), Timestamp = DateTimeOffset.UtcNow, // set the Timestamp to now as the function has been successful FunctionName = "HttpTriggeredFunction" // optional but you might want to save the function name in your case FunctionNames.GetInvoicesAsync }); await table.ExecuteAsync(insertOperation); return(new OkObjectResult(null)); }
private void CreateFunctionExecution(object sender, EventArgs args) { pol.ApplyElement apply = new pol.ApplyElement("urn:new_function", new pol.IExpressionReadWriteCollection(), XacmlVersion.Version11); FunctionExecution node = new FunctionExecution(apply); tvwCondition.Nodes.Add(node); _condition.Arguments.Add(apply); }
//执行函数校验 private ExpressionToken VerifyFunction(ExpressionToken funtionToken, Stack <ExpressionToken> verifyStack) { if (!(verifyStack.Count == 0)) { bool doPop = true; var args = new List <BaseMetadata>(); ExpressionToken parameter = null; //弹出函数的参数,直到遇到"("时终止 while (doPop && !(verifyStack.Count == 0)) { parameter = verifyStack.Pop(); if (ExpressionToken.ETokenType.ETOKEN_TYPE_CONSTANT == parameter.TokenType) { //常量 args.Add(parameter.Constant); } else if (ExpressionToken.ETokenType.ETOKEN_TYPE_VARIABLE == parameter.TokenType) { args.Add(parameter.Variable); } else if ("(".Equals(parameter.GetSplitor())) { doPop = false; } else { //没有找到应该存在的右括号 throw new IllegalExpressionException("表达式不合法,函数\"" + funtionToken.TokenText + "\"遇到非法参数" + parameter.ToString() + ";位置:" + parameter.StartPosition , funtionToken.ToString() , funtionToken.StartPosition); } } if (doPop && (verifyStack.Count == 0)) { //操作栈以空,没有找到函数的左括号( throw new IllegalExpressionException("表达式不合法,函数\"" + funtionToken.TokenText + "\"缺少\"(\";位置:" + (funtionToken.StartPosition + funtionToken.ToString().Length) , funtionToken.ToString() , funtionToken.StartPosition); } //校验函数 var arguments = new BaseMetadata[args.Count]; arguments = args.ToArray(); Constant result = FunctionExecution.Verify(funtionToken.TokenText, funtionToken.StartPosition, arguments); return(ExpressionToken.CreateConstantToken(result)); } else { //没有找到应该存在的右括号 throw new IllegalExpressionException("表达式不合法,函数\"" + funtionToken.TokenText + "\"不完整" , funtionToken.ToString() , funtionToken.StartPosition); } }
private void tvwCondition_AfterSelect(object sender, TreeViewEventArgs e) { if (e.Node is FunctionExecution) { grpElement.Text = "Function execution"; FunctionExecution node = (FunctionExecution)e.Node; txtValue.Visible = false; cmbInternalFunctions.Visible = true; cmbInternalFunctions.SelectedIndex = cmbInternalFunctions.FindStringExact(node.ApplyBaseDefinition.FunctionId); label2.Text = "FunctionId:"; cmbDataType.Enabled = false; } else if (e.Node is FunctionParameter) { grpElement.Text = "Function parameter"; FunctionParameter node = (FunctionParameter)e.Node; txtValue.Visible = false; cmbInternalFunctions.Visible = true; cmbInternalFunctions.SelectedIndex = cmbInternalFunctions.FindStringExact(node.FunctionDefinition.FunctionId); label2.Text = "FunctionId:"; cmbDataType.Enabled = false; } else if (e.Node is AttributeValue) { grpElement.Text = "Attribute value"; AttributeValue node = (AttributeValue)e.Node; txtValue.Visible = true; cmbInternalFunctions.Visible = false; txtValue.Text = node.AttributeValueDefinition.Contents; label2.Text = "Value:"; cmbDataType.Enabled = true; cmbDataType.SelectedIndex = cmbDataType.FindStringExact(node.AttributeValueDefinition.DataType); } else if (e.Node is AttributeDesignator) { grpElement.Text = "Attribute designator"; AttributeDesignator node = (AttributeDesignator)e.Node; txtValue.Visible = true; cmbInternalFunctions.Visible = false; txtValue.Text = node.AttributeDesignatorDefinition.AttributeId; label2.Text = "AttributeId:"; cmbDataType.Enabled = true; cmbDataType.SelectedIndex = cmbDataType.FindStringExact(node.AttributeDesignatorDefinition.DataType); } else if (e.Node is AttributeSelector) { grpElement.Text = "Attribute selector"; AttributeSelector node = (AttributeSelector)e.Node; txtValue.Visible = true; cmbInternalFunctions.Visible = false; txtValue.Text = node.AttributeSelectorDefinition.RequestContextPath; label2.Text = "XPath:"; cmbDataType.Enabled = false; } }
private void CreateAttributeSelectorFromFunction(object sender, EventArgs args) { FunctionExecution func = (FunctionExecution)tvwCondition.SelectedNode; pol.ApplyBaseReadWrite parentApply = func.ApplyBaseDefinition; pol.AttributeSelectorElement attr = new pol.AttributeSelectorElement(string.Empty, false, "TODO: Add XPath", XacmlVersion.Version11); AttributeSelector node = new AttributeSelector(attr); func.Nodes.Add(node); parentApply.Arguments.Add(attr); }
private void CreateAttributeValueFromFunction(object sender, EventArgs args) { FunctionExecution func = (FunctionExecution)tvwCondition.SelectedNode; pol.ApplyBaseReadWrite parentApply = func.ApplyBaseDefinition; pol.AttributeValueElementReadWrite attr = new pol.AttributeValueElementReadWrite(InternalDataTypes.XsdString, "TODO: Add content", XacmlVersion.Version11); AttributeValue node = new AttributeValue(attr); func.Nodes.Add(node); parentApply.Arguments.Add(attr); }
private void CreateFunctionParameterFromFunction(object sender, EventArgs args) { FunctionExecution func = (FunctionExecution)tvwCondition.SelectedNode; pol.ApplyBaseReadWrite parentApply = func.ApplyBaseDefinition; pol.FunctionElementReadWrite function = new pol.FunctionElementReadWrite("urn:new_function_param", XacmlVersion.Version11); FunctionParameter node = new FunctionParameter(function); func.Nodes.Add(node); parentApply.Arguments.Add(function); }
private void CreateFunctionExecutionFromFunction(object sender, EventArgs args) { FunctionExecution func = (FunctionExecution)tvwCondition.SelectedNode; pol.ApplyBaseReadWrite parentApply = func.ApplyBaseDefinition; pol.ApplyElement apply = new pol.ApplyElement("urn:new_function", new pol.IExpressionReadWriteCollection(), XacmlVersion.Version11); FunctionExecution node = new FunctionExecution(apply); func.Nodes.Add(node); parentApply.Arguments.Add(apply); }
public Reference(ExpressionToken token, Constant[] args) { this.Token = token; this.Arguments = args; //记录Reference实际的数据类型 if (ExpressionToken.ETokenType.ETOKEN_TYPE_FUNCTION == token.TokenType) { Constant result = FunctionExecution.Verify(token.TokenText, token.StartPosition, args); dataType = result.GetDataType(); } else if (ExpressionToken.ETokenType.ETOKEN_TYPE_OPERATOR == token.TokenType) { Operator op = token.Op; Constant result = op.Verify(token.StartPosition, args); dataType = result.GetDataType(); } }
/** * 执行引用对象指待的表达式(操作符或者函数) * @return */ public Constant Execute() { if (ETokenType.ETOKEN_TYPE_OPERATOR == Token.TokenType) { //执行操作符 Operator op = Token.Op; return(op.Execute(Arguments)); } else if (ETokenType.ETOKEN_TYPE_FUNCTION == Token.TokenType) { //执行函数 return(FunctionExecution.Execute(Token.TokenText, Token.StartPosition, Arguments)); } else { throw new IllegalExpressionException("不支持的Reference执行异常"); } }
private void mniDelete_Click(object sender, EventArgs e) { FunctionExecution functionNode = (FunctionExecution)tvwCondition.SelectedNode.Parent; NoBoldNode node = (NoBoldNode)tvwCondition.SelectedNode; if (node is FunctionExecution) { FunctionExecution funcNode = ((FunctionExecution)node); int index = functionNode.ApplyBaseDefinition.Arguments.GetIndex((pol.ApplyElement)funcNode.ApplyBaseDefinition); functionNode.ApplyBaseDefinition.Arguments.RemoveAt(index); functionNode.Nodes.Remove(funcNode); } else if (node is FunctionParameter) { FunctionParameter funcNode = ((FunctionParameter)node); int index = functionNode.ApplyBaseDefinition.Arguments.GetIndex(funcNode.FunctionDefinition); functionNode.ApplyBaseDefinition.Arguments.RemoveAt(index); functionNode.Nodes.Remove(funcNode); } else if (node is AttributeValue) { AttributeValue attNode = ((AttributeValue)node); int index = functionNode.ApplyBaseDefinition.Arguments.GetIndex(attNode.AttributeValueDefinition); functionNode.ApplyBaseDefinition.Arguments.RemoveAt(index); functionNode.Nodes.Remove(attNode); } else if (node is AttributeDesignator) { AttributeDesignator attNode = ((AttributeDesignator)node); int index = functionNode.ApplyBaseDefinition.Arguments.GetIndex(attNode.AttributeDesignatorDefinition); functionNode.ApplyBaseDefinition.Arguments.RemoveAt(index); functionNode.Nodes.Remove(attNode); } else if (node is AttributeSelector) { AttributeSelector attNode = ((AttributeSelector)node); int index = functionNode.ApplyBaseDefinition.Arguments.GetIndex(attNode.AttributeSelectorDefinition); functionNode.ApplyBaseDefinition.Arguments.RemoveAt(index); functionNode.Nodes.Remove(attNode); } }
private void tvwCondition_BeforeSelect(object sender, TreeViewCancelEventArgs e) { NoBoldNode node = (NoBoldNode)tvwCondition.SelectedNode; if (node is FunctionExecution) { FunctionExecution funcNode = ((FunctionExecution)node); funcNode.ApplyBaseDefinition.FunctionId = cmbInternalFunctions.Text; tvwCondition.SelectedNode = funcNode; tvwCondition.SelectedNode.Text = "[" + "dataType" + "] " + funcNode.ApplyBaseDefinition.FunctionId; } else if (node is FunctionParameter) { FunctionParameter funcNode = ((FunctionParameter)node); funcNode.FunctionDefinition.FunctionId = cmbInternalFunctions.Text; tvwCondition.SelectedNode = funcNode; tvwCondition.SelectedNode.Text = "Function: " + funcNode.FunctionDefinition.FunctionId;; } else if (node is AttributeValue) { AttributeValue attNode = ((AttributeValue)node); attNode.AttributeValueDefinition.Value = txtValue.Text; attNode.AttributeValueDefinition.DataType = cmbDataType.Text; tvwCondition.SelectedNode = attNode; tvwCondition.SelectedNode.Text = "[" + attNode.AttributeValueDefinition.DataType + "] " + attNode.AttributeValueDefinition.Contents; } else if (node is AttributeDesignator) { AttributeDesignator attNode = ((AttributeDesignator)node); attNode.AttributeDesignatorDefinition.AttributeId = txtValue.Text; attNode.AttributeDesignatorDefinition.DataType = cmbDataType.Text; tvwCondition.SelectedNode = attNode; tvwCondition.SelectedNode.Text = "[" + attNode.AttributeDesignatorDefinition.DataType + "]:" + attNode.AttributeDesignatorDefinition.AttributeId; } else if (node is AttributeSelector) { AttributeSelector attNode = ((AttributeSelector)node); attNode.AttributeSelectorDefinition.RequestContextPath = txtValue.Text; tvwCondition.SelectedNode = attNode; tvwCondition.SelectedNode.Text = "XPath: " + attNode.AttributeSelectorDefinition.RequestContextPath; } }