Claire Davis
4 years ago
6 changed files with 21022 additions and 0 deletions
diff.file_suppressed_line_too_long
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 2.1 KiB |
diff.file_suppressed_line_too_long
@ -0,0 +1,278 @@
|
||||
<Query Kind="Program"> |
||||
<NuGetReference>Newtonsoft.Json</NuGetReference> |
||||
<Namespace>Newtonsoft.Json</Namespace> |
||||
<Namespace>Newtonsoft.Json.Bson</Namespace> |
||||
<Namespace>Newtonsoft.Json.Converters</Namespace> |
||||
<Namespace>Newtonsoft.Json.Linq</Namespace> |
||||
<Namespace>Newtonsoft.Json.Schema</Namespace> |
||||
<Namespace>Newtonsoft.Json.Serialization</Namespace> |
||||
</Query> |
||||
|
||||
void Main() |
||||
{ |
||||
string Rendered = JsonFromTemplate(Globals.strTemplate, Globals.strData); |
||||
} |
||||
|
||||
// render adaptive card JSON |
||||
public string JsonFromTemplate(string strTemplate, string strData) |
||||
{ |
||||
string output = ""; |
||||
|
||||
// first create JSON objects out of the input |
||||
JObject Template = JObject.Parse(strTemplate); |
||||
JObject Data = JObject.Parse(strData); |
||||
|
||||
// body = array of jobjects |
||||
|
||||
JArray TemplateBody = (JArray)Template["body"]; |
||||
|
||||
TemplateBody.Dump(); |
||||
|
||||
return output; |
||||
} |
||||
|
||||
// set up global statics |
||||
public class Globals |
||||
{ |
||||
public static Dictionary<string, string> Containers = new Dictionary<string, string> |
||||
{ |
||||
{ "ActionSet", "actions"}, |
||||
{ "Container", "items" }, |
||||
{ "ColumnSet", "columns"}, |
||||
{ "Column", "items"}, |
||||
{ "FactSet", "facts"}, |
||||
{ "Fact", ""}, |
||||
{ "ImageSet", "images"} |
||||
}; |
||||
|
||||
public static string strData = @" |
||||
{ |
||||
""template"" : |
||||
{ |
||||
""image"" : ""image"", |
||||
""clade"" : ""Clades"", |
||||
""name"" : ""Common Name"", |
||||
""order"" : ""Order"", |
||||
""family"" : ""Family"", |
||||
""genus"" : ""Genus"", |
||||
""species"" : ""Species (Latin Name)"" |
||||
}, |
||||
""item"" : |
||||
{ |
||||
""image"" : ""almonds.jpg"", |
||||
""clade"" : [ |
||||
""Tracheophytes"", |
||||
""Angiosperms"", |
||||
""Eudicots"", |
||||
""Rosids"" |
||||
], |
||||
""name"" : ""American Hazelnut"", |
||||
""order"" : ""Fagales"", |
||||
""family"" : ""Betulaceae"", |
||||
""genus"" : ""Corylus"", |
||||
""species"" : ""Corylus Americana"" |
||||
} |
||||
} |
||||
"; |
||||
|
||||
public static string strTemplate = @" |
||||
{ |
||||
""type"": ""AdaptiveCard"", |
||||
""body"": [ |
||||
{ |
||||
""type"": ""Container"", |
||||
""items"": [ |
||||
{ |
||||
""type"": ""TextBlock"", |
||||
""text"": ""{item.name}"", |
||||
""size"": ""Large"", |
||||
""weight"": ""Bolder"", |
||||
""horizontalAlignment"": ""Center"", |
||||
""color"": ""Accent"" |
||||
}, |
||||
{ |
||||
""type"": ""Image"", |
||||
""url"": ""{item.image}"", |
||||
""altText"": """" |
||||
}, |
||||
{ |
||||
""type"": ""ColumnSet"", |
||||
""columns"": [ |
||||
{ |
||||
""type"": ""Column"", |
||||
""width"": ""stretch"", |
||||
""horizontalAlignment"": ""Right"", |
||||
""items"": [ |
||||
{ |
||||
""type"": ""TextBlock"", |
||||
""text"": ""{template.other}"", |
||||
""weight"": ""Bolder"", |
||||
""horizontalAlignment"": ""Right"" |
||||
} |
||||
] |
||||
}, |
||||
{ |
||||
""type"": ""Column"", |
||||
""width"": ""stretch"", |
||||
""items"": [ |
||||
{ |
||||
""type"": ""TextBlock"", |
||||
""text"": ""{item.other}"" |
||||
} |
||||
] |
||||
} |
||||
] |
||||
}, |
||||
{ |
||||
""type"": ""ColumnSet"", |
||||
""columns"": [ |
||||
{ |
||||
""type"": ""Column"", |
||||
""width"": ""stretch"", |
||||
""horizontalAlignment"": ""Right"", |
||||
""items"": [ |
||||
{ |
||||
""type"": ""TextBlock"", |
||||
""text"": ""{template.name}"", |
||||
""weight"": ""Bolder"", |
||||
""horizontalAlignment"": ""Right"" |
||||
} |
||||
] |
||||
}, |
||||
{ |
||||
""type"": ""Column"", |
||||
""width"": ""stretch"", |
||||
""items"": [ |
||||
{ |
||||
""type"": ""TextBlock"", |
||||
""text"": ""{item.name}"" |
||||
} |
||||
] |
||||
} |
||||
] |
||||
}, |
||||
{ |
||||
""type"": ""ColumnSet"", |
||||
""columns"": [ |
||||
{ |
||||
""type"": ""Column"", |
||||
""width"": ""stretch"", |
||||
""horizontalAlignment"": ""Right"", |
||||
""items"": [ |
||||
{ |
||||
""type"": ""TextBlock"", |
||||
""text"": ""{template.order}"", |
||||
""weight"": ""Bolder"", |
||||
""horizontalAlignment"": ""Right"" |
||||
} |
||||
] |
||||
}, |
||||
{ |
||||
""type"": ""Column"", |
||||
""width"": ""stretch"", |
||||
""items"": [ |
||||
{ |
||||
""type"": ""TextBlock"", |
||||
""text"": ""{item.order}"" |
||||
} |
||||
] |
||||
} |
||||
] |
||||
}, |
||||
{ |
||||
""type"": ""ColumnSet"", |
||||
""columns"": [ |
||||
{ |
||||
""type"": ""Column"", |
||||
""width"": ""stretch"", |
||||
""horizontalAlignment"": ""Right"", |
||||
""items"": [ |
||||
{ |
||||
""type"": ""TextBlock"", |
||||
""text"": ""{template.family}"", |
||||
""weight"": ""Bolder"", |
||||
""horizontalAlignment"": ""Right"" |
||||
} |
||||
] |
||||
}, |
||||
{ |
||||
""type"": ""Column"", |
||||
""width"": ""stretch"", |
||||
""items"": [ |
||||
{ |
||||
""type"": ""TextBlock"", |
||||
""text"": ""{item.genus}"" |
||||
} |
||||
] |
||||
} |
||||
] |
||||
}, |
||||
{ |
||||
""type"": ""ColumnSet"", |
||||
""columns"": [ |
||||
{ |
||||
""type"": ""Column"", |
||||
""width"": ""stretch"", |
||||
""horizontalAlignment"": ""Right"", |
||||
""items"": [ |
||||
{ |
||||
""type"": ""TextBlock"", |
||||
""text"": ""{template.species}"", |
||||
""weight"": ""Bolder"", |
||||
""horizontalAlignment"": ""Right"" |
||||
} |
||||
] |
||||
}, |
||||
{ |
||||
""type"": ""Column"", |
||||
""width"": ""stretch"", |
||||
""items"": [ |
||||
{ |
||||
""type"": ""TextBlock"", |
||||
""text"": ""{item.species}"" |
||||
} |
||||
] |
||||
} |
||||
] |
||||
}, |
||||
{ |
||||
""type"": ""ColumnSet"", |
||||
""columns"": [ |
||||
{ |
||||
""type"": ""Column"", |
||||
""width"": ""stretch"", |
||||
""horizontalAlignment"": ""Right"", |
||||
""items"": [ |
||||
{ |
||||
""type"": ""TextBlock"", |
||||
""text"": ""{template.clade}"", |
||||
""weight"": ""Bolder"", |
||||
""horizontalAlignment"": ""Right"" |
||||
} |
||||
] |
||||
}, |
||||
{ |
||||
""type"": ""Column"", |
||||
""width"": ""stretch"", |
||||
""items"": [ |
||||
{ |
||||
""type"": ""Container"", |
||||
""items"": [ |
||||
{ |
||||
""$data"": ""{item.clade}"", |
||||
""type"": ""TextBlock"", |
||||
""text"": ""{$data}"" |
||||
} |
||||
] |
||||
} |
||||
] |
||||
} |
||||
] |
||||
} |
||||
] |
||||
} |
||||
], |
||||
""$schema"": ""http://adaptivecards.io/schemas/adaptive-card.json"", |
||||
""version"": ""1.0"" |
||||
}"; |
||||
} |
Loading…
issues.context.reference_issue