Exemplo n.º 1
0
        private async Task <List <SelectListItem> > GetVideoSharedCodeSelectListItemsForUser()
        {
            var UserId_ = _userManager.GetUserAsync(User).GetAwaiter().GetResult().Id;

            var _LUserFile = await _context.LUserFile.Where(p => p.UserId == UserId_).ToListAsync();   //  <<<<<<<<

            var _VideoSharedCodeSelectListItems = new List <SelectListItem>()
            {
                new SelectListItem {
                    Value = Guid.Empty.ToString(), Text = "Select your video file", Selected = true
                }
            };

            _LUserFile.ForEach(p =>
            {
                if (_xUserFileHelper.GetMimes(p.Name.Split(".").LastOrDefault(), _hostingEnv).LastOrDefault().StartsWith("video"))
                {
                    _VideoSharedCodeSelectListItems.Add(
                        new SelectListItem {
                        Text  = _x_DOVEHelper.GetInPathOfFileOrDir(_context, p.InDirId) + p.Name,
                        Value = p.Id.ToString()
                    }                                   //<<<<<<<<
                        );
                }
            });
            return(_VideoSharedCodeSelectListItems);
        }
Exemplo n.º 2
0
        // GET: LDirs/Details/5
        public async Task <IActionResult> Details(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            //  ReturnUrl = ReturnUrl ?? Url.Content("~/");
            var UserId_ = _userManager.GetUserAsync(User).GetAwaiter().GetResult().Id;
            var lDir    = await _context.LDir.FirstOrDefaultAsync(m => m.Id == id && m.UserId == UserId_);

            if (lDir == null)
            {
                return(NotFound());
            }   //  lDir.ReturnUrl = ReturnUrl ?? Url.Content("~/");
            lDir.InDirName  = (await _context.LDir.Select(p => new { p.Id, p.Name }).FirstOrDefaultAsync(p => p.Id == lDir.InDirId))?.Name ?? "root";
            lDir.InFullPath = _x_DOVEHelper.GetInPathOfFileOrDir(_context, lDir.InDirId);
            return(View(lDir));  //   LocalRedirect(ReturnUrl); //  View(lDir);
        }
Exemplo n.º 3
0
        /*
         * [ActionName("GetSharedImages")]
         * public async Task<IActionResult> Index()
         * {
         *  var UserId_ = _userManager.GetUserAsync(User).GetAwaiter().GetResult().Id;
         *  var _Extensions = _mimeHelper.GetExtensions("image", _hostingEnv);
         *  var _LUserFiles = await _context.LUserFile.Where(p=>p.UserId==UserId_ && p.IsLegal).ToListAsync();
         *  _LUserFiles = _LUserFiles.Where(p => _Extensions.Contains(p.Name.Split('.').LastOrDefault())).ToList();
         *  return View("GetSharedImages", _LUserFiles);
         * }
         */

        #region
        // GET: LUserFiles
        #endregion
        public async Task <IActionResult> Index(Guid?InDirId)
        {
            #region REBARBATIVE INITIALIZATION
            if (!Directory.Exists(X_DOVEValues.AvatarStoragePath(_hostingEnv)))
            {
                Directory.CreateDirectory(X_DOVEValues.AvatarStoragePath(_hostingEnv));
            }

            var _FileNames = new DirectoryInfo(X_DOVEValues.FileStoragePath(_hostingEnv)).GetFiles().Select(p => p.Name);
            //  Console.WriteLine("FileName >> "+JsonConvert.SerializeObject(_FileNames));
            var _LFiles = await _context.LFile.ToListAsync();

            var _LUserFiles = await _context.LUserFile.ToListAsync();

            //  Console.WriteLine("File >> "+JsonConvert.SerializeObject(_LFiles));

            _LFiles.ForEach(f =>
            {
                if (!_FileNames.Contains(f.MD5))
                {
                    _context.LFile.Remove(f);
                }
            });

            _LUserFiles.ForEach(f =>
            {
                if (!_FileNames.Contains(f.MD5))
                {
                    _context.LUserFile.Remove(f);
                }
            });

            await _context.SaveChangesAsync();

            #endregion

            var _InDirName = "root";
            var _LastDirId = Guid.Empty;
            var _LDirs     = new List <LDir>();
            var _Path      = string.Empty;

            InDirId = InDirId ?? Guid.Empty;
            var UserId_ = _userManager.GetUserAsync(User).GetAwaiter().GetResult().Id;

            #region INITIAL_SIZE
            var _UserFiles_ = await _context.LUserFile.Where(p => p.UserId == UserId_).ToListAsync();

            var UsedSpace = await GetUsedSpaceAsync(_UserFiles_);   //  0.0;

            _UserFiles_ = _UserFiles_.Where(p => p.UserId == UserId_ && p.InDirId == InDirId && !string.IsNullOrWhiteSpace(p.MD5))
                          .OrderBy(p => p.DOCreate).ToList();
            _UserFiles_.ForEach(p =>
            {
                var _FileLength = new FileInfo(_xUserFileHelper.FileStoragePath(_hostingEnv) + p.MD5).Length;
                //  UsedSpace += _FileLength / (1024 * 1024);    //  MByte
                p.Size          = _FileLength;
                p.OptimizedSize = _xUserFileHelper.OptimizeSizeShow(_FileLength);
            });

            /*
             * _UserFiles_.ForEach(p=> {
             *  var _FileLength = new FileInfo(_xUserFileHelper.FileStoragePath(_hostingEnv) + p.MD5).Length;
             *  UsedSpace += _FileLength/(1024*1024);    //  MByte
             *  p.Size = _FileLength;
             * });
             */
            #endregion

            var LUserFileIds = _UserFiles_.Select(p => p.Id);

            #region PATH
            _InDirName = (await _context.LDir.Where(p => p.Id == InDirId).Select(p => p.Name).FirstOrDefaultAsync()) ?? _InDirName;
            _LastDirId = await _context.LDir.Where(p => p.Id == InDirId && p.UserId == UserId_).Select(p => p.InDirId).FirstOrDefaultAsync();

            _LDirs = await _context.LDir.Where(p => p.UserId == UserId_ && p.InDirId == InDirId && !LUserFileIds.Contains(p.Id))
                     .ToListAsync();

            _Path = _x_DOVEHelper.GetInPathOfFileOrDir(context: _context, InDirId: InDirId ?? Guid.Empty);

            //  (await _context.LDir.Where(p => p.Id == InDirId).Select(p => p.Name).FirstOrDefaultAsync()) ?? "root";
            // InDirId == Guid.Empty ? InDirId
            //    : await _context.LDir.Where(p => p.Id == InDirId && p.UserId == UserId_).Select(p => p.InDirId).FirstOrDefaultAsync();
            #endregion

            #region VIEWDATA

            ViewData[nameof(_Path)]        = _Path;
            ViewData[nameof(_LDirs)]       = _LDirs;
            ViewData[nameof(_LastDirId)]   = _LastDirId;
            ViewData[nameof(_InDirName)]   = _InDirName;
            ViewData[nameof(InDirId)]      = InDirId;
            ViewData["UsedSpace"]          = UsedSpace;
            ViewData["OptimizedUsedSpace"] = _xUserFileHelper.OptimizeSizeShow(UsedSpace);
            #endregion

            return(View(_UserFiles_));
        }