@@ -138,11 +138,7 @@ public async Task<ProcessingReportMessage> GetFeedDocumentProcessingReportAsync(
138
138
}
139
139
catch ( AmazonProcessingReportDeserializeException ex )
140
140
{
141
- throw ex ;
142
- }
143
- catch ( Exception ex )
144
- {
145
-
141
+ throw ;
146
142
}
147
143
return processingReport ;
148
144
}
@@ -171,30 +167,14 @@ public string SubmitFeed(string XmlContentOrFilePath, FeedType feedType, List<st
171
167
/// <param name="xml"></param>
172
168
/// <param name="feedType"></param>
173
169
/// <returns></returns>
174
- public async Task < string > SubmitFeedAsync ( string XmlContentOrFilePath , FeedType feedType , List < string > marketPlaceIds = null , FeedOptions feedOptions = null , ContentType contentType = ContentType . XML )
170
+ public async Task < string > SubmitFeedAsync ( string feedContentOrFilePath , FeedType feedType , List < string > marketPlaceIds = null , FeedOptions feedOptions = null , ContentType contentType = ContentType . XML )
175
171
{
176
-
177
172
//We are creating Feed Document
178
173
var feedCreate = CreateFeedDocument ( contentType ) ;
179
174
180
175
//Uploading encoded invoice file
181
- if ( contentType == ContentType . PDF )
182
- {
183
- _ = await PostFileDataAsync ( feedCreate . Url , XmlContentOrFilePath , contentType ) ;
184
- }
185
- else if ( contentType == ContentType . JSON )
186
- {
187
- _ = await PostFileDataAsync ( feedCreate . Url , XmlContentOrFilePath , contentType ) ;
188
- }
189
- else if ( contentType == ContentType . TXT )
190
- {
191
- _ = await PostFileDataAsync ( feedCreate . Url , XmlContentOrFilePath , contentType ) ;
192
- }
193
- else
194
- {
195
- _ = await PostXMLDataAsync ( feedCreate . Url , XmlContentOrFilePath ) ;
196
- }
197
-
176
+ _ = await PostFileDataAsync ( feedCreate . Url , feedContentOrFilePath , contentType ) ;
177
+
198
178
CreateFeedSpecification createFeedSpecification = new CreateFeedSpecification ( )
199
179
{
200
180
FeedType = feedType . ToString ( ) ,
@@ -220,45 +200,29 @@ private static async Task<Stream> GetStreamFromUrlAsync(string url)
220
200
return new MemoryStream ( imageData ) ;
221
201
}
222
202
223
- private async Task < string > PostXMLDataAsync ( string destinationUrl , string requestXml , ContentType contentType = ContentType . XML )
203
+ private async Task < string > PostFileDataAsync ( string destinationUrl , string contentOrFilePath , ContentType contentType = ContentType . XML )
224
204
{
225
205
HttpWebRequest request = ( HttpWebRequest ) WebRequest . Create ( destinationUrl ) ;
226
- byte [ ] bytes ;
227
- bytes = System . Text . Encoding . ASCII . GetBytes ( requestXml ) ;
228
- request . ContentType = LinqHelper . GetEnumMemberValue ( contentType ) ;
229
- request . ContentLength = bytes . Length ;
230
- request . Method = "PUT" ;
231
- Stream requestStream = await request . GetRequestStreamAsync ( ) ;
232
- requestStream . Write ( bytes , 0 , bytes . Length ) ;
233
- requestStream . Close ( ) ;
234
- HttpWebResponse response ;
235
- response = ( HttpWebResponse ) await request . GetResponseAsync ( ) ;
236
- if ( response . StatusCode == HttpStatusCode . OK )
237
- {
238
- Stream responseStream = response . GetResponseStream ( ) ;
239
- string responseStr = new StreamReader ( responseStream ) . ReadToEnd ( ) ;
240
- return responseStr ;
241
- }
242
- return null ;
243
- }
244
206
245
- private async Task < string > PostFileDataAsync ( string destinationUrl , string pathFile , ContentType contentType = ContentType . XML )
246
- {
247
- HttpWebRequest request = ( HttpWebRequest ) WebRequest . Create ( destinationUrl ) ;
248
- byte [ ] bytes = File . ReadAllBytes ( pathFile ) ;
249
- // bytes = System.Text.Encoding.ASCII .GetBytes(requestXml );
207
+ byte [ ] bytes ;
208
+ if ( Uri . IsWellFormedUriString ( contentOrFilePath , UriKind . RelativeOrAbsolute ) )
209
+ bytes = File . ReadAllBytes ( contentOrFilePath ) ;
210
+ else
211
+ bytes = System . Text . Encoding . UTF8 . GetBytes ( contentOrFilePath ) ;
250
212
request . ContentType = LinqHelper . GetEnumMemberValue ( contentType ) ;
251
213
request . ContentLength = bytes . Length ;
252
214
request . Method = "PUT" ;
253
- Stream requestStream = request . GetRequestStream ( ) ;
254
- requestStream . Write ( bytes , 0 , bytes . Length ) ;
255
- requestStream . Close ( ) ;
256
- HttpWebResponse response = ( HttpWebResponse ) await request . GetResponseAsync ( ) ;
257
- if ( response . StatusCode == HttpStatusCode . OK )
215
+ using ( Stream requestStream = request . GetRequestStream ( ) )
258
216
{
259
- Stream responseStream = response . GetResponseStream ( ) ;
260
- string responseStr = new StreamReader ( responseStream ) . ReadToEnd ( ) ;
261
- return responseStr ;
217
+ requestStream . Write ( bytes , 0 , bytes . Length ) ;
218
+ requestStream . Close ( ) ;
219
+ HttpWebResponse response = ( HttpWebResponse ) await request . GetResponseAsync ( ) ;
220
+ if ( response . StatusCode == HttpStatusCode . OK )
221
+ {
222
+ Stream responseStream = response . GetResponseStream ( ) ;
223
+ string responseStr = await new StreamReader ( responseStream ) . ReadToEndAsync ( ) ;
224
+ return responseStr ;
225
+ }
262
226
}
263
227
return null ;
264
228
}
0 commit comments