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

📄 instantmessage.cs

📁 该源代码用 C# 写成
💻 CS
字号:
using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using Org.InteliIM.Activities.Alert;
using Org.InteliIM.Activities.Conversations;
using Org.InteliIM.Activities.FileSharing;
using Org.InteliIM.Activities.LeaveWord;
using Org.InteliIM.Configurations;
using Org.InteliIM.Office;
using Org.InteliIM.Users;

namespace Org.InteliIM
{
	/// <summary>
	/// 即时消息
	/// </summary>
	// 包含XmlSerializer 序列化或反序列化对象时需要识别的即时消息类型
	[XmlInclude(typeof (ConfirmInstantMessage))]

	[XmlInclude(typeof (MessageAlert))]
	[XmlInclude(typeof (MessageAssets))]

	[XmlInclude(typeof (MessageChat))]
	[XmlInclude(typeof (MessageCloseConversation))]
	[XmlInclude(typeof (MessageContactGroups))]
	[XmlInclude(typeof (MessageContactList))]
	[XmlInclude(typeof (MessageContactStatusChanged))]

	[XmlInclude(typeof (MessageDownloadData))]
	[XmlInclude(typeof (MessageDownloadRequest))]
	[XmlInclude(typeof (MessageDownloadResponse))]

	[XmlInclude(typeof (MessageErrorOccurred))]

	[XmlInclude(typeof (MessageForceLogout))]

	[XmlInclude(typeof (MessageGetAssets))]
	[XmlInclude(typeof (MessageGetContactGroups))]
	[XmlInclude(typeof (MessageGetContactInfo))]
	[XmlInclude(typeof (MessageGetContactInfoResult))]
	[XmlInclude(typeof (MessageGetContacts))]

	[XmlInclude(typeof (MessageLeaveWord))]
	[XmlInclude(typeof (MessageLogin))]
	[XmlInclude(typeof (MessageLoginResult))]
	[XmlInclude(typeof (MessageLogout))]

	[XmlInclude(typeof (MessageModifyUserInfo))]
	[XmlInclude(typeof (MessageModifyUserInfoResult))]

	[XmlInclude(typeof (MessageOpenConversation))]
	[XmlInclude(typeof (MessageOrganizationInfoChanged))]

	[XmlInclude(typeof (MessageRegistration))]
	[XmlInclude(typeof (MessageRegistrationResult))]

	[XmlInclude(typeof (MessageSearchContacts))]
	[XmlInclude(typeof (MessageSendFeedback))]
	[XmlInclude(typeof (MessageSendFeedbackResult))]
	[XmlInclude(typeof (MessageServerServiceStatusChanged))]
	[XmlInclude(typeof (MessageSetStatus))]
	[XmlInclude(typeof (MessageStartDownload))]

	[XmlInclude(typeof (MessageTestConnection))]
	[XmlInclude(typeof (MessageTestConnectionReply))]
	public class InstantMessage
	{
		public static string TestConnection = "#TestConnection#";
		public static string TestConnectionReply = "#TestConnectionReply#";

		private string transactionId;

		/// <summary>
		/// 编号
		/// </summary>
		public string TransactionId
		{
			get
			{
				if (this.transactionId == null)
					this.transactionId = Guid.NewGuid().ToString();

				return this.transactionId;
			}
			set { this.transactionId = value; }
		}

		private string from;

		/// <summary>
		/// 用户名
		/// </summary>
		public string From
		{
			get { return from; }
			set { from = value; }
		}

		private string to;

		/// <summary>
		/// 接收该消息的用户 ID
		/// </summary>
		public string To
		{
			get { return this.to; }
			set { this.to = value; }
		}

		private InstantMessagePriority priority
			= InstantMessagePriority.Normal;

		/// <summary>
		/// 优先级
		/// </summary>
		public InstantMessagePriority Priority
		{
			get { return this.priority; }
			set { this.priority = value; }
		}

		/// <summary>
		/// 构造函数
		/// </summary>
		public InstantMessage()
		{
		}

		/// <summary>
		/// 返回当前 Org.InteliIM.InstantMessage 的 System.String 表示,已重载
		/// </summary>
		/// <returns></returns>
		public override string ToString()
		{
			StringBuilder sb = new StringBuilder();

			sb.Append("未知的消息");

			return sb.ToString();
		}

		/// <summary>
		/// 串行化
		/// </summary>
		/// <returns></returns>
		public string Serialize()
		{
			XmlSerializer serializer = new XmlSerializer(typeof (InstantMessage));

			StringBuilder sb = new StringBuilder();
			StringWriter sw = new StringWriter(sb);

			XmlWriter writer = new XmlTextWriter(sw);

			serializer.Serialize(writer, this);

			return sb.ToString();
		}

		/// <summary>
		/// 反串行化
		/// </summary>
		/// <param name="text"></param>
		/// <returns></returns>
		public InstantMessage Deserialize(string text)
		{
			XmlSerializer serializer = new XmlSerializer(typeof (InstantMessage));

			StringReader sr = new StringReader(text);

			XmlReader reader = new XmlTextReader(sr);

			return serializer.Deserialize(reader) as InstantMessage;
		}
	}
}

⌨️ 快捷键说明

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