-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRichEdit.aspx.cs
More file actions
58 lines (47 loc) · 2.51 KB
/
Copy pathRichEdit.aspx.cs
File metadata and controls
58 lines (47 loc) · 2.51 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
using DevExpress.AIIntegration.Extensions;
using DevExpress.Web;
using WebFormsAIIntegration.Models;
using System;
using System.Data;
using System.Linq;
using System.Text.Json;
namespace WebFormsAIIntegration {
public partial class RichEdit : System.Web.UI.Page {
protected void Page_Init(object sender, EventArgs e) {
ASPxRichEdit1.CreateDefaultRibbonTabs(true);
AddAITab();
}
void AddAITab() {
var aiTab = new RibbonTab("AI Assistant");
var group = aiTab.Groups.Add("");
var basicItems = new string[] { "Summarize", "Explain", "Proofread", "Expand", "Shorten" }
.Select(x => new RibbonButtonItem("AI:" + x, x)).ToArray();
var translateMenu = new RibbonDropDownButtonItem("Translate");
var translateItems = new RibbonDropDownButtonItem[] { new RibbonDropDownButtonItem("AI:Translate-en", "English"),
new RibbonDropDownButtonItem("AI:Translate-de", "German"), new RibbonDropDownButtonItem("AI:Translate-fr", "French") };
translateMenu.Items.Add(translateItems);
var changeStyleMenu = new RibbonDropDownButtonItem("ChangeStyle", "Change Style");
var changeStyleItems = Enum.GetNames(typeof(WritingStyle)).Select(x => new RibbonDropDownButtonItem("AI:ChangeStyle-" + x, x)).ToArray();
changeStyleMenu.Items.Add(changeStyleItems);
var changeToneMenu = new RibbonDropDownButtonItem("ChangeTone", "Change Tone");
var changeToneItems = Enum.GetNames(typeof(ToneStyle)).Select(x => new RibbonDropDownButtonItem("AI:ChangeTone-" + x, x)).ToArray();
changeToneMenu.Items.Add(changeToneItems);
group.Items.Add(basicItems);
group.Items.Add(translateMenu);
group.Items.Add(changeStyleMenu);
group.Items.Add(changeToneMenu);
ASPxRichEdit1.RibbonTabs.Add(aiTab);
}
protected void Page_Load(object sender, EventArgs e) {
if(!IsPostBack) {
ASPxRichEdit1.Open(Server.MapPath("Documents/sample1.docx"));
}
}
protected async void ASPxCallback1_Callback(object source, CallbackEventArgs e) {
ASPxCallback callback = (ASPxCallback)source;
var aiRequestData = JsonSerializer.Deserialize<AIHelper.AIRequestData>(e.Parameter);
var aiResponse = await AIHelper.GetResponseAsync(aiRequestData);
callback.JSProperties["cpText"] = aiResponse;
}
}
}