Beispiel #1
0
        protected void LoadImages(WebData_v2 <TSource, TData> webData)
        {
            WebImageRequest imageRequest = webData.Request.ImageRequest;

            if (imageRequest == null)
            {
                return;
            }
            if ((webData.DataLoadedFromWeb && (imageRequest.LoadImageFromWeb || imageRequest.RefreshImage)) ||
                (!webData.DataLoadedFromWeb && imageRequest.LoadMissingImageFromWeb))
            {
                if (webData.Data is IGetWebImages)
                {
                    if (_webLoadImageManager.LoadImagesFromWeb(imageRequest, ((IGetWebImages)webData.Data).GetWebImages(), _getImageSubDirectory?.Invoke(webData)))
                    {
                        SaveToStore(webData);
                    }
                }
            }

            if (imageRequest.LoadImageToData)
            {
                _webLoadImageManager.LoadImagesToData(webData.Data);
            }
        }
Beispiel #2
0
        private void LoadImages_v3(WebImageRequest imageRequest)
        {
            WebLoadImageManager_v2 <TData> webLoadImageManager = _webDataManager_v4.WebLoadImageManager;

            if (imageRequest == null)
            {
                return;
            }
            if ((_dataLoadedFromWeb && (imageRequest.LoadImageFromWeb || imageRequest.RefreshImage)) ||
                (!_dataLoadedFromWeb && imageRequest.LoadMissingImageFromWeb))
            {
                //if (webLoadImageManager.LoadImagesFromWeb(this))
                if (_data is IGetWebImages)
                {
                    if (webLoadImageManager.LoadImagesFromWeb(imageRequest, ((IGetWebImages)_data).GetWebImages(), _webDataManager_v4.GetImageSubDirectory?.Invoke(this)))
                    {
                        BsonDocument data = Serialize();
                        if (_id != null)
                        {
                            _dataStore.SaveWithId(_id, data);
                        }
                        else
                        {
                            _dataStore.SaveWithKey(_key, data);
                        }
                    }
                }
            }

            if (imageRequest.LoadImageToData)
            {
                webLoadImageManager.LoadImagesToData(_data);
            }
        }
        protected bool LoadImagesFromWeb(WebData <TData> webData)
        {
            WebImageRequest imageRequest = webData.Request.ImageRequest;

            if (!imageRequest.LoadImageFromWeb && !imageRequest.LoadImageToData && !imageRequest.RefreshImage)
            {
                return(false);
            }

            //if (imageRequest.LoadImageFromWeb || imageRequest.LoadImageToData || imageRequest.RefreshImage)
            //{
            if (!(webData.Data is IGetWebImages))
            {
                throw new PBException($"{typeof(TData).zGetTypeName()} is not IGetWebImages");
            }
            IEnumerable <WebImage> images = ((IGetWebImages)webData.Data).GetWebImages();

            if (_imageFilter != null)
            {
                images = images.Where(image => _imageFilter(image));
            }
            string subDirectory = null;

            if (_getImageSubDirectory != null)
            {
                subDirectory = _getImageSubDirectory(webData);
            }
            return(_webImageCacheManager.LoadImagesFromWeb(images, imageRequest, subDirectory: subDirectory));
            //}
        }
        protected bool LoadImageFromWeb(WebImage webImage, WebImageRequest imageRequest, HttpRequestParameters requestParameters = null, string subDirectory = null)
        {
            if (!imageRequest.LoadImageFromWeb || (webImage.File != null && !imageRequest.RefreshImage))
                return false;
            HttpRequest httpRequest = new HttpRequest { Url = webImage.Url };
            string file = _urlCache.GetUrlSubPath(httpRequest);
            if (subDirectory != null)
                file = zPath.Combine(subDirectory, file);
            string path = zPath.Combine(_urlCache.CacheDirectory, file);
            if (imageRequest.RefreshImage || !zFile.Exists(path))
                HttpManager.CurrentHttpManager.LoadToFile(httpRequest, path, _urlCache.SaveRequest, requestParameters);
            webImage.File = file;

            if (zFile.Exists(path))
            {
                Image image = LoadImageFromFile(path);
                if (image != null)
                {
                    webImage.Width = image.Width;
                    webImage.Height = image.Height;
                    if (imageRequest.LoadImageToData)
                        webImage.Image = image;
                }
            }
            return true;
        }
Beispiel #5
0
 public static void LoadImages <TData>(TData data, WebImageRequest request)
 {
     if (request.LoadImageFromWeb || request.LoadImageToData || request.RefreshImage)
     {
         if (!(data is ILoadImages))
         {
             throw new PBException($"{typeof(TData).zGetTypeName()} is not ILoadImages");
         }
         ((ILoadImages)data).LoadImages(request);
     }
 }
Beispiel #6
0
        //private LoadNewDocumentsResult _LoadNewDocuments(IEnumerable<THeaderData> headers, int maxDocumentsLoadedFromStore = 5, int maxDocumentsLoaded = 0, bool loadImageFromWeb = true)
        private LoadNewDocumentsResult _LoadNewDocuments(IEnumerable <THeaderData> headers, int maxDocumentsLoadedFromStore = 5, int maxDocumentsLoaded = 0, WebImageRequest webImageRequest = null)
        {
            bool refreshDocumentStore = false;    // obligatoire sinon nbDocumentLoadedFromStore reste à 0

            if (webImageRequest == null)
            {
                webImageRequest = new WebImageRequest {
                    LoadImageFromWeb = true
                }
            }
            ;
            int nbDocumentsLoaded          = 0;
            int nbDocumentsLoadedFromStore = 0;
            int nbDocumentsLoadedFromWeb   = 0;

            foreach (THeaderData header in headers)
            {
                if (!(header is IHeaderData))
                {
                    throw new PBException("type {0} is not IHeaderData", header.GetType().zGetTypeName());
                }
                //WebData<TDetailData> webData = _detailDataManager.Load(new WebRequest { HttpRequest = ((IHeaderData)header).GetHttpRequestDetail(), ReloadFromWeb = false, LoadImageFromWeb = loadImageFromWeb, RefreshDocumentStore = refreshDocumentStore });
                //WebData<TDetailData> webData = _detailDataManager.Load(new WebRequest { HttpRequest = ((IHeaderData)header).GetHttpRequestDetail(), ReloadFromWeb = false, ImageRequest = new WebImageRequest { LoadImageFromWeb = loadImageFromWeb }, RefreshDocumentStore = refreshDocumentStore });
                WebData <TDetailData> webData = _detailDataManager.Load(new WebRequest {
                    HttpRequest = ((IHeaderData)header).GetHttpRequestDetail(), ReloadFromWeb = false, ImageRequest = webImageRequest, RefreshDocumentStore = refreshDocumentStore
                });
                nbDocumentsLoaded++;
                if (webData.DataLoadedFromStore)
                {
                    nbDocumentsLoadedFromStore++;
                }
                if (webData.DataLoadedFromWeb)
                {
                    nbDocumentsLoadedFromWeb++;
                }

                if (_onDocumentLoaded != null)
                {
                    _onDocumentLoaded(webData);
                }
                if (maxDocumentsLoadedFromStore != 0 && nbDocumentsLoadedFromStore == maxDocumentsLoadedFromStore)
                {
                    break;
                }
                if (maxDocumentsLoaded != 0 && nbDocumentsLoaded == maxDocumentsLoaded)
                {
                    break;
                }
            }
            return(new LoadNewDocumentsResult {
                NbDocumentsLoadedFromWeb = nbDocumentsLoadedFromWeb, NbDocumentsLoadedFromStore = nbDocumentsLoadedFromStore
            });
        }
    }
        // HttpRequestParameters requestParameters = null
        protected bool LoadImageFromWeb(WebImage webImage, WebImageRequest imageRequest, string subDirectory = null)
        {
            if (!imageRequest.LoadImageFromWeb || (webImage.File != null && !imageRequest.RefreshImage))
            {
                return(false);
            }
            HttpRequest httpRequest = new HttpRequest {
                Url = webImage.Url, ReloadFromWeb = imageRequest.RefreshImage
            };

            //string file = _urlCache.GetUrlSubPath(httpRequest);
            //if (subDirectory != null)
            //    file = zPath.Combine(subDirectory, file);
            //string path = zPath.Combine(_urlCache.CacheDirectory, file);

            //if (imageRequest.RefreshImage || !zFile.Exists(path))
            //    HttpManager.CurrentHttpManager.LoadToFile(httpRequest, path, _urlCache.SaveRequest, requestParameters);
            //webImage.File = file;

            //UrlCachePathResult urlCachePath = LoadHttpToCache(httpRequest, subDirectory);
            //webImage.File = urlCachePath.SubPath;
            //string path = urlCachePath.Path;

            //if (zFile.Exists(path))
            //{
            //    Image image = LoadImageFromFile(path);
            //    if (image != null)
            //    {
            //        webImage.Width = image.Width;
            //        webImage.Height = image.Height;
            //        if (imageRequest.LoadImageToData)
            //            webImage.Image = image;
            //    }
            //}

            HttpResult <Image> httpResult = LoadImage(httpRequest, subDirectory);

            if (httpResult.Success)
            {
                Image image = httpResult.Data;
                webImage.File   = httpResult.Http.HttpRequest.UrlCachePath?.SubPath;
                webImage.Width  = image.Width;
                webImage.Height = image.Height;
                if (imageRequest.LoadImageToData)
                {
                    webImage.Image = image;
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
 public virtual bool LoadImagesFromWeb(IEnumerable<WebImage> images, WebImageRequest imageRequest, HttpRequestParameters requestParameters = null, string subDirectory = null)
 {
     if (!imageRequest.LoadImageFromWeb && !imageRequest.RefreshImage)
         return false;
     bool ret = false;
     foreach (WebImage image in images)
     {
         if (LoadImageFromWeb(image, imageRequest, requestParameters, subDirectory))
             ret = true;
     }
     return ret;
 }
Beispiel #9
0
        //public Func<WebData<TData>, string> GetImageSubDirectory { get { return _getImageSubDirectory; } set { _getImageSubDirectory = value; } }

        //public bool LoadImagesFromWeb(WebData<TData> webData)
        //{
        //    WebImageRequest imageRequest = webData.Request.ImageRequest;
        //    if (!imageRequest.LoadImageFromWeb && !imageRequest.LoadImageToData && !imageRequest.RefreshImage)
        //        return false;

        //    if (!(webData.Data is IGetWebImages))
        //        //throw new PBException($"{typeof(TData).zGetTypeName()} is not IGetWebImages");
        //        return false;
        //    IEnumerable<WebImage> images = ((IGetWebImages)webData.Data).GetWebImages();
        //    if (_imageFilter != null)
        //        images = images.Where(image => _imageFilter(image));
        //    string subDirectory = null;
        //    if (_getImageSubDirectory != null)
        //        subDirectory = _getImageSubDirectory(webData);
        //    return _webImageCacheManager.LoadImagesFromWeb(images, imageRequest, subDirectory);
        //}

        public bool LoadImagesFromWeb(WebImageRequest imageRequest, IEnumerable <WebImage> images, string subDirectory = null)
        {
            if (!imageRequest.LoadImageFromWeb && !imageRequest.LoadImageToData && !imageRequest.RefreshImage)
            {
                return(false);
            }
            if (_imageFilter != null)
            {
                images = images.Where(image => _imageFilter(image));
            }
            //string subDirectory = null;
            //if (_getImageSubDirectory != null)
            //    subDirectory = _getImageSubDirectory(webData);
            return(_webImageCacheManager.LoadImagesFromWeb(images, imageRequest, subDirectory));
        }
        //public IEnumerable<TDetailData> LoadDetails(int startPage = 1, int maxPage = 1, bool reloadHeaderPage = false, bool reloadDetail = false,
        //    bool loadImageFromWeb = false, bool loadImageToData = false, bool refreshImage = false,
        //    bool refreshDocumentStore = false)
        public IEnumerable <TDetailData> LoadDetails(int startPage = 1, int maxPage = 1, bool reloadHeaderPage = false, bool reloadDetail = false, bool refreshDocumentStore = false,
                                                     WebImageRequest imageRequest = null)
        {
            Trace.WriteLine("WebHeaderDetailManager_v4<>.LoadDetails()");

            foreach (THeaderData header in _headerDataPageManager.LoadPages(startPage, maxPage, reloadHeaderPage, false))
            {
                //if (!(header is IHeaderData))
                //    throw new PBException("type {0} is not IHeaderData", header.GetType().zGetTypeName());
                //yield return _detailDataManager.Load(
                //    new WebRequest { HttpRequest = ((IHeaderData)header).GetHttpRequestDetail(), ReloadFromWeb = reloadDetail, ImageRequest = new WebImageRequest { LoadImageFromWeb = loadImageFromWeb, LoadImageToData = loadImageToData, RefreshImage = refreshImage }, RefreshDocumentStore = refreshDocumentStore }).Data;
                yield return(_detailDataManager.Load(new WebRequest_v2 <THeaderData> {
                    Data = header, ReloadFromWeb = reloadDetail, RefreshDocumentStore = refreshDocumentStore, ImageRequest = imageRequest
                }).Data);
            }
        }
Beispiel #11
0
        public virtual bool LoadImagesFromWeb(IEnumerable <WebImage> images, WebImageRequest imageRequest, HttpRequestParameters requestParameters = null, string subDirectory = null)
        {
            if (!imageRequest.LoadImageFromWeb && !imageRequest.RefreshImage)
            {
                return(false);
            }
            bool ret = false;

            foreach (WebImage image in images)
            {
                if (LoadImageFromWeb(image, imageRequest, requestParameters, subDirectory))
                {
                    ret = true;
                }
            }
            return(ret);
        }
        // HttpRequestParameters requestParameters = null
        protected bool LoadImageFromWeb(WebImage webImage, WebImageRequest imageRequest, string subDirectory = null)
        {
            if (!imageRequest.LoadImageFromWeb || (webImage.File != null && !imageRequest.RefreshImage))
                return false;
            HttpRequest httpRequest = new HttpRequest { Url = webImage.Url, ReloadFromWeb = imageRequest.RefreshImage };

            //string file = _urlCache.GetUrlSubPath(httpRequest);
            //if (subDirectory != null)
            //    file = zPath.Combine(subDirectory, file);
            //string path = zPath.Combine(_urlCache.CacheDirectory, file);

            //if (imageRequest.RefreshImage || !zFile.Exists(path))
            //    HttpManager.CurrentHttpManager.LoadToFile(httpRequest, path, _urlCache.SaveRequest, requestParameters);
            //webImage.File = file;

            //UrlCachePathResult urlCachePath = LoadHttpToCache(httpRequest, subDirectory);
            //webImage.File = urlCachePath.SubPath;
            //string path = urlCachePath.Path;

            //if (zFile.Exists(path))
            //{
            //    Image image = LoadImageFromFile(path);
            //    if (image != null)
            //    {
            //        webImage.Width = image.Width;
            //        webImage.Height = image.Height;
            //        if (imageRequest.LoadImageToData)
            //            webImage.Image = image;
            //    }
            //}

            HttpResult<Image> httpResult = LoadImage(httpRequest, subDirectory);
            if (httpResult.Success)
            {
                Image image = httpResult.Data;
                webImage.File = httpResult.Http.HttpRequest.UrlCachePath?.SubPath;
                webImage.Width = image.Width;
                webImage.Height = image.Height;
                if (imageRequest.LoadImageToData)
                    webImage.Image = image;
                return true;
            }
            else
                return false;
        }
Beispiel #13
0
        // HttpRequestParameters requestParameters = null
        public virtual bool LoadImagesFromWeb(IEnumerable <WebImage> images, WebImageRequest imageRequest, string subDirectory = null)
        {
            if ((!imageRequest.LoadImageFromWeb && !imageRequest.RefreshImage) || images == null)
            {
                return(false);
            }
            bool ret = false;

            foreach (WebImage image in images)
            {
                if (image.Url != null)
                {
                    if (LoadImageFromWeb(image, imageRequest, subDirectory))
                    {
                        ret = true;
                    }
                }
            }
            return(ret);
        }
Beispiel #14
0
        protected bool LoadImageFromWeb(WebImage webImage, WebImageRequest imageRequest, HttpRequestParameters requestParameters = null, string subDirectory = null)
        {
            if (!imageRequest.LoadImageFromWeb || (webImage.File != null && !imageRequest.RefreshImage))
            {
                return(false);
            }
            HttpRequest httpRequest = new HttpRequest {
                Url = webImage.Url
            };
            string file = _urlCache.GetUrlSubPath(httpRequest);

            if (subDirectory != null)
            {
                file = zPath.Combine(subDirectory, file);
            }
            string path = zPath.Combine(_urlCache.CacheDirectory, file);

            if (imageRequest.RefreshImage || !zFile.Exists(path))
            {
                HttpManager.CurrentHttpManager.LoadToFile(httpRequest, path, _urlCache.SaveRequest, requestParameters);
            }
            webImage.File = file;

            if (zFile.Exists(path))
            {
                Image image = LoadImageFromFile(path);
                if (image != null)
                {
                    webImage.Width  = image.Width;
                    webImage.Height = image.Height;
                    if (imageRequest.LoadImageToData)
                    {
                        webImage.Image = image;
                    }
                }
            }
            return(true);
        }
Beispiel #15
0
        public IEnumerable <TData> LoadPages(HttpRequest httpRequest, int maxPage = 1, bool reload = false, bool loadImageFromWeb = false, bool loadImageToData = false, bool refreshImage = false, bool refreshDocumentStore = false)
        {
            WebImageRequest imageRequest = new WebImageRequest {
                LoadImageFromWeb = loadImageFromWeb, LoadImageToData = loadImageToData, RefreshImage = refreshImage
            };
            IEnumDataPages <TData> dataPage = Load(new WebRequest {
                HttpRequest = httpRequest, ReloadFromWeb = reload, ImageRequest = imageRequest, RefreshDocumentStore = refreshDocumentStore
            }).Data;

            if (dataPage == null)
            {
                yield break;
            }

            // return data from page 1
            foreach (TData data in dataPage.GetDataList())
            {
                yield return(data);
            }

            // return data from page 2, ...
            for (int nbPage = 1; maxPage == 0 || nbPage < maxPage; nbPage++)
            {
                httpRequest = dataPage.GetHttpRequestNextPage();
                if (httpRequest == null)
                {
                    break;
                }
                dataPage = Load(new WebRequest {
                    HttpRequest = httpRequest, ReloadFromWeb = reload, ImageRequest = imageRequest, RefreshDocumentStore = refreshDocumentStore
                }).Data;
                foreach (TData data in dataPage.GetDataList())
                {
                    yield return(data);
                }
            }
        }
 // maxPage = 0 : all pages
 public LoadNewDocumentsResult LoadNewDocuments(HttpRequest httpRequest, int maxDocumentsLoadedFromStore = 5, int maxDocumentsLoaded = 0, int maxPage = 20, WebImageRequest webImageRequest = null)
 {
     return(_LoadNewDocuments(_headerDataPageManager.LoadPages(httpRequest, maxPage, reload: true), maxDocumentsLoadedFromStore, maxDocumentsLoaded, webImageRequest));
 }
Beispiel #17
0
 // maxPage = 0 : all pages
 //
 //public LoadNewDocumentsResult LoadNewDocuments(int maxDocumentsLoadedFromStore = 5, int maxDocumentsLoaded = 0, int startPage = 1, int maxPage = 20, bool loadImageFromWeb = true)
 public LoadNewDocumentsResult LoadNewDocuments(int maxDocumentsLoadedFromStore = 5, int maxDocumentsLoaded = 0, int startPage = 1, int maxPage = 20, WebImageRequest webImageRequest = null)
 {
     // loadImage: false
     return(_LoadNewDocuments(_headerDataPageManager.LoadPages(startPage, maxPage, reload: true), maxDocumentsLoadedFromStore, maxDocumentsLoaded, webImageRequest));
 }
 //public IEnumerable<HeaderDetail<THeaderData, TDetailData>> LoadHeaderDetails(int startPage = 1, int maxPage = 1, bool reloadHeaderPage = false, bool reloadDetail = false,
 //    bool loadImageFromWeb = false, bool loadImageToData = false, bool refreshImage = false,
 //    bool refreshDocumentStore = false)
 public IEnumerable <HeaderDetail <THeaderData, TDetailData> > LoadHeaderDetails(int startPage = 1, int maxPage = 1, bool reloadHeaderPage = false, bool reloadDetail = false, bool refreshDocumentStore = false,
                                                                                 WebImageRequest imageRequest = null)
 {
     foreach (THeaderData header in _headerDataPageManager.LoadPages(startPage, maxPage, reloadHeaderPage, loadImageFromWeb: false, refreshDocumentStore: refreshDocumentStore))
     {
         //if (!(header is IHeaderData))
         //    throw new PBException($"type {header.GetType().zGetTypeName()} is not IHeaderData");
         //TDetailData detail = _detailDataManager.Load(new WebRequest { HttpRequest = ((IHeaderData)header).GetHttpRequestDetail(), ReloadFromWeb = reloadDetail, ImageRequest = new WebImageRequest { LoadImageFromWeb = loadImageFromWeb, LoadImageToData = loadImageToData, RefreshImage = refreshImage }, RefreshDocumentStore = refreshDocumentStore }).Data;
         TDetailData detail = _detailDataManager.Load(new WebRequest_v2 <THeaderData> {
             Data = header, ReloadFromWeb = reloadDetail, RefreshDocumentStore = refreshDocumentStore, ImageRequest = imageRequest
         }).Data;
         yield return(new HeaderDetail <THeaderData, TDetailData> {
             Header = header, Detail = detail
         });
     }
 }