コード例 #1
0
        private async Task <WebApiPagedResponseDto <FileInfo> > GetVideosViewModel(string physicalPath, int page = 1, int pageSize = 40, string orderColumn = nameof(FileInfo.LastWriteTime), string orderType = OrderByType.Descending)
        {
            var cts = TaskHelper.CreateChildCancellationTokenSource(ClientDisconnectedToken());

            var repository = _fileSystemGenericRepositoryFactory.CreateFileRepository(cts.Token, physicalPath, true, "*.*", ".mp4", ".avi", ".txt");
            var dataTask   = repository.GetAllAsync(LamdaHelper.GetOrderByFunc <FileInfo>(orderColumn, orderType), (page - 1) * pageSize, pageSize);
            var totalTask  = repository.GetCountAsync(null);

            await TaskHelper.WhenAllOrException(cts, dataTask, totalTask);

            var data  = dataTask.Result;
            var total = totalTask.Result;

            var response = new WebApiPagedResponseDto <FileInfo>
            {
                Page        = page,
                PageSize    = pageSize,
                Records     = total,
                Rows        = data.ToList(),
                OrderColumn = orderColumn,
                OrderType   = orderType
            };

            return(response);
        }
コード例 #2
0
        public async Task <ActionResult> Index(int p = 1, int pageSize = 100, string orderBy = nameof(FileInfo.LastWriteTime) + " desc")
        {
            var cts = TaskHelper.CreateChildCancellationTokenSource(ClientDisconnectedToken());

            try
            {
                var repository = _fileSystemGenericRepositoryFactory.CreateFileRepository(cts.Token, _hostingEnvironment.MapWwwPath(AppSettings.Folders[Folders.BucketList]), true, "*.*", ".jpg", ".jpeg", ".txt", ".mp4", ".avi");

                var data = await repository.GetAllAsync(UIHelper.GetOrderByIQueryableDelegate <FileInfo>(orderBy), (p - 1) *pageSize, pageSize);

                var total = await repository.GetCountAsync(null);

                var response = new WebApiPagedResponseDto <FileInfo>
                {
                    Page     = p,
                    PageSize = pageSize,
                    Records  = total,
                    Rows     = data.ToList(),
                    OrderBy  = orderBy
                };

                ViewBag.Page     = p;
                ViewBag.PageSize = pageSize;
                ViewBag.OrderBy  = orderBy;

                return(View(response));
            }
            catch
            {
                return(HandleReadException());
            }
        }
コード例 #3
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var cts = TaskHelper.CreateChildCancellationTokenSource(ClientDisconnectedToken());

            var repository = FileSystemRepository.CreateFileRepository(cts.Token, Server.GetWwwFolderPhysicalPathById(Folders.Gallery), true, "*.*", ".jpg", ".jpeg");

            IList <CategoryDto>       categories = null;
            IEnumerable <TagDto>      tags       = null;
            IEnumerable <BlogPostDto> posts      = null;
            IEnumerable <FileInfo>    photos     = null;

            var categoriesTask = _blogService.CategoryApplicationService.GetAsync(cts.Token, c => c.Published);
            var tagsTask       = _blogService.TagApplicationService.GetAllAsync(cts.Token);
            var postsTask      = _blogService.BlogPostApplicationService.GetPostsAsync(0, 10, cts.Token);
            var photosTask     = repository.GetAllAsync(d => d.OrderByDescending(f => f.LastWriteTime), 0, 6);

            await TaskHelper.WhenAllOrException(cts, tagsTask, categoriesTask);

            List <Task <int> > countTasks = new List <Task <int> >();

            //foreach (TagDto dto in tagsTask.Result)
            //{
            //    tagCountTasks.Add(_blogService.BlogPostService.GetTotalPostsForTagAsync(dto.UrlSlug, cts.Token).ContinueWith(t => dto.Count = t.Result));
            //}
            categories = categoriesTask.Result.ToList();
            foreach (CategoryDto dto in categories)
            {
                countTasks.Add(_blogService.BlogPostApplicationService.GetTotalPostsForCategoryAsync(dto.UrlSlug, cts.Token));
            }

            await TaskHelper.WhenAllOrException(cts, categoriesTask, postsTask, photosTask);

            await TaskHelper.WhenAllOrException(cts, countTasks.ToArray());

            int i = 0;

            foreach (CategoryDto dto in categories)
            {
                dto.Count = countTasks[i].Result;
                i++;
            }

            tags   = tagsTask.Result;
            posts  = postsTask.Result;
            photos = photosTask.Result;

            var widgetViewModel = new BlogWidgetViewModel
            {
                Categories   = categories,
                Tags         = tags.ToList(),
                LatestPosts  = posts.ToList(),
                LatestPhotos = photos.ToList()
            };

            return(View(widgetViewModel));
        }
コード例 #4
0
        private async Task <WebApiPagedResponseDto <FileInfo> > GetVideosViewModel(string physicalPath, int page = 1, int pageSize = 40, string orderBy = nameof(FileInfo.LastWriteTime) + " desc")
        {
            var cts = TaskHelper.CreateChildCancellationTokenSource(ClientDisconnectedToken());

            var repository = _fileSystemGenericRepositoryFactory.CreateFileRepository(cts.Token, physicalPath, true, "*.*", ".mp4", ".avi", ".txt");

            var data = await repository.GetAllAsync(UIHelper.GetOrderByIQueryableDelegate <FileInfo>(orderBy), (page - 1) *pageSize, pageSize);

            var total = await repository.GetCountAsync(null);

            var response = new WebApiPagedResponseDto <FileInfo>
            {
                Page     = page,
                PageSize = pageSize,
                Records  = total,
                Rows     = data.ToList(),
                OrderBy  = orderBy
            };

            return(response);
        }
コード例 #5
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var cts = TaskHelper.CreateChildCancellationTokenSource(ClientDisconnectedToken());

            var repository = FileSystemRepository.CreateFileRepository(cts.Token, _hostingEnvironment.MapWwwPath(_appSettings.Folders[Folders.Gallery]), true, "*.*", ".jpg", ".jpeg");

            IList <CategoryDto>       categories = null;
            IEnumerable <TagDto>      tags       = null;
            IEnumerable <BlogPostDto> posts      = null;
            IEnumerable <FileInfo>    photos     = null;

            List <Task <int> > countTasks = new List <Task <int> >();

            //foreach (TagDto dto in tagsTask.Result)
            //{
            //    tagCountTasks.Add(_blogService.BlogPostService.GetTotalPostsForTagAsync(dto.UrlSlug, cts.Token).ContinueWith(t => dto.Count = t.Result));
            //}
            categories = (await _blogService.CategoryApplicationService.GetAsync(cts.Token, c => c.Published)).ToList();
            foreach (CategoryDto dto in categories)
            {
                dto.Count = await _blogService.BlogPostApplicationService.GetTotalPostsForCategoryAsync(dto.UrlSlug, cts.Token);
            }

            tags = await _blogService.TagApplicationService.GetAllAsync(cts.Token);

            posts = await _blogService.BlogPostApplicationService.GetPostsAsync(0, 10, cts.Token);

            photos = await repository.GetAllAsync(d => d.OrderByDescending(f => f.LastWriteTime), 0, 6);

            var widgetViewModel = new BlogWidgetViewModel
            {
                Categories   = categories,
                Tags         = tags.ToList(),
                LatestPosts  = posts.ToList(),
                LatestPhotos = photos.ToList()
            };

            return(View(widgetViewModel));
        }
コード例 #6
0
        public async Task <ActionResult> Index(int page = 1, int pageSize = 100, string orderColumn = nameof(FileInfo.LastWriteTime), string orderType = "desc")
        {
            var cts = TaskHelper.CreateChildCancellationTokenSource(ClientDisconnectedToken());

            try
            {
                var repository = _fileSystemGenericRepositoryFactory.CreateFileRepository(cts.Token, Server.GetWwwFolderPhysicalPathById(Folders.BucketList), true, "*.*", ".jpg", ".jpeg", ".txt", ".mp4", ".avi");
                var dataTask   = repository.GetAllAsync(LamdaHelper.GetOrderByFunc <FileInfo>(orderColumn, orderType), (page - 1) * pageSize, pageSize);
                var totalTask  = repository.GetCountAsync(null);

                await TaskHelper.WhenAllOrException(cts, dataTask, totalTask);

                var data  = dataTask.Result;
                var total = totalTask.Result;

                var response = new WebApiPagedResponseDto <FileInfo>
                {
                    Page        = page,
                    PageSize    = pageSize,
                    Records     = total,
                    Rows        = data.ToList(),
                    OrderColumn = orderColumn,
                    OrderType   = orderType
                };

                ViewBag.Page        = page;
                ViewBag.PageSize    = pageSize;
                ViewBag.OrderColumn = orderColumn;
                ViewBag.OrderType   = orderType;

                return(View(response));
            }
            catch
            {
                return(HandleReadException());
            }
        }