Esempio n. 1
0
        public void SaveImageThumbnail(Material material, Imager imager)
        {
            if (_infrastructure.StorageService == null)
            {
                throw new CustomArgumentException("FileStorage Service is not presented!");
            }

            if (material == null || material.File == null)
            {
                throw new CustomArgumentException("Can't save Thumbnail for empty Material!");
            }

            if (imager == null)
            {
                throw new CustomArgumentException("Invalid Imager provided!");
            }

            // get path for thumbnail file
            var thumbnailPath = _infrastructure.GetThumbnailPath(material);

            // thumbnail byte array
            byte[] thumbnailData = this.CreateImageThumbnail(imager);

            _infrastructure.StorageService.SaveFile(thumbnailPath, thumbnailData);
        }
        protected void MoveMaterialToFolder(Material material, string folder)
        {
            // material should be specified
            if (material == null || material.File == null)
            {
                return;
            }

            // storage should be presented
            var storage = _infrastructure.StorageService;

            if (storage == null)
            {
                return;
            }

            // define source paths
            var materialSourcePath  = _infrastructure.GetMaterialPath(material);
            var thumbnailSourcePath = _infrastructure.GetThumbnailPath(material);

            // folder path to move
            var moveToFolder = String.IsNullOrWhiteSpace(folder) ? _infrastructure.FolderEmpty : (folder.EndsWith("/") ? folder : folder + "/");

            // changing entity folder value
            material.File.ChangeFolder(moveToFolder);

            // destination file path
            var materialDestPath  = _infrastructure.GetMaterialPath(material);
            var thumbnailDestPath = _infrastructure.GetThumbnailPath(material);

            // moving blob to new location
            if (storage.Exist(materialSourcePath))
            {
                storage.CopyFile(materialSourcePath, materialDestPath, true);
            }

            // moving thumbnail to new location
            if (storage.Exist(thumbnailSourcePath))
            {
                storage.CopyFile(thumbnailSourcePath, thumbnailDestPath, true);
            }
        }