示例#1
0
        public void Copy(string thisFileName, string copyToFileName, IFileStorageProvider targetProvider = null)
        {
            var sourceFso = GetFileSystemObject(thisFileName);
            var targetFso = GetFileSystemObject(copyToFileName);

            Copy(sourceFso, targetFso, targetProvider);
        }
示例#2
0
        public void Move(string thisFileName, string moveToFileName, IFileStorageProvider targetProvider = null)
        {
            var sourceFso = GetFileSystemObject(thisFileName);
            var targetFso = GetFileSystemObject(moveToFileName);

            Move(sourceFso, targetFso, targetProvider);
        }
        private void StoreGet(IFileStorageProvider provider,
                              FileSystemObject file,
                              FileSystemObject localFileSystemSourceFile = null,
                              byte[] sourceBytes = null)
        {
            // Pssshhhh Ahhhhh tssss Push it
            if (sourceBytes != null)
            {
                provider.Store(sourceBytes, file);
            }
            else if (localFileSystemSourceFile != null)
            {
                provider.Store(localFileSystemSourceFile, file);
                sourceBytes = File.ReadAllBytes(localFileSystemSourceFile.FullName);
            }
            else
            {
                throw new Exception("Must include either bytes or a local file reference to StoreGetDelete");
            }

            // Get it
            var getFile = provider.Get(file);

            var getFileHash = getFile.ToSha256HashBytes().ToBase64String();
            var fileHash    = sourceBytes.ToSha256HashBytes().ToBase64String();

            Assert.AreEqual(fileHash, getFileHash);
        }
示例#4
0
        public static long CopyFile(IFileStorageProviderDataProvider dataProvider, Guid oldPhysicalFileID, Guid newPhysicalFileID, string extensionName)
        {
            long result = 0;
            IFileStorageProvider oldProvider = FileStorageProviderFactory.CreateFileStorageProvider(dataProvider, oldPhysicalFileID, extensionName);
            IFileStorageProvider newProvider = FileStorageProviderFactory.CreateFileStorageProvider(dataProvider, CurrentConfigSetting, newPhysicalFileID, extensionName);

            if (oldProvider != null && newProvider != null)
            {
                try
                {
                    byte[] buffer = GetCacheBuffer(DefaultBufferSize);

                    int readLen = oldProvider.Read(buffer, 0, DefaultBufferSize);
                    while (readLen > 0)
                    {
                        newProvider.Write(buffer, 0, readLen);
                        readLen = oldProvider.Read(buffer, 0, DefaultBufferSize);
                    }
                    result = newProvider.Length;
                }
                finally
                {
                    oldProvider.Close();
                    newProvider.Close();
                }
            }
            return(result);
        }
示例#5
0
        public static long WriteFile(IFileStorageProviderDataProvider dataProvider, Guid physicalFileID, string extensionName, long position, byte[] writeData)
        {
            long result = 0;
            IFileStorageProvider provider = FileStorageProviderFactory.CreateFileStorageProvider(dataProvider, physicalFileID, extensionName);

            if (provider != null)
            {
                try
                {
                    int length = 0;
                    if (writeData != null)
                    {
                        length = writeData.Length;
                    }
                    if (length > 0)
                    {
                        provider.Seek(position, System.IO.SeekOrigin.Begin);
                        provider.Write(writeData, 0, length);
                        result = provider.Length;
                    }
                }
                finally
                {
                    provider.Close();
                }
            }
            return(result);
        }
示例#6
0
 public ChangesetUploader(IFileArchiveApi fileArchiveApi, IFileStorageProvider storageProvider, ILog logger = null)
 {
     _fileArchiveApi          = fileArchiveApi;
     _storageProvider         = storageProvider;
     _logger                  = logger;
     _minResumeUploadFileSize = MIN_RESUME_UPLOAD_FILE_SIZE;
 }
 public ComplexStringsController(IComplexStringService dataProvider, IMapper mapper, IFileStorageProvider provider, ICurrentUser currentUser)
 {
     this.dataProvider   = dataProvider;
     this.mapper         = mapper;
     fileStorageProvider = provider;
     _currentUser        = currentUser;
 }
示例#8
0
 public FileController(IFileStorageProvider fileStorageProvider, IConfigProvider configProvider,
                       FileUploadHelper fileUploadHelper)
 {
     _fileStorageProvider = fileStorageProvider;
     _configProvider      = configProvider;
     _fileUploadHelper    = fileUploadHelper;
 }
        private static async Task <string> GenerateThumbinal(IFileStorageProvider storageProvider, int width, int height, IImageFormat imageFormat, Image image)
        {
            string thumbinalPath = string.Empty;
            double ratio         = width * 1.0 / image.Width <= height * 1.0 / image.Height ?
                                   width * 1.0 / image.Width : height * 1.0 / image.Height;

            var encoder = image.GetConfiguration().ImageFormatsManager.FindEncoder(imageFormat);

            if (encoder is null)
            {
                var sb = new StringBuilder();
                sb.AppendLine($"No encoder was found for image format '{imageFormat.Name}'. Registered encoders include:");
                throw new NotSupportedException(sb.ToString());
            }

            using (MemoryStream ms = new MemoryStream())
            {
                image.Mutate(x => x
                             .Resize((int)(image.Width * ratio), (int)(image.Height * ratio)));

                image.Save(ms, encoder);
                thumbinalPath = await storageProvider.UploadFileAsync(ms.ToArray());
            }

            return(thumbinalPath);
        }
示例#10
0
        public static byte[] ReadFile(IFileStorageProviderDataProvider dataProvider, Guid physicalFileID, string extensionName, long position, int readCount)
        {
            LogHelper.Log.ErrorFormat("FileStorageManager.ReadFile(IFileStorageProviderDataProvider dataProvider='{0}', Guid physicalFileID='{1}', string extensionName='{2}', long position='{3}', int readCount='{4}')", dataProvider, physicalFileID, extensionName, position, readCount);

            byte[] result = null;
            IFileStorageProvider provider = FileStorageProviderFactory.CreateFileStorageProvider(dataProvider, physicalFileID, extensionName);

            if (provider != null)
            {
                try
                {
                    if (readCount > 0)
                    {
                        provider.Seek(position, System.IO.SeekOrigin.Begin);
                        byte[] buffer  = GetCacheBuffer(readCount);
                        int    readLen = provider.Read(buffer, 0, readCount);
                        if (readLen > 0)
                        {
                            result = new byte[readLen];
                            Buffer.BlockCopy(buffer, 0, result, 0, readLen);
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.Log.Error(ex.Message, ex);
                }
                finally
                {
                    provider.Close();
                }
            }
            LogHelper.Log.ErrorFormat("FileStorageManager.ReadFile Result Bytes Length='{0}'", result.Length);
            return(result);
        }
示例#11
0
 public DefaultController(ILogger <DefaultController> logger,
                          IServiceBusProvider serviceBusProvider,
                          IFileStorageProvider provider)
 {
     _logger             = logger;
     _serviceBusProvider = serviceBusProvider;
     _provider           = provider;
 }
示例#12
0
文件: Program.cs 项目: kl00t/Agidea
        private static void Setup()
        {
            IKernel kernel = new StandardKernel(new BindingModule());

            _messageQueue    = kernel.Get <IMessageQueue>();
            _emailRepository = kernel.Get <IEmailRepository>();
            _bucket          = kernel.Get <IFileStorageProvider>();
        }
示例#13
0
 public FileService(IFileRepository repository, IFileStorageProvider fileStorageProvider, IMimeRepository mimeRepository, IFileOwnerRepository ownerRepository, AdminDbContext dbContext)
 {
     _repository          = repository;
     _fileStorageProvider = fileStorageProvider;
     _mimeRepository      = mimeRepository;
     _ownerRepository     = ownerRepository;
     _dbContext           = dbContext;
 }
 public Task <string> GetThumbinal(IFileStorageProvider storageProvider,
                                   int width,
                                   int height,
                                   string format,
                                   byte[] imageData)
 {
     return(GenerateThumbinal(format));
 }
 public FileController(IFileStorageProvider fileStorageProvider, IFileMetaDataRepository metaDataRepository)
 {
     this.fileStorageProvider = fileStorageProvider;
     this.metaDataRepository = metaDataRepository;
     
     baseFileStoragePath = ConfigurationManager.AppSettings["BaseFileStoragePath"];
     logger = LogManager.GetLogger(GetType());
 }
 /// <summary>
 /// Registers a file storage provider.
 /// </summary>
 /// <param name="storageProvider">File storage provider, which should be registered.</param>
 public static void RegisterFileEnumerator(IFileStorageProvider storageProvider)
 {
     if (storageProvider == null)
     {
         return;
     }
     sFileStorageProviders.Add(storageProvider);
 }
        private bool TreatAsInMemoryProvider(IFileStorageProvider targetProvider)
        {
            if (targetProvider == null)
            {
                return(true);
            }

            return(targetProvider is InMemoryFileStorageProvider provider);
        }
示例#18
0
 public FileService(IOptions <BaseDataOptions> options,
                    ILogger <FileService> logger,
                    IFileStorageProvider fileStorageProvider,
                    IRepository <FileContent> fileRepository)
 {
     _options             = options.Value;
     _logger              = logger;
     _fileStorageProvider = fileStorageProvider;
     _fileRepository      = fileRepository;
 }
        private bool TreatAsLocalFileSystemProvider(IFileStorageProvider targetProvider)
        {
            if (targetProvider == null)
            {
                return true;
            }

            var provider = targetProvider as FileSystemStorageProvider;

            return provider != null;
        }
 public override void Copy(FileSystemObject thisFso, FileSystemObject targetFso, IFileStorageProvider targetProvider = null)
 {   // If targetProvider is null, copying within file system
     if (TreatAsLocalFileSystemProvider(targetProvider))
     {
         CopyInFileSystem(thisFso, targetFso);
         return;
     }
     
     // Copying across providers (from local file system to some other file provider)
     targetProvider.Store(thisFso, targetFso);
 }
        private bool TreatAsInMemoryProvider(IFileStorageProvider targetProvider)
        {
            if (targetProvider == null)
            {
                return(true);
            }

            var provider = targetProvider as InMemoryFileStorageProvider;

            return(provider != null);
        }
示例#22
0
        public async Task <byte[]> DownloadFileContentAsync(string fileFullName)
        {
            IFileStorageProvider provider = GetFileStorageProvider(fileFullName);

            if (provider == null)
            {
                throw new ArgumentException(nameof(provider) + " of the file storage service is null");
            }
            return(await provider
                   .DownloadFileAsync(fileFullName));
        }
示例#23
0
        private bool TreatAsS3Provider(IFileStorageProvider targetProvider)
        {
            if (targetProvider == null)
            {
                return(true);
            }

            var s3Provider = targetProvider as S3FileStorageProvider;

            return(s3Provider != null);
        }
示例#24
0
        private bool TreatAsLocalFileSystemProvider(IFileStorageProvider targetProvider)
        {
            if (targetProvider == null)
            {
                return(true);
            }

            var provider = targetProvider as FileSystemStorageProvider;

            return(provider != null);
        }
示例#25
0
 public void AddStorageProvider(IFileStorageProvider provider)
 {
     if (!storageProviders.ContainsKey(provider.GetType()))
     {
         storageProviders[provider.GetType()] = provider;
     }
     else
     {
         storageProviders.Add(provider.GetType(), provider);
     }
 }
示例#26
0
 public UserProfilesController(IUserService service, IRatingService ratingService, ITeamService teamService, IFileStorageProvider fileStorageProvider, IMapper mapper,
                               IRightService rightService, ICurrentUser currentUser)
 {
     this.service             = service;
     this.ratingService       = ratingService;
     this.teamService         = teamService;
     this.fileStorageProvider = fileStorageProvider;
     this.rightService        = rightService;
     _currentUser             = currentUser;
     this.mapper = mapper;
 }
        public async Task <string> GetThumbinal(IFileStorageProvider storageProvider, int width, int height, string format, Stream contentStream)
        {
            IImageFormat imageFormat   = null;
            string       thumbinalPath = string.Empty;

            using (Image image = Image.Load(contentStream, out imageFormat))
            {
                thumbinalPath = await GenerateThumbinal(storageProvider, width, height, imageFormat, image);
            }

            return(thumbinalPath);
        }
示例#28
0
 public CollectorAppsService(IUnitOfWork uow,
                             IMapper mapper,
                             IEmailProvider emailProvider,
                             IFileStorageProvider fileStorageProvider,
                             INotificationService notificationService)
 {
     _uow                 = uow;
     _mapper              = mapper;
     _emailProvider       = emailProvider;
     _fileStorageProvider = fileStorageProvider;
     _notificationService = notificationService;
 }
示例#29
0
        public Stream OpenFileContentStream(string fileFullName)
        {
            IFileStorageProvider provider = GetFileStorageProvider(fileFullName);

            if (provider == null)
            {
                throw new ArgumentException(nameof(provider) + " of the file storage service is null");
            }

            return(provider
                   .OpenFileStream(fileFullName));
        }
示例#30
0
 public NotificationService(IUnitOfWork uow,
                            IMapper mapper,
                            IHubContext <NotificationsHub> notificationsHub,
                            IEmailProvider emailProvider,
                            IFileStorageProvider fileStorageProvider)
 {
     _uow                 = uow;
     _mapper              = mapper;
     _notificationsHub    = notificationsHub;
     _emailProvider       = emailProvider;
     _fileStorageProvider = fileStorageProvider;
 }
示例#31
0
        public DefaultFileStorageService(IFileStorageProvider defaultProvider,
                                         ThumbinalConfig thumbinalConfig)
        {
            if (defaultProvider == null)
            {
                throw new ArgumentNullException(nameof(defaultProvider));
            }

            this.defaultProvider = defaultProvider;
            this.thumbinalConfig = thumbinalConfig;
            AddStorageProvider(defaultProvider);
            EnsureDBCreated();
        }
示例#32
0
 public Cabinet(IFileStorageProvider fileStorage, IFileProvider additionalFileProvider = null)
 {
     Storage = fileStorage;
     if (additionalFileProvider != null)
     {
         FileProvider = new CompositeFileProvider(fileStorage.FileProvider, additionalFileProvider);
     }
     else
     {
         FileProvider = fileStorage.FileProvider;
     }
     StorageInfo = new StorageInfo(Storage.FileProvider);
 }
示例#33
0
 public ComplexStringService(IMongoRepository <ComplexString> complexStringRepository, IMapper mapper, IUnitOfWork unitOfWork, IFileStorageProvider fileStorageProvider,
                             ICRUDService <UserProfile, UserProfileDTO> userService, ISignalRWorkspaceService signalRWorkspaceWorkspace, IElasticClient elasticClient,
                             TranslationTimerService timerService, ICurrentUser currentUser)
 {
     this._unitOfWork = unitOfWork;
     this._complexStringRepository = complexStringRepository;
     this._mapper = mapper;
     this._fileStorageProvider     = fileStorageProvider;
     this._userProfileService      = userService;
     this._signalRWorkspaceService = signalRWorkspaceWorkspace;
     this._elasticClient           = elasticClient;
     this._timerService            = timerService;
     _currentUser = currentUser;
 }
        private void CreateAndFillPathForTesting(string testSubFolder, IFileStorageProvider provider)
        {
            var testFolder = Path.Combine(baseFolderName, testSubFolder);

            provider.DeleteFolder(testFolder, recursive: true);

            // Put some files in each of the paths
            var subFolderList = new List<string>
                                {
                                    Path.Combine(testSubFolder, "nested-folder2a", "nested-folder3"),
                                    Path.Combine(testSubFolder, "nested-folder2a"),
                                    Path.Combine(testSubFolder, "nested-folder2b"),
                                    testSubFolder
                                };

            foreach (var subFolder in subFolderList)
            {
                for (var x = 1; x <= 3; x++)
                {
                    var file = GetTestFso(subFolder);
                    provider.Store(GetTestFileBytes(file.FullName), file);
                }
            }
        }
        public override void Copy(FileSystemObject thisFso, FileSystemObject targetFso, IFileStorageProvider targetProvider = null)
        {
            var bytes = Get(thisFso);

            if (bytes == null)
            {
                throw new FileNotFoundException("File does not exist in memory provider", thisFso.FullName);
            }

            if (TreatAsInMemoryProvider(targetProvider))
            {
                if (thisFso.Equals(targetFso))
                {
                    return;
                }

                Store(bytes, targetFso);
                return;
            }
            
            targetProvider.Store(bytes, targetFso);
        }
 public FileStorageManager(IFileStorageProvider fileStorageProvider)
 {
     Provider = fileStorageProvider;
 }
        public void Initialize()
        {
            storageProvider = new UfsFileStorageProvider();

            testStoragePath = ConfigurationManager.AppSettings["TestPathForWritingFiles"];
        }
        private bool TreatAsInMemoryProvider(IFileStorageProvider targetProvider)
        {
            if (targetProvider == null)
                return true;

            var provider = targetProvider as InMemoryFileStorageProvider;

            return provider != null;
        }
        public override void Move(FileSystemObject sourceFso, FileSystemObject targetFso, IFileStorageProvider targetProvider = null)
        {
            if (TreatAsS3Provider(targetProvider))
            {
                MoveInS3(sourceFso, targetFso);
                return;
            }

            // Moving across providers. With S3 in this case, need to basically download the file
            // to the local file system first, then copy from there to the target provder

            var localFile = new FileSystemObject(Path.Combine(Path.GetTempPath(), targetFso.FileNameAndExtension));

            try
            {
                GetToLocalFile(sourceFso, localFile);

                targetProvider.Store(localFile, targetFso);

                Delete(sourceFso);
            }
            finally
            {
                localFs.Delete(localFile);
            }

        }
 public void Move(string thisFileName, string moveToFileName, IFileStorageProvider targetProvider = null)
 {
     var sourceFso = GetFileSystemObject(thisFileName);
     var targetFso = GetFileSystemObject(moveToFileName);
     Move(sourceFso, targetFso, targetProvider);
 }
        private bool TreatAsS3Provider(IFileStorageProvider targetProvider)
        {
            if (targetProvider == null)
            {
                return true;
            }

            var s3Provider = targetProvider as S3FileStorageProvider;

            return s3Provider != null;
        }
        public override void Move(FileSystemObject sourceFso, FileSystemObject targetFso, IFileStorageProvider targetProvider = null)
        {
            var sourceBytes = Get(sourceFso);

            if (sourceBytes == null)
            {
                throw new FileNotFoundException("File does not exist in memory provider", sourceFso.FullName);
            }

            if (TreatAsInMemoryProvider(targetProvider))
            {
                if (sourceFso.Equals(targetFso))
                {
                    return;
                }

                Store(sourceBytes, targetFso);
                Delete(sourceFso);
                
                return;
            }

            // Moving across providers (from in-memory to some other file provider), so store then delete source
            targetProvider.Store(sourceBytes, targetFso);
            Delete(sourceFso);
        }
 public abstract void Move(FileSystemObject sourceFso, FileSystemObject targetFso, IFileStorageProvider targetProvider = null);
 public void Copy(string thisFileName, string copyToFileName, IFileStorageProvider targetProvider = null)
 {
     var sourceFso = GetFileSystemObject(thisFileName);
     var targetFso = GetFileSystemObject(copyToFileName);
     Copy(sourceFso, targetFso, targetProvider);
 }
 public override void Move(FileSystemObject sourceFso, FileSystemObject targetFso, IFileStorageProvider targetProvider = null)
 {   // If targetProvider is null, copying within file system
     if (TreatAsLocalFileSystemProvider(targetProvider))
     {
         MoveInFileSystem(sourceFso, targetFso);
         return;
     }
     
     // Moving across providers (from local file system to some other file provider), so store then delete source
     targetProvider.Store(sourceFso, targetFso);
     Delete(sourceFso);
 }
        private void StoreGet(IFileStorageProvider provider,
                              FileSystemObject file,
                              FileSystemObject localFileSystemSourceFile = null,
                              byte[] sourceBytes = null)
        {
            // Pssshhhh Ahhhhh tssss Push it
            if (sourceBytes != null)
            {
                provider.Store(sourceBytes, file);
            }
            else if (localFileSystemSourceFile != null)
            {
                provider.Store(localFileSystemSourceFile, file);
                sourceBytes = File.ReadAllBytes(localFileSystemSourceFile.FullName);
            }
            else
            {
                throw new Exception("Must include either bytes or a local file reference to StoreGetDelete");
            }

            // Get it
            var getFile = provider.Get(file);

            var getFileHash = getFile.ToSha256ByteHash().ToBase64String();
            var fileHash = sourceBytes.ToSha256ByteHash().ToBase64String();

            Assert.AreEqual(fileHash, getFileHash);
        }
        public override void Copy(FileSystemObject thisFso, FileSystemObject targetFso, IFileStorageProvider targetProvider = null)
        {   // If targetProvider is null or is an S3 provider, we are copying within S3, otherwise we
            // are copying across providers
            if (TreatAsS3Provider(targetProvider))
            {
                CopyInS3(thisFso, targetFso);
                return;
            }

            // Copying across providers. With S3 in this case, need to basically download the file
            // to the local file system first, then copy from there to the target provder

            var localFile = new FileSystemObject(Path.Combine(Path.GetTempPath(), targetFso.FileNameAndExtension));

            try
            {
                GetToLocalFile(thisFso, localFile);
                targetProvider.Store(localFile, targetFso);
            }
            finally
            {
                localFs.Delete(localFile);
            }
        }