Exemple #1
0
        /// <inheritdoc/>
        public async Task <bool> TryCreateDirectoryAsync(string path)
        {
            try
            {
                if (string.IsNullOrEmpty(path))
                {
                    return(true);
                }

                // 检查文件夹记录是否完整
                var index = await _context.FileIndexs.Where(c => c.Path == path).FirstOrDefaultAsync();

                if (index != null)
                {
                    return(true);
                }

                index = new FileIndex();

                index.Id            = IdHelper.GetLongId();
                index.Path          = PathHelper.NormalizePath(path);
                index.DirectoryPath = PathHelper.NormalizePath(Path.GetDirectoryName(path));
                index.IsDirectory   = true;

                var nowTime = DateTime.UtcNow;
                index.LastModifiedUtc  = nowTime;
                index.Visits           = 0;
                index.LastVisitTimeUtc = nowTime;

                _context.FileIndexs.Add(index);

                await _context.SaveChangesAsync();

                await TryCreateDirectoryAsync(index.DirectoryPath);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }