Пример #1
0
        public static void WriteSvgCssFile(IVirtualFiles vfs, string name,
                                           List <string> dataUris,
                                           Dictionary <string, string> adjacentCssRules = null,
                                           Dictionary <string, string> appendToCssFiles = null)
        {
            var sb = StringBuilderCache.Allocate();

            WriteDataUris(sb, dataUris);

            if (adjacentCssRules != null)
            {
                WriteAdjacentCss(sb, dataUris, adjacentCssRules);
            }

            if (appendToCssFiles != null)
            {
                if (appendToCssFiles.TryGetValue(name, out var suffix))
                {
                    sb.AppendLine(suffix);
                }
            }

            var css = StringBuilderCache.ReturnAndFree(sb);

            if (Svg.CssFillColor.TryGetValue(name, out var fillColor))
            {
                css = Svg.Fill(css, fillColor);
            }

            vfs.WriteFile($"/css/{name}.css", css);
        }
Пример #2
0
        public static List<string> GetDefaultViewLocations(IVirtualFiles virtualFiles)
        {
            var views = virtualFiles.GetDirectory("Views");
            if (views == null)
                return new List<string> { "~/Views" };

            var files = views.GetAllMatchingFiles("*.cshtml");
            var folders = files.Map(x => x.VirtualPath.LastLeftPart("/"));
            var locations = folders.Distinct().Map(x => "~/" + x);
            return locations;
        }
Пример #3
0
        public CsvRequestLogger(IVirtualFiles files = null, string requestLogsPattern = null, string errorLogsPattern = null, TimeSpan? appendEvery = null)
        {
            this.files = files ?? new FileSystemVirtualPathProvider(HostContext.AppHost, HostContext.Config.WebHostPhysicalPath);
            this.requestLogsPattern = requestLogsPattern ?? "requestlogs/{year}-{month}/{year}-{month}-{day}.csv";
            this.errorLogsPattern = errorLogsPattern ?? "requestlogs/{year}-{month}/{year}-{month}-{day}-errors.csv";
            this.appendEverySecs = (int)appendEvery.GetValueOrDefault(TimeSpan.FromSeconds(1)).TotalSeconds;

            var lastEntry = ReadLastEntry(GetLogFilePath(this.requestLogsPattern, DateTime.UtcNow));
            if (lastEntry != null)
                requestId = lastEntry.Id;

            timer = new Timer(OnFlush, null, this.appendEverySecs, Timeout.Infinite);
        }
        private static void AssertCanGetRoutingPages(IVirtualFiles vfs, Action fn = null)
        {
            Files.ForEach(vfs.WriteFile);

            foreach (var entry in Expected)
            {
                entry.Key.Print();
                var html = Config.ListeningOn.CombineWith(entry.Key).GetStringFromUrl(accept: MimeTypes.Html);
                Assert.That(html.NormalizeNewLines(), Is.EqualTo(entry.Value));
            }

            fn?.Invoke();
        }
Пример #5
0
        public CsvRequestLogger(IVirtualFiles files = null, string requestLogsPattern = null, string errorLogsPattern = null, TimeSpan?appendEvery = null)
        {
            this.files = files ?? new FileSystemVirtualFiles(HostContext.Config.WebHostPhysicalPath);
            this.requestLogsPattern = requestLogsPattern ?? "requestlogs/{year}-{month}/{year}-{month}-{day}.csv";
            this.errorLogsPattern   = errorLogsPattern ?? "requestlogs/{year}-{month}/{year}-{month}-{day}-errors.csv";
            this.appendEverySecs    = (int)appendEvery.GetValueOrDefault(TimeSpan.FromSeconds(1)).TotalSeconds;

            var lastEntry = ReadLastEntry(GetLogFilePath(this.requestLogsPattern, DateTime.UtcNow));

            if (lastEntry != null)
            {
                requestId = lastEntry.Id;
            }

            timer = new Timer(OnFlush, null, this.appendEverySecs, Timeout.Infinite);
        }
Пример #6
0
 public UploadLocation(string name,
                       IVirtualFiles virtualFiles, Func <FilesUploadContext, string>?resolvePath = null,
                       string readAccessRole    = RoleNames.AllowAnyUser, string writeAccessRole = RoleNames.AllowAnyUser,
                       string[]?allowExtensions = null, FilesUploadOperation allowOperations     = FilesUploadOperation.All,
                       int?maxFileCount         = null, long?minFileBytes = null, long?maxFileBytes = null,
                       Action <IRequest, IHttpFile>?validateUpload      = null, Action <IRequest, IVirtualFile>?validateDownload = null,
                       Action <IRequest, IVirtualFile>?validateDelete   = null,
                       Func <IRequest, IVirtualFile, object>?fileResult = null)
 {
     this.Name             = name ?? throw new ArgumentNullException(nameof(name));
     this.VirtualFiles     = virtualFiles ?? throw new ArgumentNullException(nameof(virtualFiles));
     this.ResolvePath      = resolvePath ?? (ctx => ctx.GetLocationPath($"{DateTime.UtcNow:yyyy/MM/dd}/{ctx.FileName}"));
     this.ReadAccessRole   = readAccessRole ?? throw new ArgumentNullException(nameof(readAccessRole));
     this.WriteAccessRole  = writeAccessRole ?? throw new ArgumentNullException(nameof(writeAccessRole));
     this.AllowExtensions  = allowExtensions?.ToSet(StringComparer.OrdinalIgnoreCase);
     this.AllowOperations  = allowOperations;
     this.MaxFileCount     = maxFileCount;
     this.MinFileBytes     = minFileBytes;
     this.MaxFileBytes     = maxFileBytes;
     this.ValidateUpload   = validateUpload;
     this.ValidateDownload = validateDownload;
     this.ValidateDelete   = validateDelete;
     this.FileResult       = fileResult;
 }
Пример #7
0
 public PersistentImagesHandler(string path, StaticContent fallback, IVirtualFiles virtualFiles, string dirPath)
     : base(path, fallback)
 {
     VirtualFiles = virtualFiles;
     DirPath      = dirPath;
 }
Пример #8
0
 public static void SaveTo(this IHttpFile httpFile, IVirtualFiles vfs, string filePath)
 {
     vfs.WriteFile(filePath, httpFile.InputStream);
 }
Пример #9
0
 public static void SaveTo(this IHttpFile httpFile, IVirtualFiles vfs, string filePath)
 {
     vfs.WriteFile(filePath, httpFile.InputStream);
 }
Пример #10
0
 public static async Task WriteFileAsync(this IVirtualFiles vfs, string filePath, Stream stream, CancellationToken token = default) =>
 await vfs.WriteFileAsync(filePath, stream, token).ConfigAwait();
Пример #11
0
 public static async Task WriteFileAsync(this IVirtualFiles vfs, string filePath, ReadOnlyMemory <byte> romBytes, CancellationToken token = default) =>
 await vfs.WriteFileAsync(filePath, romBytes, token).ConfigAwait();
Пример #12
0
 public static async Task WriteFileAsync(this IVirtualFiles vfs, string filePath, byte[] binaryContents, CancellationToken token = default) =>
 await vfs.WriteFileAsync(filePath, binaryContents, token).ConfigAwait();
Пример #13
0
 public static async Task SaveToAsync(this IHttpFile httpFile, IVirtualFiles vfs, string filePath, CancellationToken token = default)
 {
     await vfs.WriteFileAsync(filePath, httpFile.InputStream, token).ConfigAwait();
 }