/// <summary> /// Resolve Dialog Expression as either Dialog, or StringExpression to get dialogid. /// </summary> /// <param name="dc">dialogcontext.</param> /// <returns>dialog.</returns> protected virtual Dialog ResolveDialog(DialogContext dc) { if (this.Dialog?.Value != null) { return(this.Dialog.Value); } // NOTE: we want the result of the expression as a string so we can look up the string using external FindDialog(). var se = new StringExpression($"={this.Dialog.ExpressionText}"); var dialogId = se.GetValue(dc.State); return(dc.FindDialog(dialogId ?? throw new Exception($"{this.Dialog.ToString()} not found."))); }
/// <summary> /// Gets a value from a string expression, using a <see cref="TextTemplate"/>. /// </summary> /// <param name="stringExpression">The <see cref="StringExpression"/> to evaluate.</param> /// <param name="dc">The current <see cref="DialogContext"/>.</param> /// <param name="cancellationToken"><see cref="CancellationToken"/> for this call.</param> /// <returns>A <see cref="Task{TResult}"/> representing the result of the asynchronous operation.</returns> public static async Task <string> GetValueAsync(this StringExpression stringExpression, DialogContext dc, CancellationToken cancellationToken) { string text = await new TextTemplate(stringExpression.ExpressionText) .BindAsync(dc, cancellationToken: cancellationToken) .ConfigureAwait(false) ?? stringExpression.GetValue(dc.State); if (!string.IsNullOrEmpty(text) && text.StartsWith("=", StringComparison.OrdinalIgnoreCase)) { text = AdaptiveExpressions.Expression.Parse(text).TryEvaluate <string>(dc.State).value; } return(text); }
protected Dialog ResolveDialog(DialogContext dc) { if (this.Dialog?.Value != null) { return(this.Dialog.Value); } var dcState = dc.GetState(); // NOTE: we call TryEvaluate instead of TryGetValue because we want the result of the expression as a string so we can // look up the string using external FindDialog(). var se = new StringExpression($"={this.Dialog.ExpressionText}"); var dialogId = se.GetValue(dcState); return(dc.FindDialog(dialogId ?? throw new Exception($"{this.Dialog.ToString()} not found."))); }
public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = new CancellationToken()) { var status = string.Empty; try { var input = FilesInfo?.GetValue(dc.State); if (!string.IsNullOrEmpty(input)) { var imageList = JsonConvert.DeserializeObject <List <SaveImage> >(input); if (imageList?.Count > 0) { foreach (var saveImage in imageList) { var webClient = new WebClient(); webClient.DownloadFileAsync(saveImage.ContentUrl, saveImage.Name); } status = "successfully"; } else { status = "Failed"; } } } catch (Exception e) { status = e.Message; } await dc.Context.SendActivityAsync(MessageFactory.Text($"Files upload {status}"), cancellationToken); return(await dc.EndDialogAsync(null, cancellationToken)); }