-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTools.cs
More file actions
66 lines (54 loc) · 2.31 KB
/
Tools.cs
File metadata and controls
66 lines (54 loc) · 2.31 KB
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
using System.ComponentModel;
using System.Net;
using Microsoft.SemanticKernel;
using QRCoder;
using TextCopy;
using System.Drawing;
namespace CardMaker;
public class Tools
{
[KernelFunction("save_cards")]
[Description("Save the card suit to a local file.")]
[return: Description("The full card suit in JSON format.")]
public async Task<string> save_cards(string json_document, [Description("card suit name, such as hearts, clubs, spades, or diamonds")] string suit)
{
string filePath = $"{suit}_cards.json";
await File.WriteAllTextAsync(filePath, json_document);
var d = Directory.GetCurrentDirectory();
return "File successfully created at " + d + Path.DirectorySeparatorChar + filePath;
}
[KernelFunction("copy_to_clipboard")]
[Description("Copy the text to the clipboard.")]
[return: Description("A message indicating the text was copied.")]
public async Task<string> copy_to_clipboard(string text)
{
await ClipboardService.SetTextAsync(text);
return "Text copied to clipboard.";
}
[KernelFunction("load_cards")]
[Description("Load the card suit from a local file.")]
[return: Description("card suit as JSON document.")]
public async Task<string> load_card(string fileName)
{
// load the card suit from a local file
var filePath = Path.Combine(Directory.GetCurrentDirectory(), fileName);
var json = await File.ReadAllTextAsync(filePath);
return json;
}
[KernelFunction("create_qr_code")]
[Description("Create a QR code from the bing query text.")]
[return: Description("The path to the QR code image.")]
public async Task<string> create_qr_code(string query, int card_id)
{
// http encode query
query = WebUtility.UrlEncode(query);
var s = $"https://www.bing.com/search?q={query}++site:learn.microsoft.com&shm=cr&form=DEEPSH";
QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode(s, QRCodeGenerator.ECCLevel.Q);
QRCode qrCode = new QRCode(qrCodeData);
Bitmap qrCodeImage = qrCode.GetGraphic(20);
var qrCodePath = Path.Combine(Directory.GetCurrentDirectory(), $"{card_id}.png");
qrCodeImage.Save(qrCodePath);
return qrCodePath;
}
}