forked from CIOIL/nopcommerce-elastic-search-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGsaPlugin.cs
182 lines (169 loc) · 10.7 KB
/
GsaPlugin.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
using Nop.Core;
using Nop.Core.Plugins;
using Nop.Search.Plugin.GSA.Infrastructure.Data;
using Nop.Search.Plugin.GSA.Infrastructure.Settings;
using Nop.Services.Common;
using Nop.Services.Configuration;
using Nop.Services.Localization;
using Nop.Web.Framework.Menu;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Routing;
namespace Nop.Search.Plugin.GSA
{
class GsaPlugin : BasePlugin, IMiscPlugin , IAdminMenuPlugin
{
private readonly ISettingService _settingService;
private readonly IWebHelper _webHelper;
private readonly CollectionMappingObjectContext _context;
public GsaPlugin(ISettingService settingService, IWebHelper webHelper, CollectionMappingObjectContext context)
{
this._settingService = settingService;
this._webHelper = webHelper;
_context = context;
}
public void GetConfigurationRoute(out string actionName, out string controllerName, out RouteValueDictionary routeValues)
{
actionName = "Configure";
controllerName = "Configuration";
routeValues = new RouteValueDictionary { { "Namespaces", "Nop.Search.Plugin.GSA.Controllers" }, { "area", null } };
}
public void ManageSiteMap(SiteMapNode rootNode)
{
var menuItem = new SiteMapNode()
{
SystemName = "SearchEngine",
Title = "Search Engine configuration",
Url = "/Admin/Plugin/ConfigureMiscPlugin?systemName=SearchEngine",
Visible = true,
RouteValues = new RouteValueDictionary() { { "area", "Admin" } },
};
var pluginNode = rootNode.ChildNodes.FirstOrDefault(x => x.SystemName == "Third party plugins");
if (pluginNode != null)
pluginNode.ChildNodes.Add(menuItem);
else
rootNode.ChildNodes.Add(menuItem);
}
public override void Install()
{
/*Set Default Settings data*/
var settings = new GsaSetting
{
GsaHost = "",
Collection = "",
FrontEndClient = "",
AccessType = "p",
MaxSearchResults = 1000,
OutputOption = "xml",
ResultsPerPage = 15,
SortFormat = "Default",
ImageHost = "",
isGsa = false,
IsElastic = true,
ElasticHost = "",
SearchIndex = "",
SearchKey = "",
EResultsPerPage = 10
};
_settingService.SaveSetting(settings);
/*Set Resource */
/* Display Resource*/
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.GsaHost", "Host Name");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.DefaultCollection", "Default Collection Name");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.FrontEndClient", "Frontend client");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.AccessType", "Access Type");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.MaxSearchResults", "Max Search Results");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.OutputOption", "Output Option");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.ResultsPerPage", "Results Per Page");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.SortFormat", "SortFormat");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.Search.Result", "Search Results");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.Search.TotalResults", "Total Results For", "en-US");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.Search.TotalResults", "סה''כ תוצאות ", "he-IL");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.Search.LastUpdate", "Last update");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.Search.Photographer", "Photographer");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.Search.City","City");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.Search.Region", "Region");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.Search.Today", "Today");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.Search.Humidity", "Humidity");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.Search.WindAndSpeed", "Wind direction and speed");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.Search.Tommorow", "Tommorow");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.Search.ThreeDaysFrom", "3 days from");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.Search.Two_days_from", "Two days from");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.Search.DisplayResult", "Display Results {0} of {1}");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.Search.ExchangeRate", "Exchange rate");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.ImageHost", "Hostname for Images");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.Collection", "Collection");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.LanguageCulture", "Language Culture");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.UseGsa", "Gsa Search engine");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.UseElastic", "Elastic Search engine (with default search)");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.ElasticHost", "Elastic Host");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.SearchIndex", "Search Index");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.SearchKey","Search Key");
/*Tab Settings*/
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.Tab.General", "General");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.Tab.GsaConfig", "Gsa Configuration");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.Tab.ElasticSearchConfig", "Elastic Search Configuration");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.Config.SearchEngine", "Select Search Engine");
/*Error Resource*/
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.GsaHostError", "Host Name Required");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.CollectionError", "Collection Name Required");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.FrontEndClientError", "Frontend client Required");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.Search.EventType", "Event Type");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.Search.Time", "Time");
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.Search.Adress", "Address");
/*Hint Resorses*/
this.AddOrUpdatePluginLocaleResource("Nop.Search.Plugin.GSA.Collection.Hint", @"You can search multiple collections by separating collection names with the OR character, which is notated as the pipe symbol, or the AND character, which is notated as a period.
The following example uses the AND character: &site = col1.col2
The following example uses the OR character: &site = col1 | col2");
try
{
_context.Install();
}
catch { }
base.Install();
}
public override void Uninstall()
{
_settingService.DeleteSetting<GsaSetting>();
this.DeletePluginLocaleResource("Nop.Search.Plugin.GSA.GsaHost");
this.DeletePluginLocaleResource("Nop.Search.Plugin.GSA.Collection");
this.DeletePluginLocaleResource("Nop.Search.Plugin.GSA.FrontEndClient");
this.DeletePluginLocaleResource("Nop.Search.Plugin.GSA.AccessType");
this.DeletePluginLocaleResource("Nop.Search.Plugin.GSA.AccessType");
this.DeletePluginLocaleResource("Nop.Search.Plugin.GSA.OutputOption");
this.DeletePluginLocaleResource("Nop.Search.Plugin.GSA.ResultsPerPage");
this.DeletePluginLocaleResource("Nop.Search.Plugin.GSA.SortFormat");
this.DeletePluginLocaleResource("Nop.Search.Plugin.GSA.GsaHostError");
this.DeletePluginLocaleResource("Nop.Search.Plugin.GSA.CollectionError");
this.DeletePluginLocaleResource("Nop.Search.Plugin.GSA.FrontEndClientError");
this.DeletePluginLocaleResource("Nop.Search.Plugin.GSA.Collection.Hint");
this.DeletePluginLocaleResource("Nop.Search.Plugin.GSA.Search.Result");
this.DeletePluginLocaleResource("Nop.Search.Plugin.GSA.Search.TotalResults");
this.DeletePluginLocaleResource("Nop.Search.Plugin.GSA.Search.LastUpdate");
this.DeletePluginLocaleResource("Nop.Search.Plugin.GSA.Search.Photographer");
this.DeletePluginLocaleResource("Nop.Search.Plugin.GSA.Search.EventType");
this.DeletePluginLocaleResource("Nop.Search.Plugin.GSA.Search.Adress");
this.DeletePluginLocaleResource("Nop.Search.Plugin.GSA.Search.Time");
this.DeletePluginLocaleResource("Nop.Search.Plugin.GSA.Search.City");
this.DeletePluginLocaleResource("Nop.Search.Plugin.GSA.Search.Region");
this.DeletePluginLocaleResource("Nop.Search.Plugin.GSA.Search.Today");
this.DeletePluginLocaleResource("Nop.Search.Plugin.GSA.Search.Tommorow");
this.DeletePluginLocaleResource("Nop.Search.Plugin.GSA.Search.ThreeDaysFrom");
this.DeletePluginLocaleResource("Nop.Search.Plugin.GSA.Search.Two_days_from");
this.DeletePluginLocaleResource("Nop.Search.Plugin.GSA.Search.Humidity");
this.DeletePluginLocaleResource("Nop.Search.Plugin.GSA.ImageHost");
this.DeletePluginLocaleResource("Nop.Search.Plugin.GSA.Collection");
this.DeletePluginLocaleResource("Nop.Search.Plugin.GSA.LanguageCulture");
_context.Uninstall();
base.Uninstall();
}
}
}
/*
You can search multiple collections by separating collection names with the OR character, which is notated as the pipe symbol, or the AND character, which is notated as a period.
The following example uses the AND character: &site=col1.col2
The following example uses the OR character: &site=col1|col2
*/