-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathModule.cs
90 lines (74 loc) · 3.41 KB
/
Module.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
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using MyOrg.DomainTutorial.Components;
using MyOrg.DomainTutorial.Providers;
using MyOrg.DomainTutorial.Settings;
using MyOrg.DomainTutorial.Tasks;
using Smartstore;
using Smartstore.Core.Data;
using Smartstore.Core.DataExchange.Export;
using Smartstore.Core.Localization;
using Smartstore.Core.Widgets;
using Smartstore.Engine.Modularity;
using Smartstore.Http;
using Smartstore.Scheduling;
namespace MyOrg.DomainTutorial
{
public class Module : ModuleBase, IConfigurable, IActivatableWidget
{
private readonly SmartDbContext _db;
private readonly ITaskStore _taskStore;
private readonly IExportProfileService _exportProfileService;
public Module(SmartDbContext db, IExportProfileService exportProfileService, ITaskStore taskStore)
{
_db = db;
_exportProfileService = exportProfileService;
_taskStore = taskStore;
}
public Localizer T { get; set; } = NullLocalizer.Instance;
public RouteInfo GetConfigurationRoute()
=> new("Configure", "DomainTutorialAdmin", new { area = "Admin" });
public Widget GetDisplayWidget(string widgetZone, object model, int storeId)
=> new ComponentWidget(typeof(DomainTutorialViewComponent), new { widgetZone, model, storeId });
public string[] GetWidgetZones()
=> new string[] { "productdetails_pictures_top" };
public override async Task InstallAsync(ModuleInstallationContext context)
{
// Saves the default state of a settings class to the database
// without overwriting existing values.
await TrySaveSettingsAsync<DomainTutorialSettings>();
// Imports all language resources for the current module from
// xml files in "Localization" directory (if any found).
await ImportLanguageResourcesAsync();
// Install Tasks.
await _taskStore.GetOrAddTaskAsync<CleanupDomainTutorialTask>(x =>
{
x.Name = T("Plugins.Smartstore.DomainTutorial.TaskName");
x.CronExpression = "0 5 * * *";
x.Enabled = true;
});
// VERY IMPORTANT! Don't forget to call.
await base.InstallAsync(context);
}
public override async Task UninstallAsync()
{
// Delete existing export profiles.
var profiles = await _db.ExportProfiles
.Include(x => x.Deployments)
.Include(x => x.Task)
.Where(x => x.ProviderSystemName == DomainTutorialCsvExportProvider.SystemName || x.ProviderSystemName == DomainTutorialXmlExportProvider.SystemName)
.ToListAsync();
await profiles.EachAsync(x => _exportProfileService.DeleteExportProfileAsync(x, true));
// Deletes all "MyGreatModuleSettings" properties settings from the database.
await DeleteSettingsAsync<DomainTutorialSettings>();
// Delete Tasks.
await _taskStore.TryDeleteTaskAsync<CleanupDomainTutorialTask>();
// Deletes all language resource for the current module
// if "ResourceRootKey" is module.json is not empty.
await DeleteLanguageResourcesAsync();
// VERY IMPORTANT! Don't forget to call.
await base.UninstallAsync();
}
}
}