Skip to content

Commit e178bf5

Browse files
committed
Export of selected entities using task parameter instead of HTTP runtime cache
1 parent fadd6dd commit e178bf5

11 files changed

Lines changed: 40 additions & 55 deletions

File tree

src/Libraries/SmartStore.Core/Collections/Querystring.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,23 @@ public static string ExtractQuerystring(string s)
4545
/// </summary>
4646
/// <param name="s">the string to parse</param>
4747
/// <returns>the QueryString object </returns>
48-
public QueryString FillFromString(string s)
48+
public QueryString FillFromString(string s, bool urlDecode = false)
4949
{
5050
base.Clear();
5151
if (string.IsNullOrEmpty(s))
5252
{
5353
return this;
5454
}
55+
5556
foreach (string keyValuePair in ExtractQuerystring(s).Split('&'))
5657
{
5758
if (string.IsNullOrEmpty(keyValuePair))
5859
{
5960
continue;
6061
}
62+
6163
string[] split = keyValuePair.Split('=');
62-
base.Add(split[0],
63-
split.Length == 2 ? split[1] : "");
64+
base.Add(split[0], split.Length == 2 ? (urlDecode ? HttpUtility.UrlDecode(split[1]) : split[1]) : "");
6465
}
6566
return this;
6667
}
@@ -73,7 +74,7 @@ public QueryString FromCurrent()
7374
{
7475
if (HttpContext.Current != null)
7576
{
76-
return FillFromString(HttpContext.Current.Request.QueryString.ToString());
77+
return FillFromString(HttpContext.Current.Request.QueryString.ToString(), true);
7778
}
7879
base.Clear();
7980
return this;
@@ -182,7 +183,7 @@ public override string ToString()
182183
{
183184
if (!string.IsNullOrEmpty(base.Keys[i]))
184185
{
185-
foreach (string val in base[base.Keys[i]].Split(','))
186+
foreach (string val in base[base.Keys[i]].EmptyNull().Split(','))
186187
{
187188
builder.Append((builder.Length == 0) ? "?" : "&").Append(
188189
HttpUtility.UrlEncode(base.Keys[i])).Append("=").Append(val);

src/Libraries/SmartStore.Data/Migrations/201509150931528_ExportFramework2.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ public void MigrateLocaleResources(LocaleResourcesBuilder builder)
5656
"Cannot load the provider {0}.",
5757
"Der Provider {0} konnte nicht geladen werden.");
5858

59+
builder.AddOrUpdate("Admin.Common.NoEntriesSelected",
60+
"No entries have been selected.",
61+
"Es wurden keine Einträge ausgewählt.");
62+
5963
builder.AddOrUpdate("ActivityLog.EditPaymentMethod",
6064
"Edited payment method '{0}' ({1})",
6165
"Zahlungsart '{0}' ({1}) bearbeitet");

src/Libraries/SmartStore.Services/DataExchange/ExportExtensions.cs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
using System.Globalization;
33
using System.IO;
44
using System.Text;
5-
using System.Web;
6-
using System.Web.Caching;
75
using SmartStore.Core.Domain;
86
using SmartStore.Core.Domain.Stores;
97
using SmartStore.Core.Plugins;
@@ -96,31 +94,5 @@ public static string ResolveFileNamePattern(this ExportProfile profile, Store st
9694

9795
return result;
9896
}
99-
100-
/// <summary>
101-
/// Gets the cache key for selected entity identifiers
102-
/// </summary>
103-
/// <param name="profile">Export profile</param>
104-
/// <returns>Cache key for selected entity identifiers</returns>
105-
public static string GetSelectedEntityIdsCacheKey(this ExportProfile profile)
106-
{
107-
// do not use profile.Id because it can be 0
108-
return "ExportProfile_SelectedEntityIds_" + profile.ProviderSystemName;
109-
}
110-
111-
/// <summary>
112-
/// Caches selected entity identifiers to be considered during following export
113-
/// </summary>
114-
/// <param name="profile">Export profile</param>
115-
/// <param name="selectedIds">Comma separated entity identifiers</param>
116-
public static void CacheSelectedEntityIds(this ExportProfile profile, string selectedIds)
117-
{
118-
var selectedIdsCacheKey = profile.GetSelectedEntityIdsCacheKey();
119-
120-
if (selectedIds.HasValue())
121-
HttpRuntime.Cache.Add(selectedIdsCacheKey, selectedIds, null, DateTime.UtcNow.AddMinutes(5), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
122-
else
123-
HttpRuntime.Cache.Remove(selectedIdsCacheKey);
124-
}
12597
}
12698
}

src/Libraries/SmartStore.Services/DataExchange/ExportTask/ExportProfileTask.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2872,7 +2872,7 @@ public void Execute(TaskExecutionContext taskContext)
28722872
var profileId = taskContext.ScheduleTask.Alias.ToInt();
28732873
var profile = _exportProfileService.Value.GetExportProfileById(profileId);
28742874

2875-
var selectedIdsCacheKey = profile.GetSelectedEntityIdsCacheKey();
2875+
var selectedIdsCacheKey = "ExportProfile_SelectedEntityIds_" + profile.ProviderSystemName;
28762876
var selectedEntityIds = HttpRuntime.Cache[selectedIdsCacheKey] as string;
28772877

28782878
var provider = _exportProfileService.Value.LoadProvider(profile.ProviderSystemName);

src/Libraries/SmartStore.Services/DataExchange/Internal/DataExportTask.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ public void Execute(TaskExecutionContext ctx)
2727
var profileId = ctx.ScheduleTask.Alias.ToInt();
2828
var profile = _exportProfileService.GetExportProfileById(profileId);
2929

30-
// TODO: find a better way to transmit selected entity ids (e.g. new TaskExecutionContext.Parameters property)
31-
var selectedIdsCacheKey = profile.GetSelectedEntityIdsCacheKey();
32-
var selectedEntityIds = HttpRuntime.Cache[selectedIdsCacheKey] as string;
33-
HttpRuntime.Cache.Remove(selectedIdsCacheKey);
34-
3530
// load provider
3631
var provider = _exportProfileService.LoadProvider(profile.ProviderSystemName);
3732
if (provider == null)
@@ -50,10 +45,10 @@ public void Execute(TaskExecutionContext ctx)
5045
ctx.SetProgress(null, msg, true);
5146
};
5247

53-
if (selectedEntityIds.HasValue())
48+
if (ctx.Parameters.ContainsKey("SelectedIds"))
5449
{
55-
request.EntitiesToExport = selectedEntityIds.ToIntArray();
56-
}
50+
request.EntitiesToExport = ctx.Parameters["SelectedIds"].ToIntArray();
51+
}
5752

5853
// process!
5954
_exporter.Export(request, ctx.CancellationToken);

src/Libraries/SmartStore.Services/DataExchange/Internal/DataExporter.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,14 +1061,18 @@ public DataExportResult Export(DataExportRequest request, CancellationToken canc
10611061
{
10621062
var ctx = new DataExporterContext(request, cancellationToken);
10631063

1064+
if (request.EntitiesToExport != null)
1065+
{
1066+
ctx.EntityIdsSelected.AddRange(request.EntitiesToExport);
1067+
}
1068+
10641069
ExportCoreOuter(ctx);
10651070

10661071
if (ctx.Result != null && ctx.Result.Succeeded && ctx.Result.Files.Count > 0)
10671072
{
10681073
string prefix = null;
10691074
string suffix = null;
10701075
var extension = Path.GetExtension(ctx.Result.Files.First().FileName);
1071-
var selectedEntityCount = (request.EntitiesToExport == null ? 0 : request.EntitiesToExport.Count());
10721076

10731077
if (request.Provider.Value.EntityType == ExportEntityType.Product)
10741078
prefix = T("Admin.Catalog.Products");
@@ -1085,6 +1089,8 @@ public DataExportResult Export(DataExportRequest request, CancellationToken canc
10851089
else
10861090
prefix = request.Provider.Value.EntityType.ToString();
10871091

1092+
var selectedEntityCount = (request.EntitiesToExport == null ? 0 : request.EntitiesToExport.Count());
1093+
10881094
if (selectedEntityCount == 0)
10891095
suffix = T("Common.All");
10901096
else
@@ -1104,7 +1110,7 @@ public IList<dynamic> Preview(DataExportRequest request)
11041110
var resultData = new List<dynamic>();
11051111
var cancellation = new CancellationTokenSource(TimeSpan.FromMinutes(5.0));
11061112

1107-
var ctx = new DataExporterContext(request, cancellation.Token, null, true);
1113+
var ctx = new DataExporterContext(request, cancellation.Token, true);
11081114

11091115
var unused = Init(ctx, totalRecords);
11101116

@@ -1138,7 +1144,7 @@ public int GetDataCount(DataExportRequest request)
11381144
{
11391145
var cancellation = new CancellationTokenSource(TimeSpan.FromMinutes(5.0));
11401146

1141-
var ctx = new DataExporterContext(request, cancellation.Token, null, true);
1147+
var ctx = new DataExporterContext(request, cancellation.Token, true);
11421148

11431149
var unused = Init(ctx);
11441150

src/Libraries/SmartStore.Services/DataExchange/Internal/DataExporterContext.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,18 @@ internal class DataExporterContext
2626
public DataExporterContext(
2727
DataExportRequest request,
2828
CancellationToken cancellationToken,
29-
string selectedIds = null,
3029
bool isPreview = false)
3130
{
3231
Request = request;
3332
CancellationToken = cancellationToken;
3433
Filter = XmlHelper.Deserialize<ExportFilter>(request.Profile.Filtering);
3534
Projection = XmlHelper.Deserialize<ExportProjection>(request.Profile.Projection);
36-
EntityIdsSelected = selectedIds.SplitSafe(",").Select(x => x.ToInt()).ToList();
3735
IsPreview = isPreview;
3836

3937
FolderContent = FileSystemHelper.TempDir(@"Profile\Export\{0}\Content".FormatInvariant(request.Profile.FolderName));
4038
FolderRoot = System.IO.Directory.GetParent(FolderContent).FullName;
4139

40+
EntityIdsSelected = new List<int>();
4241
Categories = new Dictionary<int, Category>();
4342
CategoryPathes = new Dictionary<int, string>();
4443
Countries = new Dictionary<int, Country>();

src/Libraries/SmartStore.Services/Tasks/TaskScheduler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public void RunSingleTask(int scheduleTaskId, IDictionary<string, string> taskPa
113113
query = qs.ToString();
114114
}
115115

116-
CallEndpoint(_baseUrl + "/Execute/{0}{1}".FormatInvariant(scheduleTaskId, query));
116+
CallEndpoint("{0}/Execute/{1}{2}".FormatInvariant(_baseUrl, scheduleTaskId, query));
117117
}
118118

119119
private void Elapsed(object sender, System.Timers.ElapsedEventArgs e)

src/Presentation/SmartStore.Web/Administration/Controllers/ExportController.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ public ActionResult PreviewList(GridCommand command, int id, int totalRecords)
826826
}
827827

828828
[HttpPost]
829-
public ActionResult Execute(int id, string selectedIds, bool exportAll)
829+
public ActionResult Execute(int id, string selectedIds)
830830
{
831831
if (!_services.Permissions.Authorize(StandardPermissionProvider.ManageExports))
832832
return AccessDeniedView();
@@ -835,10 +835,15 @@ public ActionResult Execute(int id, string selectedIds, bool exportAll)
835835
if (profile == null)
836836
return RedirectToAction("List");
837837

838-
// TODO:
839-
profile.CacheSelectedEntityIds(selectedIds);
838+
Dictionary<string, string> taskParams = null;
840839

841-
_taskScheduler.RunSingleTask(profile.SchedulingTaskId);
840+
if (selectedIds.HasValue())
841+
{
842+
taskParams = new Dictionary<string, string>();
843+
taskParams.Add("SelectedIds", selectedIds);
844+
}
845+
846+
_taskScheduler.RunSingleTask(profile.SchedulingTaskId, taskParams);
842847

843848
NotifyInfo(T("Admin.System.ScheduleTasks.RunNow.Progress"));
844849

src/Presentation/SmartStore.Web/Administration/Views/Export/List.cshtml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
<form id="ProfileExportForm" method="POST" action="@Url.Action("Execute", "Export", new { area = "Admin" })">
2020
<input type="hidden" name="Id" value="" />
21-
<input type="hidden" name="ExportAll" value="true" />
2221
</form>
2322

2423
@if(Model.Count > 0)

0 commit comments

Comments
 (0)