Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Post.cs
1using System;
2using System.Collections.Generic;
3using System.Security.Cryptography.X509Certificates;
4using System.Threading.Tasks;
5using Waher.Content;
9
11{
16 {
26 : base(new ScriptNode[] { Url, Data }, new ArgumentType[] { ArgumentType.Scalar, ArgumentType.Normal }, Start, Length, Expression)
27 {
28 }
29
39 public Post(ScriptNode Url, ScriptNode Data, ScriptNode Headers, int Start, int Length, Expression Expression)
40 : base(new ScriptNode[] { Url, Data, Headers }, new ArgumentType[] { ArgumentType.Scalar, ArgumentType.Normal, ArgumentType.Normal }, Start, Length, Expression)
41 {
42 }
43
54 public Post(ScriptNode Url, ScriptNode Data, ScriptNode Headers, ScriptNode Certificate, int Start, int Length, Expression Expression)
55 : base(new ScriptNode[] { Url, Data, Headers, Certificate }, new ArgumentType[] { ArgumentType.Scalar, ArgumentType.Normal, ArgumentType.Normal, ArgumentType.Normal }, Start, Length, Expression)
56 {
57 }
58
62 public override string FunctionName => nameof(Post);
63
67 public override string[] DefaultArgumentNames => new string[] { "URL", "Data", "Headers", "Certificate" };
68
73 public override bool IsAsynchronous => true;
74
82 {
83 return this.EvaluateAsync(Arguments, Variables).Result;
84 }
85
92 public override async Task<IElement> EvaluateAsync(IElement[] Arguments, Variables Variables)
93 {
94 Uri Url = new Uri(Arguments[0].AssociatedObjectValue?.ToString());
95 object Data = Arguments[1].AssociatedObjectValue;
96 List<KeyValuePair<string, string>> HeaderList = null;
97 object Result;
98
99 if (Arguments.Length > 2)
100 HeaderList = Get.GetHeaders(Arguments[2].AssociatedObjectValue, this);
101
102 if (Arguments.Length > 3)
103 {
104 if (!(Arguments[3].AssociatedObjectValue is X509Certificate Certificate))
105 throw new ScriptRuntimeException("Expected X.509 certificate in fourth argument.", this);
106
107 Result = await InternetContent.PostAsync(Url, Data, Certificate, HeaderList?.ToArray() ?? new KeyValuePair<string, string>[0]);
108 }
109 else
110 Result = await InternetContent.PostAsync(Url, Data, HeaderList?.ToArray() ?? new KeyValuePair<string, string>[0]);
111
112 return Expression.Encapsulate(Result);
113 }
114 }
115}
Static class managing encoding and decoding of internet content.
static Task< object > PostAsync(Uri Uri, object Data, params KeyValuePair< string, string >[] Headers)
Posts to a resource, using a Uniform Resource Identifier (or Locator).
Post(Url,Data)
Definition: Post.cs:16
override string[] DefaultArgumentNames
Default Argument names
Definition: Post.cs:67
override bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
Definition: Post.cs:73
override async Task< IElement > EvaluateAsync(IElement[] Arguments, Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
Definition: Post.cs:92
Post(ScriptNode Url, ScriptNode Data, int Start, int Length, Expression Expression)
Post(Url,Data)
Definition: Post.cs:25
override string FunctionName
Name of the function
Definition: Post.cs:62
override IElement Evaluate(IElement[] Arguments, Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
Definition: Post.cs:81
Post(ScriptNode Url, ScriptNode Data, ScriptNode Headers, int Start, int Length, Expression Expression)
Post(Url,Data,Headers)
Definition: Post.cs:39
Post(ScriptNode Url, ScriptNode Data, ScriptNode Headers, ScriptNode Certificate, int Start, int Length, Expression Expression)
Post(Url,Data,Headers,Certificate)
Definition: Post.cs:54
Class managing a script expression.
Definition: Expression.cs:39
static IElement Encapsulate(object Value)
Encapsulates an object.
Definition: Expression.cs:4955
Base class for multivariate funcions.
ScriptNode[] Arguments
Function arguments.
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
ArgumentType
Type of parameter used in a function definition or a lambda definition.
Definition: IFunction.cs:9