Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
RelayToPrimary.cs
1using System.Text;
2using System.Threading.Tasks;
8
10{
15 {
16 private CaseInsensitiveString componentAddress;
17 private IqResultEventArgs result = null;
18
24 : base(Uri)
25 {
26 }
27
32 protected override async Task<bool> DoPrepare()
33 {
34 this.componentAddress = await this.Uri.EDaler.Server.FindComponentAsync(this.Uri.PrincipalDomain, EDalerComponent.NamespaceEDaler);
35 return true;
36 }
37
42 protected override async Task<bool> DoExecute()
43 {
44 StringBuilder Xml = new StringBuilder();
45 TaskCompletionSource<bool> Result = new TaskCompletionSource<bool>();
46
47 Xml.Append("<uri xmlns=\"");
49 Xml.Append("\" for=\"");
50 Xml.Append(XML.Encode(this.Uri.State.Sender));
51 Xml.Append("\">");
52 Xml.Append(XML.Encode(this.Uri.UriString));
53 Xml.Append("</uri>");
54
55 if (!await this.Uri.EDaler.Server.SendIqRequest("set",
57 new XmppAddress(this.componentAddress),
58 string.Empty, Xml.ToString(), (sender2, e2) =>
59 {
60 this.result = e2;
61
62 if (!e2.Ok)
63 this.Uri.State.Error(e2.ErrorType.ToString().ToLower(), string.Empty, this.Uri.PrincipalDomain + " reports: " + e2.ErrorText);
64
65 Result.TrySetResult(e2.Ok);
66
67 return Task.CompletedTask;
68
69 }, null))
70 {
71 this.Uri.State.Error(EDalerUriErrorType.ServiceUnavailable, "Unable to relay URI to principal domain.", false);
72 return false;
73 }
74
75 return await Result.Task;
76 }
77
82 protected override Task<bool> DoCommit()
83 {
84 this.Uri.State.Result(this.result.FirstElement?.OuterXml ?? string.Empty);
85
86 return Task.FromResult(true);
87 }
88
93 protected override Task<bool> DoRollback()
94 {
95 this.Uri.State.Error(EDalerUriErrorType.Conflict, "Transaction rejected and rolled back.", false);
96 return Task.FromResult(true);
97 }
98 }
99}
Helps with common XML-related tasks.
Definition: XML.cs:19
static string Encode(string s)
Encodes a string for use in XML.
Definition: XML.cs:27
XmppServer Server
XMPP Server.
Definition: Component.cs:96
Event arguments for responses to IQ queries.
XmlElement FirstElement
First child element of the Response element.
Contains information about one XMPP address.
Definition: XmppAddress.cs:9
override string ToString()
object.ToString()
Definition: XmppAddress.cs:190
Task< bool > SendIqRequest(string Type, string From, string To, string Language, string ContentXml, EventHandlerAsync< IqResultEventArgs > Callback, object State)
Sends an IQ stanza to a recipient.
Definition: XmppServer.cs:3317
CaseInsensitiveString Domain
Domain name.
Definition: XmppServer.cs:882
async Task< CaseInsensitiveString > FindComponentAsync(CaseInsensitiveString Jid, CaseInsensitiveString Feature)
Finds a component having a specific feature, servicing a JID.
Definition: XmppServer.cs:6382
Represents a case-insensitive string.
Manages eDaler on accounts connected to the broker.
const string NamespaceEDaler
Namespace of eDaler component.
Abstract base class for eDaler transactions.
Relays processing of the URI to the principal domain.
RelayToPrimary(EDalerUri Uri)
Relays processing of the URI to the principal domain.
override Task< bool > DoCommit()
Performs actual commit.
override async Task< bool > DoExecute()
Performs actual execution.
override Task< bool > DoRollback()
Performs actual rollback.
override async Task< bool > DoPrepare()
Performs actual preparation.
Abstract base class for eDaler URIs
Definition: EDalerUri.cs:20
EDalerUriState State
URI State object.
Definition: EDalerUri.cs:173
EDalerComponent EDaler
eDaler component reference
Definition: EDalerUri.cs:167
CaseInsensitiveString PrincipalDomain
Principal domain (i.e domain controlling the execution of the transaction.)
Definition: EDalerUri.cs:157
virtual void Error(EDalerUriErrorType ErrorType, string ErrorMessage, bool LogAsNotice)
Reports an error with the URI
virtual void Result(string Xml)
Reports a positive result.