diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/Ref.Standard.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/Ref.Standard.cs index 2363bc54d9..9573708f28 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/Ref.Standard.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/Ref.Standard.cs @@ -135,13 +135,37 @@ public sealed partial class HttpFileCollection : System.Collections.Specialized. internal HttpFileCollection() { } public string[] AllKeys { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public override int Count { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public System.Web.HttpPostedFile this[int index] { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public System.Web.HttpPostedFile this[string name] { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } [System.ObsoleteAttribute("Retrieving Keys is not supported on .NET 6+. Please use the enumerator instead.")] public override System.Collections.Specialized.NameObjectCollectionBase.KeysCollection Keys { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public System.Web.HttpPostedFile Get(int index) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} public System.Web.HttpPostedFile Get(string name) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} public override System.Collections.IEnumerator GetEnumerator() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} public System.Collections.Generic.IList GetMultiple(string name) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public abstract partial class HttpFileCollectionBase : System.Collections.Specialized.NameObjectCollectionBase + { + protected HttpFileCollectionBase() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public virtual string[] AllKeys { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public virtual System.Web.HttpPostedFileBase this[int index] { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public virtual System.Web.HttpPostedFileBase this[string name] { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public virtual System.Web.HttpPostedFileBase Get(int index) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public virtual System.Web.HttpPostedFileBase Get(string name) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public virtual System.Collections.Generic.IList GetMultiple(string name) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + } + public partial class HttpFileCollectionWrapper : System.Web.HttpFileCollectionBase + { + public HttpFileCollectionWrapper(System.Web.HttpFileCollection httpFileCollection) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public override string[] AllKeys { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public override int Count { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public override System.Web.HttpPostedFileBase this[int index] { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public override System.Web.HttpPostedFileBase this[string name] { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public override System.Web.HttpPostedFileBase Get(int index) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public override System.Web.HttpPostedFileBase Get(string name) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public override System.Collections.IEnumerator GetEnumerator() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public override System.Collections.Generic.IList GetMultiple(string name) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + } public sealed partial class HttpPostedFile { internal HttpPostedFile() { } @@ -150,6 +174,22 @@ internal HttpPostedFile() { } public string FileName { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public System.IO.Stream InputStream { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } } + public abstract partial class HttpPostedFileBase + { + protected HttpPostedFileBase() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public virtual int ContentLength { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public virtual string ContentType { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public virtual string FileName { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public virtual System.IO.Stream InputStream { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + } + public partial class HttpPostedFileWrapper : System.Web.HttpPostedFileBase + { + public HttpPostedFileWrapper(System.Web.HttpPostedFile httpPostedFile) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public override int ContentLength { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public override string ContentType { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public override string FileName { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public override System.IO.Stream InputStream { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + } public partial class HttpRequest { internal HttpRequest() { } @@ -202,6 +242,7 @@ public abstract partial class HttpRequestBase public virtual int ContentLength { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public virtual string ContentType { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} set { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public virtual System.Web.HttpCookieCollection Cookies { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public virtual System.Web.HttpFileCollectionBase Files { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public virtual System.Collections.Specialized.NameValueCollection Headers { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public virtual string HttpMethod { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public virtual System.IO.Stream InputStream { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } @@ -239,6 +280,7 @@ public partial class HttpRequestWrapper : System.Web.HttpRequestBase public override int ContentLength { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public override string ContentType { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} set { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public override System.Web.HttpCookieCollection Cookies { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public override System.Web.HttpFileCollectionBase Files { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public override System.Collections.Specialized.NameValueCollection Headers { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public override string HttpMethod { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public override System.IO.Stream InputStream { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/TypeForwards.Framework.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/TypeForwards.Framework.cs index 92d6700e46..9a1d24c6b6 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/TypeForwards.Framework.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/TypeForwards.Framework.cs @@ -26,7 +26,11 @@ [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpCookieCollection))] [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpException))] [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpFileCollection))] +[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpFileCollectionBase))] +[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpFileCollectionWrapper))] [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpPostedFile))] +[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpPostedFileBase))] +[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpPostedFileWrapper))] [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpRequest))] [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpRequestBase))] [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpRequestWrapper))] diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollection.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollection.cs index eda8a35484..63be3118d7 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollection.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollection.cs @@ -43,10 +43,14 @@ public override IEnumerator GetEnumerator() public HttpPostedFile? Get(string name) => FormFiles.GetFile(name) is { } file ? new(file) : null; + public HttpPostedFile? Get(int index) => FormFiles[index] is { } file ? new(file) : null; + public IList GetMultiple(string name) => FormFiles.GetFiles(name) is { Count: > 0 } files ? new ReadOnlyPostedFileCollection(files) : Array.Empty(); public HttpPostedFile? this[string name] => Get(name); + public HttpPostedFile? this[int index] => Get(index); + private string[] GetKeys() { if (FormFiles.Count == 0) @@ -86,7 +90,7 @@ public HttpPostedFile this[int index] set => throw new NotSupportedException(Message); } - private static HttpPostedFile Create(IFormFile file) => new(file); + private static HttpPostedFile Create(IFormFile file) => new HttpPostedFile(file); public int Count => _other.Count; diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionBase.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionBase.cs new file mode 100644 index 0000000000..278b6257ba --- /dev/null +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionBase.cs @@ -0,0 +1,26 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections.Generic; +using System.Collections.Specialized; + +namespace System.Web; + +[Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1010:Generic interface should also be implemented", Justification = Constants.ApiFromAspNet)] +[Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1065:Do not raise exceptions in unexpected locations", Justification = Constants.ApiFromAspNet)] +[Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1716:Identifiers should not match keywords", Justification = Constants.ApiFromAspNet)] +public abstract class HttpFileCollectionBase : NameObjectCollectionBase +{ + [Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1819:Properties should not return arrays", Justification = Constants.ApiFromAspNet)] + public virtual string[] AllKeys => throw new NotImplementedException(); + + public virtual HttpPostedFileBase? this[string name] => throw new NotImplementedException(); + + public virtual HttpPostedFileBase? this[int index] => throw new NotImplementedException(); + + public virtual HttpPostedFileBase? Get(int index) => throw new NotImplementedException(); + + public virtual HttpPostedFileBase? Get(string name) => throw new NotImplementedException(); + + public virtual IList GetMultiple(string name) => throw new NotImplementedException(); +} diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionWrapper.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionWrapper.cs new file mode 100644 index 0000000000..aba6ff30b6 --- /dev/null +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionWrapper.cs @@ -0,0 +1,43 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections; +using System.Collections.Generic; +using System.Linq; + +namespace System.Web; + +[Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1010:Generic interface should also be implemented", Justification = Constants.ApiFromAspNet)] +public class HttpFileCollectionWrapper : HttpFileCollectionBase +{ + private readonly HttpFileCollection _collection; + + public HttpFileCollectionWrapper(HttpFileCollection httpFileCollection) + { + ArgumentNullException.ThrowIfNull(httpFileCollection); + + _collection = httpFileCollection; + } + + public override string[] AllKeys => _collection.AllKeys; + + public override int Count => _collection.Count; + + public override HttpPostedFileBase? this[string name] => Get(name); + + public override HttpPostedFileBase? this[int index] => Get(index); + + public override HttpPostedFileBase? Get(string name) => + _collection[name] is { } file ? new HttpPostedFileWrapper(file) : null; + + public override HttpPostedFileBase? Get(int index) => + _collection[index] is { } file ? new HttpPostedFileWrapper(file) : null; + + public override IList GetMultiple(string name) + => _collection.GetMultiple(name) + .Select(x => (HttpPostedFileBase)new HttpPostedFileWrapper(x)) + .ToList() + .AsReadOnly(); + + public override IEnumerator GetEnumerator() => _collection.GetEnumerator(); +} diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpPostedFileBase.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpPostedFileBase.cs new file mode 100644 index 0000000000..71e7c74251 --- /dev/null +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpPostedFileBase.cs @@ -0,0 +1,18 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.IO; + +namespace System.Web; + +[Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1065:Do not raise exceptions in unexpected locations", Justification = Constants.ApiFromAspNet)] +public abstract class HttpPostedFileBase +{ + public virtual string FileName => throw new NotImplementedException(); + + public virtual string ContentType => throw new NotImplementedException(); + + public virtual int ContentLength => throw new NotImplementedException(); + + public virtual Stream InputStream => throw new NotImplementedException(); +} diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpPostedFileWrapper.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpPostedFileWrapper.cs new file mode 100644 index 0000000000..787e8a5dcd --- /dev/null +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpPostedFileWrapper.cs @@ -0,0 +1,26 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.IO; + +namespace System.Web; + +public class HttpPostedFileWrapper : HttpPostedFileBase +{ + private readonly HttpPostedFile _file; + + public HttpPostedFileWrapper(HttpPostedFile httpPostedFile) + { + ArgumentNullException.ThrowIfNull(httpPostedFile); + + _file = httpPostedFile; + } + + public override int ContentLength => _file.ContentLength; + + public override string ContentType => _file.ContentType; + + public override string FileName => _file.FileName; + + public override Stream InputStream => _file.InputStream; +} diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestBase.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestBase.cs index f6a6ab71bd..4380693a5b 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestBase.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestBase.cs @@ -38,6 +38,8 @@ public abstract class HttpRequestBase public virtual HttpCookieCollection Cookies => throw new NotImplementedException(); + public virtual HttpFileCollectionBase Files => throw new NotImplementedException(); + public virtual string? this[string key] => throw new NotImplementedException(); public virtual NameValueCollection Params => throw new NotImplementedException(); diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestWrapper.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestWrapper.cs index 1f0f9208ea..f0b7906fb4 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestWrapper.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestWrapper.cs @@ -37,6 +37,8 @@ public override string? ContentType public override NameValueCollection Headers => _request.Headers; + public override HttpFileCollectionBase Files => new HttpFileCollectionWrapper(_request.Files); + public override string HttpMethod => _request.HttpMethod; public override Stream InputStream => _request.InputStream;