コード例 #1
0
        /// <summary>
        ///		Graba las conexiones
        /// </summary>
        public void Save(JabberManager manager, string fileName)
        {
            MLFile fileML = new MLFile();
            MLNode nodeML = fileML.Nodes.Add(TagRoot);

            // Asigna los nodos de las conexión
            foreach (JabberConnection connection in manager.Connections)
            {
                MLNode connectionML = nodeML.Nodes.Add(TagConnection);
                MLNode serverML     = connectionML.Nodes.Add(TagServer);
                MLNode userML       = connectionML.Nodes.Add(TagUser);

                // Añade los datos del servidor
                serverML.Attributes.Add(TagAddress, connection.Host.Address);
                serverML.Attributes.Add(TagPort, connection.Host.Port);
                serverML.Attributes.Add(TagUseSsl, connection.Host.UseTls);
                // Añade los datos del usuario
                userML.Attributes.Add(TagAddress, connection.User.Host);
                userML.Attributes.Add(TagLogin, connection.User.Login);
                userML.Attributes.Add(TagPassword, connection.User.Password);
                userML.Attributes.Add(TagServer, connection.User.Status.Status.ToString());
            }
            // Graba el archivo
            new LibMarkupLanguage.Services.XML.XMLWriter().Save(fileName, fileML);
        }
コード例 #2
0
        /// <summary>
        ///		Carga las conexiones
        /// </summary>
        public void Load(JabberManager manager, string fileName)
        {
            MLFile fileML = new LibMarkupLanguage.Services.XML.XMLParser().Load(fileName);

            // Carga los datos
            if (fileML != null)
            {
                foreach (MLNode nodeML in fileML.Nodes)
                {
                    if (nodeML.Name == TagRoot)
                    {
                        foreach (MLNode connectionML in nodeML.Nodes)
                        {
                            if (connectionML.Name == TagConnection)
                            {
                                JabberServer server = null;
                                JabberUser   user   = null;

                                // Carga los datos del servidor
                                foreach (MLNode serverML in connectionML.Nodes)
                                {
                                    if (serverML.Name == TagServer)
                                    {
                                        server = new JabberServer(serverML.Attributes[TagAddress].Value,
                                                                  serverML.Attributes[TagPort].Value.GetInt(5222),
                                                                  serverML.Attributes[TagUseSsl].Value.GetBool(true));
                                    }
                                }
                                // Carga los datos del usuario
                                foreach (MLNode userML in connectionML.Nodes)
                                {
                                    if (userML.Name == TagUser)
                                    {
                                        // Crea el usuario
                                        user = new JabberUser(userML.Attributes[TagAddress].Value,
                                                              userML.Attributes[TagLogin].Value,
                                                              userML.Attributes[TagPassword].Value);
                                        // Y le asigna el estado
                                        user.Status.Status = userML.Attributes[TagStatus].Value.GetEnum(JabberContactStatus.Availability.Offline);
                                    }
                                }
                                // Añade la conexión
                                if (server != null && user != null)
                                {
                                    manager.AddConnection(server, user);
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #3
0
ファイル: ChatViewModel.cs プロジェクト: zaharvsb52/MyWmsPro
        public ChatViewModel()
        {
            KeyPropertyName      = "UserName";
            ParentIdPropertyName = "GroupName";
            AllowClosePanel      = true;
            PanelCaption         = _caption;
            PanelCaptionImage    = ImageResources.DCLDefault16.GetBitmapImage();

            OpenChatWindow = new DelegateCustomCommand(OnOpenChatWindow, () => true);

            _jabber = (JabberManager)IoC.Instance.Resolve <IChatManager>();
            Fields  =
                new ObservableCollection <DataField>(new[]
                                                     { new DataField()
                                                       {
                                                           FieldName = "UserName", SourceName = "UserName", Caption = "Список контактов", FieldType = typeof(string)
                                                       } });
            SelectedItems = new ObservableCollection <JidItem>();
            var rooms = _jabber.GetRooms().ToArray();

            ConversationItems = new ObservableCollection <ConversationViewModel>(rooms.Select(i => new ConversationViewModel(i.Name, i)));
            foreach (var cm in ConversationItems)
            {
                cm.PrivateRoom += conversation_PrivateRoom;
            }
            //INFO: если были входящие сообщения от пользователей, то откроем с ними вкладки
            foreach (var r in rooms)
            {
                foreach (var user in r.GetUsers())
                {
                    if (r.GetMessages(user).Any(i => i.State == MsgState.Received))
                    {
                        conversation_PrivateRoom(user, r, false);
                    }
                }
            }
            RefreshData();
        }