2013-02-20 62 views
0

我正在開發一個UCMA 3.0工作流應用程序,並試圖在我們的客戶端管理系統中生成查詢,允許最終用戶通過語音或即時消息獲取有關特定客戶端的數據。我想知道如何使用允許通用輸入的UCMA創建一個通用的問答活動。我知道我可以設置預期的輸入和語法,但是通過雙數據化選項以及最終用戶可能知道確切的客戶名稱(或客戶端號碼)的可能性,我寧願允許用戶輸入部分名稱,然後在數據庫中搜索可能符合條件的名稱列表。有沒有人知道一種方法,並有示例代碼,可以讓我做到這一點,如果可能的話?UCMA通用問題答案活動

回答

0

我有同樣的問題,不得不寫一個自定義活動來捕獲用戶的一般輸入。這需要一些工作來使其生產就緒。請注意在多個位置優先捕獲system.exception,並且如果在超時期限內沒有收到輸入,而不是重新提示用戶,則會拋出異常。也沒有正則表達式在用戶輸入...

InstanceDependencyProperty是令人沮喪的工作流的東西。如果不使用InstanceDependencyProperties,則在活動完成後將無法檢索任何結果。

希望這會有所幫助!

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 

    } 
}