public string[] Generate(ILanguageGenerator language) { CheckPrimitives(language); var code = language.ParseDesc(m_desc, this); foreach (var pkt in m_pkts) { var gc = language.Generate(pkt, this); for (var i = 0; i < code.Length; ++i) { code[i] += string.IsNullOrEmpty(gc[i]) ? "" : gc[i] + "\r\n"; } } if (m_pkts.Count > 0) { for (var i = 0; i < code.Length; ++i) { code[i] = code[i].Length > 2 ? code[i].Substring(0, code[i].Length - 2) : code[i]; } } return(code); }
/// <summary> /// Generates an instruction from the given meta data and given pois. /// </summary> /// <param name="metaData"></param> /// <param name="segmentIdx"></param> /// <param name="box"></param> /// <param name="pois"></param> internal void GenerateInstruction(Dictionary <string, object> metaData, int segmentIdx, GeoCoordinateBox box, List <PointPoi> pois) { string text; if (_generator.Generate(metaData, out text)) { // add the instruction to the instructions list. _instructions.Add(new Instruction(metaData, segmentIdx, box, text, pois)); } }
public virtual async Task <Activity> BindToData(ITurnContext context, object data) { if (!string.IsNullOrEmpty(this.Template)) { // if there is a message generator use that IActivityGenerator activityGenerator = context.TurnState.Get <IActivityGenerator>(); if (activityGenerator != null) { var result = await activityGenerator.Generate( turnContext : context, template : this.Template, data : data).ConfigureAwait(false); return(result); } // fallback to just text based LG if there is a language generator var message = Activity.CreateMessageActivity(); message.Text = this.Template; message.Speak = this.Template; ILanguageGenerator languageGenerator = context.TurnState.Get <ILanguageGenerator>(); if (languageGenerator != null) { var result = await languageGenerator.Generate( turnContext : context, template : Template, data : data).ConfigureAwait(false); if (result != null) { message.Text = result; message.Speak = result; } } return(message as Activity); } return(null); }
public virtual async Task <string> BindToData(ITurnContext turnContext, object data) { if (string.IsNullOrEmpty(this.Template)) { throw new ArgumentNullException(nameof(this.Template)); } ILanguageGenerator languageGenerator = turnContext.TurnState.Get <ILanguageGenerator>(); if (languageGenerator != null) { var result = await languageGenerator.Generate( turnContext, template : Template, data : data).ConfigureAwait(false); return(result); } return(null); }