示例#1
0
        public async Task <List <Hall> > GetAllAsync()
        {
            var halls = await _halls.Find(hall => true).ToListAsync();

            foreach (var hall in halls)
            {
                if (!string.IsNullOrEmpty(hall?.Photo?.Id))
                {
                    hall.Photo.Photo = await _gridFS.DownloadAsBytesAsync(ObjectId.Parse(hall.Photo.Id));
                }
            }
            return(halls);
        }
示例#2
0
        public async Task <List <Stand> > GetAllAsync(string hallId)
        {
            var hall = await _halls.Find(hall => hall.Id.Equals(hallId)).FirstOrDefaultAsync();

            if (hall != null)
            {
                foreach (var stand in hall.Stands)
                {
                    if (!string.IsNullOrEmpty(stand?.Photo?.Id))
                    {
                        stand.Photo.Photo = await _gridFS.DownloadAsBytesAsync(ObjectId.Parse(stand.Photo.Id));
                    }
                }
            }
            return(hall?.Stands.ToList());
        }
示例#3
0
        public async Task <ActionResult> GetFile(string videoFileId)
        {
            var file = await gridFS.DownloadAsBytesAsync(new ObjectId(videoFileId));

            if (file == null)
            {
                return(NotFound());
            }
            return(File(file, "video/mp4"));
        }
示例#4
0
        public async Task <ActionResult> GetFile(string Userid)
        {
            var localVideo = await GetVideoFileId(Userid);//Finding video file ID

            var file = await gridFS.DownloadAsBytesAsync(new ObjectId(localVideo.videoFileId));

            if (file == null)
            {
                return(NotFound());
            }
            return(File(file, "video/mp4"));
        }
        public async Task <OperationResult> ExecuteAsync(CancellationToken cancellationToken)
        {
            try
            {
                var result = await _bucket.DownloadAsBytesAsync(_id, cancellationToken : cancellationToken);

                return(OperationResult.FromResult(BsonUtils.ToHexString(result)));
            }
            catch (Exception exception)
            {
                return(OperationResult.FromException(exception));
            }
        }
示例#6
0
        public async Task <byte[]> GetAsync(string id, CancellationToken token)
        {
            token.ThrowIfCancellationRequested();

            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            var objectId = ObjectId.Parse(id);
            var file     = await files.DownloadAsBytesAsync(objectId, null, token).ConfigureAwait(false);

            return(file);
        }
示例#7
0
        public async Task <List <Exhibit> > GetAllAsync(string hallId, string standId)
        {
            var hall = await _halls.Find(h => h.Id.Equals(hallId)).FirstOrDefaultAsync();

            var exhibits = hall?.Stands?.FirstOrDefault(s => s.Id.Equals(standId))?.Exhibits?.ToList();

            if (exhibits != null)
            {
                foreach (var exhibit in exhibits)
                {
                    if (exhibit?.Photos != null)
                    {
                        foreach (var photo in exhibit.Photos)
                        {
                            if (!string.IsNullOrEmpty(photo?.Id))
                            {
                                photo.Photo = await _gridFS.DownloadAsBytesAsync(ObjectId.Parse(photo.Id));
                            }
                        }
                    }
                }
            }
            return(exhibits);
        }
示例#8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pngId"></param>
        /// <returns></returns>
        public async static Task <MemoryStream> QueryBitmap(string pngId)
        {
            try
            {
                byte[] buffer = await bucket.DownloadAsBytesAsync(new ObjectId(pngId));

                MemoryStream m = new MemoryStream(buffer);
                return(m);
            }
            catch
            {
                byte[]       buffer = new byte[] { 0 };
                MemoryStream m      = new MemoryStream(buffer);
                return(m);
            }
        }
示例#9
0
        public async Task <byte[]> GetImageSource(ProductPhoto photo)
        {
            try
            {
                Log.Instance.LogAsInfo($"{nameof(ProductPhotoRepository)}.{nameof(GetImageSource)}: GetImageSource is starting");
                var result = await _gridFS.DownloadAsBytesAsync(new ObjectId(photo.ImageSourceId));

                Log.Instance.LogAsInfo($"{nameof(ProductPhotoRepository)}.{nameof(GetImageSource)}: GetImageSource is successfully ended.");
                return(result);
            }
            catch (Exception e)
            {
                Log.Instance.ExceptionInfo(e).LogAsError($"{nameof(ProductPhotoRepository)}.{nameof(GetImageSource)}: Error");
                throw;
            }
        }
示例#10
0
        public byte[] Download(ObjectId fileId)
        {
            var filter = Builders <GridFSFileInfo <ObjectId> >
                         .Filter.Eq(x => x.Id, fileId);

            var searchResult = bucket.FindAsync(filter);

            var fileEntry = searchResult.Result.SingleOrDefault();

            if (fileEntry == null)
            {
                content = null;
            }
            else
            {
                content = bucket.DownloadAsBytesAsync(fileId).Result;
            }

            return(content);
        }
        public async Task <byte[]> GetFileAsync(HostConfig host, string file)
        {
            int index = file.LastIndexOf('.');

            file = index == -1 ? file : file.Substring(0, index); //remove extension if any

            IGridFSBucket bucket = GetBucket(host);

            byte[] bytes;
            try
            {
                var ob = new ObjectId(file);
                if (ob == ObjectId.Empty)
                {
                    return(null);
                }

                bytes = await bucket.DownloadAsBytesAsync(ob);
            }
            catch (ArgumentException ex)
            {
                throw new GridFsObjectIdException(ex.Message);
            }
            catch (FormatException ex)
            {
                throw new GridFsObjectIdException(ex.Message);
            }
            catch (Exception ex)
            {
                if (ex is GridFSFileNotFoundException || ex is IndexOutOfRangeException || ex is ArgumentNullException)
                {
                    return(null);
                }

                //log other errors....
                throw;
            }

            return(bytes);
        }
示例#12
0
 public async Task <byte[]> GetLogFile(ObjectId id)
 {
     return(await _gridFS.DownloadAsBytesAsync(id));
 }
示例#13
0
 public async Task <byte[]> GetFile(string id)
 {
     return(await gridFS.DownloadAsBytesAsync(new ObjectId(id)));
 }
示例#14
0
 public async Task <byte[]> GetPhotoBytesAsync(ObjectId fileId)
 {
     return(fileId != ObjectId.Empty ? await _gridFs.DownloadAsBytesAsync(fileId) : null);
 }
 public async Task <byte[]> GetImageContent(ObjectId id)
 {
     return(await buket.DownloadAsBytesAsync(id));
 }