diff --git a/.circleci/config.yml b/.circleci/config.yml index 2fbe8ec..df4d031 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,7 @@ version: 2 jobs: build: docker: - - image: mcr.microsoft.com/dotnet/core/sdk:3.1 + - image: mcr.microsoft.com/dotnet/sdk:5.0 steps: - checkout - run: diff --git a/Directory.build.props b/Directory.build.props index 513947f..f17a139 100644 --- a/Directory.build.props +++ b/Directory.build.props @@ -1,5 +1,6 @@ true + preview \ No newline at end of file diff --git a/WopiHost.Abstractions/WopiHost.Abstractions.csproj b/WopiHost.Abstractions/WopiHost.Abstractions.csproj index d72814f..aa4a054 100644 --- a/WopiHost.Abstractions/WopiHost.Abstractions.csproj +++ b/WopiHost.Abstractions/WopiHost.Abstractions.csproj @@ -3,7 +3,7 @@ WopiHost.Abstractions Class Library Petr Svihlik - netstandard2.1 + net5.0 WopiHost.Abstractions WopiHost.Abstractions https://github.com/petrsvihlik/WopiHost/blob/master/LICENSE.txt @@ -29,13 +29,13 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/WopiHost.Cobalt/CobaltSession.cs b/WopiHost.Cobalt/CobaltSession.cs index 3b23fcc..a6e371b 100644 --- a/WopiHost.Cobalt/CobaltSession.cs +++ b/WopiHost.Cobalt/CobaltSession.cs @@ -50,12 +50,10 @@ private CobaltFile GetCobaltFile(IWopiFile file, ClaimsPrincipal principal) if (file.Exists) { - using (var stream = file.GetReadStream()) - { - var srcAtom = new AtomFromStream(stream); - tempCobaltFile.GetCobaltFilePartition(FilePartitionId.Content).SetStream(RootId.Default.Value, srcAtom, out var o1); - tempCobaltFile.GetCobaltFilePartition(FilePartitionId.Content).GetStream(RootId.Default.Value).Flush(); - } + using var stream = file.GetReadStream(); + var srcAtom = new AtomFromStream(stream); + tempCobaltFile.GetCobaltFilePartition(FilePartitionId.Content).SetStream(RootId.Default.Value, srcAtom, out var o1); + tempCobaltFile.GetCobaltFilePartition(FilePartitionId.Content).GetStream(RootId.Default.Value).Flush(); } return tempCobaltFile; } @@ -65,11 +63,9 @@ private CobaltFile GetCobaltFile(IWopiFile file, ClaimsPrincipal principal) public Stream GetFileStream(IWopiFile file, ClaimsPrincipal principal) { //TODO: use in filescontroller - using (var ms = new MemoryStream()) - { - new GenericFda(GetCobaltFile(file, principal).CobaltEndpoint).GetContentStream().CopyTo(ms); - return ms; - } + using var ms = new MemoryStream(); + new GenericFda(GetCobaltFile(file, principal).CobaltEndpoint).GetContentStream().CopyTo(ms); + return ms; } @@ -86,10 +82,8 @@ public Action ProcessCobalt(IWopiFile file, ClaimsPrincipal principal, b if (requestBatch.Requests.Any(request => request is PutChangesRequest && request.PartitionId == FilePartitionId.Content)) { - using (var stream = file.GetWriteStream()) - { - new GenericFda(cobaltFile.CobaltEndpoint).GetContentStream().CopyTo(stream); - } + using var stream = file.GetWriteStream(); + new GenericFda(cobaltFile.CobaltEndpoint).GetContentStream().CopyTo(stream); } var response = requestBatch.SerializeOutputToProtocol(protocolVersion); Action copyToAction = s => { response.CopyTo(s); }; diff --git a/WopiHost.Cobalt/WopiHost.Cobalt.csproj b/WopiHost.Cobalt/WopiHost.Cobalt.csproj index 15a732f..38e0872 100644 --- a/WopiHost.Cobalt/WopiHost.Cobalt.csproj +++ b/WopiHost.Cobalt/WopiHost.Cobalt.csproj @@ -3,7 +3,7 @@ WopiHost.Cobalt Class Library Petr Svihlik - netstandard2.1 + net5.0 WopiHost.Cobalt WopiHost.Cobalt https://github.com/petrsvihlik/WopiHost/blob/master/LICENSE.txt @@ -31,7 +31,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/WopiHost.Core/Controllers/FilesController.cs b/WopiHost.Core/Controllers/FilesController.cs index af0646e..bef14bb 100644 --- a/WopiHost.Core/Controllers/FilesController.cs +++ b/WopiHost.Core/Controllers/FilesController.cs @@ -26,13 +26,13 @@ public class FilesController : WopiControllerBase private HostCapabilities HostCapabilities => new HostCapabilities { - SupportsCobalt = CobaltProcessor is { }, + SupportsCobalt = CobaltProcessor is not null, SupportsGetLock = true, SupportsLocks = true, SupportsExtendedLockLength = true, SupportsFolders = true,//? SupportsCoauth = true,//? - SupportsUpdate = nameof(PutFile) is { } //&& PutRelativeFile - usercannotwriterelative + SupportsUpdate = nameof(PutFile) is not null //&& PutRelativeFile - usercannotwriterelative }; /// @@ -87,7 +87,7 @@ public async Task GetFile(string id) // Check expected size var maximumExpectedSize = HttpContext.Request.Headers[WopiHeaders.MAX_EXPECTED_SIZE].ToString().ToNullableInt(); - if (maximumExpectedSize is { } && file.GetCheckFileInfo(User, HostCapabilities).Size > maximumExpectedSize.Value) + if (maximumExpectedSize is not null && file.GetCheckFileInfo(User, HostCapabilities).Size > maximumExpectedSize.Value) { return new PreconditionFailedResult(); } @@ -161,7 +161,7 @@ public async Task ProcessCobalt(string id) // TODO: remove workaround https://github.com/aspnet/Announcements/issues/342 (use FileBufferingWriteStream) var syncIoFeature = HttpContext.Features.Get(); - if (syncIoFeature is { }) + if (syncIoFeature is not null) { syncIoFeature.AllowSynchronousIO = true; } diff --git a/WopiHost.Core/FileExtensions.cs b/WopiHost.Core/FileExtensions.cs index 182ce70..123ac4a 100644 --- a/WopiHost.Core/FileExtensions.cs +++ b/WopiHost.Core/FileExtensions.cs @@ -24,7 +24,7 @@ public static CheckFileInfo GetCheckFileInfo(this IWopiFile file, ClaimsPrincipa } var checkFileInfo = new CheckFileInfo(); - if (principal is { }) + if (principal is not null) { checkFileInfo.UserId = principal.FindFirst(ClaimTypes.NameIdentifier)?.Value.ToSafeIdentity(); checkFileInfo.UserFriendlyName = principal.FindFirst(ClaimTypes.Name)?.Value; diff --git a/WopiHost.Core/HttpHeaderAttribute.cs b/WopiHost.Core/HttpHeaderAttribute.cs index e7c80d8..148c240 100644 --- a/WopiHost.Core/HttpHeaderAttribute.cs +++ b/WopiHost.Core/HttpHeaderAttribute.cs @@ -4,22 +4,34 @@ namespace WopiHost.Core { + /// + /// A header-based constraint for HTTP actions. + /// + [AttributeUsage(AttributeTargets.Method)] public class HttpHeaderAttribute : Attribute, IActionConstraint { - public string Header { get; set; } - public string[] Values { get; set; } + private string Header { get; set; } + private string[] Values { get; set; } + + /// + /// Creates an instance of a constraint based on a header name and allowed values. + /// + /// Header name to check. + /// Accepted header values. public HttpHeaderAttribute(string header, params string[] values) { Header = header; Values = values; } + /// public bool Accept(ActionConstraintContext context) { - return (context is null) && (context.RouteContext.HttpContext.Request.Headers.TryGetValue(Header, out var value) && Values.Contains(value[0])); + return (context is not null) && context.RouteContext.HttpContext.Request.Headers.TryGetValue(Header, out var value) && Values.Contains(value[0]); } + /// public int Order => 0; } } diff --git a/WopiHost.Core/Results/FileResult.cs b/WopiHost.Core/Results/FileResult.cs index 8890d3e..582e789 100644 --- a/WopiHost.Core/Results/FileResult.cs +++ b/WopiHost.Core/Results/FileResult.cs @@ -40,14 +40,14 @@ public override async Task ExecuteResultAsync(ActionContext context) var response = context.HttpContext.Response; response.ContentType = ContentType; var targetStream = response.Body; - if (CopyStream is { }) + if (CopyStream is not null) { await Task.Factory.StartNew(() => { CopyStream(targetStream); }); } - else if (Content is { }) + else if (Content is not null) { await targetStream.WriteAsync(Content, 0, Content.Length); } diff --git a/WopiHost.Core/WopiHost.Core.csproj b/WopiHost.Core/WopiHost.Core.csproj index 9a074cc..c82317d 100644 --- a/WopiHost.Core/WopiHost.Core.csproj +++ b/WopiHost.Core/WopiHost.Core.csproj @@ -3,7 +3,7 @@ WopiHost.Core Class Library Petr Svihlik - netcoreapp3.1 + net5.0 WopiHost.Core WopiHost.Core https://github.com/petrsvihlik/WopiHost/blob/master/LICENSE.txt @@ -34,12 +34,12 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/WopiHost.Core/WopiOverrideHeaderAttribute.cs b/WopiHost.Core/WopiOverrideHeaderAttribute.cs index 2282501..77ca125 100644 --- a/WopiHost.Core/WopiOverrideHeaderAttribute.cs +++ b/WopiHost.Core/WopiOverrideHeaderAttribute.cs @@ -1,7 +1,17 @@ -namespace WopiHost.Core +using System; + +namespace WopiHost.Core { + /// + /// An action constraint based on the X-WOPI-Override header. + /// + [AttributeUsage(AttributeTargets.Method)] public class WopiOverrideHeaderAttribute : HttpHeaderAttribute { + /// + /// Creates an instance of the header-based constraint based on allowed values. + /// + /// Accepted header values. public WopiOverrideHeaderAttribute(string[] values) : base(WopiHeaders.WOPI_OVERRIDE, values) { } diff --git a/WopiHost.Discovery.Tests/WopiDiscovererTests.cs b/WopiHost.Discovery.Tests/WopiDiscovererTests.cs index 9d0b26d..f1bddc7 100644 --- a/WopiHost.Discovery.Tests/WopiDiscovererTests.cs +++ b/WopiHost.Discovery.Tests/WopiDiscovererTests.cs @@ -176,7 +176,7 @@ public async void FavIconTests(string extension, string expectedValue, string fi var result = await _wopiDiscoverer.GetApplicationFavIconAsync(extension); // Assert - Assert.Equal(expectedValue != null ? new Uri(expectedValue) : null, result); + Assert.Equal(expectedValue is not null ? new Uri(expectedValue) : null, result); } [Theory] diff --git a/WopiHost.Discovery.Tests/WopiHost.Discovery.Tests.csproj b/WopiHost.Discovery.Tests/WopiHost.Discovery.Tests.csproj index 7c4773d..70ce798 100644 --- a/WopiHost.Discovery.Tests/WopiHost.Discovery.Tests.csproj +++ b/WopiHost.Discovery.Tests/WopiHost.Discovery.Tests.csproj @@ -2,7 +2,7 @@ Petr Svihlik - netcoreapp3.1 + net5.0 WopiHost.Discovery.Tests WopiHost.Discovery.Tests true @@ -25,16 +25,16 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers - + all runtime; build; native; contentfiles; analyzers diff --git a/WopiHost.Discovery/WopiDiscoverer.cs b/WopiHost.Discovery/WopiDiscoverer.cs index 007c417..064737b 100644 --- a/WopiHost.Discovery/WopiDiscoverer.cs +++ b/WopiHost.Discovery/WopiDiscoverer.cs @@ -37,7 +37,7 @@ public WopiDiscoverer(IDiscoveryFileProvider discoveryFileProvider, NetZoneEnum private async Task> GetAppsAsync() { - if (_apps == null) + if (_apps is null) { _apps = (await DiscoveryFileProvider.GetDiscoveryXmlAsync()) .Elements(ElementNetZone) @@ -65,7 +65,7 @@ public async Task SupportsExtensionAsync(string extension) { var query = (await GetAppsAsync()).Elements() .FirstOrDefault(e => (string)e.Attribute(AttrActionExtension) == extension); - return query is { }; + return query is not null; } /// @@ -73,7 +73,7 @@ public async Task SupportsActionAsync(string extension, WopiActionEnum act { var actionString = action.ToString().ToLowerInvariant(); - var query = (await GetAppsAsync()).Elements().Where(e => (string)e.Attribute(AttrActionExtension) == extension && (string)e.Attribute(AttrActionName).Value.ToLowerInvariant() == actionString); + var query = (await GetAppsAsync()).Elements().Where(e => (string)e.Attribute(AttrActionExtension) == extension && e.Attribute(AttrActionName).Value.ToLowerInvariant() == actionString); return query.Any(); } @@ -83,7 +83,7 @@ public async Task> GetActionRequirementsAsync(string extensi { var actionString = action.ToString().ToLowerInvariant(); - var query = (await GetAppsAsync()).Elements().Where(e => (string)e.Attribute(AttrActionExtension) == extension && (string)e.Attribute(AttrActionName).Value.ToLowerInvariant() == actionString).Select(e => e.Attribute(AttrActionRequires).Value.Split(',')); + var query = (await GetAppsAsync()).Elements().Where(e => (string)e.Attribute(AttrActionExtension) == extension && e.Attribute(AttrActionName).Value.ToLowerInvariant() == actionString).Select(e => e.Attribute(AttrActionRequires).Value.Split(',')); return query.FirstOrDefault(); } @@ -92,7 +92,7 @@ public async Task> GetActionRequirementsAsync(string extensi public async Task RequiresCobaltAsync(string extension, WopiActionEnum action) { var requirements = await GetActionRequirementsAsync(extension, action); - return requirements is { } && requirements.Contains(AttrValCobalt); + return requirements is not null && requirements.Contains(AttrValCobalt); } /// @@ -116,7 +116,7 @@ public async Task GetApplicationFavIconAsync(string extension) { var query = (await GetAppsAsync()).Where(e => e.Descendants(ElementAction).Any(d => (string)d.Attribute(AttrActionExtension) == extension)).Select(e => e.Attribute(AttrAppFavicon).Value); var result = query.FirstOrDefault(); - return result != null ? new Uri(result) : null; + return result is not null ? new Uri(result) : null; } } } diff --git a/WopiHost.Discovery/WopiHost.Discovery.csproj b/WopiHost.Discovery/WopiHost.Discovery.csproj index 22f20a6..5d881e2 100644 --- a/WopiHost.Discovery/WopiHost.Discovery.csproj +++ b/WopiHost.Discovery/WopiHost.Discovery.csproj @@ -3,7 +3,7 @@ WopiHost.Discovery Class Library Petr Svihlik - netstandard2.1 + net5.0 WopiHost.Discovery WopiHost.Discovery https://github.com/petrsvihlik/WopiHost/blob/master/LICENSE.txt @@ -29,7 +29,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/WopiHost.FileSystemProvider.Tests/WopiHost.FileSystemProvider.Tests.csproj b/WopiHost.FileSystemProvider.Tests/WopiHost.FileSystemProvider.Tests.csproj index 3e068ce..5f0cd18 100644 --- a/WopiHost.FileSystemProvider.Tests/WopiHost.FileSystemProvider.Tests.csproj +++ b/WopiHost.FileSystemProvider.Tests/WopiHost.FileSystemProvider.Tests.csproj @@ -2,7 +2,7 @@ Petr Svihlik - netcoreapp3.1 + net5.0 WopiHost.FileSystemProvider.Tests WopiHost.FileSystemProvider.Tests true @@ -19,16 +19,16 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers - + all runtime; build; native; contentfiles; analyzers diff --git a/WopiHost.FileSystemProvider/WopiHost.FileSystemProvider.csproj b/WopiHost.FileSystemProvider/WopiHost.FileSystemProvider.csproj index 2445ac8..cbbb6a4 100644 --- a/WopiHost.FileSystemProvider/WopiHost.FileSystemProvider.csproj +++ b/WopiHost.FileSystemProvider/WopiHost.FileSystemProvider.csproj @@ -3,7 +3,7 @@ WopiHost.FileSystemProvider Class Library Petr Svihlik - netstandard2.1 + net5.0 WopiHost.FileSystemProvider WopiHost.FileSystemProvider https://github.com/petrsvihlik/WopiHost/blob/master/LICENSE.txt @@ -25,7 +25,7 @@ - + @@ -34,19 +34,19 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + - - + + diff --git a/WopiHost.Url.Tests/WopiHost.Url.Tests.csproj b/WopiHost.Url.Tests/WopiHost.Url.Tests.csproj index 1762a7f..7a089da 100644 --- a/WopiHost.Url.Tests/WopiHost.Url.Tests.csproj +++ b/WopiHost.Url.Tests/WopiHost.Url.Tests.csproj @@ -2,7 +2,7 @@ Petr Svihlik - netcoreapp3.1 + net5.0 WopiHost.Url.Tests WopiHost.Url.Tests true @@ -19,20 +19,20 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers - + all runtime; build; native; contentfiles; analyzers - + diff --git a/WopiHost.Url/WopiHost.Url.csproj b/WopiHost.Url/WopiHost.Url.csproj index 59aad9b..591ad73 100644 --- a/WopiHost.Url/WopiHost.Url.csproj +++ b/WopiHost.Url/WopiHost.Url.csproj @@ -3,7 +3,7 @@ WopiHost.Url Class Library Petr Svihlik - netstandard2.1 + net5.0 WopiHost.Url WopiHost.Url https://github.com/petrsvihlik/WopiHost/blob/master/LICENSE.txt @@ -33,7 +33,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/WopiHost.Url/WopiUrlSettings.cs b/WopiHost.Url/WopiUrlSettings.cs index 588edb9..184795c 100644 --- a/WopiHost.Url/WopiUrlSettings.cs +++ b/WopiHost.Url/WopiUrlSettings.cs @@ -128,7 +128,7 @@ public WopiUrlSettings() public WopiUrlSettings(IDictionary settings) { - if (settings is { }) + if (settings is not null) { foreach (var pair in settings) { diff --git a/WopiHost.Web/WopiHost.Web.csproj b/WopiHost.Web/WopiHost.Web.csproj index 4a6b215..5e84dbf 100644 --- a/WopiHost.Web/WopiHost.Web.csproj +++ b/WopiHost.Web/WopiHost.Web.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1 + net5.0 true true WopiHost.Web @@ -13,7 +13,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/WopiHost/WopiHost.csproj b/WopiHost/WopiHost.csproj index 9f813b5..c0e2bb5 100644 --- a/WopiHost/WopiHost.csproj +++ b/WopiHost/WopiHost.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1 + net5.0 WopiHost Exe true @@ -22,29 +22,23 @@ - - - - - - - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - + + + + + + + + + + diff --git a/appveyor.yml b/appveyor.yml index f48ce23..9cc8416 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -image: Visual Studio 2019 +image: Visual Studio 2019 Preview configuration: Debug