77
88namespace 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}
0 commit comments