Esempio n. 1
0
        public static WebData <TData> Load_v1(WebDataManager <TData> webDataManager, WebRequest request)
        {
            WebData <TData> webData = new WebData <TData>(webDataManager, request);

            webData.Load_v1();
            return(webData);
        }
Esempio n. 2
0
        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));
            //}
        }
Esempio n. 3
0
 public void SaveWithKey(WebData <TData> webData)
 {
     if (_documentStore != null && !_desactivateDocumentStore)
     {
         _documentStore.SaveWithKey(webData.Data.zGetKey_v2(), webData.Data);
     }
 }
Esempio n. 4
0
 public void SaveWithId(BsonValue id, WebData <TData> webData)
 {
     if (_documentStore != null && !_desactivateDocumentStore)
     {
         _documentStore.SaveWithId(id, webData.Data);
     }
 }
Esempio n. 5
0
 public WebData <TData> Load(WebRequest request)
 {
     //if (_version == 1)
     //    return Load_v1(request);
     //else if (_version == 2)
     //    return WebData<TData>.Load(this, request);
     //else // if (_version == 3)
     //    return WebData<TData>.Load_v2(this, request);
     return(WebData <TData> .Load_v2(this, request));
 }
Esempio n. 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
            });
        }
    }
Esempio n. 7
0
 protected BsonValue GetId(WebData <TData> webData)
 {
     if (_documentStore != null && !_desactivateDocumentStore)
     {
         BsonValue key = _GetKeyFromHttpRequest(webData.Request.HttpRequest);
         return(_documentStore.GetId(key));
     }
     else
     {
         return(null);
     }
 }
Esempio n. 8
0
 protected void _LoadFromWeb(WebData <TData> webData)
 {
     if (!webData.DataLoaded)
     {
         //loadWebData.Document = _webLoadDataManager.LoadData(loadWebData.Request);
         WebDataResult <TData> webDataResult = _webLoadDataManager.LoadData(webData.Request);
         webData.Result            = webDataResult.Result;
         webData.Data              = webDataResult.Data;
         webData.DataLoaded        = true;
         webData.DataLoadedFromWeb = true;
     }
 }
Esempio n. 9
0
 protected bool Exists(WebData <TData> webData)
 {
     if (_documentStore != null && !_desactivateDocumentStore)
     {
         BsonValue key = _GetKeyFromHttpRequest(webData.Request.HttpRequest);
         return(_documentStore.Exists(key));
     }
     else
     {
         return(false);
     }
 }
Esempio n. 10
0
        //[Obsolete]
        //public Action<TData> LoadImages { get { return _loadImages; } set { _loadImages = value; } }

        //public WebDataManager()
        //{
        //    InitSerializer();
        //}

        public WebData <TData> Load(WebRequest request)
        {
            if (_version == 1)
            {
                return(Load_v1(request));
            }
            else if (_version == 2)
            {
                return(WebData <TData> .Load_v1(this, request));
            }
            //else // if (_version == 3)
            //    return WebData<TData>.Load_v2(this, request);
            throw new PBException($"bad version {_version}");
        }
Esempio n. 11
0
        public WebData <TData> LoadFromWeb(WebRequest request)
        {
            WebData <TData> webData = new WebData <TData>(request);

            _LoadFromWeb(webData);
            if (_imageLoadVersion == 1)
            {
                LoadImages_v1(webData.Data, request.ImageRequest);
            }
            else
            {
                LoadImagesFromWeb(webData);
                LoadImagesToData(webData.Data);
            }
            return(webData);
        }
Esempio n. 12
0
        protected void _Load(WebData <TData> webData)
        {
            if (_documentStore != null && !_desactivateDocumentStore)
            {
                if (!webData.DataLoaded)
                {
                    BsonValue key = _GetKeyFromHttpRequest(webData.Request.HttpRequest);
                    webData.Data = _documentStore.LoadFromKey(key);

                    //LoadImages(webData);
                    if (webData.Request.ImageRequest.LoadImageToData)
                    {
                        //if (_imageLoadVersion == 1)
                        if (_webLoadImageManager == null)
                        {
                            //LoadImages_v1(webData.Document, webData.Request.ImageRequest);
                            WebLoadImageManager_v1.LoadImages(webData.Data, webData.Request.ImageRequest);
                        }
                        else
                        {
                            //LoadImagesToData(webData.Document);
                            _webLoadImageManager.LoadImagesToData(webData.Data);
                        }
                    }

                    //if (webData.Request.LoadImageFromWeb || webData.Request.LoadImageToData || webData.Request.RefreshImage)
                    //    LoadImages(webData.Document, WebImageRequest.FromWebRequest(webData.Request));

                    //    if (!(webData.Document is ILoadImages))
                    //        throw new PBException($"{typeof(TData).zGetTypeName()} is not ILoadImages");
                    //    ((ILoadImages)webData.Document).LoadImages(ImageRequest.FromWebRequest(webData.Request));
                    webData.DataLoaded          = true;
                    webData.DataLoadedFromStore = true;
                }
            }
            else
            {
                _LoadFromWeb(webData);
            }
        }
Esempio n. 13
0
        public WebData <TData> LoadFromWeb(WebRequest request)
        {
            WebData <TData> webData = new WebData <TData>(request);

            _LoadFromWeb(webData);
            //if (_imageLoadVersion == 1)
            if (_webLoadImageManager == null)
            {
                //LoadImages_v1(webData.Document, webData.Request.ImageRequest);
                WebLoadImageManager_v1.LoadImages(webData.Data, webData.Request.ImageRequest);
            }
            else
            {
                //_webLoadImageManager.LoadImagesFromWeb(webData);
                if (webData.Data is IGetWebImages)
                {
                    _webLoadImageManager.LoadImagesFromWeb(request.ImageRequest, ((IGetWebImages)webData.Data).GetWebImages(), _getImageSubDirectory?.Invoke(webData));
                }
                _webLoadImageManager.LoadImagesToData(webData.Data);
            }
            return(webData);
        }
Esempio n. 14
0
        public WebData <TData> Load_v1(WebRequest request)
        {
            WebData <TData> webData = new WebData <TData>(request);

            if (_documentStore != null && _documentStore.GenerateId)
            {
                BsonValue id = GetId(webData);
                if (request.ReloadFromWeb || request.RefreshDocumentStore || id == null)
                {
                    _LoadFromWeb(webData);
                    if (id == null)
                    {
                        id = _documentStore.GetNewId();
                    }
                    SetDataId(webData, id);
                    SaveWithId(id, webData);
                    //if (_imageLoadVersion == 1)
                    if (_webLoadImageManager == null)
                    {
                        //LoadImages_v1(webData.Document, request.ImageRequest);
                        WebLoadImageManager_v1.LoadImages(webData.Data, request.ImageRequest);
                    }
                    else
                    {
                        //if (_webLoadImageManager.LoadImagesFromWeb(webData))
                        if (webData.Data is IGetWebImages && _webLoadImageManager.LoadImagesFromWeb(request.ImageRequest, ((IGetWebImages)webData.Data).GetWebImages(), _getImageSubDirectory?.Invoke(webData)))
                        {
                            SaveWithId(id, webData);
                        }
                    }
                }
            }
            //else
            //{
            //    // todo : remplacer Exists() par GetKey() puis Exists(key)
            //    if (request.ReloadFromWeb || request.RefreshDocumentStore || !Exists(webData))
            //    {
            //        _LoadFromWeb(webData);
            //        SaveWithKey(webData);
            //        if (_imageLoadVersion == 1)
            //            LoadImages_v1(webData.Document, webData.Request.ImageRequest);
            //        else
            //        {
            //            if (LoadImagesFromWeb(webData))
            //                SaveWithKey(webData);
            //        }
            //    }
            //}
            else if (request.ReloadFromWeb || request.RefreshDocumentStore || !Exists(webData))
            {
                // todo : remplacer Exists() par GetKey() puis Exists(key)
                _LoadFromWeb(webData);
                SaveWithKey(webData);
                //if (_imageLoadVersion == 1)
                if (_webLoadImageManager == null)
                {
                    //LoadImages_v1(webData.Document, webData.Request.ImageRequest);
                    WebLoadImageManager_v1.LoadImages(webData.Data, webData.Request.ImageRequest);
                }
                else
                {
                    //if (_webLoadImageManager.LoadImagesFromWeb(webData))
                    if (webData.Data is IGetWebImages && _webLoadImageManager.LoadImagesFromWeb(request.ImageRequest, ((IGetWebImages)webData.Data).GetWebImages(), _getImageSubDirectory?.Invoke(webData)))
                    {
                        SaveWithKey(webData);
                    }
                }
            }

            _Load(webData);
            return(webData);
        }
Esempio n. 15
0
 protected void SetDataId(WebData <TData> webData, BsonValue id)
 {
     webData.Data.zSetId(id);
 }
Esempio n. 16
0
        //[Obsolete]
        //public Action<TData> LoadImages { get { return _loadImages; } set { _loadImages = value; } }

        public WebData <TData> Load(WebRequest request)
        {
            WebData <TData> webData    = new WebData <TData>(request);
            BsonValue       id         = null;
            bool            dataExists = false;

            if (_documentStore != null && !_desactivateDocumentStore)
            {
                BsonValue key = _GetKeyFromHttpRequest(request.HttpRequest);
                if (_documentStore.GenerateId)
                {
                    //id = GetId(webData);
                    id = _documentStore.GetId(key);
                    if (id != null)
                    {
                        dataExists = true;
                    }
                }
                else
                {
                    //dataExists = Exists(webData);
                    dataExists = _documentStore.Exists(key);
                }
                if (!dataExists || request.ReloadFromWeb || request.RefreshDocumentStore)
                {
                    _LoadFromWeb(webData);
                }
                if (_documentStore.GenerateId)
                {
                    if (id == null)
                    {
                        id = _documentStore.GetNewId();
                    }
                    SetDataId(webData, id);
                    SaveWithId(id, webData);
                }
                else
                {
                    //SaveWithKey(webData);
                    _documentStore.SaveWithKey(key, webData.Data);
                }
            }

            if (_documentStore != null && _documentStore.GenerateId)
            {
                id = GetId(webData);
                if (request.ReloadFromWeb || request.RefreshDocumentStore || id == null)
                {
                    _LoadFromWeb(webData);
                    if (id == null)
                    {
                        id = _documentStore.GetNewId();
                    }
                    SetDataId(webData, id);
                    SaveWithId(id, webData);
                    if (_imageLoadVersion == 1)
                    {
                        LoadImages_v1(webData.Data, request.ImageRequest);
                    }
                    else
                    {
                        if (LoadImagesFromWeb(webData))
                        {
                            SaveWithId(id, webData);
                        }
                    }
                }
            }
            else if (request.ReloadFromWeb || request.RefreshDocumentStore || !Exists(webData))
            {
                // todo : remplacer Exists() par GetKey() puis Exists(key)
                _LoadFromWeb(webData);
                SaveWithKey(webData);
                if (_imageLoadVersion == 1)
                {
                    LoadImages_v1(webData.Data, request.ImageRequest);
                }
                else
                {
                    if (LoadImagesFromWeb(webData))
                    {
                        SaveWithKey(webData);
                    }
                }
            }

            _Load(webData);
            return(webData);
        }
Esempio n. 17
0
 protected void SetDataId(WebData <TData> webData, BsonValue id)
 {
     // call IIdData.SetId()
     webData.Data.zSetId(id);
 }
Esempio n. 18
0
        public WebData <TData> Load_v1(WebRequest request)
        {
            WebData <TData> webData = new WebData <TData>(request);

            if (_documentStore != null && _documentStore.GenerateId)
            {
                BsonValue id = GetId(webData);
                if (request.ReloadFromWeb || request.RefreshDocumentStore || id == null)
                {
                    _LoadFromWeb(webData);
                    if (id == null)
                    {
                        id = _documentStore.GetNewId();
                    }
                    SetDataId(webData, id);
                    SaveWithId(id, webData);
                    if (_imageLoadVersion == 1)
                    {
                        LoadImages_v1(webData.Data, request.ImageRequest);
                    }
                    else
                    {
                        if (LoadImagesFromWeb(webData))
                        {
                            SaveWithId(id, webData);
                        }
                    }
                }
            }
            //else
            //{
            //    // todo : remplacer Exists() par GetKey() puis Exists(key)
            //    if (request.ReloadFromWeb || request.RefreshDocumentStore || !Exists(webData))
            //    {
            //        _LoadFromWeb(webData);
            //        SaveWithKey(webData);
            //        if (_imageLoadVersion == 1)
            //            LoadImages_v1(webData.Document, request.ImageRequest);
            //        else
            //        {
            //            if (LoadImagesFromWeb(webData))
            //                SaveWithKey(webData);
            //        }
            //    }
            //}
            else if (request.ReloadFromWeb || request.RefreshDocumentStore || !Exists(webData))
            {
                // todo : remplacer Exists() par GetKey() puis Exists(key)
                _LoadFromWeb(webData);
                SaveWithKey(webData);
                if (_imageLoadVersion == 1)
                {
                    LoadImages_v1(webData.Data, request.ImageRequest);
                }
                else
                {
                    if (LoadImagesFromWeb(webData))
                    {
                        SaveWithKey(webData);
                    }
                }
            }

            _Load(webData);
            return(webData);
        }