Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ConnectOleDb.cs
1using System;
2using System.Data.OleDb;
3using System.Threading.Tasks;
8
10{
15 {
23 public ConnectOleDb(ScriptNode ConnectionString, int Start, int Length, Expression Expression)
24 : base(new ScriptNode[] { ConnectionString }, argumentTypes1Scalar, Start, Length, Expression)
25 {
26 }
27
37 public ConnectOleDb(ScriptNode ConnectionString, ScriptNode UserName, ScriptNode Password, int Start, int Length, Expression Expression)
38 : base(new ScriptNode[] { ConnectionString, UserName, Password }, argumentTypes3Scalar, Start, Length, Expression)
39 {
40 }
41
45 public override string FunctionName => nameof(ConnectOleDb);
46
50 public override string[] DefaultArgumentNames => new string[] { "ConnectionString", "UserName", "Password" };
51
56 public override bool IsAsynchronous => true;
57
65 {
66 return this.EvaluateAsync(Arguments, Variables).Result;
67 }
68
75 public override async Task<IElement> EvaluateAsync(IElement[] Arguments, Variables Variables)
76 {
77 string ConnectionString = Arguments[0].AssociatedObjectValue?.ToString() ?? string.Empty;
78 OleDbConnection Connection;
79
80 switch (Arguments.Length)
81 {
82 case 1:
83 default:
84 Connection = new OleDbConnection(ConnectionString);
85 break;
86
87 case 3:
88 string UserName = Arguments[1].AssociatedObjectValue?.ToString() ?? string.Empty;
89 string Password = Arguments[2].AssociatedObjectValue?.ToString() ?? string.Empty;
90
91 ConnectionString = ConnectionString.Trim();
92 if (!ConnectionString.EndsWith(";"))
93 ConnectionString += ";";
94
95 ConnectionString += "User Id=" + UserName + ";Password=" + Password + ";";
96 Connection = new OleDbConnection(ConnectionString);
97 break;
98 }
99
100 await Connection.OpenAsync();
101
102 return new ObjectValue(new OleDbDatabase(Connection));
103 }
104 }
105}
Creates a connection to an external OLE DB database.
Definition: ConnectOleDb.cs:15
override string FunctionName
Name of the function
Definition: ConnectOleDb.cs:45
override string[] DefaultArgumentNames
Default Argument names
Definition: ConnectOleDb.cs:50
ConnectOleDb(ScriptNode ConnectionString, int Start, int Length, Expression Expression)
Creates a connection to an external OLE DB database.
Definition: ConnectOleDb.cs:23
override IElement Evaluate(IElement[] Arguments, Variables Variables)
Evaluates the function.
Definition: ConnectOleDb.cs:64
override async Task< IElement > EvaluateAsync(IElement[] Arguments, Variables Variables)
Evaluates the function.
Definition: ConnectOleDb.cs:75
ConnectOleDb(ScriptNode ConnectionString, ScriptNode UserName, ScriptNode Password, int Start, int Length, Expression Expression)
Creates a connection to an external OLE DB database.
Definition: ConnectOleDb.cs:37
override bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
Definition: ConnectOleDb.cs:56
Manages an OLE DB SQL Server connection
Class managing a script expression.
Definition: Expression.cs:39
Base class for multivariate funcions.
ScriptNode[] Arguments
Function arguments.
static readonly ArgumentType[] argumentTypes3Scalar
Three scalar parameters.
static readonly ArgumentType[] argumentTypes1Scalar
One scalar parameter.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
override string ToString()
Definition: ScriptNode.cs:359
Expression Expression
Expression of which the node is a part.
Definition: ScriptNode.cs:177
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20