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

📄 autoreplyer.cs

📁 这个版本(InteliIM Open Kernel Release 2)是目前最新的(首次公开)
💻 CS
字号:
using System;
using System.ComponentModel;

using Org.InteliIM;
using Org.InteliIM.Applications.Messenger.Conversations;
using Org.InteliIM.Communications;

namespace Org.InteliIM.Applications.Messenger.Interactive
{
	/// <summary>
	/// Represents the auto replyer for interactive services.
	/// </summary>
	public class AutoReplyer
	{
		/// <summary>
		/// Initializes a new instance of the AutoReplyer class.
		/// </summary>
		public AutoReplyer()
		{
		}

		private IMClient client = null;

		/// <summary>
		/// Gets or sets the client.
		/// </summary>
		public IMClient Client
		{
			get
			{
				return this.client;
			}
			set
			{
				this.client = value;

				this.UpdateConversationState();
			}
		}

		private Conversation conversation = null;

		/// <summary>
		/// Gets or sets the conversation.
		/// </summary>
		public Conversation Conversation
		{
			get
			{
				return this.conversation;
			}
			set
			{
				this.conversation = value;

				this.UpdateConversationState();
			}
		}

		private AbstractEngine engine = null;

		/// <summary>
		/// Gets or sets the engine.
		/// </summary>
		public AbstractEngine Engine
		{
			get
			{
				return this.engine;
			}
			set
			{
				this.engine = value;

				this.UpdateConversationState();
			}
		}

		private bool enabled = false;

		/// <summary>
		/// Gets or sets the enabled.
		/// </summary>
		public bool Enabled
		{
			get
			{
				return this.enabled;
			}
			set
			{
				this.enabled = value;

				this.UpdateConversationState();
			}
		}

		/// <summary>
		/// Update the state of the conversation.
		/// </summary>
		private void UpdateConversationState()
		{
			if(this.Enabled)
			{
				if(this.Conversation != null)
				{
					this.Conversation.ChatMessageReceived +=new ChatMessageReceivedEventHandler(Conversation_ChatMessageReceived);
				}
			}
			else
			{
				if(this.Conversation != null)
				{
					this.Conversation.ChatMessageReceived -= new ChatMessageReceivedEventHandler(Conversation_ChatMessageReceived);
				}
			}
		}

		private void Conversation_ChatMessageReceived(object sender, ChatMessageReceivedEventArgs e)
		{
			if(this.Enabled && this.Client != null
				&& this.Engine != null && this.Conversation != null
				&& this.Engine.CurrentStatus != null
				&& e.From != this.Client.Owner.Id)
			{				
				string expr = e.ChatContent.Content;
													
				this.Engine.CurrentStatus.Accept(expr);
													
				Status nextStatus = this.Engine.CurrentStatus.NextStatus;
													
				String strResult = null;
													
				if (nextStatus != null)
				{
					this.Engine.CurrentStatus = nextStatus;
					strResult = this.Engine.CurrentStatus.getDisplayString();
				}
				else
				{
					strResult = "Service Completed.";
				}

				ChatContent message = new ChatContent();
				message.Content = strResult;

				this.Client.Chat(this.Conversation, message);	
			}
		}
	}
}

⌨️ 快捷键说明

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