@@ -140,11 +140,7 @@ public async Task<ProcessingReportMessage> GetFeedDocumentProcessingReportAsync(
140
140
}
141
141
catch ( AmazonProcessingReportDeserializeException ex )
142
142
{
143
- throw ex ;
144
- }
145
- catch ( Exception ex )
146
- {
147
-
143
+ throw ;
148
144
}
149
145
return processingReport ;
150
146
}
@@ -209,30 +205,14 @@ public string SubmitFeed(string XmlContentOrFilePath, FeedType feedType, List<st
209
205
/// <param name="xml"></param>
210
206
/// <param name="feedType"></param>
211
207
/// <returns></returns>
212
- public async Task < string > SubmitFeedAsync ( string XmlContentOrFilePath , FeedType feedType , List < string > marketPlaceIds = null , FeedOptions feedOptions = null , ContentType contentType = ContentType . XML )
208
+ public async Task < string > SubmitFeedAsync ( string feedContentOrFilePath , FeedType feedType , List < string > marketPlaceIds = null , FeedOptions feedOptions = null , ContentType contentType = ContentType . XML )
213
209
{
214
-
215
210
//We are creating Feed Document
216
211
var feedCreate = CreateFeedDocument ( contentType ) ;
217
212
218
213
//Uploading encoded invoice file
219
- if ( contentType == ContentType . PDF )
220
- {
221
- _ = await PostFileDataAsync ( feedCreate . Url , XmlContentOrFilePath , contentType ) ;
222
- }
223
- else if ( contentType == ContentType . JSON )
224
- {
225
- _ = await PostFileDataAsync ( feedCreate . Url , XmlContentOrFilePath , contentType ) ;
226
- }
227
- else if ( contentType == ContentType . TXT )
228
- {
229
- _ = await PostFileDataAsync ( feedCreate . Url , XmlContentOrFilePath , contentType ) ;
230
- }
231
- else
232
- {
233
- _ = await PostXMLDataAsync ( feedCreate . Url , XmlContentOrFilePath ) ;
234
- }
235
-
214
+ _ = await PostFileDataAsync ( feedCreate . Url , feedContentOrFilePath , contentType ) ;
215
+
236
216
CreateFeedSpecification createFeedSpecification = new CreateFeedSpecification ( )
237
217
{
238
218
FeedType = feedType . ToString ( ) ,
@@ -258,45 +238,29 @@ private static async Task<Stream> GetStreamFromUrlAsync(string url)
258
238
return new MemoryStream ( imageData ) ;
259
239
}
260
240
261
- private async Task < string > PostXMLDataAsync ( string destinationUrl , string requestXml , ContentType contentType = ContentType . XML )
241
+ private async Task < string > PostFileDataAsync ( string destinationUrl , string contentOrFilePath , ContentType contentType = ContentType . XML )
262
242
{
263
243
HttpWebRequest request = ( HttpWebRequest ) WebRequest . Create ( destinationUrl ) ;
264
- byte [ ] bytes ;
265
- bytes = System . Text . Encoding . ASCII . GetBytes ( requestXml ) ;
266
- request . ContentType = LinqHelper . GetEnumMemberValue ( contentType ) ;
267
- request . ContentLength = bytes . Length ;
268
- request . Method = "PUT" ;
269
- Stream requestStream = await request . GetRequestStreamAsync ( ) ;
270
- requestStream . Write ( bytes , 0 , bytes . Length ) ;
271
- requestStream . Close ( ) ;
272
- HttpWebResponse response ;
273
- response = ( HttpWebResponse ) await request . GetResponseAsync ( ) ;
274
- if ( response . StatusCode == HttpStatusCode . OK )
275
- {
276
- Stream responseStream = response . GetResponseStream ( ) ;
277
- string responseStr = new StreamReader ( responseStream ) . ReadToEnd ( ) ;
278
- return responseStr ;
279
- }
280
- return null ;
281
- }
282
244
283
- private async Task < string > PostFileDataAsync ( string destinationUrl , string pathFile , ContentType contentType = ContentType . XML )
284
- {
285
- HttpWebRequest request = ( HttpWebRequest ) WebRequest . Create ( destinationUrl ) ;
286
- byte [ ] bytes = File . ReadAllBytes ( pathFile ) ;
287
- // bytes = System.Text.Encoding.ASCII .GetBytes(requestXml );
245
+ byte [ ] bytes ;
246
+ if ( Uri . IsWellFormedUriString ( contentOrFilePath , UriKind . RelativeOrAbsolute ) )
247
+ bytes = File . ReadAllBytes ( contentOrFilePath ) ;
248
+ else
249
+ bytes = System . Text . Encoding . UTF8 . GetBytes ( contentOrFilePath ) ;
288
250
request . ContentType = LinqHelper . GetEnumMemberValue ( contentType ) ;
289
251
request . ContentLength = bytes . Length ;
290
252
request . Method = "PUT" ;
291
- Stream requestStream = request . GetRequestStream ( ) ;
292
- requestStream . Write ( bytes , 0 , bytes . Length ) ;
293
- requestStream . Close ( ) ;
294
- HttpWebResponse response = ( HttpWebResponse ) await request . GetResponseAsync ( ) ;
295
- if ( response . StatusCode == HttpStatusCode . OK )
253
+ using ( Stream requestStream = request . GetRequestStream ( ) )
296
254
{
297
- Stream responseStream = response . GetResponseStream ( ) ;
298
- string responseStr = new StreamReader ( responseStream ) . ReadToEnd ( ) ;
299
- return responseStr ;
255
+ requestStream . Write ( bytes , 0 , bytes . Length ) ;
256
+ requestStream . Close ( ) ;
257
+ HttpWebResponse response = ( HttpWebResponse ) await request . GetResponseAsync ( ) ;
258
+ if ( response . StatusCode == HttpStatusCode . OK )
259
+ {
260
+ Stream responseStream = response . GetResponseStream ( ) ;
261
+ string responseStr = await new StreamReader ( responseStream ) . ReadToEndAsync ( ) ;
262
+ return responseStr ;
263
+ }
300
264
}
301
265
return null ;
302
266
}
0 commit comments