public override async Task <DialogTurnResult> ContinueDialogAsync(DialogContext dc, CancellationToken cancellationToken = new CancellationToken()) { var current = dc.State.GetStringValue("dialog.current", string.Empty); if (dc.Context.Activity.Text == CompleteDtmfChar.GetValue(dc.State)) { string path = ResultProperty.GetValue(dc.State); if (path == string.Empty) { throw new InvalidOperationException("Unable to save the DTMF value, incorrect Result expression"); } else { dc.State.SetValue(path, current); return(await dc.EndDialogAsync(result : current, cancellationToken : cancellationToken)); } } if (Regex.IsMatch(dc.Context.Activity.Text, "^[0123456789]{1}$")) { dc.State.SetValue("dialog.current", $"{current}{dc.Context.Activity.Text}"); } return(EndOfTurn); }
/// <summary> /// Processes the specified <see cref="IDataReader"/> /// when a ResultMap is specified on the statement. /// </summary> /// <param name="request">The request.</param> /// <param name="reader">The reader.</param> /// <param name="resultObject">The result object.</param> public object Process(RequestScope request, ref IDataReader reader, object resultObject) { object outObject = resultObject; IResultMap resultMap = request.CurrentResultMap.ResolveSubMap(reader); //查询返回结果带构造函数的类 if (outObject == null) { object[] parameters = null; if (resultMap.Parameters.Count > 0) { parameters = new object[resultMap.Parameters.Count]; // Fill parameters array for (int index = 0; index < resultMap.Parameters.Count; index++) { ResultProperty resultProperty = resultMap.Parameters[index]; parameters[index] = resultProperty.GetValue(request, ref reader, null); } } outObject = resultMap.CreateInstanceOfResult(parameters); } // For each Property in the ResultMap, set the property in the object for (int index = 0; index < resultMap.Properties.Count; index++) { ResultProperty property = resultMap.Properties[index]; property.PropertyStrategy.Set(request, resultMap, property, ref outObject, reader, null); } return(outObject); }
/// <summary> /// Processes the specified <see cref="IDataReader"/>. /// </summary> /// <param name="request">The request.</param> /// <param name="reader">The reader.</param> /// <param name="resultObject">The result object.</param> /// <returns></returns> public object Process(RequestScope request, ref IDataReader reader, object resultObject) { object outObject = resultObject; IResultMap resultMap = request.CurrentResultMap.ResolveSubMap(reader); string circularKey = GetCircularKey(resultMap, reader); // Gets the [key, result object] already build IDictionary <string, object> buildObjects = request.GetCirularKeys(resultMap); if (buildObjects != null && buildObjects.ContainsKey(circularKey)) { // circular key is already known, so get the existing result object outObject = buildObjects[circularKey]; } else if (circularKey == null || buildObjects == null || !buildObjects.ContainsKey(circularKey)) { // circular key is NOT known, so create a new result object. if (outObject == null) { object[] parameters = null; if (resultMap.Parameters.Count > 0) { parameters = new object[resultMap.Parameters.Count]; // Fill parameters array for (int index = 0; index < resultMap.Parameters.Count; index++) { ResultProperty resultProperty = resultMap.Parameters[index]; parameters[index] = resultProperty.GetValue(request, ref reader, null); } } outObject = resultMap.CreateInstanceOfResult(parameters); } // For each Property in the ResultMap, set the property in the object for (int index = 0; index < resultMap.Properties.Count; index++) { ResultProperty resultProperty = resultMap.Properties[index]; resultProperty.PropertyStrategy.Set(request, resultMap, resultProperty, ref outObject, reader, null); } if (buildObjects == null) { buildObjects = new Dictionary <string, object>(); request.SetCirularKeys(resultMap, buildObjects); } buildObjects[circularKey] = outObject; } return(outObject); }
public override Task <DialogTurnResult> ContinueDialogAsync(DialogContext dc, CancellationToken cancellationToken = default) { if (dc.Context.Activity.Type == ActivityTypes.EndOfConversation) { // Capture the result of the dialog if the property is set if (ResultProperty != null) { dc.State.SetValue(ResultProperty.GetValue(dc.State), dc.Context.Activity.Value); } } return(base.ContinueDialogAsync(dc, cancellationToken)); }
/// <summary> /// Gets the value of the specified <see cref="ResultProperty"/> that must be set on the target object. /// </summary> /// <param name="request">The request.</param> /// <param name="resultMap">The result map.</param> /// <param name="mapping">The mapping.</param> /// <param name="reader">The reader.</param> /// <param name="target">The target object</param> public object Get(RequestScope request, IResultMap resultMap, ResultProperty mapping, ref object target, IDataReader reader) { object[] parameters = null; bool isParameterFound = false; IResultMap resultMapping = mapping.NestedResultMap.ResolveSubMap(reader); if (resultMapping.Parameters.Count > 0) { parameters = new object[resultMapping.Parameters.Count]; // Fill parameters array //获取返回结果类构造函数所需要的参数的值 for (int index = 0; index < resultMapping.Parameters.Count; index++) { ResultProperty resultProperty = resultMapping.Parameters[index]; parameters[index] = resultProperty.GetValue(request, ref reader, null); request.IsRowDataFound = request.IsRowDataFound || (parameters[index] != null); isParameterFound = isParameterFound || (parameters[index] != null); } } object obj = null; // If I have a constructor tag and all argumments values are null, the obj is null if (resultMapping.Parameters.Count > 0 && isParameterFound == false) { obj = null; } else { //创建返回类对象 动态初始化 ResultMap类中实现 obj = resultMapping.CreateInstanceOfResult(parameters); // Fills properties on the new object //实现对obj中每一个属性的赋值 BaseStrategy中实现 if (FillObjectWithReaderAndResultMap(request, reader, resultMapping, ref obj) == false) { obj = null; } } return(obj); }
/// <summary> /// Gets the value of an argument constructor. /// </summary> /// <param name="request">The current <see cref="RequestScope"/>.</param> /// <param name="mapping">The <see cref="ResultProperty"/> with the argument infos.</param> /// <param name="reader">The current <see cref="IDataReader"/>.</param> /// <param name="keys">The keys</param> /// <returns>The paremeter value.</returns> public object GetValue(RequestScope request, ResultProperty mapping, ref IDataReader reader, object keys) { object[] parameters = null; bool isParameterFound = false; IResultMap resultMapping = mapping.NestedResultMap.ResolveSubMap(reader); if (resultMapping.Parameters.Count > 0) { parameters = new object[resultMapping.Parameters.Count]; // Fill parameters array for (int index = 0; index < resultMapping.Parameters.Count; index++) { ResultProperty property = resultMapping.Parameters[index]; parameters[index] = property.GetValue(request, ref reader, null); request.IsRowDataFound = request.IsRowDataFound || (parameters[index] != null); isParameterFound = isParameterFound || (parameters[index] != null); } } object obj = null; // If I have a constructor tag and all argumments values are null, the obj is null if (resultMapping.Parameters.Count > 0 && isParameterFound == false) { obj = null; } else { obj = resultMapping.CreateInstanceOfResult(parameters); if (FillObjectWithReaderAndResultMap(request, reader, resultMapping, ref obj) == false) { obj = null; } } return(obj); }
/// <inheritdoc/> public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object opts = null, CancellationToken cancellationToken = default(CancellationToken)) { if (opts != null) { throw new NotSupportedException($"{nameof(opts)} is not supported by this action."); } if (this.Disabled != null && this.Disabled.GetValue(dc.State) == true) { return(await dc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false)); } var gitHubClient = GetGitHubClient(dc); var result = await CallGitHubApi(dc, gitHubClient, cancellationToken).ConfigureAwait(false); if (this.ResultProperty != null) { dc.State.SetValue(ResultProperty.GetValue(dc.State), result); } return(await dc.EndDialogAsync(result, cancellationToken : cancellationToken).ConfigureAwait(false)); }