44using System . Net ;
55using System . Threading . Tasks ;
66using Newtonsoft . Json ;
7+ using Nito . AsyncEx . Synchronous ;
78using Recombee . ApiClient . ApiRequests ;
89using Recombee . ApiClient . Bindings ;
910
@@ -34,9 +35,9 @@ public async Task<PropertyInfo> SendAsync(GetItemPropertyInfo request)
3435 /// <returns>Response from the API</returns>
3536 public PropertyInfo Send ( GetItemPropertyInfo request )
3637 {
37- var task = SendAsync ( request ) ;
38- RaiseExceptionOnFault ( task ) ;
39- return task . Result ;
38+ var task = Task . Run ( async ( ) => await SendAsync ( request ) ) ;
39+ var result = task . WaitAndUnwrapException ( ) ;
40+ return result ;
4041 }
4142
4243
@@ -63,9 +64,9 @@ public async Task<IEnumerable<PropertyInfo>> SendAsync(ListItemProperties reques
6364 /// <returns>Response from the API</returns>
6465 public IEnumerable < PropertyInfo > Send ( ListItemProperties request )
6566 {
66- var task = SendAsync ( request ) ;
67- RaiseExceptionOnFault ( task ) ;
68- return task . Result ;
67+ var task = Task . Run ( async ( ) => await SendAsync ( request ) ) ;
68+ var result = task . WaitAndUnwrapException ( ) ;
69+ return result ;
6970 }
7071
7172
@@ -93,9 +94,9 @@ public async Task<IEnumerable<Series>> SendAsync(ListSeries request)
9394 /// <returns>Response from the API</returns>
9495 public IEnumerable < Series > Send ( ListSeries request )
9596 {
96- var task = SendAsync ( request ) ;
97- RaiseExceptionOnFault ( task ) ;
98- return task . Result ;
97+ var task = Task . Run ( async ( ) => await SendAsync ( request ) ) ;
98+ var result = task . WaitAndUnwrapException ( ) ;
99+ return result ;
99100 }
100101
101102
@@ -122,9 +123,9 @@ public async Task<IEnumerable<SeriesItem>> SendAsync(ListSeriesItems request)
122123 /// <returns>Response from the API</returns>
123124 public IEnumerable < SeriesItem > Send ( ListSeriesItems request )
124125 {
125- var task = SendAsync ( request ) ;
126- RaiseExceptionOnFault ( task ) ;
127- return task . Result ;
126+ var task = Task . Run ( async ( ) => await SendAsync ( request ) ) ;
127+ var result = task . WaitAndUnwrapException ( ) ;
128+ return result ;
128129 }
129130
130131
@@ -152,9 +153,9 @@ public async Task<IEnumerable<Group>> SendAsync(ListGroups request)
152153 /// <returns>Response from the API</returns>
153154 public IEnumerable < Group > Send ( ListGroups request )
154155 {
155- var task = SendAsync ( request ) ;
156- RaiseExceptionOnFault ( task ) ;
157- return task . Result ;
156+ var task = Task . Run ( async ( ) => await SendAsync ( request ) ) ;
157+ var result = task . WaitAndUnwrapException ( ) ;
158+ return result ;
158159 }
159160
160161
@@ -181,9 +182,9 @@ public async Task<IEnumerable<GroupItem>> SendAsync(ListGroupItems request)
181182 /// <returns>Response from the API</returns>
182183 public IEnumerable < GroupItem > Send ( ListGroupItems request )
183184 {
184- var task = SendAsync ( request ) ;
185- RaiseExceptionOnFault ( task ) ;
186- return task . Result ;
185+ var task = Task . Run ( async ( ) => await SendAsync ( request ) ) ;
186+ var result = task . WaitAndUnwrapException ( ) ;
187+ return result ;
187188 }
188189
189190
@@ -210,9 +211,9 @@ public async Task<PropertyInfo> SendAsync(GetUserPropertyInfo request)
210211 /// <returns>Response from the API</returns>
211212 public PropertyInfo Send ( GetUserPropertyInfo request )
212213 {
213- var task = SendAsync ( request ) ;
214- RaiseExceptionOnFault ( task ) ;
215- return task . Result ;
214+ var task = Task . Run ( async ( ) => await SendAsync ( request ) ) ;
215+ var result = task . WaitAndUnwrapException ( ) ;
216+ return result ;
216217 }
217218
218219
@@ -239,9 +240,9 @@ public async Task<IEnumerable<PropertyInfo>> SendAsync(ListUserProperties reques
239240 /// <returns>Response from the API</returns>
240241 public IEnumerable < PropertyInfo > Send ( ListUserProperties request )
241242 {
242- var task = SendAsync ( request ) ;
243- RaiseExceptionOnFault ( task ) ;
244- return task . Result ;
243+ var task = Task . Run ( async ( ) => await SendAsync ( request ) ) ;
244+ var result = task . WaitAndUnwrapException ( ) ;
245+ return result ;
245246 }
246247
247248
@@ -268,9 +269,9 @@ public async Task<IEnumerable<DetailView>> SendAsync(ListItemDetailViews request
268269 /// <returns>Response from the API</returns>
269270 public IEnumerable < DetailView > Send ( ListItemDetailViews request )
270271 {
271- var task = SendAsync ( request ) ;
272- RaiseExceptionOnFault ( task ) ;
273- return task . Result ;
272+ var task = Task . Run ( async ( ) => await SendAsync ( request ) ) ;
273+ var result = task . WaitAndUnwrapException ( ) ;
274+ return result ;
274275 }
275276
276277
@@ -297,9 +298,9 @@ public async Task<IEnumerable<DetailView>> SendAsync(ListUserDetailViews request
297298 /// <returns>Response from the API</returns>
298299 public IEnumerable < DetailView > Send ( ListUserDetailViews request )
299300 {
300- var task = SendAsync ( request ) ;
301- RaiseExceptionOnFault ( task ) ;
302- return task . Result ;
301+ var task = Task . Run ( async ( ) => await SendAsync ( request ) ) ;
302+ var result = task . WaitAndUnwrapException ( ) ;
303+ return result ;
303304 }
304305
305306
@@ -326,9 +327,9 @@ public async Task<IEnumerable<Purchase>> SendAsync(ListItemPurchases request)
326327 /// <returns>Response from the API</returns>
327328 public IEnumerable < Purchase > Send ( ListItemPurchases request )
328329 {
329- var task = SendAsync ( request ) ;
330- RaiseExceptionOnFault ( task ) ;
331- return task . Result ;
330+ var task = Task . Run ( async ( ) => await SendAsync ( request ) ) ;
331+ var result = task . WaitAndUnwrapException ( ) ;
332+ return result ;
332333 }
333334
334335
@@ -355,9 +356,9 @@ public async Task<IEnumerable<Purchase>> SendAsync(ListUserPurchases request)
355356 /// <returns>Response from the API</returns>
356357 public IEnumerable < Purchase > Send ( ListUserPurchases request )
357358 {
358- var task = SendAsync ( request ) ;
359- RaiseExceptionOnFault ( task ) ;
360- return task . Result ;
359+ var task = Task . Run ( async ( ) => await SendAsync ( request ) ) ;
360+ var result = task . WaitAndUnwrapException ( ) ;
361+ return result ;
361362 }
362363
363364
@@ -384,9 +385,9 @@ public async Task<IEnumerable<Rating>> SendAsync(ListItemRatings request)
384385 /// <returns>Response from the API</returns>
385386 public IEnumerable < Rating > Send ( ListItemRatings request )
386387 {
387- var task = SendAsync ( request ) ;
388- RaiseExceptionOnFault ( task ) ;
389- return task . Result ;
388+ var task = Task . Run ( async ( ) => await SendAsync ( request ) ) ;
389+ var result = task . WaitAndUnwrapException ( ) ;
390+ return result ;
390391 }
391392
392393
@@ -413,9 +414,9 @@ public async Task<IEnumerable<Rating>> SendAsync(ListUserRatings request)
413414 /// <returns>Response from the API</returns>
414415 public IEnumerable < Rating > Send ( ListUserRatings request )
415416 {
416- var task = SendAsync ( request ) ;
417- RaiseExceptionOnFault ( task ) ;
418- return task . Result ;
417+ var task = Task . Run ( async ( ) => await SendAsync ( request ) ) ;
418+ var result = task . WaitAndUnwrapException ( ) ;
419+ return result ;
419420 }
420421
421422
@@ -442,9 +443,9 @@ public async Task<IEnumerable<CartAddition>> SendAsync(ListItemCartAdditions req
442443 /// <returns>Response from the API</returns>
443444 public IEnumerable < CartAddition > Send ( ListItemCartAdditions request )
444445 {
445- var task = SendAsync ( request ) ;
446- RaiseExceptionOnFault ( task ) ;
447- return task . Result ;
446+ var task = Task . Run ( async ( ) => await SendAsync ( request ) ) ;
447+ var result = task . WaitAndUnwrapException ( ) ;
448+ return result ;
448449 }
449450
450451
@@ -471,9 +472,9 @@ public async Task<IEnumerable<CartAddition>> SendAsync(ListUserCartAdditions req
471472 /// <returns>Response from the API</returns>
472473 public IEnumerable < CartAddition > Send ( ListUserCartAdditions request )
473474 {
474- var task = SendAsync ( request ) ;
475- RaiseExceptionOnFault ( task ) ;
476- return task . Result ;
475+ var task = Task . Run ( async ( ) => await SendAsync ( request ) ) ;
476+ var result = task . WaitAndUnwrapException ( ) ;
477+ return result ;
477478 }
478479
479480
@@ -500,9 +501,9 @@ public async Task<IEnumerable<Bookmark>> SendAsync(ListItemBookmarks request)
500501 /// <returns>Response from the API</returns>
501502 public IEnumerable < Bookmark > Send ( ListItemBookmarks request )
502503 {
503- var task = SendAsync ( request ) ;
504- RaiseExceptionOnFault ( task ) ;
505- return task . Result ;
504+ var task = Task . Run ( async ( ) => await SendAsync ( request ) ) ;
505+ var result = task . WaitAndUnwrapException ( ) ;
506+ return result ;
506507 }
507508
508509
@@ -529,9 +530,9 @@ public async Task<IEnumerable<Bookmark>> SendAsync(ListUserBookmarks request)
529530 /// <returns>Response from the API</returns>
530531 public IEnumerable < Bookmark > Send ( ListUserBookmarks request )
531532 {
532- var task = SendAsync ( request ) ;
533- RaiseExceptionOnFault ( task ) ;
534- return task . Result ;
533+ var task = Task . Run ( async ( ) => await SendAsync ( request ) ) ;
534+ var result = task . WaitAndUnwrapException ( ) ;
535+ return result ;
535536 }
536537
537538
@@ -558,9 +559,9 @@ public async Task<IEnumerable<ViewPortion>> SendAsync(ListItemViewPortions reque
558559 /// <returns>Response from the API</returns>
559560 public IEnumerable < ViewPortion > Send ( ListItemViewPortions request )
560561 {
561- var task = SendAsync ( request ) ;
562- RaiseExceptionOnFault ( task ) ;
563- return task . Result ;
562+ var task = Task . Run ( async ( ) => await SendAsync ( request ) ) ;
563+ var result = task . WaitAndUnwrapException ( ) ;
564+ return result ;
564565 }
565566
566567
@@ -587,9 +588,9 @@ public async Task<IEnumerable<ViewPortion>> SendAsync(ListUserViewPortions reque
587588 /// <returns>Response from the API</returns>
588589 public IEnumerable < ViewPortion > Send ( ListUserViewPortions request )
589590 {
590- var task = SendAsync ( request ) ;
591- RaiseExceptionOnFault ( task ) ;
592- return task . Result ;
591+ var task = Task . Run ( async ( ) => await SendAsync ( request ) ) ;
592+ var result = task . WaitAndUnwrapException ( ) ;
593+ return result ;
593594 }
594595
595596
@@ -616,9 +617,9 @@ public async Task<RecommendationResponse> SendAsync(RecommendItemsToUser request
616617 /// <returns>Response from the API</returns>
617618 public RecommendationResponse Send ( RecommendItemsToUser request )
618619 {
619- var task = SendAsync ( request ) ;
620- RaiseExceptionOnFault ( task ) ;
621- return task . Result ;
620+ var task = Task . Run ( async ( ) => await SendAsync ( request ) ) ;
621+ var result = task . WaitAndUnwrapException ( ) ;
622+ return result ;
622623 }
623624
624625
@@ -645,9 +646,9 @@ public async Task<RecommendationResponse> SendAsync(RecommendUsersToUser request
645646 /// <returns>Response from the API</returns>
646647 public RecommendationResponse Send ( RecommendUsersToUser request )
647648 {
648- var task = SendAsync ( request ) ;
649- RaiseExceptionOnFault ( task ) ;
650- return task . Result ;
649+ var task = Task . Run ( async ( ) => await SendAsync ( request ) ) ;
650+ var result = task . WaitAndUnwrapException ( ) ;
651+ return result ;
651652 }
652653
653654
@@ -674,9 +675,9 @@ public async Task<RecommendationResponse> SendAsync(RecommendItemsToItem request
674675 /// <returns>Response from the API</returns>
675676 public RecommendationResponse Send ( RecommendItemsToItem request )
676677 {
677- var task = SendAsync ( request ) ;
678- RaiseExceptionOnFault ( task ) ;
679- return task . Result ;
678+ var task = Task . Run ( async ( ) => await SendAsync ( request ) ) ;
679+ var result = task . WaitAndUnwrapException ( ) ;
680+ return result ;
680681 }
681682
682683
@@ -703,9 +704,9 @@ public async Task<RecommendationResponse> SendAsync(RecommendUsersToItem request
703704 /// <returns>Response from the API</returns>
704705 public RecommendationResponse Send ( RecommendUsersToItem request )
705706 {
706- var task = SendAsync ( request ) ;
707- RaiseExceptionOnFault ( task ) ;
708- return task . Result ;
707+ var task = Task . Run ( async ( ) => await SendAsync ( request ) ) ;
708+ var result = task . WaitAndUnwrapException ( ) ;
709+ return result ;
709710 }
710711
711712
@@ -732,9 +733,9 @@ public async Task<SearchResponse> SendAsync(SearchItems request)
732733 /// <returns>Response from the API</returns>
733734 public SearchResponse Send ( SearchItems request )
734735 {
735- var task = SendAsync ( request ) ;
736- RaiseExceptionOnFault ( task ) ;
737- return task . Result ;
736+ var task = Task . Run ( async ( ) => await SendAsync ( request ) ) ;
737+ var result = task . WaitAndUnwrapException ( ) ;
738+ return result ;
738739 }
739740
740741 private object ParseOneBatchResponse ( string json , int statusCode , Request request )
0 commit comments