Skip to content

Commit cd037cd

Browse files
committed
Export refactoring: removed ExportExecuteContext interface (the concrete type is sufficient)
1 parent 811246b commit cd037cd

6 files changed

Lines changed: 107 additions & 131 deletions

File tree

src/Libraries/SmartStore.Services/DataExchange/Events/RowExportingEvent.cs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,32 @@ namespace SmartStore.Services.DataExchange.Export.Events
44
{
55
// TODO: Another event message must be implemented, say 'ColumnsBuildingEvent'
66
// The consumer of this event (most likely a plugin) could push a list of specific column headers
7-
// into global the export definition.
7+
// into the global export definition.
88

99
public class RowExportingEvent
1010
{
11-
public dynamic Row { get; internal set; }
12-
public ExportEntityType EntityType { get; internal set; }
13-
public DataExportRequest ExportRequest { get; internal set; }
14-
public IExportExecuteContext ExecuteContext { get; internal set; }
11+
public dynamic Row
12+
{
13+
get;
14+
internal set;
15+
}
16+
17+
public ExportEntityType EntityType
18+
{
19+
get;
20+
internal set;
21+
}
22+
23+
public DataExportRequest ExportRequest
24+
{
25+
get;
26+
internal set;
27+
}
28+
29+
public ExportExecuteContext ExecuteContext
30+
{
31+
get;
32+
internal set;
33+
}
1534
}
1635
}

src/Libraries/SmartStore.Services/DataExchange/Export/ExportExecuteContext.cs

Lines changed: 75 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -7,131 +7,177 @@
77

88
namespace SmartStore.Services.DataExchange.Export
99
{
10-
public interface IExportExecuteContext
10+
public class ExportExecuteContext
1111
{
12+
private DataExportResult _result;
13+
private CancellationToken _cancellation;
14+
private DataExchangeAbortion _providerAbort;
15+
16+
internal ExportExecuteContext(DataExportResult result, CancellationToken cancellation, string folder)
17+
{
18+
_result = result;
19+
_cancellation = cancellation;
20+
Folder = folder;
21+
ExtraDataStreams = new List<ExportExtraStreams>();
22+
CustomProperties = new Dictionary<string, object>();
23+
}
24+
1225
/// <summary>
1326
/// Provides the data to be exported
1427
/// </summary>
15-
IExportDataSegmenterConsumer Segmenter { get; }
28+
public IExportDataSegmenterConsumer Segmenter { get; set; }
1629

1730
/// <summary>
1831
/// The store context to be used for the export
1932
/// </summary>
20-
dynamic Store { get; }
33+
public dynamic Store { get; internal set; }
2134

2235
/// <summary>
2336
/// The customer context to be used for the export
2437
/// </summary>
25-
dynamic Customer { get; }
38+
public dynamic Customer { get; internal set; }
2639

2740
/// <summary>
2841
/// The currency context to be used for the export
2942
/// </summary>
30-
dynamic Currency { get; }
43+
public dynamic Currency { get; internal set; }
3144

3245
/// <summary>
3346
/// The language context to be used for the export
3447
/// </summary>
35-
dynamic Language { get; }
48+
public dynamic Language { get; internal set; }
3649

3750
/// <summary>
3851
/// Projection data
3952
/// </summary>
40-
ExportProjection Projection { get; }
53+
public ExportProjection Projection { get; internal set; }
4154

4255
/// <summary>
4356
/// To log information into the export log file
4457
/// </summary>
45-
ILogger Log { get; }
58+
public ILogger Log { get; internal set; }
4659

4760
/// <summary>
4861
/// Indicates whether and how to abort the export
4962
/// </summary>
50-
DataExchangeAbortion Abort { get; set; }
63+
public DataExchangeAbortion Abort
64+
{
65+
get
66+
{
67+
if (_cancellation.IsCancellationRequested || IsMaxFailures)
68+
return DataExchangeAbortion.Hard;
69+
70+
return _providerAbort;
71+
}
72+
set
73+
{
74+
_providerAbort = value;
75+
}
76+
}
5177

78+
public bool IsMaxFailures
79+
{
80+
get { return RecordsFailed > 11; }
81+
}
5282

5383
/// <summary>
5484
/// Identifier of current data stream. Can be <c>null</c>.
5585
/// </summary>
56-
string DataStreamId { get; set; }
86+
public string DataStreamId { get; set; }
5787

5888
/// <summary>
5989
/// Stream used to write data to
6090
/// </summary>
61-
Stream DataStream { get; }
91+
public Stream DataStream { get; internal set; }
6292

6393
/// <summary>
6494
/// List with extra data streams required by provider
6595
/// </summary>
66-
List<ExportExtraStreams> ExtraDataStreams { get; set; }
67-
96+
public List<ExportExtraStreams> ExtraDataStreams { get; set; }
6897

6998
/// <summary>
7099
/// The maximum allowed file name length
71100
/// </summary>
72-
int MaxFileNameLength { get; }
101+
public int MaxFileNameLength { get; internal set; }
73102

74103
/// <summary>
75104
/// The name of the current export file
76105
/// </summary>
77-
string FileName { get; }
106+
public string FileName { get; internal set; }
78107

79108
/// <summary>
80109
/// The path of the export content folder
81110
/// </summary>
82-
string Folder { get; }
83-
111+
public string Folder { get; private set; }
84112

85113
/// <summary>
86114
/// Whether the profile has a public deployment into "Exchange" folder
87115
/// </summary>
88-
bool HasPublicDeployment { get; }
116+
public bool HasPublicDeployment { get; internal set; }
89117

90118
/// <summary>
91119
/// The local path to the public export folder "Exchange". <c>null</c> if the profile has no public deployment.
92120
/// </summary>
93-
string PublicFolderPath { get; }
121+
public string PublicFolderPath { get; internal set; }
94122

95123
/// <summary>
96124
/// The public URL of the export file (accessible through the internet). <c>null</c> if the profile has no public deployment.
97125
/// </summary>
98-
string PublicFileUrl { get; }
99-
126+
public string PublicFileUrl { get; internal set; }
100127

101128
/// <summary>
102129
/// Provider specific configuration data
103130
/// </summary>
104-
object ConfigurationData { get; }
131+
public object ConfigurationData { get; internal set; }
105132

106133
/// <summary>
107134
/// Use this dictionary for any custom data required along the export
108135
/// </summary>
109-
Dictionary<string, object> CustomProperties { get; set; }
136+
public Dictionary<string, object> CustomProperties { get; set; }
110137

111138
/// <summary>
112139
/// Number of successful processed records
113140
/// </summary>
114-
int RecordsSucceeded { get; set; }
141+
public int RecordsSucceeded { get; set; }
115142

116143
/// <summary>
117144
/// Number of failed records
118145
/// </summary>
119-
int RecordsFailed { get; set; }
146+
public int RecordsFailed { get; set; }
120147

121148
/// <summary>
122149
/// Processes an exception that occurred while exporting a record
123150
/// </summary>
124-
/// <param name="exc">Exception</param>
125-
void RecordException(Exception exc, int entityId);
151+
/// <param name="exception">Exception</param>
152+
public void RecordException(Exception exception, int entityId)
153+
{
154+
++RecordsFailed;
155+
156+
Log.Error("Error while processing record with id {0}: {1}".FormatInvariant(entityId, exception.ToAllMessages()), exception);
157+
158+
if (IsMaxFailures)
159+
_result.LastError = exception.ToString();
160+
}
161+
162+
public ProgressValueSetter ProgressValueSetter { get; internal set; }
126163

127164
/// <summary>
128165
/// Allows to set a progress message
129166
/// </summary>
130167
/// <param name="message">Output message</param>
131-
void SetProgress(string message);
168+
public void SetProgress(string message)
169+
{
170+
if (ProgressValueSetter != null && message.HasValue())
171+
{
172+
try
173+
{
174+
ProgressValueSetter.Invoke(0, 0, message);
175+
}
176+
catch { }
177+
}
178+
}
132179
}
133180

134-
135181
public class ExportExtraStreams
136182
{
137183
/// <summary>
@@ -149,93 +195,4 @@ public class ExportExtraStreams
149195
/// </summary>
150196
public string FileName { get; set; }
151197
}
152-
153-
154-
public class ExportExecuteContext : IExportExecuteContext
155-
{
156-
private DataExportResult _result;
157-
private CancellationToken _cancellation;
158-
private DataExchangeAbortion _providerAbort;
159-
160-
internal ExportExecuteContext(DataExportResult result, CancellationToken cancellation, string folder)
161-
{
162-
_result = result;
163-
_cancellation = cancellation;
164-
Folder = folder;
165-
ExtraDataStreams = new List<ExportExtraStreams>();
166-
CustomProperties = new Dictionary<string, object>();
167-
}
168-
169-
public IExportDataSegmenterConsumer Segmenter { get; set; }
170-
171-
public dynamic Store { get; internal set; }
172-
public dynamic Customer { get; internal set; }
173-
public dynamic Currency { get; internal set; }
174-
public dynamic Language { get; internal set; }
175-
public ExportProjection Projection { get; internal set; }
176-
177-
public ILogger Log { get; internal set; }
178-
public ProgressValueSetter ProgressValueSetter { get; internal set; }
179-
180-
public DataExchangeAbortion Abort
181-
{
182-
get
183-
{
184-
if (_cancellation.IsCancellationRequested || IsMaxFailures)
185-
return DataExchangeAbortion.Hard;
186-
187-
return _providerAbort;
188-
}
189-
set
190-
{
191-
_providerAbort = value;
192-
}
193-
}
194-
195-
public bool IsMaxFailures
196-
{
197-
get { return RecordsFailed > 11; }
198-
}
199-
200-
public string DataStreamId { get; set; }
201-
public Stream DataStream { get; internal set; }
202-
public List<ExportExtraStreams> ExtraDataStreams { get; set; }
203-
204-
public int MaxFileNameLength { get; internal set; }
205-
public string FileName { get; internal set; }
206-
public string Folder { get; private set; }
207-
208-
public bool HasPublicDeployment { get; internal set; }
209-
public string PublicFolderPath { get; internal set; }
210-
public string PublicFileUrl { get; internal set; }
211-
212-
public object ConfigurationData { get; internal set; }
213-
214-
public Dictionary<string, object> CustomProperties { get; set; }
215-
216-
public int RecordsSucceeded { get; set; }
217-
public int RecordsFailed { get; set; }
218-
219-
public void RecordException(Exception exc, int entityId)
220-
{
221-
++RecordsFailed;
222-
223-
Log.Error("Error while processing record with id {0}: {1}".FormatInvariant(entityId, exc.ToAllMessages()), exc);
224-
225-
if (IsMaxFailures)
226-
_result.LastError = exc.ToString();
227-
}
228-
229-
public void SetProgress(string message)
230-
{
231-
if (ProgressValueSetter != null && message.HasValue())
232-
{
233-
try
234-
{
235-
ProgressValueSetter.Invoke(0, 0, message);
236-
}
237-
catch { }
238-
}
239-
}
240-
}
241198
}

src/Libraries/SmartStore.Services/DataExchange/Export/ExportProviderBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public virtual ExportConfigurationInfo ConfigurationInfo
3232
/// Export data to a file
3333
/// </summary>
3434
/// <param name="context">Export execution context</param>
35-
protected abstract void Export(IExportExecuteContext context);
35+
protected abstract void Export(ExportExecuteContext context);
3636

37-
public void Execute(IExportExecuteContext context)
37+
public void Execute(ExportExecuteContext context)
3838
{
3939
Export(context);
4040
}
@@ -43,7 +43,7 @@ public void Execute(IExportExecuteContext context)
4343
/// Called once per store when export execution ended
4444
/// </summary>
4545
/// <param name="context">Export execution context</param>
46-
public virtual void OnExecuted(IExportExecuteContext context)
46+
public virtual void OnExecuted(ExportExecuteContext context)
4747
{
4848
}
4949
}

src/Libraries/SmartStore.Services/DataExchange/Export/IExportProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ public partial interface IExportProvider : IProvider, IUserEditable
2424
/// Export data to a file
2525
/// </summary>
2626
/// <param name="context">Export execution context</param>
27-
void Execute(IExportExecuteContext context);
27+
void Execute(ExportExecuteContext context);
2828

2929
/// <summary>
3030
/// Called once per store when export execution ended
3131
/// </summary>
3232
/// <param name="context">Export execution context</param>
33-
void OnExecuted(IExportExecuteContext context);
33+
void OnExecuted(ExportExecuteContext context);
3434
}
3535
}

src/Plugins/SmartStore.GoogleMerchantCenter/Providers/GmcXmlExportProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public override string FileExtension
153153
get { return "XML"; }
154154
}
155155

156-
protected override void Export(IExportExecuteContext context)
156+
protected override void Export(ExportExecuteContext context)
157157
{
158158
dynamic currency = context.Currency;
159159
string measureWeightSystemKey = "";

0 commit comments

Comments
 (0)