private async Task <Workflow> LoadWorkflowDefinitionAsync(IFileStoreEntry file, CancellationToken cancellationToken)
        {
            var data = await fileStore.ReadToEndAsync(file.Path);

            var workflow = await workflowSerializer.DeserializeAsync(data, Format, cancellationToken);

            workflow.Metadata.Id = file.Name;
            return(workflow);
        }
        public Task <Stream> GetFileStreamAsync(IFileStoreEntry fileStoreEntry)
        {
            if (!File.Exists(fileStoreEntry.Path))
            {
                throw new FileStoreException($"Cannot get file stream because the file '{fileStoreEntry.Path}' does not exist.");
            }

            var stream = File.OpenRead(fileStoreEntry.Path);

            return(Task.FromResult <Stream>(stream));
        }
        // Reduces the need to call blob.FetchAttributes, and blob.ExistsAsync,
        // as Azure Storage Library will perform these actions on OpenReadAsync().
        public Task <Stream> GetFileStreamAsync(IFileStoreEntry fileStoreEntry)
        {
            var blobFile = fileStoreEntry as BlobFile;

            if (blobFile == null || blobFile.BlobReference == null)
            {
                throw new FileStoreException("Cannot get file stream because the file does not exist.");
            }

            return(blobFile.BlobReference.OpenReadAsync());
        }
Esempio n. 4
0
 public object CreateFileResult(IFileStoreEntry mediaFile)
 {
     return(new
     {
         name = mediaFile.Name,
         size = mediaFile.Length,
         folder = mediaFile.DirectoryPath,
         url = _mediaFileStore.MapPathToPublicUrl(mediaFile.Path),
         mediaPath = mediaFile.Path,
         mime = MimeMapping.MimeUtility.GetMimeMapping(mediaFile.Path)
     });
 }
Esempio n. 5
0
        public Task <Stream> GetFileStream(IFileStoreEntry fileStoreEntry)
        {
            var physicalPath = GetPhysicalPath(fileStoreEntry.Path);

            if (!File.Exists(physicalPath))
            {
                throw new Exception($"Cannot get file stream because the file '{fileStoreEntry.Path}' does not exist.");
            }

            var stream = File.OpenRead(physicalPath);

            return(Task.FromResult <Stream>(stream));
        }
Esempio n. 6
0
        public object CreateFileResult(IFileStoreEntry mediaFile)
        {
            _contentTypeProvider.TryGetContentType(mediaFile.Name, out var contentType);

            return(new
            {
                name = mediaFile.Name,
                size = mediaFile.Length,
                folder = mediaFile.DirectoryPath,
                url = _mediaFileStore.MapPathToPublicUrl(mediaFile.Path),
                mediaPath = mediaFile.Path,
                mime = contentType ?? "application/octet-stream"
            });
        }
Esempio n. 7
0
        public async Task SetCacheAsync(Stream stream, IFileStoreEntry fileStoreEntry, CancellationToken cancellationToken)
        {
            // File store semantics include a leading slash.
            var cachePath = Path.Combine(Root, fileStoreEntry.Path.Substring(1));
            var directory = Path.GetDirectoryName(cachePath);

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            // A file download may fail, so a partially downloaded file should be deleted so the next request can reprocess.
            // All exceptions here are recaught by the MediaFileStoreResolverMiddleware.
            try
            {
                if (File.Exists(cachePath))
                {
                    File.Delete(cachePath);
                }
                using (var fileStream = File.Create(cachePath))
                {
                    await stream.CopyToAsync(fileStream, StreamCopyBufferSize);

                    await stream.FlushAsync();

                    if (fileStream.Length == 0)
                    {
                        throw new Exception($"Error retrieving file (length equals 0 byte) : {cachePath}");
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error saving file {Path}", cachePath);
                if (File.Exists(cachePath))
                {
                    try
                    {
                        File.Delete(cachePath);
                    }
                    catch (Exception e)
                    {
                        _logger.LogError(e, "Error deleting file {Path}", cachePath);
                        throw;
                    }
                }
                throw;
            }
        }
Esempio n. 8
0
        public object CreateFileResult(IFileStoreEntry mediaFile)
        {
            _contentTypeProvider.TryGetContentType(mediaFile.Name, out var contentType);

            return(new
            {
                name = mediaFile.Name,
                size = mediaFile.Length,
                lastModify = mediaFile.LastModifiedUtc.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds,
                folder = mediaFile.DirectoryPath,
                url = _mediaFileStore.MapPathToPublicUrl(mediaFile.Path),
                mediaPath = mediaFile.Path,
                mime = contentType ?? "application/octet-stream"
            });
        }
        public async Task SetCacheAsync(Stream stream, IFileStoreEntry fileStoreEntry, CancellationToken cancellationToken)
        {
            // File store semantics include a leading slash.
            var cachePath = Path.Combine(Root, fileStoreEntry.Path.Substring(1));
            var directory = Path.GetDirectoryName(cachePath);

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            using (var fileStream = File.Create(cachePath))
            {
                await stream.CopyToAsync(fileStream, StreamCopyBufferSize, cancellationToken);
            }
        }
Esempio n. 10
0
        public async Task <Stream> GetFileStreamAsync(IFileStoreEntry fileStoreEntry)
        {
            var fileEntity = await GetFileEntityByPath(fileStoreEntry.Path);

            try
            {
                var stream = await _mongoRepository.GetFileStreamAsync(fileEntity._id);

                return(stream);
            }
            catch (Exception e)
            {
                _logger.LogError(e.StackTrace);
                return(null);
            }
        }
Esempio n. 11
0
        public Task <Permission> GetPermissionAsync(IFileStoreEntry fileStoreEntry)
        {
            if (_permissions.Any())
            {
                var r = _permissions.Select(async f => await f.GetPermissionAsync(fileStoreEntry));
                return(Task.Run(() =>
                {
                    return (Permission)r.Sum(f => (int)f.Result);
                }));
            }
            else
            {
                //var read = Permission.ListSubFolders | Permission.ListFiles | Permission.Download | Permission.Copy | Permission.Preview | Permission.Print;
                var full = Permission.ListSubFolders | Permission.ListFiles | Permission.Download | Permission.Copy | Permission.Preview | Permission.Print
                           | Permission.Create | Permission.Delete | Permission.Rename | Permission.Edit | Permission.Upload | Permission.Compress | Permission.Extract | Permission.Cut | Permission.Paste | Permission.CreatePublicLink;

                return(Task.FromResult(full));
            }
        }
Esempio n. 12
0
 internal StoreFileInfo(IFileStore store, IFileStoreEntry fileStore)
 {
     this._store     = store;
     this._fileStore = fileStore;
 }
Esempio n. 13
0
 public async Task <Stream> GetFileStreamAsync(IFileStoreEntry fileStoreEntry)
 {
     return(await GetFileStreamAsync(fileStoreEntry.Path));
 }
Esempio n. 14
0
 public Task <Stream> GetFileStreamAsync(IFileStoreEntry fileStoreEntry)
 {
     return(_fileStore.GetFileStreamAsync(fileStoreEntry));
 }
Esempio n. 15
0
        //public Task<Permission> GetFilePermissionAsync(string path)
        //{
        //    throw new NotImplementedException();
        //}

        public Task <Permission> GetPermissionAsync(IFileStoreEntry fileStoreEntry)
        {
            return(_func(fileStoreEntry));
        }
Esempio n. 16
0
 public virtual Task <Stream> GetFileStream(IFileStoreEntry fileStoreEntry)
 {
     return(_fileStore.GetFileStream(fileStoreEntry));
 }