/// <summary> /// Graba las conexiones /// </summary> public void Save(JabberManager objManager, string strFileName) { MLFile objMLFile = new MLFile(); MLNode objMLNode = objMLFile.Nodes.Add(cnstStrTagRoot); // Asigna los nodos de las conexión foreach (JabberConnection objConnection in objManager.Connections) { MLNode objMLConnection = objMLNode.Nodes.Add(cnstStrTagConnection); MLNode objMLServer = objMLConnection.Nodes.Add(cnstStrTagServer); MLNode objMLUser = objMLConnection.Nodes.Add(cnstStrTagUser); // Añade los datos del servidor objMLServer.Attributes.Add(cnstStrTagAddress, objConnection.Host.Address); objMLServer.Attributes.Add(cnstStrTagPort, objConnection.Host.Port); objMLServer.Attributes.Add(cnstStrTagUseSsl, objConnection.Host.UseTls); // Añade los datos del usuario objMLUser.Attributes.Add(cnstStrTagAddress, objConnection.User.Host); objMLUser.Attributes.Add(cnstStrTagLogin, objConnection.User.Login); objMLUser.Attributes.Add(cnstStrTagPassword, objConnection.User.Password); objMLUser.Attributes.Add(cnstStrTagServer, (int) objConnection.User.Status.Status); } // Crea el directorio Bau.Libraries.LibHelper.Files.HelperFiles.MakePath(System.IO.Path.GetDirectoryName(strFileName)); // Graba el archivo new Bau.Libraries.LibMarkupLanguage.Services.XML.XMLWriter().Save(objMLFile, strFileName); }
/// <summary> /// Carga las conexiones /// </summary> public void Load(JabberManager objManager, string strFileName) { if (System.IO.File.Exists(strFileName)) { MLFile objMLFile = new Bau.Libraries.LibMarkupLanguage.Services.XML.XMLParser().Load(strFileName); // Carga los datos foreach (MLNode objMLNode in objMLFile.Nodes) if (objMLNode.Name == cnstStrTagRoot) foreach (MLNode objMLConnection in objMLNode.Nodes) if (objMLConnection.Name == cnstStrTagConnection) { JabberServer objServer = null; JabberUser objUser = null; // Carga los datos del servidor foreach (MLNode objMLServer in objMLConnection.Nodes) if (objMLServer.Name == cnstStrTagServer) objServer = new JabberServer(objMLServer.Attributes[cnstStrTagAddress].Value, objMLServer.Attributes[cnstStrTagPort].Value.GetInt(5222), objMLServer.Attributes[cnstStrTagUseSsl].Value.GetBool(true)); // Carga los datos del usuario foreach (MLNode objMLUser in objMLConnection.Nodes) if (objMLUser.Name == cnstStrTagUser) { // Crea el usuario objUser = new JabberUser(objMLUser.Attributes[cnstStrTagAddress].Value, objMLUser.Attributes[cnstStrTagLogin].Value, objMLUser.Attributes[cnstStrTagPassword].Value); // Y le asigna el estado objUser.Status.Status = (JabberContactStatus.Availability) objMLUser.Attributes[cnstStrTagStatus].Value.GetInt(0); } // Añade la conexión if (objServer != null && objUser != null) objManager.AddConnection(objServer, objUser); } } }
/// <summary> /// Carga el árbol de contactos /// </summary> internal void LoadContacts(JabberManager objXmppClient) { // Asigna las propiedades Manager = objXmppClient; // Inicializa el árbol trvContacts.SaveOpenNodes(); trvContacts.Nodes.Clear(); trvContacts.ImageList = imgList; // Carga los grupos if (Manager != null) foreach (JabberConnection objConnection in objXmppClient.Connections) { TreeNode trnConnection = AddNode(null, TreeNodeType.Connection, GetImage(objConnection), $"{objConnection.User.Jid} - {objConnection.Host.Address}" + new string(' ', 20), true, Color.Navy, objConnection); // Añade los grupos foreach (JabberGroup objGroup in objConnection.Groups) { TreeNode trnGroup = AddNode(trnConnection, TreeNodeType.Group, ImageKey.Group, objGroup.Name + new string(' ', 20), true, Color.Red, objGroup); // Añade los contactos foreach (KeyValuePair<string, JabberContact> objContact in objGroup.Contacts) AddNode(trnGroup, TreeNodeType.Contact, GetImage(objContact.Value.Status), objContact.Value.FullName, false, Color.Black, objContact.Value); } } // Recarga el árbol trvContacts.RestoreOpenNodes(); }