首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UCMA通用QuestionAnswer活动

UCMA通用QuestionAnswer活动
EN

Stack Overflow用户
提问于 2013-02-21 06:41:53
回答 1查看 168关注 0票数 0

我正在开发一个UCMA 3.0工作流应用程序,并试图在我们的客户管理系统中生成查询,允许最终用户通过语音或即时消息获取有关特定客户的数据。我想知道有谁知道如何使用UCMA创建一个允许通用输入的通用问题回答活动。我知道我可以设置预期的输入和语法,但是使用双大写选项,以及最终用户可能知道确切的客户名称(或客户编号),我更愿意允许用户输入部分名称,然后在数据库中搜索可能满足条件的名称列表。有没有人知道一种方法,如果可能的话,有样例代码可以让我这样做吗?

EN

回答 1

Stack Overflow用户

发布于 2013-03-15 02:25:24

我遇到了同样的问题,不得不编写一个自定义活动来捕获来自用户的通用输入。这需要一些工作来使其为生产做好准备。注意在多个地方对system.exception的优雅捕获,以及如果在超时期间没有收到输入就抛出异常,而不是重新提示用户。在用户输入上也没有正则表达式...

InstanceDependencyProperty是工作流的另一个令人沮丧的地方。如果不使用InstanceDependencyProperties,您将无法在活动完成后检索任何结果。

希望这能有所帮助!

代码语言:javascript
复制
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Threading;

using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.Runtime;
using Microsoft.Rtc.Collaboration;
using Microsoft.Rtc.Workflow.Activities;
using Microsoft.Rtc.Workflow.Common;


namespace ActivityLibrary
{
    public partial class CaptureIMInput : Activity, IInstanceDependencyContainer
    {
        #region Private member variables
        private CallProvider _callProvider;
        private Timer _maximumTimer;
        private string _imText;
        private bool messageReceived = false;
        private bool _maximumTimerElapsed = false;
        #endregion

        public CaptureIMInput()
        {
            InitializeComponent();
            _instanceDependencyProperties = new Dictionary<string, object>();
        }

        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            try
            {
                this._callProvider = Utilities.GetCallProviderFromParent<InstantMessagingCall>(this);
                InstantMessagingCall call = (InstantMessagingCall)this._callProvider.Call;

                try
                {

                    if (call.State == CallState.Established)
                    {
                        call.Flow.EndSendInstantMessage(call.Flow.BeginSendInstantMessage(MainPrompt, null, null));
                        _maximumTimer = new Timer(new TimerCallback(OnMaximumTimerFired), null, MaximumPrompt, new TimeSpan(0, 0, 0, 0, -1));
                        call.Flow.MessageReceived += this.InstantMessagingFlow_MessageReceived;
                        while (!messageReceived)
                            {
                                if (_maximumTimerElapsed)
                                    throw new TimeoutException("User input was not detected within alloted time");
                            }
                        if (!string.IsNullOrEmpty(_imText))
                        {
                            IMText = _imText;
                            {
                                this.Stop();
                                return ActivityExecutionStatus.Closed;
                            }
                        }
                    }

                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return ActivityExecutionStatus.Closed;
        }

        protected override ActivityExecutionStatus Cancel(ActivityExecutionContext executionContext)
        {
            this.Stop(); //Clean up timer
            return ActivityExecutionStatus.Canceling;
        }

        private void Stop()
        {
            if (_maximumTimer != null)
            {
                _maximumTimer.Dispose();
                _maximumTimer = null;
            }
        }

        private void InstantMessagingFlow_MessageReceived(object sender, InstantMessageReceivedEventArgs e)
        {
            //Can't set dependencyproperties directly from sub-thread
            _imText = e.TextBody;
            //Mark bool so main while loop exits
            messageReceived = true;
        }

        //Callback to 
        private void OnMaximumTimerFired(object state)
        {
            _maximumTimerElapsed = true;
        }


        #region InstanceDependency dictionary
        private Dictionary<string, object> _instanceDependencyProperties;
        [Browsable(false)]
        public Dictionary<string, object> InstanceDependencyProperties
        {
            get { return _instanceDependencyProperties; }
        }
        #endregion

        #region Maximum Prompt Timeout
        [NonSerialized]
        private static readonly InstanceDependencyProperty MaximumPromptProperty = InstanceDependencyProperty.Register("MaximumPrompt", typeof(TimeSpan), typeof(CaptureIMInput), new TimeSpan(0, 0, 30));

        [TypeConverter(typeof(TimeSpanConverter))]
        public TimeSpan MaximumPrompt
        {
            get
            {
                if (base.DesignMode)
                    return (TimeSpan)InstanceDependencyHelper.GetValue<CaptureIMInput>(this, MaximumPromptProperty);
                else
                    return (TimeSpan)InstanceDependencyHelper.GetValue<CaptureIMInput>(this, this.WorkflowInstanceId, MaximumPromptProperty);
            }
            set
            {
                if (base.DesignMode)
                    InstanceDependencyHelper.SetValue<CaptureIMInput>(this, MaximumPromptProperty, value);
                else
                    InstanceDependencyHelper.SetValue<CaptureIMInput>(this, this.WorkflowInstanceId, MaximumPromptProperty, value);
            }
        }
        #endregion

        #region MainPrompt
        public static DependencyProperty MainPromptProperty =
            DependencyProperty.Register("MainPrompt", typeof(string), typeof(CaptureIMInput));

        [ValidationOption(ValidationOption.Required)]
        public string MainPrompt
        {
            get
            {
                return (string)base.GetValue(MainPromptProperty);
            }
            set
            {
                base.SetValue(MainPromptProperty, value);
            }
        }
        #endregion

        #region Instant Message Text
        public static InstanceDependencyProperty IMTextProperty =
            InstanceDependencyProperty.Register("IMText",
                typeof(string),
                typeof(CaptureIMInput));

        [Description("InstantMessaging Text from user")]
        [Browsable(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public string IMText
        {
            get
            {
                if (base.DesignMode) return ((string)InstanceDependencyHelper.GetValue<CaptureIMInput>(this, CaptureIMInput.IMTextProperty));
                else return ((string)(InstanceDependencyHelper.GetValue<CaptureIMInput>(this, this.WorkflowInstanceId, CaptureIMInput.IMTextProperty)));
            }
            set
            {
                if (base.DesignMode) InstanceDependencyHelper.SetValue<CaptureIMInput>(this, CaptureIMInput.IMTextProperty, value);
                else InstanceDependencyHelper.SetValue<CaptureIMInput>(this, this.WorkflowInstanceId, CaptureIMInput.IMTextProperty, value);
            }
        }
        #endregion

    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14991329

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档