/// <summary> /// Checks if a control operation can be performed. /// </summary> /// <param name="RequestFromBareJid">Readout request came from this bare JID.</param> /// <param name="Nodes">Any nodes included in the request.</param> /// <param name="ParameterNames">And parameter names included in the request. If null, all parameter names are requested.</param> /// <param name="ServiceTokens">Any service tokens provided.</param> /// <param name="DeviceTokens">Any device tokens provided.</param> /// <param name="UserTokens">Any user tokens provided.</param> /// <param name="Callback">Method to call when result is received.</param> /// <param name="State">State object to pass on to the callback method.</param> public void CanControl(string RequestFromBareJid, IEnumerable <ThingReference> Nodes, IEnumerable <string> ParameterNames, string[] ServiceTokens, string[] DeviceTokens, string[] UserTokens, CanControlCallback Callback, object State) { if ((!string.IsNullOrEmpty(this.ownerJid) && string.Compare(RequestFromBareJid, this.ownerJid, true) == 0) || string.Compare(RequestFromBareJid, this.provisioningServerAddress, true) == 0) { if (Callback != null) { try { ThingReference[] Nodes2 = Nodes as ThingReference[]; if (Nodes2 == null && Nodes != null) { List <ThingReference> List = new List <ThingReference>(); List.AddRange(Nodes); Nodes2 = List.ToArray(); } string[] ParameterNames2 = ParameterNames as string[]; if (ParameterNames2 == null && ParameterNames != null) { List <string> List = new List <string>(); List.AddRange(ParameterNames); ParameterNames2 = List.ToArray(); } IqResultEventArgs e0 = new IqResultEventArgs(null, string.Empty, this.client.FullJID, this.provisioningServerAddress, true, State); CanControlResponseEventArgs e = new CanControlResponseEventArgs(e0, State, RequestFromBareJid, true, Nodes2, ParameterNames2); Callback(this.client, e); } catch (Exception ex) { Log.Critical(ex); } } return; } StringBuilder Xml = new StringBuilder(); Xml.Append("<canControl xmlns='"); Xml.Append(NamespaceProvisioningDevice); Xml.Append("' jid='"); Xml.Append(XML.Encode(RequestFromBareJid)); this.AppendTokens(Xml, "st", ServiceTokens); this.AppendTokens(Xml, "dt", DeviceTokens); this.AppendTokens(Xml, "ut", UserTokens); if (Nodes == null && ParameterNames == null) { Xml.Append("'/>"); } else { Xml.Append("'>"); if (Nodes != null) { foreach (ThingReference Node in Nodes) { Xml.Append("<nd id='"); Xml.Append(XML.Encode(Node.NodeId)); if (!string.IsNullOrEmpty(Node.SourceId)) { Xml.Append("' src='"); Xml.Append(XML.Encode(Node.SourceId)); } if (!string.IsNullOrEmpty(Node.Partition)) { Xml.Append("' pt='"); Xml.Append(XML.Encode(Node.Partition)); } Xml.Append("'/>"); } } if (ParameterNames != null) { foreach (string ParameterName in ParameterNames) { Xml.Append("<parameter name='"); Xml.Append(XML.Encode(ParameterName)); Xml.Append("'/>"); } } Xml.Append("</canControl>"); } this.CachedIqGet(Xml.ToString(), (sender, e) => { XmlElement E = e.FirstElement; List <ThingReference> Nodes2 = null; List <string> ParameterNames2 = null; string Jid = string.Empty; string NodeId; string SourceId; string Partition; bool CanControl; if (e.Ok && E.LocalName == "canControlResponse" && E.NamespaceURI == NamespaceProvisioningDevice) { CanControl = XML.Attribute(E, "result", false); foreach (XmlAttribute Attr in E.Attributes) { if (Attr.Name == "jid") { Jid = Attr.Value; } } foreach (XmlNode N in E.ChildNodes) { switch (N.LocalName) { case "nd": if (Nodes2 == null) { Nodes2 = new List <ThingReference>(); } E = (XmlElement)N; NodeId = XML.Attribute(E, "id"); SourceId = XML.Attribute(E, "src"); Partition = XML.Attribute(E, "pt"); Nodes2.Add(new ThingReference(NodeId, SourceId, Partition)); break; case "parameter": if (ParameterNames2 == null) { ParameterNames2 = new List <string>(); } ParameterNames2.Add(XML.Attribute((XmlElement)N, "name")); break; } } } else { CanControl = false; } CanControlResponseEventArgs e2 = new CanControlResponseEventArgs(e, State, Jid, CanControl, Nodes2?.ToArray(), ParameterNames2?.ToArray()); try { Callback(this, e2); } catch (Exception ex) { Log.Critical(ex); } }, null); }
void PopulateData2() { var RootNode1 = new FileInfoModel { Header = "Work Documents", Image = folder, IsExpanded = true }; var RootNode2 = new FileInfoModel { Header = "Personal Folder", Image = folder, IsExpanded = true }; var ChildNode1 = new FileInfoModel { Header = "Functional Specifications", Image = folder, IsExpanded = true }; var ChildNode2 = new FileInfoModel { Header = "TreeView spec", Image = file, IsExpanded = true }; var ChildNode3 = new FileInfoModel { Header = "Feature Schedule", Image = file, IsExpanded = false }; var ChildNode4 = new FileInfoModel { Header = "Overall Project Plan", Image = file, IsExpanded = false }; var ChildNode5 = new FileInfoModel { Header = "Feature Resource Allocation", Image = file, IsExpanded = false }; var ChildNode6 = new FileInfoModel { Header = "Home Remodel Folder", Image = folder, IsExpanded = true }; var ChildNode7 = new FileInfoModel { Header = "Contractor Contact Info", Image = file, IsExpanded = false }; var ChildNode8 = new FileInfoModel { Header = "Paint Color Scheme", Image = file, IsExpanded = false }; var ChildNode9 = new FileInfoModel { Header = "Flooring Woodgrain type", Image = file, IsExpanded = false }; var ChildNode10 = new FileInfoModel { Header = "Kitchen Cabinet Style", Image = file, IsExpanded = false }; var ChildNode11 = new FileInfoModel { Header = "My Network Places", Image = folder, IsExpanded = true }; var ChildNode12 = new FileInfoModel { Header = "Server", Image = folder, IsExpanded = false }; var ChildNode13 = new FileInfoModel { Header = "My Folders", Image = folder, IsExpanded = false }; var ChildNode14 = new FileInfoModel { Header = "My Computer", Image = folder, IsExpanded = true }; var ChildNode15 = new FileInfoModel { Header = "Music", Image = folder, IsExpanded = false }; var ChildNode16 = new FileInfoModel { Header = "Videos", Image = folder, IsExpanded = false }; var ChildNode17 = new FileInfoModel { Header = "Wallpaper.png", Image = image, IsExpanded = false }; var ChildNode18 = new FileInfoModel { Header = "My Banner.png", Image = image, IsExpanded = false }; var ChildNode19 = new FileInfoModel { Header = "Favourites", Image = folder, IsExpanded = true }; var ChildNode20 = new FileInfoModel { Header = "Image3.png", Image = image, IsExpanded = false }; var ChildNode21 = new FileInfoModel { Header = "Image4.png", Image = image, IsExpanded = false }; var ChildNode22 = new FileInfoModel { Header = "Image5.png", Image = image, IsExpanded = false }; var ChildNode23 = new FileInfoModel { Header = "Image1.png", Image = image, IsExpanded = false }; var ChildNode24 = new FileInfoModel { Header = "Image2.png", Image = image, IsExpanded = false }; RootNode1.Childs.Add(ChildNode1); RootNode1.Childs.Add(ChildNode3); RootNode1.Childs.Add(ChildNode4); RootNode1.Childs.Add(ChildNode5); RootNode2.Childs.Add(ChildNode6); RootNode2.Childs.Add(ChildNode11); RootNode2.Childs.Add(ChildNode14); RootNode2.Childs.Add(ChildNode19); ChildNode1.Childs.Add(ChildNode2); ChildNode6.Childs.Add(ChildNode7); ChildNode6.Childs.Add(ChildNode8); ChildNode6.Childs.Add(ChildNode9); ChildNode6.Childs.Add(ChildNode10); ChildNode11.Childs.Add(ChildNode12); ChildNode11.Childs.Add(ChildNode13); ChildNode11.Childs.Add(ChildNode23); ChildNode11.Childs.Add(ChildNode24); ChildNode14.Childs.Add(ChildNode15); ChildNode14.Childs.Add(ChildNode16); ChildNode14.Childs.Add(ChildNode17); ChildNode14.Childs.Add(ChildNode18); ChildNode19.Childs.Add(ChildNode20); ChildNode19.Childs.Add(ChildNode21); ChildNode19.Childs.Add(ChildNode22); Nodes2.Add(RootNode1); Nodes2.Add(RootNode2); }
/// <summary> /// Checks if a readout can be performed. /// </summary> /// <param name="RequestFromBareJid">Readout request came from this bare JID.</param> /// <param name="FieldTypes">Field types requested.</param> /// <param name="Nodes">Any nodes included in the request.</param> /// <param name="FieldNames">And field names included in the request. If null, all field names are requested.</param> /// <param name="ServiceTokens">Any service tokens provided.</param> /// <param name="DeviceTokens">Any device tokens provided.</param> /// <param name="UserTokens">Any user tokens provided.</param> /// <param name="Callback">Method to call when result is received.</param> /// <param name="State">State object to pass on to the callback method.</param> public void CanRead(string RequestFromBareJid, FieldType FieldTypes, IEnumerable <ThingReference> Nodes, IEnumerable <string> FieldNames, string[] ServiceTokens, string[] DeviceTokens, string[] UserTokens, CanReadCallback Callback, object State) { if ((!string.IsNullOrEmpty(this.ownerJid) && string.Compare(RequestFromBareJid, this.ownerJid, true) == 0) || string.Compare(RequestFromBareJid, this.provisioningServerAddress, true) == 0) { if (Callback != null) { try { ThingReference[] Nodes2 = Nodes as ThingReference[]; if (Nodes2 == null && Nodes != null) { List <ThingReference> List = new List <ThingReference>(); List.AddRange(Nodes); Nodes2 = List.ToArray(); } string[] FieldNames2 = FieldNames as string[]; if (FieldNames2 == null && FieldNames != null) { List <string> List = new List <string>(); List.AddRange(FieldNames); FieldNames2 = List.ToArray(); } IqResultEventArgs e0 = new IqResultEventArgs(null, string.Empty, this.client.FullJID, this.provisioningServerAddress, true, State); CanReadResponseEventArgs e = new CanReadResponseEventArgs(e0, State, RequestFromBareJid, true, FieldTypes, Nodes2, FieldNames2); Callback(this.client, e); } catch (Exception ex) { Log.Critical(ex); } } return; } StringBuilder Xml = new StringBuilder(); Xml.Append("<canRead xmlns='"); Xml.Append(NamespaceProvisioningDevice); Xml.Append("' jid='"); Xml.Append(XML.Encode(RequestFromBareJid)); this.AppendTokens(Xml, "st", ServiceTokens); this.AppendTokens(Xml, "dt", DeviceTokens); this.AppendTokens(Xml, "ut", UserTokens); if ((FieldTypes & FieldType.All) == FieldType.All) { Xml.Append("' all='true"); } else { if (FieldTypes.HasFlag(FieldType.Momentary)) { Xml.Append("' m='true"); } if (FieldTypes.HasFlag(FieldType.Peak)) { Xml.Append("' p='true"); } if (FieldTypes.HasFlag(FieldType.Status)) { Xml.Append("' s='true"); } if (FieldTypes.HasFlag(FieldType.Computed)) { Xml.Append("' c='true"); } if (FieldTypes.HasFlag(FieldType.Identity)) { Xml.Append("' i='true"); } if (FieldTypes.HasFlag(FieldType.Historical)) { Xml.Append("' h='true"); } } if (Nodes == null && FieldNames == null) { Xml.Append("'/>"); } else { Xml.Append("'>"); if (Nodes != null) { foreach (ThingReference Node in Nodes) { Xml.Append("<nd id='"); Xml.Append(XML.Encode(Node.NodeId)); if (!string.IsNullOrEmpty(Node.SourceId)) { Xml.Append("' src='"); Xml.Append(XML.Encode(Node.SourceId)); } if (!string.IsNullOrEmpty(Node.Partition)) { Xml.Append("' pt='"); Xml.Append(XML.Encode(Node.Partition)); } Xml.Append("'/>"); } } if (FieldNames != null) { foreach (string FieldName in FieldNames) { Xml.Append("<f n='"); Xml.Append(XML.Encode(FieldName)); Xml.Append("'/>"); } } Xml.Append("</canRead>"); } this.CachedIqGet(Xml.ToString(), (sender, e) => { XmlElement E = e.FirstElement; List <ThingReference> Nodes2 = null; List <string> Fields2 = null; FieldType FieldTypes2 = (FieldType)0; string Jid = string.Empty; string NodeId; string SourceId; string Partition; bool b; bool CanRead; if (e.Ok && E.LocalName == "canReadResponse" && E.NamespaceURI == NamespaceProvisioningDevice) { CanRead = XML.Attribute(E, "result", false); foreach (XmlAttribute Attr in E.Attributes) { switch (Attr.Name) { case "jid": Jid = Attr.Value; break; case "all": if (CommonTypes.TryParse(Attr.Value, out b) && b) { FieldTypes2 |= FieldType.All; } break; case "h": if (CommonTypes.TryParse(Attr.Value, out b) && b) { FieldTypes2 |= FieldType.Historical; } break; case "m": if (CommonTypes.TryParse(Attr.Value, out b) && b) { FieldTypes2 |= FieldType.Momentary; } break; case "p": if (CommonTypes.TryParse(Attr.Value, out b) && b) { FieldTypes2 |= FieldType.Peak; } break; case "s": if (CommonTypes.TryParse(Attr.Value, out b) && b) { FieldTypes2 |= FieldType.Status; } break; case "c": if (CommonTypes.TryParse(Attr.Value, out b) && b) { FieldTypes2 |= FieldType.Computed; } break; case "i": if (CommonTypes.TryParse(Attr.Value, out b) && b) { FieldTypes2 |= FieldType.Identity; } break; } } foreach (XmlNode N in E.ChildNodes) { switch (N.LocalName) { case "nd": if (Nodes2 == null) { Nodes2 = new List <ThingReference>(); } E = (XmlElement)N; NodeId = XML.Attribute(E, "id"); SourceId = XML.Attribute(E, "src"); Partition = XML.Attribute(E, "pt"); Nodes2.Add(new ThingReference(NodeId, SourceId, Partition)); break; case "f": if (Fields2 == null) { Fields2 = new List <string>(); } Fields2.Add(XML.Attribute((XmlElement)N, "n")); break; } } } else { CanRead = false; } CanReadResponseEventArgs e2 = new CanReadResponseEventArgs(e, State, Jid, CanRead, FieldTypes2, Nodes2?.ToArray(), Fields2?.ToArray()); try { Callback(this, e2); } catch (Exception ex) { Log.Critical(ex); } }, null); }