Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
DropIndex.cs
1using System;
2using System.Threading.Tasks;
7
9{
14 {
15 private ScriptNode name;
16 private SourceDefinition source;
17
27 : base(Start, Length, Expression)
28 {
29 this.name = Name;
30 this.name?.SetParent(this);
31
32 this.source = Source;
33 this.source?.SetParent(this);
34 }
35
40 public override bool IsAsynchronous => true;
41
48 {
49 return this.EvaluateAsync(Variables).Result;
50 }
51
58 public override async Task<IElement> EvaluateAsync(Variables Variables)
59 {
60 IDataSource Source = await this.source.GetSource(Variables);
61 string Name = await InsertValues.GetNameAsync(this.name, Variables);
62
63 if (!await Source.DropIndex(Name))
64 throw new ScriptRuntimeException("Index not found.", this);
65
66 return new StringValue(Name);
67 }
68
76 public override bool ForAllChildNodes(ScriptNodeEventHandler Callback, object State, SearchMethod Order)
77 {
78 if (Order == SearchMethod.DepthFirst)
79 {
80 if (!(this.name?.ForAllChildNodes(Callback, State, Order) ?? true))
81 return false;
82
83 if (!(this.source?.ForAllChildNodes(Callback, State, Order) ?? true))
84 return false;
85 }
86
87 ScriptNode NewNode;
88 bool b;
89
90 if (!(this.name is null))
91 {
92 b = !Callback(this.name, out NewNode, State);
93 if (!(NewNode is null))
94 {
95 this.name = NewNode;
96 this.name.SetParent(this);
97 }
98
99 if (b || (Order == SearchMethod.TreeOrder && !this.name.ForAllChildNodes(Callback, State, Order)))
100 return false;
101 }
102
103 if (!(this.source is null))
104 {
105 b = !Callback(this.source, out NewNode, State);
106 if (!(NewNode is null) && NewNode is SourceDefinition Source2)
107 {
108 this.source = Source2;
109 this.source.SetParent(this);
110 }
111
112 if (b || (Order == SearchMethod.TreeOrder && !this.source.ForAllChildNodes(Callback, State, Order)))
113 return false;
114 }
115
116 if (Order == SearchMethod.BreadthFirst)
117 {
118 if (!(this.name?.ForAllChildNodes(Callback, State, Order) ?? true))
119 return false;
120
121 if (!(this.source?.ForAllChildNodes(Callback, State, Order) ?? true))
122 return false;
123 }
124
125 return true;
126 }
127
129 public override bool Equals(object obj)
130 {
131 return (obj is DropIndex O &&
132 AreEqual(this.name, O.name) &&
133 AreEqual(this.source, O.source) &&
134 base.Equals(obj));
135 }
136
138 public override int GetHashCode()
139 {
140 int Result = base.GetHashCode();
141 Result ^= Result << 5 ^ GetHashCode(this.name);
142 Result ^= Result << 5 ^ GetHashCode(this.source);
143 return Result;
144 }
145
146 }
147}
Class managing a script expression.
Definition: Expression.cs:39
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
static bool AreEqual(ScriptNode S1, ScriptNode S2)
Compares if two script nodes are equal.
Definition: ScriptNode.cs:275
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
void SetParent(ScriptNode Parent)
Sets the parent node. Can only be used when expression is being parsed.
Definition: ScriptNode.cs:132
Executes an DROP INDEX ... ON ... statement against the object database.
Definition: DropIndex.cs:14
override IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
Definition: DropIndex.cs:47
override bool ForAllChildNodes(ScriptNodeEventHandler Callback, object State, SearchMethod Order)
Calls the callback method for all child nodes.
Definition: DropIndex.cs:76
override bool Equals(object obj)
Definition: DropIndex.cs:129
DropIndex(ScriptNode Name, SourceDefinition Source, int Start, int Length, Expression Expression)
Executes an DROP INDEX ... ON ... statement against the object database.
Definition: DropIndex.cs:26
override async Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node asynchronously, using the variables provided in the Variables collection.
Definition: DropIndex.cs:58
override bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
Definition: DropIndex.cs:40
Executes an INSERT ... VALUES ... statement against the object database.
Definition: InsertValues.cs:16
static async Task< string > GetNameAsync(ScriptNode Node, Variables Variables)
Gets a name from a script node, either by using the name of a variable reference, or evaluating the n...
Abstract base class for source definitions
abstract Task< IDataSource > GetSource(Variables Variables)
Gets the actual data source, from its definition.
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20
Interface for script nodes with asynchronous evaluation
Interface for data sources that can be used in SQL statements.
Definition: IDataSource.cs:13
Task< bool > DropIndex(string Name)
Drops an index from the source.
delegate bool ScriptNodeEventHandler(ScriptNode Node, out ScriptNode NewNode, object State)
Delegate for ScriptNode callback methods.
SearchMethod
Method to traverse the expression structure
Definition: ScriptNode.cs:38