/// <summary> /// Loads this instance. /// </summary> /// <returns></returns> public Boolean Load() { try { /* Try to load the XML document that contains the server list */ XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(m_XmlFileName); /* Get root node */ XmlElement root = xmlDoc.DocumentElement; if (!root.Name.Equals("configuration")) return false; /* Load setting */ try { Int32 qsize = Convert.ToInt32(root.Attributes["qsize"].Value); Int32 thc = Convert.ToInt32(root.Attributes["thc"].Value); Type lbt = TypeFromName(root.Attributes["lbid"].Value); Type rbt = TypeFromName(root.Attributes["rbid"].Value); if (qsize < 1 || thc < 0 || lbt == null || rbt == null) return false; m_QueueSize = qsize; m_NumberOfThreads = thc; m_LocalBalancer = lbt; m_RemoteBalancer = rbt; } catch { return false; } XmlNode xmlServerList; try { xmlServerList = root.GetElementsByTagName("servers")[0]; } catch { return false; } List<IServer> servers = new List<IServer>(); /* Circle in each node */ foreach (XmlNode xmlServerNode in xmlServerList.ChildNodes) { IServer server = null; if (xmlServerNode.Name.Equals("remote")) { String _name = xmlServerNode.Attributes["name"].Value; String _host = xmlServerNode.Attributes["host"].Value; String _key = xmlServerNode.Attributes["key"].Value; Int32 _port = Convert.ToInt32(xmlServerNode.Attributes["port"].Value); ConnectionType _ctype = ConnectionType.Http; try { _ctype = (ConnectionType)(Convert.ToInt32(xmlServerNode.Attributes["ctype"].Value)); } catch { } Boolean _enabled = (Convert.ToInt32(xmlServerNode.Attributes["enabled"].Value) != 0); server = new RemoteServer(_name, _host, _port, _key, _ctype, _enabled); } else if (xmlServerNode.Name.Equals("local")) { Boolean _enabled = (Convert.ToInt32(xmlServerNode.Attributes["enabled"].Value) != 0); server = new LocalServer(_enabled); } else return false; servers.Add(server); } /* Check if we have the local server and that it's only once opy of it */ m_Servers = CheckForLocalServer(servers); /* Load provider */ XmlNode xmlProvider; try { xmlProvider = root.GetElementsByTagName("provider")[0]; String _id = xmlProvider.Attributes["id"].Value; Dictionary<String, String> settings = new Dictionary<String, String>(); /* Circle in each node */ foreach (XmlNode xmlOptionNode in xmlProvider.ChildNodes) { if (xmlOptionNode.Name.Equals("option")) { String _key = xmlOptionNode.Attributes["key"].Value; String _value = xmlOptionNode.Attributes["value"].Value; if (!settings.ContainsKey(_key)) settings.Add(_key, _value); } } /* Find the algorithm */ foreach(IAlgorithmProvider provider in m_Algorithms.Providers) { if (provider.GetType().FullName.Equals(_id)) { provider.SetSettings(settings); m_Provider = provider; break; } } } catch { } } catch { return false; } return true; }
/// <summary> /// Creates a new object that is a copy of the current instance. /// </summary> /// <returns> /// A new object that is a copy of this instance. /// </returns> public Object Clone() { RemoteServer copy = new RemoteServer(m_ServerName, m_ServerHost, m_ServerPort, m_ServerKey, m_ConnectionType, m_Enabled); return copy; }