forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ActivityLog.cs
47 lines (39 loc) · 1.24 KB
/
ActivityLog.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Schema;
namespace Microsoft.BotBuilderSamples
{
public class ActivityLog
{
private IStorage _storage;
public ActivityLog(IStorage storage)
{
_storage = storage;
}
public async Task Append(string activityId, Activity activity)
{
if (activityId == null)
{
throw new ArgumentNullException("activityId");
}
if (activity == null)
{
throw new ArgumentNullException("activity");
}
await _storage.WriteAsync(new Dictionary<string, object> { { activityId, activity } });
}
public async Task<Activity> Find(string activityId)
{
if (activityId == null)
{
throw new ArgumentNullException("activityId");
}
var activities = await _storage.ReadAsync(new[] { activityId });
return activities.Count >= 1 ? (Activity)activities[activityId] : null;
}
}
}