Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ScriptExtensions.cs
1using System.Reflection;
2using Waher.Script;
14
15namespace LegalLab.Extensions
16{
20 public static class ScriptExtensions
21 {
22 private readonly static Assembly scriptContent = typeof(GraphEncoder).Assembly;
23 private readonly static Assembly[] prohibitedAssemblies = new Assembly[]
24 {
25 scriptContent, // Waher.Script.Content
26 typeof(FractalGraph).Assembly, // Waher.Script.Fractals
27 typeof(WhoIs).Assembly, // Waher.Script.Networking
28 typeof(Select).Assembly, // Waher.Script.Persistence
29 typeof(ConnectMsSql).Assembly // Waher.Script.Data
30 };
31
38 public static bool CheckExpressionSafe(this Expression Expression, out ScriptNode Prohibited)
39 {
40 return CheckExpressionSafe(Expression, false, false, false, out Prohibited);
41 }
42
52 public static bool CheckExpressionSafe(this Expression Expression, bool AllowNamedMembers, bool AllowError,
53 bool AllowCustomFunctions, out ScriptNode Prohibited)
54 {
55 ScriptNode Prohibited2 = null;
56 bool Safe = Expression.ForAll((ScriptNode Node, out ScriptNode NewNode, object State) =>
57 {
58 NewNode = null;
59
60 Assembly Assembly = Node.GetType().Assembly;
61
62 foreach (Assembly A in prohibitedAssemblies)
63 {
64 if (A.FullName == Assembly.FullName)
65 {
66 if (A == scriptContent &&
67 (Node is Waher.Script.Content.Functions.Duration ||
68 Node.GetType().Namespace == typeof(Utf8Encode).Namespace))
69 {
70 return true;
71 }
72
73 Prohibited2 = Node;
74 return false;
75 }
76 }
77
78 if ((Node is NamedMember && !AllowNamedMembers) ||
79 (Node is NamedMemberAssignment && !AllowNamedMembers) ||
80 (Node is LambdaDefinition && !AllowCustomFunctions) ||
81 Node is NamedMethodCall ||
82 Node is DynamicFunctionCall ||
83 Node is DynamicMember ||
84 Node is Create ||
85 Node is Destroy ||
86 (Node is Error && !AllowError))
87 {
88 Prohibited2 = Node;
89 return false;
90 }
91
92 return true;
93
94 }, null, SearchMethod.TreeOrder);
95
96 Prohibited = Prohibited2;
97 return Safe;
98 }
99 }
100}
Encodes graphs as images
Definition: GraphEncoder.cs:16
Creates a connection to an external MS SQL database.
Definition: ConnectMsSql.cs:16
Class managing a script expression.
Definition: Expression.cs:39
bool ForAll(ScriptNodeEventHandler Callback, object State, bool DepthFirst)
Calls the callback method for all script nodes defined for the expression.
Definition: Expression.cs:5196
Defines a clickable fractal graph in the complex plane.
Definition: FractalGraph.cs:22
Creates an object of a specific class. The first argument must evaluate to the type that is to be cre...
Definition: Create.cs:17
Destroys a value. If the function references a variable, the variable is also removed.
Definition: Destroy.cs:13
Throws an exception.
Definition: Error.cs:11
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
Makes a WHOIS query regarding an IP address.
Definition: WhoIs.cs:16
Executes a SELECT statement against the object database.
Definition: Select.cs:20
SearchMethod
Method to traverse the expression structure
Definition: ScriptNode.cs:38