Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ServiceDescriptionDocument.cs
1using System;
2using System.Collections.Generic;
3using System.Threading.Tasks;
4using System.Xml;
5
7{
12 {
13 private readonly Dictionary<string, UPnPAction> actionsByName = new Dictionary<string, UPnPAction>();
14 private readonly Dictionary<string, UPnPStateVariable> variablesByName = new Dictionary<string, UPnPStateVariable>();
15 private readonly UPnPAction[] actions;
16 private readonly UPnPStateVariable[] variables;
17 private readonly UPnPService service;
18 private readonly XmlDocument xml;
19 private readonly int majorVersion;
20 private readonly int minorVersion;
21
22 internal ServiceDescriptionDocument(XmlDocument Xml, UPnPClient Client, UPnPService Service)
23 {
24 List<UPnPStateVariable> Variables = new List<UPnPStateVariable>();
25 List<UPnPAction> Actions = new List<UPnPAction>();
26 this.xml = Xml;
27 this.service = Service;
28
29 if (!(Xml.DocumentElement is null) && Xml.DocumentElement.LocalName == "scpd" &&
30 Xml.DocumentElement.NamespaceURI == "urn:schemas-upnp-org:service-1-0")
31 {
32 foreach (XmlNode N in Xml.DocumentElement.ChildNodes)
33 {
34 switch (N.LocalName)
35 {
36 case "specVersion":
37 foreach (XmlNode N2 in N.ChildNodes)
38 {
39 switch (N2.LocalName)
40 {
41 case "major":
42 this.majorVersion = int.Parse(N2.InnerText);
43 break;
44
45 case "minor":
46 this.minorVersion = int.Parse(N2.InnerText);
47 break;
48 }
49 }
50 break;
51
52 case "actionList":
53 foreach (XmlNode N2 in N.ChildNodes)
54 {
55 if (N2.LocalName == "action")
56 {
57 UPnPAction Action = new UPnPAction((XmlElement)N2, this);
58 Actions.Add(Action);
59 this.actionsByName[Action.Name] = Action;
60 }
61 }
62 break;
63
64 case "serviceStateTable":
65 foreach (XmlNode N2 in N.ChildNodes)
66 {
67 if (N2.LocalName == "stateVariable")
68 {
69 UPnPStateVariable Variable = new UPnPStateVariable((XmlElement)N2);
70 Variables.Add(Variable);
71 this.variablesByName[Variable.Name] = Variable;
72 }
73 }
74 break;
75 }
76 }
77 }
78 else
79 throw new Exception("Unrecognized file format.");
80
81 this.actions = Actions.ToArray();
82 this.variables = Variables.ToArray();
83 }
84
88 public XmlDocument Xml => this.xml;
89
93 public int MajorVersion => this.majorVersion;
94
98 public int MinorVersion => this.minorVersion;
99
103 public UPnPAction[] Actions => this.actions;
104
108 public UPnPStateVariable[] Variables => this.variables;
109
113 public UPnPService Service => this.service;
114
120 public UPnPAction GetAction(string Name)
121 {
122 if (this.actionsByName.TryGetValue(Name, out UPnPAction Action))
123 return Action;
124 else
125 return null;
126 }
127
133 public UPnPStateVariable GetVariable(string Name)
134 {
135 if (this.variablesByName.TryGetValue(Name, out UPnPStateVariable Variable))
136 return Variable;
137 else
138 return null;
139 }
140
149 public Task<KeyValuePair<object, Dictionary<string, object>>> InvokeAsync(string ActionName, int Timeout, params KeyValuePair<string, object>[] InputValues)
150 {
151 UPnPAction Action = this.GetAction(ActionName);
152 if (Action is null)
153 throw new ArgumentException("Action not found: " + ActionName, nameof(ActionName));
154
155 return Action.InvokeAsync(Timeout, InputValues);
156 }
157
166 public Task<KeyValuePair<object, Dictionary<string, object>>> InvokeAsync(string ActionName, Dictionary<string, object> InputValues, int Timeout)
167 {
168 UPnPAction Action = this.GetAction(ActionName);
169 if (Action is null)
170 throw new ArgumentException("Action not found: " + ActionName, nameof(ActionName));
171
172 return Action.InvokeAsync(InputValues, Timeout);
173 }
174
175 }
176}
Contains the information provided in a Service Description Document, downloaded from a service in the...
Task< KeyValuePair< object, Dictionary< string, object > > > InvokeAsync(string ActionName, int Timeout, params KeyValuePair< string, object >[] InputValues)
Invokes an action.
UPnPAction GetAction(string Name)
Gets an action, given its name. If not found, null is returned.
UPnPStateVariable GetVariable(string Name)
Gets an action, given its name. If not found, null is returned.
Task< KeyValuePair< object, Dictionary< string, object > > > InvokeAsync(string ActionName, Dictionary< string, object > InputValues, int Timeout)
Invokes an action.
Contains information about an action.
Definition: UPnPAction.cs:15
Implements support for the UPnP protocol, as described in: http://upnp.org/specs/arch/UPnP-arch-Devic...
Definition: UPnPClient.cs:21
Contains information about a service.
Definition: UPnPService.cs:12
Contains information about a state variable.