forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtractCodeScorable.cs
47 lines (41 loc) · 1.46 KB
/
ExtractCodeScorable.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
namespace TestBot.Scorables
{
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Hosting;
using System.Xml.Linq;
using Microsoft.Bot.Builder.Dialogs.Internals;
using Microsoft.Bot.Connector;
public abstract class ExtractCodeScorable : TriggerScorable
{
private const string TypeAttrib = "type";
public ExtractCodeScorable(IBotToUser botToUser, IBotData botData) : base(botToUser, botData)
{
}
protected override Task PostAsync(IActivity item, bool state, CancellationToken token)
{
if (state)
{
this.SaveCode("/Assets/CSharpCode.xml", Constants.LastCSharpKey);
this.SaveCode("/Assets/NodeJsCode.xml", Constants.LastNodeJsKey);
}
return Task.CompletedTask;
}
private void SaveCode(string sourceFile, string key)
{
var commandsCode = XElement.Load(HostingEnvironment.MapPath(sourceFile));
var element = (XElement)commandsCode
.Nodes()
.FirstOrDefault(n => (n as XElement).Attribute(TypeAttrib).Value.Equals(this.GetType().Name));
if (element != null)
{
this.BotData.PrivateConversationData.SetValue(key, element.Value);
}
else
{
this.BotData.PrivateConversationData.RemoveValue(key);
}
}
}
}