You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
278 lines
10 KiB
278 lines
10 KiB
4 years ago
|
<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""
|
||
|
}";
|
||
|
}
|