public void Validate_FunctionReference_SelectionSetNotEmpty_ShouldFail() { //arrange var functionName = "fake"; var workflow = WorkflowDefinition.Create("fake", "fake", "fake") .AddFunction(function => function .WithName(functionName) .OfType(FunctionType.Rest)) .StartsWith("fake", flow => flow .Execute(action => action.Invoke(functionName))) .End() .Build(); var functionRef = new FunctionReference() { RefName = functionName, SelectionSet = "{ id, name }" }; //act var result = new FunctionReferenceValidator(workflow).Validate(functionRef); //assert result.Should() .NotBeNull(); result.Errors.Should() .NotBeNullOrEmpty() .And.Contain(e => e.PropertyName == nameof(FunctionReference.SelectionSet)); }
private static FunctionReference ParseLink(XElement data) { var link = new FunctionReference(); link.LoadXml(data); return(link); }
protected internal override void CheckSemantics(AstHelper astHelper) { FunctionName.CheckSemantics(astHelper); foreach (Expression expression in Parameters) { expression.CheckSemantics(astHelper); } Type[] parameterTypes = Parameters.Select(param => param.Type).ToArray(); if (!astHelper.Errors.Check(new FunctionNotDefinedError(FunctionName.Name, parameterTypes, astHelper.Functions, Start))) { FunctionReference functionReference = astHelper.Functions[FunctionName.Name, parameterTypes]; _type = functionReference.ReturnType; _pointer = functionReference.Function; } else { // if there is any error _type = typeof(Null); _pointer = MAst.Empty(); } }
private string TryFormatAsFunctionReference(FunctionReference functionReference, bool excludeAlias) { if (ReferenceEquals(functionReference, null)) { return(null); } var sqlName = _functionNameConverter.ConvertToSqlName(functionReference.Name); string formatted; if (sqlName.Equals("countdistinct", StringComparison.OrdinalIgnoreCase)) { formatted = string.Format("count(distinct {0})", FormatColumnClause(functionReference.Argument)); } else { formatted = string.Format("{0}({1}{2})", sqlName, FormatColumnClause(functionReference.Argument), FormatAdditionalArguments(functionReference.AdditionalArguments)); } if ((!excludeAlias) && functionReference.GetAlias() != null) { formatted = string.Format("{0} AS {1}", formatted, _schema.QuoteObjectName(functionReference.GetAlias())); } return(formatted); }
private void OnSurfaceMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if (_sourceConnector != null) { var targetConnector = VisualTreeHelper.FindElementsInHostCoordinates(e.GetPosition(null), _surface).OfType <ObjectConnector>().FirstOrDefault(); if (targetConnector != null && targetConnector != _sourceConnector && targetConnector.DesignerControl != _sourceConnector.DesignerControl && CanFinishConnection(targetConnector)) { var sourceId = _sourceConnector.DesignerControl.Id; var targetId = targetConnector.DesignerControl.Id; var workflowLink = new FunctionReference { SourceId = sourceId, SourcePin = _sourceConnector.PinName, TargetId = targetId, TargetPin = targetConnector.PinName }; Workflow.AddItem(workflowLink); } } RemoveConnectionLine(); if (SelectedItemHost != null) { SelectedItemHost.ReleaseMouseCapture(); _dragStarted = false; } }
public override void TranslateFunctionInvocation(TranspilerContext sb, FunctionReference funcRef, Expression[] args) { this.TranslateFunctionReference(sb, funcRef); sb.Append('('); this.TranslateCommaDelimitedExpressions(sb, args); sb.Append(')'); }
private string TryFormatAsFunctionReference(FunctionReference functionReference) { if (ReferenceEquals(functionReference, null)) { return(null); } var odataName = _functionNameConverter.ConvertToODataName(functionReference.Name); var columnArgument = FormatColumnClause(functionReference.Argument); if (functionReference.AdditionalArguments.Any()) { var additionalArguments = FormatAdditionalArguments(functionReference.AdditionalArguments); if (odataName == "substringof") { return(string.Format("{0}({1},{2})", odataName, additionalArguments, columnArgument)); } else { return(string.Format("{0}({1},{2})", odataName, columnArgument, additionalArguments)); } } else { return(string.Format("{0}({1})", odataName, columnArgument)); } }
public static void Compile(ParserContext parser, ByteBuffer buffer, FunctionReference funcRef, bool outputUsed) { ByteCodeCompiler.EnsureUsed(funcRef, outputUsed); FunctionDefinition funcDef = funcRef.FunctionDefinition; int classIdStaticCheck = 0; int type = 0; if (funcDef.Owner is ClassDefinition) { if (funcDef.Modifiers.HasStatic) { classIdStaticCheck = ((ClassDefinition)funcDef.Owner).ClassID; type = 2; } else { type = 1; } } buffer.Add(funcRef.FirstToken, OpCode.PUSH_FUNC_REF, funcDef.FunctionID, type, classIdStaticCheck); }
protected internal override void CheckSemantics(AstHelper astHelper) { FunctionName.CheckSemantics(astHelper); // initialize the scopes for each one of the arguments var scopes = new AstHelper[Args.Count()]; for (int i = 0; i < scopes.Length; scopes[i++] = astHelper.CreateChild(expecting: true)) { } foreach (var item in Args.Zip(scopes, (arg, scope) => new { arg, scope })) { item.arg.CheckSemantics(item.scope); } Type[] argTypes = (from arg in Args select arg.Type).ToArray(); if (astHelper.Errors.Check(new FunctionNotDefinedError(FunctionName.Name, argTypes, astHelper.Functions, Start))) { return; } _pointer = astHelper.Functions[FunctionName.Name, argTypes]; // SPEC: The following are legal: function f(p:rec) = f(nil) // for that reason the expected type for each one of the arguments is the // type of the function argument (in the definition) foreach (var item in _pointer.ArgTypes.Zip(scopes, (type, scope) => new { type, scope })) { item.scope.Expecting.Type = item.type; } }
public void RemoveItem(FunctionReference item) { if (item == null) { return; } Workflow.RemoveItem(item); }
public BinaryExpression(int start, int length, Expression a, FunctionReference op, Expression b) : base(start, length) { A = a; Operator = op; B = b; A.SetParent(this); B.SetParent(this); Operator.SetParent(this); }
public void return_function_implemented_if_added() { var scope = new FunctionScope(); var functionReference = new FunctionReference(null, typeof(void)); scope.Add("Foo", functionReference); FunctionReference function = scope["Foo"]; Assert.AreSame(functionReference, function); }
private static bool AreEquivalentReferences(FunctionReference reference1, FunctionReference reference2) { if (reference1.IsNull()) { return(reference2.IsNull()); } if (reference2.IsNull()) { return(false); } return(reference1.Name == reference2.Name && reference1.Argument == reference2.Argument); }
private string TryFormatAsFunctionReference(FunctionReference functionReference) { if (ReferenceEquals(functionReference, null)) return null; var sqlName = _functionNameConverter.ConvertToSqlName(functionReference.Name); return functionReference.GetAlias() == null ? string.Format("{0}({1}{2})", sqlName, FormatColumnClause(functionReference.Argument), FormatAdditionalArguments(functionReference.AdditionalArguments)) : string.Format("{0}({1}) AS {2}", sqlName, FormatColumnClause(functionReference.Argument), _schema.QuoteObjectName(functionReference.GetAlias())); }
public void return_same_function_when_requested_two_times() { var scope = new FunctionScope(); scope.Add("Foo", new FunctionReference(null, typeof(void))); // request for function "Foo()" FunctionReference function = scope["Foo"]; FunctionReference function1 = scope["Foo"]; Assert.AreSame(function, function1); }
public override void VisitChildren(AstVisitor visitor) { if (HasExpression) { Expression.Accept(visitor); } LiteralBoolean?.Accept(visitor); LiteralNumeric?.Accept(visitor); LiteralString?.Accept(visitor); VariableReference?.Accept(visitor); FunctionReference?.Accept(visitor); FieldReference?.Accept(visitor); }
public LinkHost(UIElement surface, FunctionReference workflowLink, ObjectConnector source, ObjectConnector target, Orientation orientation) { Stroke = _commonBrush; StrokeThickness = 2; _workflowLink = workflowLink; _surface = surface; _source = source; _target = target; _orientation = orientation; InitializeGeometry(); }
public void resolves_function_wih_same_number_of_parameters() { var scope = new FunctionScope(); ConstantExpression function1 = Expression.Constant(1); ConstantExpression function2 = Expression.Constant(2); scope.Add("f1", new FunctionReference(function1, typeof(void), typeof(string))); scope.Add("f1", new FunctionReference(function2, typeof(void), typeof(int))); FunctionReference result = scope["f1", typeof(int)]; Assert.AreSame(function2, result.Function); }
public void resolves_function_when_called_with_nil_parameter_and_different_number_of_args() { var scope = new FunctionScope(); ConstantExpression function1 = Expression.Constant(1); ConstantExpression function2 = Expression.Constant(2); scope.Add("f1", new FunctionReference(function1, typeof(void))); scope.Add("f1", new FunctionReference(function2, typeof(void), typeof(string))); FunctionReference result = scope["f1", typeof(Null)]; Assert.AreSame(function2, result.Function); }
public void resolves_correct_function_with_different_arguments_returns_function_with_no_args() { var scope = new FunctionScope(); ConstantExpression function1 = Expression.Constant(1); ConstantExpression function2 = Expression.Constant(2); scope.Add("f1", new FunctionReference(function1, typeof(void))); scope.Add("f1", new FunctionReference(function2, typeof(void), typeof(int))); FunctionReference result = scope["f1"]; Assert.AreSame(function1, result.Function); }
private string TryFormatAsFunctionReference(FunctionReference functionReference) { if (ReferenceEquals(functionReference, null)) { return(null); } var sqlName = _functionNameConverter.ConvertToSqlName(functionReference.Name); return(functionReference.Alias == null ? string.Format("{0}({1}{2})", sqlName, FormatColumnClause(functionReference.Argument), FormatAdditionalArguments(functionReference.AdditionalArguments)) : string.Format("{0}({1}) AS {2}", sqlName, FormatColumnClause(functionReference.Argument), _schema.QuoteObjectName(functionReference.Alias))); }
private string GetResolvedFunctionName(FunctionReference function) { if (function.IsSystem) { // This is a built-in function return(function.SystemFunctionName.ToUpperInvariant()); } else if (function.DatabaseObject != null) { // If it is linked up to the schema already return(GetResolvedFunctionName(function.DatabaseObject.DatabaseName, function.DatabaseObject.SchemaName, function.DatabaseObject.ObjectName)); } else { // If it's not resolved yet against the schema return(GetResolvedFunctionName(function.DatabaseName, function.SchemaName, function.DatabaseObjectName)); } }
public void Validate_FunctionReference_NameNotSet_ShouldFail() { //arrange var workflow = WorkflowDefinition.Create("fake", "fake", "fake") .StartsWith("fake", flow => flow.Inject(new { })) .End() .Build(); var functionRef = new FunctionReference(); //act var result = new FunctionReferenceValidator(workflow).Validate(functionRef); //assert result.Should() .NotBeNull(); result.Errors.Should() .NotBeNullOrEmpty() .And.Contain(e => e.PropertyName == nameof(FunctionReference.RefName)); }
private string TryFormatAsFunctionReference(FunctionReference functionReference, bool excludeAlias) { if (ReferenceEquals(functionReference, null)) { return(null); } var sqlName = _functionNameConverter.ConvertToSqlName(functionReference.Name); if (excludeAlias || functionReference.GetAlias() == null) { return(string.Format("{0}({1}{2})", sqlName, FormatColumnClause(functionReference.Argument), FormatAdditionalArguments(functionReference.AdditionalArguments))); } return(string.Format("{0}({1}{2}) AS {3}", sqlName, FormatColumnClause(functionReference.Argument), FormatAdditionalArguments(functionReference.AdditionalArguments), _schema.QuoteObjectName(functionReference.GetAlias()))); }
public void observe_variable(string variable_name, Godot.Object gd_object, string method_name) { if (story == null) { PushNullStoryError(); return; } try { var instanceId = (int)gd_object.Call("get_instance_id"); var funcRef = GD.FuncRef(gd_object, method_name); Ink.Runtime.Story.VariableObserver lambda = (string variableName, object value) => { funcRef.CallFuncv(new Godot.Collections.Array() { variableName, value }); }; var functionReference = new FunctionReference(instanceId, method_name, lambda); if (observers.TryGetValue(variable_name, out List <FunctionReference> referenceList)) { referenceList.Append(functionReference); } else { observers[variable_name] = new List <FunctionReference> () { functionReference }; } story.ObserveVariable(variable_name, lambda); } catch (Exception e) { HandleException(e); } }
public void FunctionReferenceWithIndexCanBeEncodedAndDecoded() { var reference = new FunctionReference( "cidrsubnets", new List <object> { "10.0.0.0/20", 8, 8, 8 }, 1); var jtoken = JObject.Parse(json); var property = (JProperty)jtoken.SelectToken("Property")?.Parent; property.Value = reference.ToJConstructor(); var json1 = jtoken.ToString(); var token1 = JObject.Parse(jtoken.ToString(Formatting.None)); var con = (JConstructor)token1.SelectToken("Property"); var outReference = Reference.FromJConstructor(con); outReference.ReferenceExpression.Should().Be(reference.ReferenceExpression); }
public void SelectLengthShouldUseLengthFunction() { var tableRef = new ObjectReference("FooTable"); var function = new FunctionReference("Length", new ObjectReference("Name", tableRef)).As("NameLength"); var selectClause = new SelectClause(new SimpleReference[] { new ObjectReference("Name", tableRef), function }); var runner = new DictionaryQueryRunner(SelectSource(), selectClause); var actual = runner.Run().ToList(); Assert.AreEqual(4, actual.Count); Assert.AreEqual(2, actual[0].Count); Assert.AreEqual("Alice", actual[0]["Name"]); Assert.AreEqual(5, actual[0]["NameLength"]); Assert.AreEqual(2, actual[1].Count); Assert.AreEqual("Bob", actual[1]["Name"]); Assert.AreEqual(3, actual[1]["NameLength"]); Assert.AreEqual(2, actual[2].Count); Assert.AreEqual("Charlie", actual[2]["Name"]); Assert.AreEqual(7, actual[2]["NameLength"]); Assert.AreEqual(2, actual[3].Count); Assert.AreEqual("David", actual[3]["Name"]); Assert.AreEqual(5, actual[3]["NameLength"]); }
// Generally this is used with the name resolver. So for example, you have a refernce to a ClassDefinition // instance from the resolver, but you want to turn it into a ClassReference instance. // TODO: put this in a method on these classes and implement an interface. The function signatures are all close enough. public static Expression ConvertStaticReferenceToExpression(TopLevelEntity item, Token primaryToken, Node owner) { Expression output = null; TopLevelEntity referencedEntity = null; if (item is ClassDefinition) { ClassDefinition classDef = (ClassDefinition)item; output = new ClassReference(primaryToken, classDef, owner); referencedEntity = classDef; } else if (item is EnumDefinition) { EnumDefinition enumDef = (EnumDefinition)item; output = new EnumReference(primaryToken, enumDef, owner); referencedEntity = enumDef; } else if (item is ConstDefinition) { ConstDefinition constDef = (ConstDefinition)item; output = new ConstReference(primaryToken, constDef, owner); referencedEntity = constDef; } else if (item is FunctionDefinition) { FunctionDefinition funcDef = (FunctionDefinition)item; output = new FunctionReference(primaryToken, funcDef, owner); referencedEntity = funcDef; } else { throw new InvalidOperationException(); } Node.EnsureAccessIsAllowed(primaryToken, owner, referencedEntity); return(output); }
public void FunctionReferenceCanBeEncodedAndDecoded() { var reference = new FunctionReference( "join", new object[] { "-", new List <object> { "a", new InputVariableReference("my_variable").ToJConstructor(), "b" } }); var jtoken = JObject.Parse(json); var property = (JProperty)jtoken.SelectToken("Property")?.Parent; property.Value = reference.ToJConstructor(); var json1 = jtoken.ToString(); var token1 = JObject.Parse(jtoken.ToString(Formatting.None)); var con = (JConstructor)token1.SelectToken("Property"); var outReference = Reference.FromJConstructor(con); outReference.ReferenceExpression.Should().Be(reference.ReferenceExpression); }
private void ProcessNewLink(FunctionReference link) { if (link == null) { return; } var sourceHost = _surface.Children.OfType <ActivityHost>().FirstOrDefault(c => c.Id == link.SourceId); var targetHost = _surface.Children.OfType <ActivityHost>().FirstOrDefault(c => c.Id == link.TargetId); var sourceConnector = sourceHost.View.FindConnectorByName(link.SourcePin); var targetConnector = targetHost.View.FindConnectorByName(link.TargetPin); var conn = new LinkHost(_surface, link, sourceConnector, targetConnector, Orientation.Vertical); // TODO: outgoing links should be also kept by connector? sourceHost.OutgoingLinks.Add(conn); targetHost.OutgoingLinks.Add(conn); // TODO: temp hack sourceConnector.HasOutgoingConnections = true; targetConnector.HasIncomingConnections = true; _surface.Children.Add(conn); }
private void ProcessDeletedLink(FunctionReference link) { if (link == null) { return; } var host = _surface.Children.OfType <LinkHost>().FirstOrDefault(l => l.Id == link.Id); if (host == null) { return; } // TODO: temp hack host.Source.HasOutgoingConnections = false; host.Target.HasIncomingConnections = false; // TODO: Denis: find out more structured way host.Source.DesignerControl.OutgoingLinks.Remove(host); host.Target.DesignerControl.IncomingLinks.Remove(host); _surface.Children.Remove(host); }
private string TryFormatAsFunctionReference(FunctionReference functionReference, bool excludeAlias) { if (ReferenceEquals(functionReference, null)) return null; var sqlName = _functionNameConverter.ConvertToSqlName(functionReference.Name); string formatted; if (sqlName.Equals("countdistinct", StringComparison.OrdinalIgnoreCase)) { formatted = string.Format("count(distinct {0})", FormatColumnClause(functionReference.Argument)); } else { formatted = string.Format("{0}({1}{2})", sqlName, FormatColumnClause(functionReference.Argument), FormatAdditionalArguments(functionReference.AdditionalArguments)); } if ((!excludeAlias) && functionReference.GetAlias() != null) { formatted = string.Format("{0} AS {1}", formatted, _schema.QuoteObjectName(functionReference.GetAlias())); } return formatted; }
public AggregateValueResolver(FunctionReference reference) { _reference = reference; _argumentResolver = Create(reference.Argument); _handler = FunctionHandlers.Get(reference.Name); }
private ODataExpression Convert(FunctionReference function) { return ODataDynamic.ExpressionFromFunction(function.Name, function.Argument.GetAliasOrName(), function.AdditionalArguments); }
private string GetResolvedFunctionName(FunctionReference function) { if (!function.IsUdf) { return function.GetFullyResolvedName(); } else { if (function.DatabaseObject != null) { return function.DatabaseObject.GetFullyResolvedName(); } else { string res = String.Empty; // If it's not resolved yet if (function.DatabaseName != null) res += QuoteIdentifier(function.DatabaseName) + "."; if (function.SchemaName != null) res += QuoteIdentifier(function.SchemaName) + "."; if (function.DatabaseObjectName != null) res += QuoteIdentifier(function.DatabaseObjectName); return res; } } }
protected internal FunctionValueResolver(FunctionReference reference) { _reference = reference; _argumentResolver = Create(_reference.Argument); }
private string QuoteFunctionReferenceName(FunctionReference function) { string res = String.Empty; if (!function.IsUdf) { throw new NotImplementedException(); } else { if (function.DatabaseObject != null) { if (function.DatabaseObject.ObjectName != null) res += QuoteIdentifier(function.DatabaseObject.ObjectName); } else { if (function.DatabaseObjectName != null) res += QuoteIdentifier(function.DatabaseObjectName); } } return res; }