Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
NodeAdded.cs
1using System;
2using System.Collections.Generic;
3using System.Threading.Tasks;
7
9{
14 {
15 private string afterNodeId = string.Empty;
16 private string afterPartition = string.Empty;
17 private string displayName = string.Empty;
18 private string nodeType = string.Empty;
19 private bool sniffable = false;
20
24 public NodeAdded()
25 : base()
26 {
27 }
28
36 public static Task<NodeAdded> FromNode(INode Node, Language Language, RequestOrigin Caller, bool Sniffable)
37 {
38 return FromNode(Node, Language, Caller, Sniffable, null);
39 }
40
49 public static async Task<NodeAdded> FromNode(INode Node, Language Language, RequestOrigin Caller, bool Sniffable,
50 params Parameter[] AdditionalParameters)
51 {
52 List<Parameter> Parameters = new List<Parameter>();
53
54 foreach (Parameter P in await Node.GetDisplayableParametersAsync(Language, Caller))
55 Parameters.Add(P);
56
57 if (!(AdditionalParameters is null))
58 {
59 foreach (Parameter P in AdditionalParameters)
60 Parameters.Add(P);
61 }
62
63 return new NodeAdded()
64 {
65 Parameters = Parameters.ToArray(),
66 NodeType = Node.GetType().FullName,
68 DisplayName = await Node.GetTypeNameAsync(Language),
69 HasChildren = Node.HasChildren,
70 ChildrenOrdered = Node.ChildrenOrdered,
71 IsReadable = Node.IsReadable,
72 IsControllable = Node.IsControllable,
73 HasCommands = Node.HasCommands,
74 ParentId = Node.Parent?.NodeId ?? string.Empty,
75 ParentPartition = Node.Parent?.Partition ?? string.Empty,
76 Updated = DateTime.MinValue,
77 State = Node.State,
78 NodeId = Node.NodeId,
79 Partition = Node.Partition,
80 LogId = EmptyIfSame(Node.LogId, Node.NodeId),
81 LocalId = EmptyIfSame(Node.LocalId, Node.NodeId),
82 SourceId = Node.SourceId,
83 Timestamp = DateTime.Now
84 };
85 }
86
93 public static string EmptyIfSame(string Id1, string Id2)
94 {
95 return Id1 == Id2 ? string.Empty : Id1;
96 }
97
101 [DefaultValueStringEmpty]
102 public string AfterNodeId
103 {
104 get => this.afterNodeId;
105 set => this.afterNodeId = value;
106 }
107
111 [DefaultValueStringEmpty]
112 public string AfterPartition
113 {
114 get => this.afterPartition;
115 set => this.afterPartition = value;
116 }
117
121 [DefaultValueStringEmpty]
122 public string DisplayName
123 {
124 get => this.displayName;
125 set => this.displayName = value;
126 }
127
131 [DefaultValueStringEmpty]
132 public string NodeType
133 {
134 get => this.nodeType;
135 set => this.nodeType = value;
136 }
137
141 [DefaultValue(false)]
142 public bool Sniffable
143 {
144 get => this.sniffable;
145 set => this.sniffable = value;
146 }
147
152 {
153 get { return SourceEventType.NodeAdded; }
154 }
155 }
156}
Contains information about a language.
Definition: Language.cs:17
Base class for all node parameters.
Definition: Parameter.cs:10
Tokens available in request.
Definition: RequestOrigin.cs:9
NodeAdded()
Node added event.
Definition: NodeAdded.cs:24
static Task< NodeAdded > FromNode(INode Node, Language Language, RequestOrigin Caller, bool Sniffable)
Creates an event object from a node object.
Definition: NodeAdded.cs:36
string AfterNodeId
In an ordered set of nodes, the new node is added after this node, if provided.
Definition: NodeAdded.cs:103
override SourceEventType EventType
Type of data source event.
Definition: NodeAdded.cs:152
string AfterPartition
In an ordered set of nodes, the new node is added after the node defined by AfterNodeId,...
Definition: NodeAdded.cs:113
string DisplayName
Display name.
Definition: NodeAdded.cs:123
string NodeType
Type of node, at time of event.
Definition: NodeAdded.cs:133
bool Sniffable
If node was sniffable, at time of event.
Definition: NodeAdded.cs:143
static string EmptyIfSame(string Id1, string Id2)
Returns Id1 if different, string.Empty if the same.
Definition: NodeAdded.cs:93
static async Task< NodeAdded > FromNode(INode Node, Language Language, RequestOrigin Caller, bool Sniffable, params Parameter[] AdditionalParameters)
Creates an event object from a node object.
Definition: NodeAdded.cs:49
string NodeId
Node identity.
Definition: NodeEvent.cs:29
string LogId
Log identity, if different from NodeId.
Definition: NodeEvent.cs:51
string Partition
Optional partition.
Definition: NodeEvent.cs:40
string LocalId
Local identity, if different from NodeId.
Definition: NodeEvent.cs:62
Abstract base class for all node events with parameters.
string ParentPartition
Partition of parent of node, at time of event.
string ParentId
Parent identity of node, at time of event.
bool HasChildren
If node had children, at time of event.
bool ChildrenOrdered
If node children was ordered, at time of event.
bool IsControllable
If node was controllable, at time of event.
Parameter[] Parameters
Displayable parameters.
DateTime Updated
When node was last updated, at time of event.
bool HasCommands
If node had commands, at time of event.
bool IsReadable
If node was readable, at time of event.
NodeState State
State of node, at time of event.
string SourceId
Data source identity.
Definition: SourceEvent.cs:40
DateTime Timestamp
Timestamp of event.
Definition: SourceEvent.cs:50
Interface for nodes that are published through the concentrator interface.
Definition: INode.cs:49
SourceEventType
Data Source event types