mirror of
https://github.com/fergalmoran/SilkierQuartz.git
synced 2026-01-03 07:25:55 +00:00
删除owin
This commit is contained in:
@@ -1,199 +0,0 @@
|
||||
#if NETFRAMEWORK
|
||||
|
||||
using Microsoft.Owin.FileSystems;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace SilkierQuartz.Owin
|
||||
{
|
||||
/// <summary>
|
||||
/// Looks up files using embedded resources in the specified assembly.
|
||||
/// This file system is case sensitive.
|
||||
/// </summary>
|
||||
internal class FixedEmbeddedResourceFileSystem : IFileSystem
|
||||
{
|
||||
private readonly Assembly _assembly;
|
||||
private readonly string _baseNamespace;
|
||||
private readonly DateTime _lastModified;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FixedEmbeddedResourceFileSystem" /> class using the calling
|
||||
/// assembly and empty base namespace.
|
||||
/// </summary>
|
||||
public FixedEmbeddedResourceFileSystem()
|
||||
: this(Assembly.GetCallingAssembly())
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FixedEmbeddedResourceFileSystem" /> class using the specified
|
||||
/// assembly and empty base namespace.
|
||||
/// </summary>
|
||||
/// <param name="assembly"></param>
|
||||
public FixedEmbeddedResourceFileSystem(Assembly assembly)
|
||||
: this(assembly, string.Empty)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FixedEmbeddedResourceFileSystem" /> class using the calling
|
||||
/// assembly and specified base namespace.
|
||||
/// </summary>
|
||||
/// <param name="baseNamespace">The base namespace that contains the embedded resources.</param>
|
||||
public FixedEmbeddedResourceFileSystem(string baseNamespace)
|
||||
: this(Assembly.GetCallingAssembly(), baseNamespace)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FixedEmbeddedResourceFileSystem" /> class using the specified
|
||||
/// assembly and base namespace.
|
||||
/// </summary>
|
||||
/// <param name="assembly">The assembly that contains the embedded resources.</param>
|
||||
/// <param name="baseNamespace">The base namespace that contains the embedded resources.</param>
|
||||
public FixedEmbeddedResourceFileSystem(Assembly assembly, string baseNamespace)
|
||||
{
|
||||
if (assembly == null)
|
||||
{
|
||||
throw new ArgumentNullException("assembly");
|
||||
}
|
||||
_baseNamespace = string.IsNullOrEmpty(baseNamespace) ? string.Empty : baseNamespace + ".";
|
||||
_assembly = assembly;
|
||||
_lastModified = new FileInfo(assembly.Location).LastWriteTime;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Locate a file at the given path
|
||||
/// </summary>
|
||||
/// <param name="subpath">The path that identifies the file</param>
|
||||
/// <param name="fileInfo">The discovered file if any</param>
|
||||
/// <returns>True if a file was located at the given path</returns>
|
||||
public bool TryGetFileInfo(string subpath, out IFileInfo fileInfo)
|
||||
{
|
||||
// "/file.txt" expected.
|
||||
if (string.IsNullOrEmpty(subpath) || subpath[0] != '/')
|
||||
{
|
||||
fileInfo = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
string fileName = subpath.Substring(1); // Drop the leading '/'
|
||||
|
||||
var parts = fileName.Split('/');
|
||||
// replace '/' with '.' and '-' with '_' except last part of path
|
||||
string resourcePath = _baseNamespace + string.Join(".", parts.SkipLast().Select(x => x.Replace("-", "_")).Concat(new[] { parts.Last() }));
|
||||
|
||||
if (_assembly.GetManifestResourceInfo(resourcePath) == null)
|
||||
{
|
||||
fileInfo = null;
|
||||
return false;
|
||||
}
|
||||
fileInfo = new EmbeddedResourceFileInfo(_assembly, resourcePath, fileName, _lastModified);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enumerate a directory at the given path, if any.
|
||||
/// This file system uses a flat directory structure. Everything under the base namespace is considered to be one directory.
|
||||
/// </summary>
|
||||
/// <param name="subpath">The path that identifies the directory</param>
|
||||
/// <param name="contents">The contents if any</param>
|
||||
/// <returns>True if a directory was located at the given path</returns>
|
||||
public bool TryGetDirectoryContents(string subpath, out IEnumerable<IFileInfo> contents)
|
||||
{
|
||||
// The file name is assumed to be the remainder of the resource name.
|
||||
|
||||
// Non-hierarchal.
|
||||
if (!subpath.Equals("/"))
|
||||
{
|
||||
contents = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
IList<IFileInfo> entries = new List<IFileInfo>();
|
||||
|
||||
string[] resources = _assembly.GetManifestResourceNames();
|
||||
for (int i = 0; i < resources.Length; i++)
|
||||
{
|
||||
string resourceName = resources[i];
|
||||
if (resourceName.StartsWith(_baseNamespace))
|
||||
{
|
||||
entries.Add(new EmbeddedResourceFileInfo(
|
||||
_assembly, resourceName, resourceName.Substring(_baseNamespace.Length), _lastModified));
|
||||
}
|
||||
}
|
||||
|
||||
contents = entries;
|
||||
return true;
|
||||
}
|
||||
|
||||
private class EmbeddedResourceFileInfo : IFileInfo
|
||||
{
|
||||
private readonly Assembly _assembly;
|
||||
private readonly DateTime _lastModified;
|
||||
private readonly string _resourcePath;
|
||||
private readonly string _fileName;
|
||||
|
||||
private long? _length;
|
||||
|
||||
public EmbeddedResourceFileInfo(Assembly assembly, string resourcePath, string fileName, DateTime lastModified)
|
||||
{
|
||||
_assembly = assembly;
|
||||
_lastModified = lastModified;
|
||||
_resourcePath = resourcePath;
|
||||
_fileName = fileName;
|
||||
}
|
||||
|
||||
public long Length
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_length.HasValue)
|
||||
{
|
||||
using (Stream stream = _assembly.GetManifestResourceStream(_resourcePath))
|
||||
{
|
||||
_length = stream.Length;
|
||||
}
|
||||
}
|
||||
return _length.Value;
|
||||
}
|
||||
}
|
||||
|
||||
// Not directly accessible.
|
||||
public string PhysicalPath
|
||||
{
|
||||
get { return null; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return _fileName; }
|
||||
}
|
||||
|
||||
public DateTime LastModified
|
||||
{
|
||||
get { return _lastModified; }
|
||||
}
|
||||
|
||||
public bool IsDirectory
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public Stream CreateReadStream()
|
||||
{
|
||||
Stream stream = _assembly.GetManifestResourceStream(_resourcePath);
|
||||
if (!_length.HasValue)
|
||||
{
|
||||
_length = stream.Length;
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,43 +0,0 @@
|
||||
#if NETFRAMEWORK
|
||||
|
||||
using Microsoft.Owin;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Web.Management;
|
||||
|
||||
namespace SilkierQuartz.Owin
|
||||
{
|
||||
internal class SeekableRequestMiddleware : OwinMiddleware
|
||||
{
|
||||
public SeekableRequestMiddleware(OwinMiddleware next) : base(next)
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task Invoke(IOwinContext context)
|
||||
{
|
||||
// read out body (wait for all bytes)
|
||||
using (var streamCopy = new MemoryStream())
|
||||
{
|
||||
try
|
||||
{
|
||||
context.Request.Body.CopyTo(streamCopy);
|
||||
}
|
||||
catch (HttpException ex) when (ex?.WebEventCode == WebEventCodes.RuntimeErrorPostTooLarge)
|
||||
{
|
||||
context.Response.Body = null;
|
||||
context.Response.StatusCode = (int)HttpStatusCode.RequestEntityTooLarge;
|
||||
return;
|
||||
}
|
||||
|
||||
streamCopy.Position = 0; // rewind
|
||||
context.Request.Body = streamCopy; // put back in place for downstream handlers
|
||||
|
||||
await Next.Invoke(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -27,7 +27,7 @@
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<PackageId>SilkierQuartz</PackageId>
|
||||
<PackageIcon>logo.png</PackageIcon>
|
||||
<IsPackable>true</IsPackable>
|
||||
<IsPackable>true</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
@@ -43,13 +43,11 @@
|
||||
<PackageReference Include="JsonSubTypes" Version="1.8.0" />
|
||||
<PackageReference Include="Quartz" Version="3.2.4" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net5'">
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.3" />
|
||||
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="5.0.3" />
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net5'">
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="5.0.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
|
||||
@@ -61,8 +59,8 @@
|
||||
<ItemGroup>
|
||||
<None Include="..\..\LICENSE" Pack="true" PackagePath="" />
|
||||
<None Include="Content\Images\logo.png">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath></PackagePath>
|
||||
<Pack>True</Pack>
|
||||
<PackagePath></PackagePath>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
@@ -76,5 +74,4 @@
|
||||
<EmbeddedResource Include="TypeHandlers\*.hbs" />
|
||||
<EmbeddedResource Include="TypeHandlers\*.js" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user