-
Notifications
You must be signed in to change notification settings - Fork 358
/
Copy pathExtensionAdaptiveCardSession.cs
81 lines (68 loc) · 2.29 KB
/
ExtensionAdaptiveCardSession.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using System.Threading.Tasks;
using Microsoft.Windows.DevHome.SDK;
using Serilog;
using Windows.Foundation;
namespace DevHome.Common.Models;
/// <summary>
/// Wrapper class for the IExtensionAdaptiveCardSession and IExtensionAdaptiveCardSession2 interfaces.
/// </summary>
public class ExtensionAdaptiveCardSession
{
private readonly ILogger _log = Log.ForContext("SourceContext", nameof(ExtensionAdaptiveCardSession));
public IExtensionAdaptiveCardSession Session { get; private set; }
public event TypedEventHandler<ExtensionAdaptiveCardSession, ExtensionAdaptiveCardSessionStoppedEventArgs>? Stopped;
public ExtensionAdaptiveCardSession(IExtensionAdaptiveCardSession cardSession)
{
Session = cardSession;
if (Session is IExtensionAdaptiveCardSession2 cardSession2)
{
cardSession2.Stopped += OnSessionStopped;
}
}
public ProviderOperationResult Initialize(IExtensionAdaptiveCard extensionUI)
{
try
{
return Session.Initialize(extensionUI);
}
catch (Exception ex)
{
_log.Error(ex, $"Initialize failed due to exception");
return new ProviderOperationResult(ProviderOperationStatus.Failure, ex, ex.Message, ex.Message);
}
}
public void Dispose()
{
try
{
if (Session is IExtensionAdaptiveCardSession2 cardSession2)
{
cardSession2.Stopped -= OnSessionStopped;
}
Session.Dispose();
}
catch (Exception ex)
{
_log.Error(ex, $"Dispose failed due to exception");
}
}
public async Task<ProviderOperationResult> OnAction(string action, string inputs)
{
try
{
return await Session.OnAction(action, inputs);
}
catch (Exception ex)
{
_log.Error(ex, $"OnAction failed due to exception");
return new ProviderOperationResult(ProviderOperationStatus.Failure, ex, ex.Message, ex.Message);
}
}
public void OnSessionStopped(IExtensionAdaptiveCardSession2 sender, ExtensionAdaptiveCardSessionStoppedEventArgs args)
{
Stopped?.Invoke(this, args);
}
}