public static IFileInfo GetContentFileInfo(this PathString path, IFileProvider fileProvider)
        {
            string    rPath    = (path == null || !path.HasValue || path.Value == "") ? "/" : path.Value;
            IFileInfo fileInfo = null;

            try
            {
                fileInfo = fileProvider.GetFileInfo(rPath);
                if (fileInfo == null)
                {
                    fileInfo = new NotFoundFileInfo(rPath);
                }
                else if (fileInfo.Exists)
                {
                    if (!fileInfo.IsDirectory)
                    {
                        return(fileInfo);
                    }
                    IDirectoryContents contents = fileProvider.GetDirectoryContents(rPath);
                    IFileInfo          page     = DefaultPageNames.Select(p => contents.FirstOrDefault(c => String.Equals(p, c.Name, StringComparison.InvariantCultureIgnoreCase)))
                                                  .FirstOrDefault(f => f != null);
                    if (page != null)
                    {
                        fileInfo = page;
                    }
                }
            } catch (Exception exception) { fileInfo = new GetFileError(rPath, exception); }
            return(fileInfo);
        }
Beispiel #2
0
        public async Task <IFileInfo> GetRunFileAsync(
            int jid, int rid, string type, int?sid, int?pid)
        {
            var notfound = new NotFoundFileInfo($"j{jid}/r{rid}.{type}");
            var fileInfo = Files.GetFileInfo($"j{jid}/r{rid}.{type}");

            if (!fileInfo.Exists)
            {
                return(notfound);
            }
            var accessQuery =
                from r in Details
                where r.JudgingId == jid && r.TestId == rid
                join j in Judgings on r.JudgingId equals j.JudgingId
                join s in Submissions on j.SubmissionId equals s.SubmissionId
                select new { s.SubmissionId, s.ProblemId };
            var result = await accessQuery.SingleOrDefaultAsync();

            if (sid.HasValue && result.SubmissionId != sid.Value)
            {
                return(notfound);
            }
            if (pid.HasValue && result.ProblemId != pid.Value)
            {
                return(notfound);
            }
            return(fileInfo);
        }
Beispiel #3
0
        /// <summary>
        /// ISpaModule
        /// This implementation accepts path in Orchard-like format:
        ///
        /// </summary>
        public IFileInfo GetFileInfo(string subpath)
        {
            if (!_fileInfos.TryGetValue(subpath, out var fileInfo))
            {
                lock (_fileInfos)
                {
                    if (!_fileInfos.TryGetValue(subpath, out fileInfo))
                    {
                        var resourcePath = _baseNamespace + subpath.Replace('/', '>');
                        var fileName     = Path.GetFileName(subpath);

                        if (_assembly.GetManifestResourceInfo(resourcePath) == null)
                        {
                            _logger.LogDebug(1, null, $"SpaModuleAssembly.GetFileInfo(): cannot find resource '{subpath}'");
                            fileInfo = new NotFoundFileInfo(fileName);
                        }
                        else
                        {
                            _logger.LogDebug(2, null, $"SpaModuleAssembly.GetFileInfo(): successfully loaded resource '{subpath}'");
                            _fileInfos[subpath] = fileInfo = new EmbeddedResourceFileInfo(_assembly.Object, resourcePath, fileName, _lastModified);
                        }
                    }
                }
            }

            return(fileInfo);
        }
        public void Construction_FileInfoIsNotFoundFileInfo_ThrowsArgumentException()
        {
            // Arrange
            IFileInfo fileInfo = new NotFoundFileInfo("foo.xml");

            // Act
            void CreateUploadItem() => new UploadItem(fileInfo);

            // Assert
            Assert.That(CreateUploadItem, Throws.ArgumentException);
        }
Beispiel #5
0
        public IFileInfo GetFileInfo(string subpath)
        {
            var result = new RazorFileInfo(_store, subpath);

            result.GetView().GetAwaiter().GetResult();
            IFileInfo r = null;

            if (result.Exists)
            {
                r = result;
            }
            else
            {
                r = new NotFoundFileInfo(subpath);
            }
            return(r);
        }
Beispiel #6
0
 public void OnRemoved()
 {
     FileInfo = new NotFoundFileInfo(this.FileInfo.Name);
     OnRaiseItemDeleted();
     ParentFolder = null; // no need to monitor parent anymore as we have been removed from the directory.
 }