11using eShopOnContainers . Core . Models . Basket ;
22using eShopOnContainers . Core . Models . Catalog ;
33using eShopOnContainers . ViewModels . Base ;
4+ using System ;
45using System . Collections . Generic ;
6+ using System . Diagnostics ;
57using System . Text . RegularExpressions ;
68
79namespace eShopOnContainers . Core . Helpers
@@ -12,27 +14,35 @@ public static class ServicesHelper
1214
1315 public static void FixCatalogItemPictureUri ( IEnumerable < CatalogItem > catalogItems )
1416 {
15- if ( catalogItems == null )
17+ if ( catalogItems == null )
1618 {
1719 return ;
1820 }
1921
20- if ( ! ViewModelLocator . Instance . UseMockService
21- && Settings . UrlBase != GlobalSetting . DefaultEndpoint )
22+ try
2223 {
23- foreach ( var catalogItem in catalogItems )
24+ if ( ! ViewModelLocator . Instance . UseMockService
25+ && Settings . UrlBase != GlobalSetting . DefaultEndpoint )
2426 {
25- MatchCollection serverResult = IpRegex . Matches ( catalogItem . PictureUri ) ;
26- MatchCollection localResult = IpRegex . Matches ( Settings . UrlBase ) ;
27-
28- if ( serverResult . Count != - 1 && localResult . Count != - 1 )
27+ foreach ( var catalogItem in catalogItems )
2928 {
30- var serviceIp = serverResult [ 0 ] . Value ;
31- var localIp = localResult [ 0 ] . Value ;
32- catalogItem . PictureUri = catalogItem . PictureUri . Replace ( serviceIp , localIp ) ;
29+ MatchCollection serverResult = IpRegex . Matches ( catalogItem . PictureUri ) ;
30+ MatchCollection localResult = IpRegex . Matches ( Settings . UrlBase ) ;
31+
32+ if ( serverResult . Count != - 1 && localResult . Count != - 1 )
33+ {
34+ var serviceIp = serverResult [ 0 ] . Value ;
35+ var localIp = localResult [ 0 ] . Value ;
36+
37+ catalogItem . PictureUri = catalogItem . PictureUri . Replace ( serviceIp , localIp ) ;
38+ }
3339 }
3440 }
3541 }
42+ catch ( Exception ex )
43+ {
44+ Debug . WriteLine ( ex . Message ) ;
45+ }
3646 }
3747
3848 public static void FixBasketItemPictureUri ( IEnumerable < BasketItem > basketItems )
@@ -42,22 +52,29 @@ public static void FixBasketItemPictureUri(IEnumerable<BasketItem> basketItems)
4252 return ;
4353 }
4454
45- if ( ! ViewModelLocator . Instance . UseMockService
46- && Settings . UrlBase != GlobalSetting . DefaultEndpoint )
55+ try
4756 {
48- foreach ( var basketItem in basketItems )
57+ if ( ! ViewModelLocator . Instance . UseMockService
58+ && Settings . UrlBase != GlobalSetting . DefaultEndpoint )
4959 {
50- MatchCollection serverResult = IpRegex . Matches ( basketItem . PictureUrl ) ;
51- MatchCollection localResult = IpRegex . Matches ( Settings . UrlBase ) ;
52-
53- if ( serverResult . Count != - 1 && localResult . Count != - 1 )
60+ foreach ( var basketItem in basketItems )
5461 {
55- var serviceIp = serverResult [ 0 ] . Value ;
56- var localIp = localResult [ 0 ] . Value ;
57- basketItem . PictureUrl = basketItem . PictureUrl . Replace ( serviceIp , localIp ) ;
62+ MatchCollection serverResult = IpRegex . Matches ( basketItem . PictureUrl ) ;
63+ MatchCollection localResult = IpRegex . Matches ( Settings . UrlBase ) ;
64+
65+ if ( serverResult . Count != - 1 && localResult . Count != - 1 )
66+ {
67+ var serviceIp = serverResult [ 0 ] . Value ;
68+ var localIp = localResult [ 0 ] . Value ;
69+ basketItem . PictureUrl = basketItem . PictureUrl . Replace ( serviceIp , localIp ) ;
70+ }
5871 }
5972 }
6073 }
74+ catch ( Exception ex )
75+ {
76+ Debug . WriteLine ( ex . Message ) ;
77+ }
6178 }
6279 }
6380}
0 commit comments