/// <summary>
 /// Gets all data sources from the server.
 /// </summary>
 /// <param name="To">Address of server.</param>
 /// <param name="Callback">Method to call when response is returned.</param>
 /// <param name="State">State object to pass on to callback method.</param>
 public void GetAllDataSources(string To, DataSourcesEventHandler Callback, object State)
 {
     this.client.SendIqGet(To, "<getAllDataSources xmlns='" + ConcentratorServer.NamespaceConcentrator + "'/>", (sender, e) =>
     {
         if (Callback != null)
         {
             this.DataSourcesResponse(e, "getAllDataSourcesResponse", Callback, State);
         }
     }, State);
 }
        private void DataSourcesResponse(IqResultEventArgs e, string ExpectedElement, DataSourcesEventHandler Callback, object State)
        {
            List <DataSourceReference> DataSources = new List <DataSourceReference>();
            XmlElement E;

            if (e.Ok && (E = e.FirstElement) != null && E.LocalName == ExpectedElement && E.NamespaceURI == ConcentratorServer.NamespaceConcentrator)
            {
                foreach (XmlNode N in E)
                {
                    if (N is XmlElement E2 && E2.LocalName == "dataSource")
                    {
                        DataSources.Add(new DataSourceReference(E2));
                    }
                }
            }
            else
            {
                e.Ok = false;
            }

            if (Callback != null)
            {
                try
                {
                    Callback(this, new DataSourcesEventArgs(DataSources.ToArray(), e));
                }
                catch (Exception ex)
                {
                    Log.Critical(ex);
                }
            }
        }