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

📄 contactgroup.cs

📁 破解的飞信源代码
💻 CS
📖 第 1 页 / 共 2 页
字号:
namespace Imps.Client.Core
{
    using Imps.Base.Sipc;
    using Imps.Client.Base;
    using Imps.Client.Resource;
    using Imps.Common;
    using Imps.Utils;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.IO;
    using System.Xml;

    public class ContactGroup : ContactGroupBase
    {
        private int _id;
        private string _name;

        public ContactGroup(Imps.Client.Core.User owner, int id, string name) : base(owner)
        {
            this._id = id;
            this._name = name;
        }

        public static bool AsyncCopyContactTo(Imps.Client.Core.User owner, IicUri uri, int? sourceGroupId, int? targetGroupId, AsyncBizOperation op)
        {
            return AsyncSetBuddyLists(owner, uri, SetBuddyListsType.Copy, sourceGroupId, targetGroupId, op);
        }

        public bool AsyncDelete(AsyncBizOperation op)
        {
            if (this.Id == -1)
            {
                return false;
            }
            if (((base.Owner.ContactList.Groups[-1] != null) && (base.Owner.ContactList.Groups.Count == 2)) || ((base.Owner.ContactList.Groups[-1] == null) && (base.Owner.ContactList.Groups.Count == 1)))
            {
                base.Owner.FireImpsErrorInUiThread(new ImpsErrorEventArgs(StringTable.ContactGroup.MsgCannotDelelte_OnlyOne), op);
                return false;
            }
            if (base.Contacts.Count > 0)
            {
                base.Owner.FireImpsErrorInUiThread(new ImpsErrorEventArgs(StringTable.ContactGroup.MsgCannotDelelte_HasContacts, 0x192), op);
                return false;
            }
            SipRequest req = base.Owner.CreateSipRequest("S");
            req.Message.AddHeader(new SipcEventHeader("DeleteBuddyList"));
            StringWriter tw = new StringWriter();
            XmlHelper.CreateXmlWriterForSipRequest(tw, null, delegate (XmlWriter writer, object context) {
                writer.WriteStartElement("contacts");
                writer.WriteStartElement("buddy-lists");
                writer.WriteStartElement("buddy-list");
                writer.WriteAttributeString("id", this.Id.ToString());
                writer.WriteEndElement();
                writer.WriteEndElement();
                writer.WriteEndElement();
            });
            req.Message.Body = tw.ToString();
            ErrorHelper.HandleSendRequestErrorAndTimeout(req);
            req.FinalResponseReceived += new EventHandler<SipResponseReceivedEventArgs>(this, (IntPtr) this.finalResponse_AsyncDelete);
            base.SendSipMessage(req);
            return true;
        }

        public static bool AsyncMoveContactTo(Imps.Client.Core.User owner, IicUri uri, int? sourceGroupID, int? targetGroupID, AsyncBizOperation op)
        {
            return AsyncSetBuddyLists(owner, uri, SetBuddyListsType.Move, sourceGroupID, targetGroupID, op);
        }

        public static bool AsyncRemoveContact(Imps.Client.Core.User owner, IicUri uri, int? sourceGroupId, AsyncBizOperation op)
        {
            return AsyncSetBuddyLists(owner, uri, SetBuddyListsType.Delete, sourceGroupId, null, op);
        }

        internal static bool AsyncSetBuddyLists(Imps.Client.Core.User user, IicUri uri, SetBuddyListsType type, int? sourceGroupId, int? targetGroupId, AsyncBizOperation op)
        {
            string buddyList;
            Imps.Client.Core.Contact contact = user.ContactList.Contacts[uri.Raw];
            if (contact == null)
            {
                return false;
            }
            if (((contact.Type != ContactType.Buddy) && (contact.Type != ContactType.MobileBuddy)) && (contact.Type != ContactType.Vodafone))
            {
                return false;
            }
            if (type != SetBuddyListsType.Delete)
            {
                if (!targetGroupId.get_HasValue())
                {
                    return false;
                }
                if (user.ContactList.Groups.FindContactGroup(targetGroupId) is Imps.Client.Core.ContactGroup)
                {
                    goto Label_00B9;
                }
                return false;
            }
            if (!sourceGroupId.get_HasValue())
            {
                return false;
            }
            if (!(user.ContactList.Groups.FindContactGroup(sourceGroupId) is Imps.Client.Core.ContactGroup))
            {
                return false;
            }
        Label_00B9:
            buddyList = string.Empty;
            using (IEnumerator<int> enumerator = contact.BelongToGroups.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    int num = enumerator.get_Current();
                    int? nullable = targetGroupId;
                    if ((nullable.GetValueOrDefault() == num) && nullable.get_HasValue())
                    {
                        return false;
                    }
                    if ((type == SetBuddyListsType.Move) || (type == SetBuddyListsType.Delete))
                    {
                        int? nullable2 = sourceGroupId;
                        if ((num == nullable2.GetValueOrDefault()) && nullable2.get_HasValue())
                        {
                            continue;
                        }
                    }
                    buddyList = buddyList + num + ";";
                }
            }
            if (targetGroupId.get_HasValue())
            {
                buddyList = buddyList + targetGroupId.ToString();
            }
            SipRequest req = user.CreateSipRequest("S");
            req.Message.AddHeader(new SipcEventHeader("SetBuddyLists"));
            ParamForBiz biz = new ParamForBiz();
            biz.User = user;
            biz.Int1 = targetGroupId;
            op.ContextForBiz = biz;
            req.Context = op;
            StringWriter tw = new StringWriter();
            XmlHelper.CreateXmlWriterForSipRequest(tw, null, delegate (XmlWriter writer, object context) {
                writer.WriteStartElement("contacts");
                if ((contact.Type == ContactType.Buddy) || (contact.Type == ContactType.Vodafone))
                {
                    writer.WriteStartElement("buddies");
                    writer.WriteStartElement("buddy");
                }
                else if (contact.Type == ContactType.MobileBuddy)
                {
                    writer.WriteStartElement("mobile-buddies");
                    writer.WriteStartElement("mobile-buddy");
                }
                writer.WriteAttributeString("uri", contact.Uri.ToString());
                writer.WriteAttributeString("buddy-lists", buddyList);
                writer.WriteEndElement();
                writer.WriteEndElement();
                writer.WriteEndElement();
            });
            req.Message.Body = tw.ToString();
            ErrorHelper.HandleSendRequestErrorAndTimeout(req);
            req.FinalResponseReceived += new EventHandler<SipResponseReceivedEventArgs>(null, (IntPtr) finalResponse_AsyncSetBuddyLists);
            user.SendSipMessage(req);
            return true;
        }

        public bool AsyncUpdate(string newName, AsyncBizOperation op)
        {
            newName = newName.Trim();
            if (newName.Length == 0)
            {
                base.Owner.FireImpsErrorInUiThread(new ImpsErrorEventArgs(StringTable.ContactGroup.MsgNameNotAllowEmpty, 110), op);
                return false;
            }
            if (newName.Length > 0x40)
            {
                base.Owner.FireImpsErrorInUiThread(new ImpsErrorEventArgs(StringTable.ContactGroup.MsgAddGroupNameTooLong), op);
                return false;
            }
            if (newName != this.Name)
            {
                if ((newName == StringTable.ContactGroup.ChatFriendGroup) || (newName == StringTable.ContactGroup.UnGrouped))
                {
                    base.Owner.FireImpsErrorInUiThread(new ImpsErrorEventArgs(StringTable.ContactGroup.NotAllowFixedGroupName), op);
                    return false;
                }
                lock (base.Owner.ContactList.Groups.SyncRoot)
                {
                    using (IEnumerator<ContactGroupBase> enumerator = base.Owner.ContactList.Groups.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            Imps.Client.Core.ContactGroup group = (Imps.Client.Core.ContactGroup) enumerator.get_Current();
                            if (group.Name == newName)
                            {
                                base.Owner.FireImpsErrorInUiThread(new ImpsErrorEventArgs(StringTable.ContactGroup.NotAllowSameName), op);
                                return false;
                            }
                        }
                    }
                }
                SipRequest req = base.CreateSipRequest("S");
                req.Message.AddHeader(new SipcEventHeader("SetBuddyListInfo"));
                StringWriter tw = new StringWriter();
                XmlHelper.CreateXmlWriterForSipRequest(tw, null, delegate (XmlWriter writer, object context) {
                    writer.WriteStartElement("contacts");
                    writer.WriteStartElement("buddy-lists");
                    writer.WriteStartElement("buddy-list");
                    writer.WriteAttributeString("id", this.Id.ToString());
                    writer.WriteAttributeString("name", newName);
                    writer.WriteEndElement();
                    writer.WriteEndElement();
                    writer.WriteEndElement();
                });
                req.Message.Body = tw.ToString();
                ErrorHelper.HandleSendRequestErrorAndTimeout(req);
                req.FinalResponseReceived += new EventHandler<SipResponseReceivedEventArgs>(this, (IntPtr) this.finalResponse_AsyncUpdate);
                base.SendSipMessage(req);
            }
            return true;
        }

        public void finalResponse_AsyncDelete(object sender, SipResponseReceivedEventArgs e)
        {
            SipResponse sipMsg = e.Response;
            if (!sipMsg.IsOK)
            {
                LogHelper.LogReceivedSipMessage(sipMsg);
                switch (sipMsg.Message.StatusCode)
                {
                    case 0x1cd:
                        base.Owner.FireImpsErrorInUiThread(new ImpsErrorEventArgs(StringTable.ContactGroup.MsgCannotDelelte_HasContacts));
                        return;

                    case 500:
                        base.Owner.FireImpsErrorInUiThread(new ImpsErrorEventArgs(StringTable.MsgSipRespInternalServerError));
                        return;

                    case 400:
                        base.Owner.FireImpsErrorInUiThread(new ImpsErrorEventArgs(StringTable.MsgBadRequest));
                        return;

                    case 0x194:
                        base.Owner.ContactList.AsyncReGetContactList(new AsyncBizOperation(), false);
                        return;
                }
                base.Owner.FireImpsErrorInUiThread(new ImpsErrorEventArgs(StringTable.ContactGroup.MsgDeleteFailed));
            }
            else
            {
                XmlDocument document = new XmlDocument();
                document.LoadXml(sipMsg.Message.Body);
                string text = XmlHelper.ReadXmlAttributeString(document.DocumentElement.SelectSingleNode("contacts"), "version");
                if (text.Length == 0)
                {
                    LogHelper.LogFatalError("DeleteGroup,返回版本号错误");
                    LogHelper.LogReceivedSipMessage(sipMsg);
                    base.Owner.FireImpsErrorInUiThread(new ImpsErrorEventArgs(StringTable.ContactGroup.MsgDeleteFailed));
                }
                else
                {
                    string xpath = "contacts" + "/" + "buddy-lists" + "/" + "buddy-list";
                    if (XmlHelper.ReadXmlAttributeInt32(document.DocumentElement.SelectSingleNode(xpath), "id", 0) != this.Id)
                    {
                        LogHelper.LogFatalError("DeleteGroup,返回Id错误");
                        LogHelper.LogReceivedSipMessage(sipMsg);
                        base.Owner.FireImpsErrorInUiThread(new ImpsErrorEventArgs(StringTable.ContactGroup.MsgDeleteFailed));
                    }
                    else
                    {
                        base.Owner.ContactList.Groups.Remove(this);
                        base.Owner.ContactList.Version = text;
                        base.Owner.ContactList.SaveContactListXml();
                    }
                }
            }
        }

        private static void finalResponse_AsyncSetBuddyLists(object sender, SipResponseReceivedEventArgs e)
        {
            SipResponse sipMsg = e.Response;

⌨️ 快捷键说明

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