-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathModule.cs
72 lines (59 loc) · 2.75 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
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using MyOrg.ExportTutorial.Components;
using MyOrg.ExportTutorial.Providers;
using MyOrg.ExportTutorial.Settings;
using Smartstore;
using Smartstore.Core.Data;
using Smartstore.Core.DataExchange.Export;
using Smartstore.Core.Widgets;
using Smartstore.Engine.Modularity;
using Smartstore.Http;
namespace MyOrg.ExportTutorial
{
public class Module : ModuleBase, IConfigurable, IActivatableWidget
{
private readonly SmartDbContext _db;
private readonly IExportProfileService _exportProfileService;
public Module(SmartDbContext db, IExportProfileService exportProfileService)
{
_db = db;
_exportProfileService = exportProfileService;
}
public RouteInfo GetConfigurationRoute()
=> new("Configure", "ExportTutorialAdmin", new { area = "Admin" });
public Widget GetDisplayWidget(string widgetZone, object model, int storeId)
=> new ComponentWidget(typeof(ExportTutorialViewComponent), 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<ExportTutorialSettings>();
// Imports all language resources for the current module from
// xml files in "Localization" directory (if any found).
await ImportLanguageResourcesAsync();
// 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 == ExportTutorialCsvExportProvider.SystemName || x.ProviderSystemName == ExportTutorialXmlExportProvider.SystemName)
.ToListAsync();
await profiles.EachAsync(x => _exportProfileService.DeleteExportProfileAsync(x, true));
// Deletes all "MyGreatModuleSettings" properties settings from the database.
await DeleteSettingsAsync<ExportTutorialSettings>();
// 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();
}
}
}