-
Notifications
You must be signed in to change notification settings - Fork 6
/
Main.cs
87 lines (76 loc) · 3.06 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
using System.Collections.Generic;
using SiteServer.Plugin;
using SS.Photo.Core;
using Menu = SiteServer.Plugin.Menu;
namespace SS.Photo
{
public class Main : PluginBase
{
private static readonly Dictionary<int, ConfigInfo> ParmConfigInfoDict = new Dictionary<int, ConfigInfo>();
public static ConfigInfo GetConfigInfo(int siteId)
{
if (!ParmConfigInfoDict.ContainsKey(siteId))
{
ParmConfigInfoDict[siteId] = Context.ConfigApi.GetConfig<ConfigInfo>(Utils.PluginId, siteId) ?? new ConfigInfo();
}
return ParmConfigInfoDict[siteId];
}
public override void Startup(IService service)
{
var repository = new PhotoRepository();
service
.AddSiteMenu(siteId => new Menu
{
Text = "内容相册",
IconClass = "ion-images",
Menus = new List<Menu>
{
new Menu
{
Text = "图片上传设置",
Href = "pages/settings.html"
}
}
})
.AddContentMenu(contentInfo => new Menu
{
Text = "内容相册",
Href = "pages/photos.html"
})
.AddDatabaseTable(repository.TableName, repository.TableColumns)
.AddStlElementParser(StlPhotos.ElementName, StlPhotos.Parse)
.AddStlElementParser(StlPhoto.ElementName, StlPhoto.Parse)
.AddStlElementParser(StlSlide.ElementName, StlSlide.Parse)
;
service.ContentTranslateCompleted += Service_ContentTranslateCompleted;
service.ContentDeleteCompleted += Service_ContentDeleteCompleted;
}
private static void Service_ContentDeleteCompleted(object sender, ContentEventArgs e)
{
var repository = new PhotoRepository();
repository.Delete(e.SiteId, e.ChannelId, e.ContentId);
}
private void Service_ContentTranslateCompleted(object sender, ContentTranslateEventArgs e)
{
var repository = new PhotoRepository();
var photoInfoList = repository.GetPhotoInfoList(e.SiteId, e.ChannelId, e.ContentId);
if (photoInfoList.Count <= 0) return;
foreach (var photoInfo in photoInfoList)
{
photoInfo.SiteId = e.TargetSiteId;
photoInfo.ChannelId = e.TargetChannelId;
photoInfo.ContentId = e.TargetContentId;
if (e.SiteId != e.TargetSiteId)
{
Context.SiteApi.MoveFiles(e.SiteId, e.TargetSiteId, new List<string>
{
photoInfo.SmallUrl,
photoInfo.MiddleUrl,
photoInfo.LargeUrl
});
}
repository.Insert(photoInfo);
}
}
}
}