コード例 #1
0
ファイル: Import.cs プロジェクト: sei-mmcdonough/caster-test
            private bool BeAValidArchiveType(IFormFile file)
            {
                var isValid = false;

                foreach (var extension in ArchiveTypeHelpers.GetValidExtensions())
                {
                    if (file.FileName.ToLower().EndsWith(extension))
                    {
                        isValid = true;
                    }
                }

                return(isValid);
            }
コード例 #2
0
ファイル: ArchiveService.cs プロジェクト: cmu-sei/Caster.Api
        private void Extract(System.IO.Stream stream, string filename, Project project = null, Directory directory = null)
        {
            using (var archiveInputStream = ArchiveInputStream.Create(stream, ArchiveTypeHelpers.GetType(filename)))
            {
                while (archiveInputStream.GetNextEntry() is ArchiveEntry archiveEntry)
                {
                    var file = this.EnsureCreated(project, directory, archiveEntry.Name, archiveEntry.IsFile);

                    if (file != null && archiveEntry.IsFile)
                    {
                        var buffer = new byte[4096];

                        using (var contentStream = new System.IO.MemoryStream())
                        {
                            StreamUtils.Copy(archiveInputStream.Stream, contentStream, buffer);
                            file.Content = Encoding.ASCII.GetString(contentStream.ToArray());
                        }
                    }
                }
            }
        }
コード例 #3
0
ファイル: Import.cs プロジェクト: sei-mmcdonough/caster-test
 public ImportValidator()
 {
     RuleFor(x => x.Archive)
     .NotNull().Must(BeAValidArchiveType)
     .WithMessage($"File extension must be one of {string.Join(", ", ArchiveTypeHelpers.GetValidExtensions())}");
 }