⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 messagelist.cs

📁 飞信的收发使用csharp进行开发
💻 CS
字号:
namespace Imps.Client.Pc
{
    using Imps.Client.Core;
    using Imps.Client.Utils;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Reflection;
    using System.Runtime.CompilerServices;

    public class MessageList : IList<Imps.Client.Pc.Message>, ICollection<Imps.Client.Pc.Message>, IEnumerable<Imps.Client.Pc.Message>, IEnumerable
    {
        private Contact _contact;
        private int _currentPage = 1;
        private List<Imps.Client.Pc.Message> _dataSource;
        private IFrameworkWindow _framework;
        private List<Imps.Client.Pc.Message> _list;
        private MessageCompare _messageCompare = new MessageCompare();
        private string _path;

        public event EventHandler DataSourceInit;

        public MessageList(IFrameworkWindow framework)
        {
            this._framework = framework;
            this._list = new List<Imps.Client.Pc.Message>();
            this._dataSource = new List<Imps.Client.Pc.Message>();
        }

        public void Add(Imps.Client.Pc.Message item)
        {
            this._list.Add(item);
        }

        public void Clear()
        {
            this._list.Clear();
        }

        public bool Contains(Imps.Client.Pc.Message item)
        {
            return this._list.Contains(item);
        }

        public void CopyTo(Imps.Client.Pc.Message[] array, int arrayIndex)
        {
            this._list.CopyTo(array, arrayIndex);
        }

        public void DeleteMessages(Contact contact)
        {
            try
            {
                this.MsgManager.AsyncDelete(contact);
                this.Clear();
                this.InitDataSource();
            }
            catch (Exception exception)
            {
                ClientLogger.WriteException(exception);
            }
        }

        public void DeleteMessages(Contact contact, IList<string> messageIds)
        {
            try
            {
                if (messageIds.Count > 0)
                {
                    this.MsgManager.AsyncDelete(contact, messageIds);
                    foreach (string str in messageIds)
                    {
                        Imps.Client.Pc.Message item = this.FindMessageById(str);
                        if (item != null)
                        {
                            this.Remove(item);
                        }
                    }
                    this.InitDataSource();
                }
            }
            catch (Exception exception)
            {
                ClientLogger.WriteException(exception);
            }
        }

        internal Imps.Client.Pc.Message FindMessageById(string messageId)
        {
            foreach (Imps.Client.Pc.Message message in this)
            {
                if (message.MessageId == messageId)
                {
                    return message;
                }
            }
            return null;
        }

        public IEnumerator<Imps.Client.Pc.Message> GetEnumerator()
        {
            return this._list.GetEnumerator();
        }

        public int IndexOf(Imps.Client.Pc.Message item)
        {
            return this._list.IndexOf(item);
        }

        private void InitDataSource()
        {
            this._dataSource = new List<Imps.Client.Pc.Message>();
            int pageCount = this.PageCount;
            if (pageCount == 0)
            {
                this._currentPage = 0;
            }
            else if ((this._currentPage != 0) && (pageCount != 0))
            {
                if (this._currentPage > pageCount)
                {
                    this._currentPage = pageCount;
                }
                int num2 = (this._currentPage - 1) * this.PageSize;
                int count = (pageCount <= 1) ? this.Count : (this._currentPage * this.PageSize);
                if (this._currentPage == pageCount)
                {
                    count = this.Count;
                }
                for (int i = num2; i < count; i++)
                {
                    if ((this._list.Count > i) && (this._list[i] != null))
                    {
                        this._dataSource.Add(this._list[i]);
                    }
                }
            }
            if (this.DataSourceInit != null)
            {
                this.DataSourceInit(this, EventArgs.Empty);
            }
        }

        public void InitMessageHistoryList(List<Contact> contacts, string key)
        {
            foreach (Contact contact in contacts)
            {
                this.MsgManager.InitContactMessageHistoryList(contact, this, key);
            }
            this._list.Sort(this._messageCompare);
            this._currentPage = this.PageCount;
            this.InitDataSource();
        }

        public void InitMessageHistoryList(Contact contact, string key)
        {
            this.MsgManager.InitContactMessageHistoryList(contact, this, key);
            this._list.Sort(this._messageCompare);
            this._currentPage = this.PageCount;
            this.InitDataSource();
        }

        public void Insert(int index, Imps.Client.Pc.Message item)
        {
            this._list.Insert(index, item);
        }

        public bool Remove(Imps.Client.Pc.Message item)
        {
            return this._list.Remove(item);
        }

        public void RemoveAt(int index)
        {
            this._list.RemoveAt(index);
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return this._list.GetEnumerator();
        }

        public int Count
        {
            get
            {
                return this._list.Count;
            }
        }

        public int CurrentPage
        {
            get
            {
                return this._currentPage;
            }
            set
            {
                if (value != this._currentPage)
                {
                    if (value < 1)
                    {
                        value = 1;
                    }
                    if (value > this.PageCount)
                    {
                        value = this.PageCount;
                    }
                    this._currentPage = value;
                    this.InitDataSource();
                }
            }
        }

        public IList<Imps.Client.Pc.Message> DataSource
        {
            get
            {
                return this._dataSource;
            }
        }

        public bool IsReadOnly
        {
            get
            {
                return false;
            }
        }

        public Imps.Client.Pc.Message this[int index]
        {
            get
            {
                return this._list[index];
            }
            set
            {
                this._list[index] = value;
            }
        }

        public MessageHistoryManager MsgManager
        {
            get
            {
                return (this._framework.MessageHistoryManager as MessageHistoryManager);
            }
        }

        public User Owner
        {
            get
            {
                return this._framework.AccountManager.CurrentUser;
            }
        }

        public int PageCount
        {
            get
            {
                int num = this.Count / this.PageSize;
                if ((this.Count % this.PageSize) != 0)
                {
                    num++;
                }
                return num;
            }
        }

        public int PageSize
        {
            get
            {
                return this._framework.AccountManager.CurrentUser.Configuration.SystemSetting.MsgHistorySetting.MsgHistoryPageSize;
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -