?? autoreplyer.cs
字號:
using System;
using System.ComponentModel;
using Org.InteliIM;
using Org.InteliIM.Activities.Conversations;
namespace Org.InteliIM.Activities.Interactive
{
/// <summary>
/// 自動應答器
/// </summary>
public class AutoReplyer: Component
{
/// <summary>
/// 構造函數(shù)
/// </summary>
public AutoReplyer()
{
this.InitializeComponent();
}
private void InitializeComponent()
{
}
private IMClient client = null;
/// <summary>
/// 相關聯(lián)的 IM 客戶端對象
/// </summary>
public IMClient Client
{
get
{
return this.client;
}
set
{
this.client = value;
this.UpdateConversationState();
}
}
private Conversation conversation = null;
/// <summary>
/// 相關聯(lián)的談話對象
/// </summary>
public Conversation Conversation
{
get
{
return this.conversation;
}
set
{
this.conversation = value;
this.UpdateConversationState();
}
}
private AbstractEngine engine = null;
/// <summary>
/// 相關聯(lián)的自動應答引擎
/// </summary>
public AbstractEngine Engine
{
get
{
return this.engine;
}
set
{
this.engine = value;
this.UpdateConversationState();
}
}
private bool enabled = false;
/// <summary>
/// 是否啟用
/// </summary>
public bool Enabled
{
get
{
return this.enabled;
}
set
{
this.enabled = value;
this.UpdateConversationState();
}
}
/// <summary>
/// 刷新談話狀態(tài)(事件)
/// </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.User.Id)
{
string expr = e.Message.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 = "系統(tǒng)已經(jīng)完成服務,歡迎再次使用.";
}
ChatMessage message = new ChatMessage();
message.Content = strResult;
this.Client.Chat(this.Conversation, message);
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -