public void DictionaryBindingTest() { var rawContainer = new Container { Data = new Dictionary <string, object> { { "test", "thing" } }, }; var dataBoundContainer = new Container { Data = APLValue.To <Dictionary <string, object> >("$data.random.stuff") }; var rawJson = JsonConvert.SerializeObject(rawContainer); var boundJson = JsonConvert.SerializeObject(dataBoundContainer); var newRaw = JsonConvert.DeserializeObject <APLComponent>(rawJson); var newBound = JsonConvert.DeserializeObject <APLComponent>(boundJson); var newRawContainer = Assert.IsType <Container>(newRaw); var newBoundContainer = Assert.IsType <Container>(newBound); Assert.Single(newRawContainer.Data.Value); Assert.Equal("$data.random.stuff", newBoundContainer.Data.Expression); }
public void Bindings() { var component = Utility.ExampleFileContent <Text>("Binding.json"); component.When = APLValue.To <bool?>("${@viewportProfile == @hubLandscapeSmall}"); Assert.Equal(2, component.Bindings.Count); var first = component.Bindings.First(); Assert.Equal("foo", first.Name); Assert.Equal("27", first.Value); var second = component.Bindings.Skip(1).First(); Assert.Equal("bar", second.Name); Assert.Equal("${foo + 23}", second.Value); }
public void APLComponentValue() { var text = new Text("Hello World") { Color = APLValue.To<string>("${color}"), Disabled = APLValue.To<bool?>("${disabled}"), FontSize = "24dp", Left = new AbsoluteDimension(24, "vw"), PaddingLeft = new RelativeDimension(5), Top = "${top}", Right = new APLAbsoluteDimensionValue("345"), Bottom = new APLAbsoluteDimensionValue("test") }; var jobject = JObject.FromObject(text); Assert.Equal("24dp", jobject.Value<string>("fontSize")); Assert.Equal("24vw", jobject.Value<string>("left")); Assert.Equal("5%", jobject.Value<string>("paddingLeft")); Assert.Equal("${top}", jobject.Value<string>("top")); Assert.Equal("345", jobject.Value<string>("right")); Assert.Equal("test", jobject.Value<string>("bottom")); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var valueList = new List <TValue>(); if (reader.TokenType == SingleToken) { ReadSingle(reader, serializer, valueList); } else if (reader.TokenType == JsonToken.String) { return(APLValue.To <IList <TValue> >(reader.Value.ToString())); } else { serializer.Populate(reader, valueList); } if (objectType == typeof(APLValue <IList <TValue> >)) { return(new APLValue <IList <TValue> >(valueList)); } return(valueList); }
private RenderDocumentDirective BuildDirective(string sentences, string bg = "") { if (string.IsNullOrEmpty(bg)) { bg = "https://i.ibb.co/5cWztFH/brown-on-seashore-near-mountain-1007657.jpg"; } var mainLayout = new Layout( new Container( new AlexaTextList { BackgroundImageSource = APLValue.To <string>("${textListData.backgroundImageSource}"), HeaderTitle = APLValue.To <string>("${textListData.headerTitle}"), HeaderSubtitle = APLValue.To <string>("${textListData.headerSubtitle}"), HeaderDivider = true, BackgroundScale = new APLValue <Scale>(Scale.BestFill), BackgroundAlign = new APLValue <string>("center"), BackgroundColor = new APLValue <string>("transparent"), ListItems = APLValue.To <APLValue <List <AlexaTextListItem> > >("${textListData.listItemsToShow}") } ) { Width = "100vw", Height = "100vh" } ); mainLayout.Parameters = new List <Parameter>(); mainLayout.Parameters.Add(new Parameter("textListData")); var renderDocument = new RenderDocumentDirective { Token = "randomToken", Document = new APLDocument { MainTemplate = mainLayout }, DataSources = new Dictionary <string, APLDataSource> { { "textListData", new ObjectDataSource { Properties = new Dictionary <string, object> { { "headerTitle", "Alexa text list header title" }, { "headerSubtitle", "Header subtitle" }, { "backgroundImageSource", bg }, { "listItemsToShow", new APLValue <List <AlexaTextListItem> >() { Value = new List <AlexaTextListItem> { new AlexaTextListItem { PrimaryText = "Hello world! 1" }, new AlexaTextListItem { PrimaryText = "Hello world! 2" }, new AlexaTextListItem { PrimaryText = "Hello world! 3" } } } } } } } } }; return(renderDocument); }
private RenderDocumentDirective BuildAPLDirective(string sentences, string bg = "") { if (string.IsNullOrEmpty(bg)) { bg = "https://i.ibb.co/5cWztFH/brown-on-seashore-near-mountain-1007657.jpg"; } var mainLayout = new Layout( new Container( new Image("${payload.bodyTemplate1Data.Properties.backgroundImage.sources[0].url}") { Width = "100vw", Height = "100vh", Position = new APLValue <string>("absolute"), Scale = new APLValue <Scale?>(Scale.BestFill) }, new Text(sentences) { FontSize = "40dp", Style = new APLValue <string>("textStyleBody"), TextAlign = new APLValue <string>("center"), Id = "talker", Content = APLValue.To <string>("${payload.script.properties.textContent.primaryText.text}"), Speech = APLValue.To <string>("${payload.script.properties.textContent.primaryText.text}") } ) { Width = "100vw", Height = "100vh", JustifyContent = new APLValue <string>("center"), Grow = new APLValue <int?>(1) } ); mainLayout.Parameters = new List <Parameter>(); mainLayout.Parameters.Add(new Parameter("payload")); var speech = new Speech(new PlainText(sentences)); var renderDocument = new RenderDocumentDirective { Token = "randomToken", Document = new APLDocument { MainTemplate = mainLayout }, DataSources = new Dictionary <string, APLDataSource> { { "script", new Alexa.NET.APL.DataSources.ObjectDataSource { ObjectId = "bt1Sample", Title = "Sylvester Assistant", Properties = new Dictionary <string, object> { { "backgroundImage", new Dictionary <string, object> { { "contentDescription", null }, { "smallSourceUrl", null }, { "largeSourceUrl", null }, { "sources", new List <object> { new Dictionary <string, object> { { "url", "https://d2o906d8ln7ui1.cloudfront.net/images/BT1_Background.png" }, { "size", "small" }, { "widthPixels", 0 }, { "heightPixels", 0 } }, new Dictionary <string, object> { { "url", "https://d2o906d8ln7ui1.cloudfront.net/images/BT1_Background.png" }, { "size", "small" }, { "widthPixels", 0 }, { "heightPixels", 0 } } } } } }, { "textContent", new Dictionary <string, object> { { "primaryText", new Dictionary <string, object> { { "type", "PlainText" }, { "text", sentences } } } } }, { "logoUrl", "https://d2o906d8ln7ui1.cloudfront.net/images/cheeseskillicon.png" } } } } } }; return(renderDocument); }
public RenderDocumentDirective BuildScrollingSequenceWithVoiceDirective(string sentences, string bg = "", string title = "", string subtitle = "") { if (!string.IsNullOrEmpty(bg)) { bgUrl = bg; } var items = new List <APLComponent>(); var prayers = sentences.Replace("\n", "").Split(","); for (int i = 0; i < prayers.Length; i++) { items.Add(new Text() { Id = $"itm{i.ToString()}", Width = "100vw", Height = "100vh", PaddingLeft = 40, PaddingRight = 40, TextAlign = new APLValue <string>("center"), AlignSelf = new APLValue <string>("center"), TextAlignVertical = new APLValue <string>("center"), Content = APLValue.To <string>("${payload.script.properties.text" + i.ToString() + "}"), //Speech = APLValue.To<string>("${payload.script.properties.speech" + i.ToString() + "}") }); } var ppt = new Dictionary <string, object>(); Speech speech = null; for (int i = 0; i < prayers.Length; i++) { speech = new Speech(new PlainText($"{i + 1}. {prayers[i]}")); ppt.Add($"ssml{i}", speech.ToXml()); } var ff = new List <APLTransformer>(); for (int i = 0; i < prayers.Length; i++) { ff.Add(APLTransformer.SsmlToText($"ssml{i}", $"text{i}")); ff.Add(APLTransformer.SsmlToSpeech($"ssml{i}", $"speech{i}")); } var layout = new Layout { Parameters = new List <Parameter> { new Parameter("payload") }, Items = new Container[] { new Container { Height = "100vh", Items = new APLValue <List <APLComponent> > { Value = new List <APLComponent> { //new Video //{ // Width = "100vw", // Height = "100vh", // Position = new APLValue<string>("absolute"), // Scale = new APLValue<Scale>(Scale.BestFill), // Autoplay = new APLValue<bool?>(true), // AudioTrack = new APLValue<string>("none"), // //Source = new APLValue<string>("https://bestilldemo.azurewebsites.net/images/gifbg.gif") // Source = new APLValue<IList<VideoSource>> // { // Value = new List<VideoSource> // { // new VideoSource // { // RepeatCount = new APLValue<int?>(10), // Uri = new APLValue<Uri>(new Uri("https://bestilldemo.azurewebsites.net/images/soundwave.mp4")) // } // } // } //}, new AlexaBackground { Width = "100vw", Height = "100vh", Position = new APLValue <string>("absolute"), VideoAudioTrack = new APLValue <string>("none"), BackgroundVideoSource = new APLValue <VideoSource> { Value = new VideoSource { Uri = new APLValue <Uri>(new Uri("https://bestilldemo.azurewebsites.net/images/soundwave.mp4")), RepeatCount = new APLValue <int?>(10) } }, VideoAutoPlay = new APLValue <bool?>(true) }, new AlexaHeader { HeaderTitle = new APLValue <string>(title), HeaderSubtitle = new APLValue <string>(subtitle), HeaderAttributionImage = new APLValue <string>(logoUrl) }, new Pager { Id = "myPager", Width = "100vw", Height = "100vh", PaddingBottom = 140, AlignSelf = new APLValue <string>("center"), Items = new APLValue <List <APLComponent> > { Value = items }, OnMount = new APLValue <IList <APLCommand> > { Value = new List <APLCommand> { new AutoPage { ComponentId = "myPager", ScreenLock = new APLValue <bool?>(true), DelayMilliseconds = new APLValue <int?>(40000), Count = new APLValue <int?>(items.Count), Duration = new APLValue <int?>(40000), } //new Parallel //{ // Commands= new APLValue<IList<APLCommand>> // { // Value = new List<APLCommand> // { // new SpeakList // { // ComponentId = "myPager", // Start = new APLValue<int>(0), // Count = new APLValue<int>(items.Count), // MinimumDwellTime = new APLValue<int?>(40000), // ScreenLock = new APLValue<bool?>(true), // Align = new APLValue<ItemAlignment?>(ItemAlignment.Center), // }, // new AutoPage // { // ComponentId = "myPager", // ScreenLock = new APLValue<bool?>(true), // DelayMilliseconds = new APLValue<int?>(40000), // Count = new APLValue<int?>(items.Count), // Duration = new APLValue<int?>(40000), // } // } // } //} } } } } } } } }; var renderDocument = new RenderDocumentDirective { Token = "randomToken", Document = new APLDocument { MainTemplate = layout, Version = APLDocumentVersion.V1_3, Imports = new List <Import> { new Import { Name = "alexa-layouts", Version = "1.1.0" } } }, DataSources = new Dictionary <string, APLDataSource> { { "script", new ObjectDataSource { Properties = ppt, Transformers = ff } } } }; return(renderDocument); }
public RenderDocumentDirective BuildScrollingTextDirective(string sentences, string bg = "", string title = "", string subtitle = "") { if (!string.IsNullOrEmpty(bg)) { bgUrl = bg; } var speech = new Speech(new PlainText(sentences)); var layout = new Layout { Parameters = new List <Parameter> { new Parameter("payload") }, Items = new Container[] { new Container { Height = "100vh", Items = new APLValue <List <APLComponent> > { Value = new List <APLComponent> { new Image { Width = "100vw", Height = "100vh", Position = new APLValue <string>("absolute"), Scale = new APLValue <Scale?>(Scale.BestFill), Source = new APLValue <string>(bgUrl) }, new AlexaHeader { HeaderTitle = new APLValue <string>(title), HeaderSubtitle = new APLValue <string>(subtitle), HeaderAttributionImage = new APLValue <string>(logoUrl) }, new ScrollView( new Text(sentences) { FontSize = "40dp", TextAlign = "Center", Id = "talker", Content = APLValue.To <string>("${payload.script.properties.text}"), Speech = APLValue.To <string>("${payload.script.properties.speech}"), OnMount = new APLValue <IList <APLCommand> > { Value = new List <APLCommand> { new SpeakItem { ComponentId = "talker", HighlightMode = new APLValue <HighlightMode?>(HighlightMode.Line) } } } } ) { Width = "100vw", Height = "100vh", PaddingLeft = 60, PaddingRight = 60, PaddingBottom = 140 } } } } } }; var renderDocument = new RenderDocumentDirective { Token = "randomToken", Document = new APLDocument { MainTemplate = layout, Version = APLDocumentVersion.V1_3, Imports = new List <Import> { new Import { Name = "alexa-layouts", Version = "1.1.0" } } }, DataSources = new Dictionary <string, APLDataSource> { { "script", new ObjectDataSource { Properties = new Dictionary <string, object> { { "ssml", speech.ToXml() } }, Transformers = new List <APLTransformer> { APLTransformer.SsmlToText( "ssml", "text"), APLTransformer.SsmlToSpeech( "ssml", "speech") } } } } }; return(renderDocument); }