public BitmapImage LoadAd(string name)
        {
            //здесь может возникнуть ошибка при загрузке картинке например
            //System.NotSupportedException: No imaging component suitable to complete this operation was found.
            //---> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x88982F50
            //все бы ничего но caliburn деактивации\активации формы не сможет установить форму из-за этого исключения
            return(Cache.Cache(name.ToLower(), x => {
                try {
                    x = Path.Combine(RootDir, "ads", x);
                    if (!File.Exists(x))
                    {
                        return null;
                    }

                    var bi = new BitmapImage();
                    bi.BeginInit();
                    bi.StreamSource = new MemoryStream(File.ReadAllBytes(x));
                    bi.EndInit();
                    bi.Freeze();
                    return bi;
                } catch (Exception e) {
                    log.Error($"Не удалось загрузить изображение {x}", e);
                    return null;
                }
            }));
        }
Exemple #2
0
 public static List <SentOrderLine> LoadOrderHistory(IStatelessSession session, SimpleMRUCache cache,
                                                     Settings settings, BaseOffer offer, Address address)
 {
     if (offer == null || address == null)
     {
         return(new List <SentOrderLine>());
     }
     return(cache.Cache(HistoryOrdersCacheKey(settings, offer), k => {
         IQueryable <SentOrderLine> query = session.Query <SentOrderLine>()
                                            .OrderByDescending(o => o.Order.SentOn);
         //ошибка в nhibernate, если .Where(o => o.Order.Address == Address)
         //переместить в общий блок то первый
         //where применяться не будет
         var addressId = address.Id;
         if (settings.GroupByProduct)
         {
             var productId = offer.ProductId;
             query = query.Where(o => o.ProductId == productId)
                     .Where(o => o.Order.Address.Id == addressId);
         }
         else
         {
             var catalogId = offer.CatalogId;
             query = query.Where(o => o.CatalogId == catalogId)
                     .Where(o => o.Order.Address.Id == addressId);
         }
         return query
         .Fetch(l => l.Order)
         .ThenFetch(o => o.Price)
         .Take(20)
         .ToList();
     }));
 }