Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

ExtractCodeScorable.cs 1.5 KB

You have to be logged in to leave a comment. Sign In
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
  1. namespace TestBot.Scorables
  2. {
  3. using System.Linq;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6. using System.Web.Hosting;
  7. using System.Xml.Linq;
  8. using Microsoft.Bot.Builder.Dialogs.Internals;
  9. using Microsoft.Bot.Connector;
  10. public abstract class ExtractCodeScorable : TriggerScorable
  11. {
  12. private const string TypeAttrib = "type";
  13. public ExtractCodeScorable(IBotToUser botToUser, IBotData botData) : base(botToUser, botData)
  14. {
  15. }
  16. protected override Task PostAsync(IActivity item, bool state, CancellationToken token)
  17. {
  18. if (state)
  19. {
  20. this.SaveCode("/Assets/CSharpCode.xml", Constants.LastCSharpKey);
  21. this.SaveCode("/Assets/NodeJsCode.xml", Constants.LastNodeJsKey);
  22. }
  23. return Task.CompletedTask;
  24. }
  25. private void SaveCode(string sourceFile, string key)
  26. {
  27. var commandsCode = XElement.Load(HostingEnvironment.MapPath(sourceFile));
  28. var element = (XElement)commandsCode
  29. .Nodes()
  30. .FirstOrDefault(n => (n as XElement).Attribute(TypeAttrib).Value.Equals(this.GetType().Name));
  31. if (element != null)
  32. {
  33. this.BotData.PrivateConversationData.SetValue(key, element.Value);
  34. }
  35. else
  36. {
  37. this.BotData.PrivateConversationData.RemoveValue(key);
  38. }
  39. }
  40. }
  41. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...