microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
core/src/Microsoft.Bot.Core.Compat/CompatActivity.cs
30lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | using System.Text; |
| 5 | |
| 6 | using Microsoft.Bot.Builder.Integration.AspNet.Core.Handlers; |
| 7 | using Microsoft.Bot.Core.Schema; |
| 8 | using Microsoft.Bot.Schema; |
| 9 | |
| 10 | using Newtonsoft.Json; |
| 11 | |
| 12 | namespace Microsoft.Bot.Core.Compat; |
| 13 | |
| 14 | internal static class CompatActivity |
| 15 | { |
| 16 | public static Activity ToCompatActivity(this CoreActivity activity) |
| 17 | { |
| 18 | using JsonTextReader reader = new(new StringReader(activity.ToJson())); |
| 19 | return BotMessageHandlerBase.BotMessageSerializer.Deserialize<Activity>(reader)!; |
| 20 | } |
| 21 | |
| 22 | public static CoreActivity FromCompatActivity(this Activity activity) |
| 23 | { |
| 24 | StringBuilder sb = new(); |
| 25 | using StringWriter stringWriter = new(sb); |
| 26 | using JsonTextWriter json = new(stringWriter); |
| 27 | BotMessageHandlerBase.BotMessageSerializer.Serialize(json, activity); |
| 28 | return CoreActivity.FromJsonString(sb.ToString()); |
| 29 | } |
| 30 | } |
| 31 | |