forked from siteserver/SS.Form
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cs
115 lines (98 loc) · 4.15 KB
/
Main.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System;
using System.Linq;
using System.Web.UI.WebControls;
using SiteServer.Plugin;
using SS.Form.Core;
using SS.Form.Model;
using SS.Form.Pages;
using SS.Form.Parse;
using SS.Form.Provider;
using Menu = SiteServer.Plugin.Menu;
namespace SS.Form
{
public class Main : PluginBase
{
public static Main Instance { get; private set; }
public FormDao FormDao { get; private set; }
public LogDao LogDao { get; private set; }
public FieldDao FieldDao { get; private set; }
public FieldItemDao FieldItemDao { get; private set; }
public override void Startup(IService service)
{
FormDao = new FormDao(ConnectionString, DataApi);
LogDao = new LogDao(ConnectionString, DataApi);
FieldDao = new FieldDao(ConnectionString, DataApi);
FieldItemDao = new FieldItemDao(ConnectionString, DataApi);
service
.AddSiteMenu(siteId =>
{
var formInfoList = FormDao.GetFormInfoListNotInChannel(siteId);
var menus = formInfoList.Select(formInfo => new Menu
{
Text = $"{formInfo.Title}",
Href = $"{nameof(PageLogs)}.aspx?formId={formInfo.Id}"
}).ToList();
menus.Add(new Menu
{
Text = "表单管理",
Href = $"{nameof(PageManagement)}.aspx"
});
return new Menu
{
Text = "表单",
IconClass = "ion-android-list",
Menus = menus
};
})
.AddContentLink(new HyperLink
{
Text = "表单管理",
NavigateUrl = $"{nameof(PageLogs)}.aspx"
})
.AddDatabaseTable(FormDao.TableName, FormDao.Columns)
.AddDatabaseTable(LogDao.TableName, LogDao.Columns)
.AddDatabaseTable(FieldDao.TableName, FieldDao.Columns)
.AddDatabaseTable(FieldItemDao.TableName, FieldItemDao.Columns)
.AddStlElementParser(StlForm.ElementName, StlForm.Parse)
;
service.ContentTranslateCompleted += Service_ContentTranslateCompleted;
service.ContentDeleteCompleted += Service_ContentDeleteCompleted;
service.ApiPost += ServiceOnApiPost;
service.ApiGet += Service_ApiGet;
Instance = this;
}
private object ServiceOnApiPost(object sender, ApiEventArgs args)
{
if (Utils.EqualsIgnoreCase(args.Action, nameof(ApiUtils.Submit)))
{
return ApiUtils.Submit(args.Request, args.Id);
}
throw new Exception("请求的资源不在服务器上");
}
private object Service_ApiGet(object sender, ApiEventArgs args)
{
if (Utils.EqualsIgnoreCase(args.Action, nameof(ApiUtils.Captcha)))
{
return ApiUtils.Captcha(args.Request, args.Id);
}
throw new Exception("请求的资源不在服务器上");
}
private void Service_ContentTranslateCompleted(object sender, ContentTranslateEventArgs e)
{
var formInfo = FormDao.GetFormInfoOrCreateIfNotExists(e.SiteId, e.ChannelId, e.ContentId);
formInfo.SiteId = e.TargetSiteId;
formInfo.ChannelId = e.TargetChannelId;
formInfo.ContentId = e.TargetContentId;
formInfo.IsTimeout = false;
formInfo.TimeToStart = DateTime.Now;
formInfo.TimeToEnd = formInfo.TimeToStart.AddMonths(3);
FormDao.Insert(formInfo);
}
private void Service_ContentDeleteCompleted(object sender, ContentEventArgs e)
{
var formId = FormDao.GetFormIdByContentId(e.SiteId, e.ChannelId, e.ContentId);
FormDao.Delete(formId);
}
//public override Func<IRequestContext, string, string, HttpResponseMessage> HttpGetWithNameAndId => StlForm.HttpGetWithNameAndId;
}
}