Example #1
0
        private string ZipperExtractFileToPath(string destRootPath, System.IO.Compression.ZipArchiveEntry item)
        {
            var destFilename = CleanFilenameString(System.IO.Path.Combine(destRootPath, item.Name));

            FileStorageHelper.DeleteFile(destFilename);
            FileStorageHelper.CreateDirectory(System.IO.Path.GetDirectoryName(destFilename));
            //
            var count = 5;

            do
            {
                try
                {
                    item.ExtractToFile(destFilename, true);
                    if (System.IO.File.Exists(destFilename))
                    {
                        var fileInfo = new System.IO.FileInfo(destFilename);
                        fileInfo.LastWriteTime = DateTime.Now;
                    }
                    break;
                }
                catch
                {
                    if (--count <= 0)
                    {
                        throw;
                    }
                    Threading.ThreadingHelper.Sleep(200);
                }
            } while (true);
            //
            return(destFilename);
        }
        public ResponseModel <Product> Delete([FromForm] Product product)
        {
            ResponseModel <Product> productResult = new ResponseModel <Product>();

            try
            {
                productResult = _productManager.Delete(product);
                var photo         = photoManager.GetByProductId(productResult.result.ProductID);
                var photoResult   = FileStorageHelper.DeleteFile(Path.Combine(Environment.CurrentDirectory, "wwwroot", photo.result.PhotoUrl));
                var photoDBResult = photoManager.Delete(new Photo
                {
                    PhotoID   = photo.result.PhotoID,
                    PhotoUrl  = photo.result.PhotoUrl,
                    ProductID = photo.result.ProductID,
                    isMain    = photo.result.isMain
                });
                return(productResult);
            }
            catch (Exception ex)
            {
                productResult.Success = false;
                productResult.Message = ex.Message;
            }
            return(productResult);
        }
Example #3
0
 private void InitializeStore()
 {
     // clean self
     ((dodSON.Core.FileStorage.IFileStoreAdvanced) this).ResetLists();
     // only initialize if the back end store exists.
     if (System.IO.File.Exists(BackendStorageZipFilename))
     {
         // iterate all files, in all subdirectories, in the zip file
         using (var zipper = CreateZipper(System.IO.Compression.ZipArchiveMode.Read))
         {
             // process all files
             foreach (var zipItem in zipper.Entries)
             {
                 var filename = CleanFilenameString(zipItem.FullName);
                 // do not process non-files
                 if (!filename.EndsWith(@"\"))
                 {
                     // do not process the (ORIGINAL FILENAMES) file
                     if (!filename.Equals(_OriginalFilenames_Filename, StringComparison.InvariantCultureIgnoreCase))
                     {
                         // create new store item/add to self
                         var newItem = this.Add(filename, "", zipItem.LastWriteTime.UtcDateTime, zipItem.Length);
                         // clear all state flags
                         ((dodSON.Core.FileStorage.IFileStoreItemAdvanced)newItem).StateChangeTracker.ClearAll();
                         // set compressed size and uncompressed size
                         ((dodSON.Core.FileStorage.ICompressedFileStoreItemAdvanced)newItem).SetCompressionValues(zipItem.CompressedLength);
                     }
                     else
                     {
                         // load original filenames file.
                         // extract to temp file
                         var tempFilename = System.IO.Path.Combine(System.IO.Path.GetTempPath(), Guid.NewGuid().ToString());
                         try
                         {
                             zipItem.ExtractToFile(tempFilename, true);
                             // read temp file
                             using (var sr = new System.IO.StreamReader(tempFilename))
                             {
                                 // read file and convert
                                 var originalFilenames = StringToOriginalFilenames(sr.ReadToEnd());
                                 // set all original filenames
                                 ((dodSON.Core.FileStorage.IFileStoreAdvanced) this).SetOriginalFilenames(originalFilenames);
                             }
                         }
                         catch { }
                         finally
                         {
                             // delete temp file
                             FileStorageHelper.DeleteFile(tempFilename);
                         }
                     }
                 }
             }
         }
     }
 }
Example #4
0
 /// <summary>
 /// Will finalize the adding, updating and removing of files from the .zip file.
 /// </summary>
 /// <param name="state">A reference to an initialized System.IO.Compression.ZipArchive object. This reference, created in the <see cref="Save_Startup(out object)"/> will be destroyed and set to null in this method.</param>
 protected override void Save_Shutdown(ref object state)
 {
     try
     {
         // save state (zipper)
         if (state != null)
         {
             if (this.Count == 0)
             {
                 // #### no files left; delete back end storage
                 // dispose of zipper --> closes and commits the zip file
                 DisposeOfZipper(ref state);
                 FileStorageHelper.DeleteFile(BackendStorageZipFilename);
             }
             else
             {
                 if (_BackendChanged)
                 {
                     // #### back end has changed; save zip and update compression information
                     // dispose of zipper --> closes and commits the zip file
                     DisposeOfZipper(ref state);
                     // create a NEW zipper
                     // use a stand-in variable for the lambda expression
                     System.IO.Compression.ZipArchive zipState = CreateZipper(System.IO.Compression.ZipArchiveMode.Read);
                     // set the 'ref' object to the NEW zipper
                     state = zipState;
                     // **** update all compression information
                     ForEach(item =>
                     {
                         // reinitialize all compressed/uncompressed values
                         var found = zipState.Entries.FirstOrDefault((zf) => { return(CleanFilenameString(zf.FullName).Equals(item.RootFilename, StringComparison.InvariantCultureIgnoreCase)); });
                         if (found != null)
                         {
                             ((dodSON.Core.FileStorage.ICompressedFileStoreItemAdvanced)item).SetCompressionValues(found.CompressedLength);
                             ((dodSON.Core.FileStorage.ICompressedFileStoreItemAdvanced)item).SetCompressionStrategy(NormalizeCompressionStrategy(found));
                         }
                         else
                         {
                             ((dodSON.Core.FileStorage.ICompressedFileStoreItemAdvanced)item).SetCompressionValues(0);
                             ((dodSON.Core.FileStorage.ICompressedFileStoreItemAdvanced)item).SetCompressionStrategy(CompressionStorageStrategy.Store);
                         }
                     });
                     // **** clear the lambda stand-in variable
                     zipState        = null;
                     _BackendChanged = false;
                 }
             }
         }
     }
     finally
     {
         // #### fail-safe
         DisposeOfZipper(ref state);
     }
 }
Example #5
0
        public IResult Delete(CarImage carImage)
        {
            var result = FileStorageHelper.DeleteFile(_carImageDal.Get(i => i.CarImageId == carImage.CarImageId).ImagePath);

            if (!result.Success)
            {
                return(new ErrorResult("Image file remove failed!"));
            }

            _carImageDal.Delete(carImage);
            return(new SuccessResult(Messages.EntityDeleted));
        }
        //public ResponseModel<Photo> Update(Photo entity,IFormFile file)
        //{
        //    try
        //    {
        //        responseModel.result = entity;
        //        _logger.Log(LogLevel.Information, "Fotoğraf güncellendi");
        //        var result = FileStorageHelper.UpdateFile(file,entity.PhotoUrl);
        //        entity.PhotoUrl = result.Message;
        //        responseModel.Success = _photoDAL.Update(entity);
        //        return responseModel;
        //    }
        //    catch (Exception ex)
        //    {

        //        _logger.LogError(ex, ex.Message + "Fotoğraf güncelleme hatası");
        //        responseModel.Success = false;
        //        responseModel.Message = ex.Message;
        //        return responseModel;
        //    }
        //}


        public ResponseModel <Photo> Delete(Photo entity)
        {
            try
            {
                responseModel.Success = _photoDAL.Delete(entity);
                if (responseModel.Success)
                {
                    FileStorageHelper.DeleteFile(entity.PhotoUrl);
                    return(responseModel);
                }
                return(responseModel);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message + "Fotoğraf silme hatası");
                responseModel.Success = false;
                responseModel.Message = ex.Message;
                return(responseModel);
            }
        }
 public bool Delete(Guid id, string filename)
 {
     return(fileStorageHelper.DeleteFile(configuration.Share, configuration.Folder, GetFullFilename(id, filename)));
 }
 public bool Delete(string fileName)
 {
     return(fileStorageHelper.DeleteFile(configuration.Share, configuration.Folder, fileName));
 }