コード例 #1
0
        private void SynchronizeWithServiceDB()
        {
            try
            {
                ImageDatabaseService imgDbService = new ImageDatabaseService();
                ImageService         imgService   = new ImageService();

                imgService.SynchronizeWithServiceDB();

                List <ImageModel> serviceImages = imgDbService.GetAllImages().Where(img => !img.IsProcessed).ToList();

                foreach (ImageModel img in serviceImages)
                {
                    ImageHelperService.SaveImageToDisk(img);
                }

                List <ImageModel> inconsistentImages = imgDbService.GetAllImages().Where(img => string.IsNullOrEmpty(img.ImagePath)).ToList();
                foreach (ImageModel image in inconsistentImages)
                {
                    imgDbService.DeleteImageFromDatabase(image);
                }
            }
            catch (Exception)
            {
                return;
            }
        }
コード例 #2
0
ファイル: ImageModel.cs プロジェクト: valsinats94/Legacy
        private void GetImageData(string imagePath)
        {
            if (string.IsNullOrEmpty(imagePath))
            {
                return;
            }

            if (!File.Exists(imagePath))
            {
                DeleteImageFromDB(this);
                return;
            }

            if (!ImageHelperService.IsImageFile(imagePath))
            {
                throw new FileNotAnImageException();
            }

            ImageData = File.ReadAllBytes(imagePath);
        }
コード例 #3
0
        public async Task <UploadProductImageResponse> UploadImageDb(UploadProductImageRequest request)
        {
            bool probablyBase64String = _validator.IsBase64String(request.Base64str);

            if (probablyBase64String)
            {
                string path = ImageHelperService.SaveImage(request);
                if (path.Length > 5)
                {
                    var media = await _repository.UploadProductImageAsync(request, path);

                    if (media != null)
                    {
                        return(new UploadProductImageResponse(true, media.Path));
                    }
                    return(new UploadProductImageResponse(false, "något gått fel med att spara imagePath till databasen"));
                }
                return(new UploadProductImageResponse(false, "något gått fel med att spara bilden"));
            }
            return(new UploadProductImageResponse(false, "skicka in en valid base64sträng"));
        }
コード例 #4
0
        private void SyncAsyncImages()
        {
            try
            {
                ImageDatabaseService imgDbService = new ImageDatabaseService();
                ImageService         imgService   = new ImageService();
                imgService.SynchronizeWithServiceDB();

                List <ImageModel> serviceImages = imgDbService.GetAllImages().Where(img => !img.IsProcessed).ToList();

                foreach (ImageModel img in serviceImages)
                {
                    img.ImagePath = ImageHelperService.SaveImageToDisk(img);
                    Images.Add(img);
                }
            }
            catch (Exception)
            {
                return;
            }
        }