Bot Framework Change form prompt message - botframework

I'm currently tying to make a formflow in C# using bot framework, here's my code so far:
[Serializable]
[Template(TemplateUsage.EnumSelectOne, "Selecciona un estadio: {||}", ChoiceStyle = ChoiceStyleOptions.PerLine)]
public class StadiumInfoForm
{
[Prompt("Selecciona un estadio: ", ChoiceFormat = "{1}")]
public StadiumOptions? estadio;
public static IForm<StadiumInfoForm> BuildForm()
{
var form = new FormBuilder<StadiumInfoForm>()
.Message($"¿De qué estadio te gustaría saber?")
.AddRemainingFields();
PromptAttribute title = new PromptAttribute();
List<string> quitCommands = new List<string>();
quitCommands.Add("Salir");
quitCommands.Add("Cancelar");
quitCommands.Add("No");
quitCommands.Add("Quiero salir");
quitCommands.Add("Nada");
form.Configuration.Commands[FormCommand.Quit].Terms = quitCommands.ToArray();
return form.Build();
}
}
As you can see the form will be in spanish, the problem is that the prompt displayed at the top of the form always reads "Please select an estadio", I tried changing it following this documentation but to no avail, how can I change this attribute of the form to display something like "Seleccione un estadio por favor"
I'll upload more code if needed.

Maybe the template of the class "confusing" the FormFlow?
[Serializable]
[Template(TemplateUsage.NavigationFormat, "{&}")]
public class StadiumInfoForm
{
[Prompt("Seleccione un estadio por favor{||}", ChoiceFormat = "{1}")]
public StadiumOptions? estadio;
{&} is a pattern language
With only these changes it works for me
P.S. If you want to change the language of the entire FormFlow you can add activity.Locale = "es-ES"; in the Post method of your "MessagesController"

Related

Specifying LUIS dialog spellCheck, slot programmatically

so far I was able to avoid hardcoding my LUIS appId and key by doing the following:
var luisService = new LuisService(new LuisModelAttribute(ConfigurationManager.AppSettings["LuisAppId"], ConfigurationManager.AppSettings["LuisAppKey"]));
context.Call(new LuisDialog(luisService), ResumeAfterDialog);
And then having my LUIS dialog declared as:
[Serializable]
public class LuisDialog : LuisDialog<object>
{
public LuisDialog(ILuisService ls) : base(ls)
{
}
....
}
}
But I would also like to be able to set SpellCheck=true, Log, Verbose and other parameters available in the LuisModel attribute programmatically, is there a way of doing that?
Thanks
I figured it out, I just need to set the LuisModelAttribute properties in code before creating the LuisService:
var luisSettings = new LuisModelAttribute(ConfigurationManager.AppSettings["LuisAppId"], ConfigurationManager.AppSettings["LuisAppKey"]);
luisSettings.Log = true;
luisSettings.SpellCheck = true;
luisSettings.Log = true;
var luisService = new LuisService(luisSettings);
context.Call(new LuisDialog(luisService), ResumeAfterDialog);

Sitecore ContentEditor Callback and Custom Field Type

I'm developing a custom field type that extends from LookupEx. The purpose of the control is to allow the user to select from the drop down, and based upon that selection populated additional fields of type Multilist.
public class CascadingDroplink : LookupEx
{
private const string sourceFieldName = "CascadingDroplink";
protected override void DoRender(System.Web.UI.HtmlTextWriter output)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("<script type=\"text / javascript\">");
sb.AppendLine(" var $j = jQuery.noConflict(); ");
sb.AppendLine(string.Format(" $j(\"#{0}\").change(function(event) {{ ", this.ID));
sb.AppendLine(string.Format("scForm.invoke('contenteditor:save', event);"));
sb.AppendLine(string.Format(" }});"));
sb.AppendLine("</script>");
output.Write(sb.ToString());
Fromt the embeded javascript, you can see I have found a way to perform a callback by simulating the click even of the Save button:
scForm.invoke('contenteditor:save', event);
And while this works, the content editor is refreshed, and the Multilist fields are updated with custom datasources, saving isn't ideal because there could be validation present.
How can the contenteditor be refreshed, as if the area was within a callback panel, without calling save?
Thanks!

isolated storage in windows phone developement

Im using VS to develop a windows phone app. Im doing it wp8 but it doesnt matter because it the code works for 7 too. Anyway, I have a text box and a button. When the text from the text box is entered, and the button is clicked it adds that to isolated storage.
On my other page, I have a textblock. Which should display what I wrote in the text box. It does work, but first let me sho you my code.
if (appsettings.Contains("name"))
{
appsettings.Remove("name");
appsettings.Add("name", TitleTextBox.Text); //rename if already exists
}
and then the second page that collects the info is below.
if (appsettings.Contains("name"))
{
string content = appsettings["name"].ToString(); //converts to string
titleTextBlock.Text = content; //shows title in text block
}
The problem is, the "name" works. However, if I call it ANYTHING else it does not. I want to add a different name because i want to be able to input two lots. For example two text box's and then when you press the button and go to the other page, it has two textblocks displaying each string in each one. I can't seem to do this because only "name" works. Ive changed it to other names and it doesnt work. Does anyone know why?
IsolatedStorageSettings works as a Dictionary. If you want to acces a specific key it should exist in the Dictionary.
If you try to change the value that already exists you can do like this:
if (appSettings.Contains("key")) appSettings["key"] = "new value";
else appSettings.Add("key", "new value");
Don't also forget to save your appSettings:
appSettings.Save();
And also according to your code - in ISS you can put not only string - it can be any object, if you want to get it, you should make a cast or use as:
string content = (string)appsettings["name"]; //converts to string
string content = appsettings["name"] as string;
EDIT - after comments, rebuild once more
If you want to have a to-do-list and you know that every task has its specific title, description and time then I would advise to create a special class for this, for example:
public class myTodo
{
public string TaskTitle { get; set; }
public string TaskDescription { get; set; }
public TimeSpan ElapsedTime { get; set; }
}
I used TimeSpan because I think it's easier to manage Time with it. Then if you want to Save/Load your myTodo you can do like this:
// create an example of your task
myTodo newTask = new myTodo() { TaskTitle = "Clean", TaskDescription = "Clean room", ElapsedTime = new TimeSpan(2, 0, 0) };
// add it to ISS and save
if (appSettings.Contains("firatTask")) appSettings["firatTask"] = newTask;
else appSettings.Add("firatTask", newTask);
appSettings.Save();
// try to load
myTodo read = appSettings["firatTask"] as myTodo;
You can access your item like this:
read.Title = TitleTextBox.Text; // and so on
Consider also making a List<myToDo> and be aware that ISS shoul also handle this:
List<myTodo> listJob = new List<myTodo>();
listJob.Add(firstTask); // firstTask is myToDo
listJob.Add(secondTask); // secondTask is myToDo
if (appSettings.Contains("listTask")) appSettings["listTask"] = listJob;
else appSettings.Add("listTask", listJob);
appSettings.Save();
List<myTodo> readList = appSettings["listTask"] as List<myTodo>;

Adding syntax highlighting rules to AvalonEdit programmatically

I'm using AvalonEdit in an app that runs my own custom-built language. I want to put in appropriate syntax highlighting into Avalon Edit. Normally this is done by defining the highlighting rules in an xml file by hand.
However, I don't want the highlighting rules to always be falling out of sync with the language grammar whenever I extend the language. So I'm hoping to use the grammar info that's already contained in my coco/R parser to automatically generate these rules.
So is there a way to programmatically add syntax highlighting rules to Avalon Edit?
Thanks
The below code worked for me at least.
Assembly assembly = Assembly.GetExecutingAssembly();
using (Stream s = assembly.GetManifestResourceStream("Your.xshd"))
{
using (XmlTextReader reader = new XmlTextReader(s))
{
//Load default Syntax Highlighting
InternalEditor.SyntaxHighlighting = HighlightingLoader.Load(reader, HighlightingManager.Instance);
// Dynamic syntax highlighting for your own purpose
var rules = InternalEditor.SyntaxHighlighting.MainRuleSet.Rules;
_HighlightingRule = new HighlightingRule();
_HighlightingRule.Color = new HighlightingColor()
{
Foreground = new CustomizedBrush(SomeColor)
};
String[] wordList = PseudoGetKeywords(); // Your own logic
String regex = String.Format(#"\b({0})\w*\b", String.Join("|", wordList));
_HighlightingRule.Regex = new Regex(regex);
rules.Add(_HighlightingRule);
}
}
internal sealed class CustomizedBrush : HighlightingBrush
{
private readonly SolidColorBrush brush;
public CustomizedBrush(Color color)
{
brush = CreateFrozenBrush(color);
}
public CustomizedBrush(System.Drawing.Color c)
{
var c2 = System.Windows.Media.Color.FromArgb(c.A, c.R, c.G, c.B);
brush = CreateFrozenBrush(c2);
}
public override Brush GetBrush(ITextRunConstructionContext context)
{
return brush;
}
public override string ToString()
{
return brush.ToString();
}
private static SolidColorBrush CreateFrozenBrush(Color color)
{
SolidColorBrush brush = new SolidColorBrush(color);
brush.Freeze();
return brush;
}
}
You can generate an .xshd file in memory using the object model in ICSharpCode.AvalonEdit.Highlighting.Xshd (XshdSyntaxDefinition etc.).
To convert it into an IHighlightingDefinition, use the HighlightingLoader.Load() method. You can also save it to disk (for debugging purposes) by applying the SaveXshdVisitor.
Alternatively, you could implement IHighlightingDefinition yourself and directly create HighlightingRuleSet instances.

How to set the System.Web.WebPages.WebPage.Model property

I am planning on creating a custom route using ASP.NET Web Pages by dynamically creating WebPage instances as follows:
IHttpHandler handler = System.Web.WebPages.WebPageHttpHandler.CreateFromVirtualPath("~/Default.cshtml");
How can I supply an object to the underlying WebPage object so that it can become the web pages's "Model"? In other words I want to be able to write #Model.Firstname in the file Default.cshtml.
Any help will be greatly appreciated.
UPDATE
By modifying the answer by #Pranav, I was able to retrieve the underlying WebPage object using reflection:
public void ProcessRequest(HttpContext context)
{
//var page = (WebPage) System.Web.WebPages.WebPageHttpHandler.CreateFromVirtualPath(this.virtualPath);
var handler = System.Web.WebPages.WebPageHttpHandler.CreateFromVirtualPath(this.virtualPath);
var field = handler.GetType().GetField("_webPage", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
var page = field.GetValue(handler) as System.Web.WebPages.WebPage;
var contextWrapper = new HttpContextWrapper(context);
var pageContext = new WebPageContext(contextWrapper, page, context.Items[CURRENT_NODE]);
page.ExecutePageHierarchy(pageContext, contextWrapper.Response.Output);
}
Unfortunately this is not reliable as it does not work in Medium Trust (BindingFlags.NonPublic is ignored if application is not running in full trust). So while we have made significant progress, the solution is not yet complete.
Any suggestions will be greatly appreciated.
The Model property of a WebPage comes from the WebPageContext. To set a Model, you could create a WebPageContext with the right parameters:-
var page = (WebPage)WebPageHttpHandler.CreateFromVirtualPath("~/Default.cshtml");
var httpContext = new HttpContextWrapper(HttContext.Current);
var model = new { FirstName = "Foo", LastName = "Bar" };
var pageContext = new WebPageContext(httpContext, page, model);
page.ExecutePageHierarchy(pageContext, httpContext.Response.Output);
The model instance should now be available as a dynamic type to you in your page.

Resources